Testing POST Request [ Karate Framework – 2024 ]
Testing POST Request with Karate Framework
In this tutorial, we will test the POST Rest API Endpoint with the Karate Framework. We will use the Mantis Bug Tracker Restful API. We will create an issue with a Post Rest API call to the local Bug Tracker instance using Automation.
Mantis Rest API Guide.
Steps to create Karate Automation Project with Maven Build Tool
POST API Request
The HTTP Post method is used to create server-side resources, create side effects, or specify relations between the resources. A successful API call would get a 201 Response code.
The POST method using the Karate DSL with BDD Gherkin syntax can be specified. The syntax would be similar to the Cucumber tool. The tool already defines the step definitions. We need to add the Gherkin as shown below:
HTTP POST method step can be specified as:
When method POST
API Header step can be specified as:
And header Authorization = ‘<API_Token>’
Request body step can be specified as:
And request <request body>
The complete Gherkin feature for the POST call is displayed below:
Sample Feature with Karate DSL
#Sample Feature Definition Template Feature: Post Mantis Issue I want create an issue using POST Mantis API call @Mantis Scenario: Create MantisBT Issue Given url 'http://localhost/mantis/api/rest/issues/' And header Authorization = 'DoZSsCCiTFEx8jIm67F4mM7RWh_NLEVd' And request { "summary": "This issue created using Karate Tool-JUnit5 Demo", "description": "[TestingDocs.com]Issue Description sample test bug API", "category": { "name": "General" }, "project": { "name": "TestingDocsProject" } } When method POST Then status 201
Additionally verification steps can be added to verify the POST request API Response. Run the feature and check the Mantis bug tracker web instance in the browser. An issue would be created in the project specified in the API request.
—
Karate Automation Tutorials
Karate tool tutorials on this website can be found at:
More information on the tool: