TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Karate

Testing POST Request with Karate Framework

Overview

In this tutorial, we will test POST Rest API Endpoint with Karate Framework. We will use the Mantis Bug Tracker Restful API. We will create an issue with Post Rest API call to the local Bug tracker instance using Automation.

Mantis Rest API Guide.

https://www.testingdocs.com/mantisbt-rest-api-guide/

Steps to create Karate Automation Project with Maven Build Tool

https://www.testingdocs.com/create-karate-automation-project/

POST API Request

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 201 Response code.

The POST method can be specified using the Karate DSL with BDD Gherkin syntax. The syntax would be similar to Cucumber tool.  The step definitions are already defined by the tool. We just 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:

https://www.testingdocs.com/karate-automation-tool-tutorials/

More information on the tool:

https://github.com/intuit/karate

Related Posts

Karate /

Parallel Test Execution using Karate DSL

Karate /

Test GET API Request with Karate DSL

Karate /

Create Karate API Test Script( Feature File )

Karate /

CRUD Operations API Test Automation with Karate

Karate /

Data Driven Testing using Karate Automation Tool

‹ Run Karate Test with JUnit5› Getting Started with Karate DSL

Recent Posts

  • Scaler Academy – An Online Learning Platform
  • Difference between PHP and JavaScript?
  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com