Karate is the only open-source tool to combine API test-automation, mocks and performance-testing
into a single, unified framework.
The BDD syntax popularized by Cucumber is language-neutral,and easy for even non-programmers. Besides powerful JSON & XML assertions, you can run tests in parallel for speed - which is critical for HTTP API testing. A new capability in Karate is to be able to start an HTTP server and script
Features of Karate Framework:
- compilation not required
- parallel execution
- data driven testing
- enviroment switching
- match full payload in one step( complex assertions/ deep equals
- update JSON payload/ object
- HTTP Mocks/Test-Doubles
Linux command to run Karate test:
...mvn test -DargLine="-Dkarate.env=e2e"
run from command prompt
ls
run mock.feature
java -jar karate-netty-o.7.0-all.jar -m mock.feature
java -jar karate-netty-o.7.0-all.jar -m mock.feature -p 8080
..............
ls
java -jar karate-netty-o.7.0-all.jar -t cats.feature
java -jar karate-netty-o.7.0-all.jar -u
*****************************************************************************
Karate Framework
*****************************************************************************
into a single, unified framework.
The BDD syntax popularized by Cucumber is language-neutral,and easy for even non-programmers. Besides powerful JSON & XML assertions, you can run tests in parallel for speed - which is critical for HTTP API testing. A new capability in Karate is to be able to start an HTTP server and script
responses to an incoming HTTP request. It inheritates the BDD framework.
Tools for API testing: Postman, SOAP-UI, JMeter, karate
Features of Karate Framework:
- compilation not required
- parallel execution
- data driven testing
- enviroment switching
- match full payload in one step( complex assertions/ deep equals
- update JSON payload/ object
- HTTP Mocks/Test-Doubles
Linux command to run Karate test:
...mvn test -DargLine="-Dkarate.env=e2e"
run from command prompt
ls
run mock.feature
java -jar karate-netty-o.7.0-all.jar -m mock.feature
java -jar karate-netty-o.7.0-all.jar -m mock.feature -p 8080
..............
ls
java -jar karate-netty-o.7.0-all.jar -t cats.feature
java -jar karate-netty-o.7.0-all.jar -u
Examples:
It needs one Karate Runner java file and scenario on features files, which is written in Gerkin language
package demo;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import com.intuit.karate.junit4.Karate;
import cucumber.api.CucumberOptions;
@RunWith(Karate.class)
//this runs only userFeatureScenarioOutline.feature
@CucumberOptions(
// features = {"classpath:demo/usersFeature.feature"}
features = {"classpath:demo/userFeatureScenarioOutline.feature"}
, plugin = {"pretty", "json:target/reports/json/userFeatureScenarioOutline.json"}
)
public class KarateRunner {
@BeforeClass
public static void setupTestEnvironment() {
if(!System.getProperties().containsKey("karate.url")) {
System.setProperty("karate.url","https://reqres.in/api/");
}
}
}
Features files: it is for 2 scenario:
Feature: Test User feature demonstating Scenario Outline
#https://reqres.in/api/users?page=2
Scenario Outline: Testing a GET endpoint with id parameter
Given url 'https://reqres.in/api/users'
And path page = <param>
When method get
Then status 200
And match $ contains {<value>}
Examples:
| param | value |
| 1 | "data":"#notnull"|
| 2 | "data":"#notnull"|
Feature: Test User feature
Scenario: Testing a GET endpoint with id parameter
Given url baseUrl
And path 'users/23'
When method get
Then status 404
And match $ contains {"data": "#notnull"}
Results:
POM.xml file
<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.cerotid.qa</groupId>
<artifactId>demoKarate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.version>3.6.0</maven.compiler.version>
</properties>
<dependencies>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>4.11.2</version>
</dependency>
<!-- 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>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgument>-Werror</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
</project>
*****************************************************************************
Karate Framework
*****************************************************************************
No comments:
Post a Comment