Bonjour TestCommunity !!!
According to worldwide Google Trends of the IT sector, the demand for well-trained API (Backend) testing professionals has increased substantially.
This trend has encouraged me to create a blog series in this area.
Before starting with API Automation using Karate DSL, let us understand the key aspects of API and its related functionalities.
What is an API ?
API is an acronym which stands for Application Programming Interface.
It is an interface that defines interactions between multiple softwares. In simple terms, API is a communication language which defines how a software should interact with other software.
This communication system can be categorized into two types, namely Simple Object Access Protocol or SOAP, and Representational State Transfer or REST (to understand more about REST and SOAP, refer this link).
API testing has become an integral aspect for a QA professional to ensure that our application is responding as per defined expectations in terms of the functionality, performance, security, and reliability.
Which are the most commonly used HTTP Methods ?
- For retrieving data, the HTTP GET method is used. It is a read-only call and it is not possible to alter data. If it is a successful request, without any errors, then a code status of 200(OK) is obtained along with the requested data in the specific format, which is typically JSON or XML.
- If this is an error-free call, the status code is returned as either 201 or 200 which means successful response.
- POST methods are liable for data alteration which means this method should be triggered carefully.
- The HTTP PUT method is more like a command for an update, used to alter any resource’s value whose original value was something other.
- PUT methods can also be used, but only if the request is from the client and not the server.
- The HTTP DELETE method is used to delete a resource.
- The server state can be modified by DELETE requests.
- Operations on DELETE are idempotent. If you DELETE a resource, it’s deleted from the resource collection. Calling the DELETE API repeatedly on that resource will not alter the result, but calling DELETE on a resource a second time will return a 404 (NOT FOUND) because it has already been discarded.
HTTP Response codes
The HTTP response codes are divided broadly in five categories :
• 1xx — Informational codes
• 2xx — Success codes
• 3xx — Redirect codes
• 4xx — Client error codes
• 5xx — Server error codes
For detailed explanation on above response code categories, Please refer this link.
Famous Automation tools
- Katalon Studio
- Soap UI
- Karate DSL
You might wonder, “Why should I use Karate DSL ?”
With 4.4K GitHub stars and 1.1K GitHub forks, Karate DSL is progressively becoming popular amongst the QA community.
It is an Open Source Web-Services Test Automation Solution that integrates in a unified framework API test-automation, performance-testing, mocks and even UI automation.
It is built on top of Cucumber-JVM which helps us create test scenarios for API-based BDD (Behaviour Driven Development) tests.
However, unlike the BDD framework, Karate DSL has omitted step-definition file writing attempts for the corresponding feature file, i.e. we can run the feature file consisting of all test cases without defining the step-definition.
With the help of the TestRunner class, Karate has incorporated parallel test execution with the intent of reducing test execution time. Hence, making it a really quick tool for API testing.
For non-programmers, it would be easier to understand and write the test cases, as it is based on the popular Cucumber (Gherkin) standard with syntax colouring options.
Multiple IDEs including IntelliJ, Eclipse and Visual Studio Code are supported.
Complex response payload matching and assertions (with the help of “match contains”, “match each”, “match == ” etc.) is much easier and more practical to use.
For complex nested payloads, “deep contains” is convenient when you are sure you want to look for any values in the different data trees.
Also, the Github repository describes a structured documentation along with examples.
With the increased enthusiasm for this tool, the Stack Overflow community is highly active and responsive.
Like any standard Java project, It can run tests and generate a report in various formats such as JUnit-HTML report,Cucumber report etc.
Looking at these wide range of features offered by Karate DSL, Aren’t you curious to explore more about this amazing tool? In my forthcoming blogs, I shall be dealing with every feature in detail.
If you find this blog informative, please share your views in the comments section below and hit the Follow button for regular updates. You can connect with me on LinkedIn or write to me at email@example.com.
Till then stay safe and keep learning !!!