Search This Blog

About Me

Chennai, TamilNadu, India
I am a craftsperson by passion and quality assurer by profession. I love to build - a craft or a piece of code. I look for reusability in crafts and usability in APPs. I always find something new to create and something new to learn. I believe in liberal world, flexible schedules and boundaryless place . https://automationautomated.blogspot.com/p/am-into-software-test-automation-and-r.html

Wednesday, April 12, 2017

API Automated Testing + KARATE 2

API Automated Testing + KARATE  2


We have have seen basic setup and a simple sample in previous post simple-api-automated-testing-BDD-Karate . Wondering wheres the Step definitions? Thats the beauty, you don't have to write step definition in Karate. All are inbuilt but you have to remember few keywords while writing the Feature file.

Now lets try some complex stuff with multiple examples. 

REST API test design with Karate and Cucumber : Example 2
Create a package country under src/test/java 
Inside the country package create a file  getStates.feature  and getStatesTest.java

We are going to try the API for different countries. [IND and USA]

Restful REST web-service to get and search States and territories of a Country 

http://services.groupkt.com/state/get/{countryCode}/all
getStates.feature
#Sample Karate Feature Definition Template
@karatesample

Feature: Sample Karate API Automation

Scenario Outline: Get states for different countries

Given url 'http://services.groupkt.com/state/get/<country>/all'
When method get
Then status 200

Examples:
    | country |
    | IND |
    | USA |

getStatesTest.java
Use the same as in previous post

Reports:
Refresh the karasmaple project and in taget>cucumber>index.html view the cucumber -BDD report.
index.html
#Sample Karate Feature Definition Template
@karatesample Feature: Sample Karate API Automation

Scenario Outline: Get states for different countries

  • Given url 'http://services.groupkt.com/state/get/<country>/all'
  • When method get
  • Then status 200
Examples:

country
IND
USA
@karatesample Scenario Outline: Get states for different countries

  • Given url 'http://services.groupkt.com/state/get/IND/all'
  • When method get
  • Then status 200
@karatesample Scenario Outline: Get states for different countries

  • Given url 'http://services.groupkt.com/state/get/USA/all'
  • When method get
  • Then status 200

No comments:

Post a Comment

AutomationAutomated Blog