Karate Framework : Dedicated for API Testing

Here you can find how to use KARATE framework in API Testing, in simple way. Here I have used maven framework:

1. Create a Maven Framework : and respective directories - files & folders;


 2. Add dependencies into POM.XML: get it from Maven Repository
 
1.  karate-core

2. karate-apache

3. karate-junit4 

 

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>KarateTesting</groupId>
<artifactId>KarateTesting</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.intuit.karate/karate-core -->
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-core</artifactId>
<version>1.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.intuit.karate/karate-apache -->
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<version>0.9.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>


3. Create .feature FILE:
Here I have created named myFeature.feature (u can name any thing)
Here I have shown four example with GET & POST method similary it can used for other API operation methods such as PUT , DELETE, etc.
Feature: check api response first testing
Background:
* url 'https://reqres.in'
* header Content-Type = 'application/json'

Scenario: Testing api
Given path '/api/users'
When param per_page = '20'
When method GET
Then status 200'

Scenario: Testing param only 2
Given path '/api/users'
When param '2'
When method GET
Then status 200'

Scenario: Testing post
Given path '/api/register'
And request {"email" : "sydney@fife","password" : "pistol"}
When method POST
#Then status 200'

Scenario: Testing post second
Given path '/api/users'
And request {"name": "{{name}}","job": "{{job}}"}
When method POST
Then status 201'

4. Create Runner file .JAVA : here I have used MyTestRunner.java ( u can name anything) , just defined class and annotated as shown in snapshot RunWith - Karate.class, which can import from Karate and Junit.

package com.testing.karate;

import org.junit.runner.RunWith;

import com.intuit.karate.junit4.Karate;

@RunWith(Karate.class)
public class MyTestRunner {

}

5. Check the HTML report inside the Target directory of Maven Framework , once test script run u can find the report in html format inside target folder.


Comments

Popular posts from this blog

The self healing automation framework - Healenium Updated Dec2023

Heleanium - Web without using Docker