Steps by Steps , to Configure Karate for API testing :
2. Add Karate dependency :
So complete Pom.xml file is looks like this :
3. Create Feature file and Runner.class (in same package ) :
3.1 Create Runner.class :
3.2 Create Feature File :
3.3 How to execute the Test :
--->> Just Right click on Runner.class file and run as junit test
Reference : https://github.com/intuit/karate
- Create Maven project
- Add Karate dependency in pom.xml file
- Create Feature file and Runner.class (in same package )
2. Add Karate dependency :
<dependency> <groupId>com.intuit.karate</groupId> <artifactId>karate-apache</artifactId> <version>0.9.4</version> <scope>test</scope> </dependency> <dependency> <groupId>com.intuit.karate</groupId> <artifactId>karate-junit4</artifactId> <version>0.9.4</version> <scope>test</scope> </dependency>
So complete Pom.xml file is looks like this :
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cant</groupId>
<artifactId>Karate.api-testing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Karate.api-testing</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<version>0.9.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>0.9.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
</build>
</project>
3. Create Feature file and Runner.class (in same package ) :
3.1 Create Runner.class :
package com..Karate.FeatureFile; import org.junit.runner.RunWith; import com.intuit.karate.KarateOptions; import com.intuit.karate.junit4.Karate; @RunWith(Karate.class) @KarateOptions(features = "classpath:com/cop/Karate/FeatureFile/test.feature") public class testRunner { }
3.2 Create Feature File :
Feature: demorest api testing
Scenario: testing a valida get endpoint
Given url 'https://some-api.com/api/users'
When method GET
Then status 200
And assert response.length ==2
And match response[0].name = 'FirstUser'
3.3 How to execute the Test :
--->> Just Right click on Runner.class file and run as junit test
Reference : https://github.com/intuit/karate