Commit f8eb9b78 authored by Training Purpose's avatar Training Purpose

Karate Frame Work 1st Commit

parents
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>Karate</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.version>4.8.1</cucumber.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.intuit.karate/karate-core -->
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-core</artifactId>
<version>1.3.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>
<!-- https://mvnrepository.com/artifact/com.intuit.karate/karate-junit4 -->
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>1.3.1</version>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.cucumber</groupId>-->
<!-- <artifactId>cucumber-core</artifactId>-->
<!-- <version>${cucumber.version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.cucumber</groupId>-->
<!-- <artifactId>cucumber-junit</artifactId>-->
<!-- <version>${cucumber.version}</version>-->
<!-- </dependency>-->
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
</build>
</project>
\ No newline at end of file
Feature: First Sample API Test
Background:
* url baseURL
* header Accept = 'application/json'
* def req_payload = read('request.json')
Scenario: First Get Call
Given path '/users?page=2'
When method GET
Then status 200
Scenario: Demo Get call 1
Given path '/users'
When param page = 2
When method GET
Then status 200
And print response
And print responseHeaders
And print responseStatus
And print responseTime
Scenario: Demo Get Call 2
Given path '/users'
When param page = 2
When method GET
Then status 200
And print response
Then assert response.data[0].first_name == 'Michael'
Then match response.data[0].first_name == 'Michaelq'
Scenario: Demo Post Call 1
Given path '/users'
And request {"name": "nazoor","job": "leader"}
When method POST
Then status 201
Then print response
And match response == { "name": "nazoor","job": "leader","id": "#string","createdAt": "#ignore"}
Scenario: Demo Post Call 2
Given path '/users'
And request req_payload
When method POST
Then status 201
Then print response
And def exp_payload = karate.properties['user.dir']+'/src/test/resources/ExpectedOutput.json'
And print 'paht = '+exp_payload
And def exp = read('file:'+exp_payload)
And print exp
And match response == exp
Scenario: Demo Put Call 1
Given path '/users/2'
And request req_payload
When method PUT
And print response
Then status 200
Scenario: Demo Patch Call 2
Given path '/users/2'
And request req_payload
When method PATCH
And print response
Then status 200
Scenario: Demo Delete Call 1
Given path '/users/2'
When method DELETE
And print response
Then status 204
Scenario: Demo Karate Config file
Given print name
When print baseURL
{
"name": "nazoor",
"job": "leader"
}
\ No newline at end of file
import com.intuit.karate.junit4.Karate;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
@RunWith(Karate.class)
public class TestRunner {
@BeforeClass
public static void before() {
System.setProperty("karate.env","QA1");
}
}
\ No newline at end of file
function fn(){
var config = {
name : "Nazoor",
baseURL : "https://reqres.in/api"
};
karate.log('The Value of name is : ', config.name);
karate.log('The Value of baseURL is : ', config.baseURL);
var env = karate.env;
karate.log('The Value of env is : ', env);
karate.configure('connectTimeout', 5000);
karate.configure('readTimeout', 5000);
if(env=='QA1')
{
config.baseURL = 'https://reqres.in/api/';
}
else if(env == 'QA2'){
config.baseURL = 'https://reqres.in/api/';
}
karate.log('Base URL = ',config.baseURL)
return config;
}
\ No newline at end of file
{
"name": "nazoor",
"job": "leader",
"id": "#string",
"createdAt": "#ignore"
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment