-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cd5c746
Showing
14 changed files
with
329 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<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.mycompany</groupId> | ||
<artifactId>webinar</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
<maven.compiler.version>3.8.1</maven.compiler.version> | ||
<maven.surefire.version>2.22.2</maven.surefire.version> | ||
<karate.version>1.3.1</karate.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.intuit.karate</groupId> | ||
<artifactId>karate-junit5</artifactId> | ||
<version>${karate.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>net.masterthought</groupId> | ||
<artifactId>cucumber-reporting</artifactId> | ||
<version>5.0.0</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> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${maven.surefire.version}</version> | ||
<configuration> | ||
<argLine>-Dfile.encoding=UTF-8</argLine> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Kloia Karate Webinar 2023 Karate API Functional Testing Automation Project | ||
|
||
|
||
# Tool stack | ||
|
||
* **Karate Framework** - Development Framework | ||
* **Gatling Framework** - Performance Test Framework | ||
* **Java/Javascript/Scala** - Development Language (For situations where it is necessary) | ||
* **IntelliJ IDE** - Development IDE | ||
* **Maven** - Package Management | ||
|
||
# Quick Setup ( for mac and windows ) | ||
|
||
* cd /Users/gsahin/Desktop/WEBINAR | ||
* mvn archetype:generate -DarchetypeGroupId=com.intuit.karate -DarchetypeArtifactId=karate-archetype -DarchetypeVersion=1.3.1 -DgroupId=com.mycompany -DartifactId=webinar | ||
|
||
# Running Tests | ||
|
||
1. It can be run based on scenario or feature by pressing the green RUN button on the IDE. | ||
|
||
|
||
2. Scenarios determined on the JUnit runner can be run again by pressing the green RUN button. | ||
|
||
|
||
3. `Running it via CLI by giving 'Runner class' and 'tagname'. | ||
|
||
`mvn clean test -Dtest=RunnerName "-Dkarate.options=--tags @tagName"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import com.intuit.karate.Results; | ||
import com.intuit.karate.Runner; | ||
import net.masterthought.cucumber.Configuration; | ||
import net.masterthought.cucumber.ReportBuilder; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import static java.lang.Integer.parseInt; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class CucumberRunner { | ||
|
||
@Test | ||
void testAll() { | ||
// mvn clean test -Dtest="CucumberRunner#testAll" -DbuildNumber=4445 | ||
// run command line: mvn test -Dtest="CucumberRunner#testAll" | ||
// mvn clean test -Dtest="CucumberRunner#testAll" -Dkarate.options="--tags @regression" | ||
List<String> tagList = Arrays.asList("~@excluded", "~@wip"); | ||
Results results = Runner.path("classpath:features").tags(tagList).outputCucumberJson(true).parallel(0); | ||
generateReport(results.getReportDir()); | ||
} | ||
|
||
@Test | ||
void testSmoke() { | ||
//run command line: mvn test -Dtest="CucumberRunner#testSmoke" | ||
List<String> tagList = Arrays.asList("@smoke", "~@excluded", "~@wip"); | ||
Results results = Runner.path("classpath:features").tags(tagList).outputCucumberJson(true).parallel(0); | ||
generateReport(results.getReportDir()); | ||
} | ||
|
||
@Test | ||
void testParallel() { | ||
// run command line: mvn clean test -Dtest="CucumberRunner#testParallel" "-Dkarate.options=--tags @smoke" -Dcount=10 | ||
String threadCount = System.getProperty("count"); | ||
List<String> tagList = Arrays.asList("~@excluded", "~@wip"); | ||
int count = (threadCount == null) ? 5 : parseInt(threadCount); | ||
Results results = Runner.path("classpath:features").tags(tagList).outputCucumberJson(true).parallel(count); | ||
generateReport(results.getReportDir()); | ||
assertEquals(0, results.getFailCount(), results.getErrorMessages()); | ||
} | ||
|
||
public static void generateReport(String karateOutputPath) { | ||
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[]{"json"}, true); | ||
List<String> jsonPaths = new ArrayList(jsonFiles.size()); | ||
jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath())); | ||
Configuration config = new Configuration(new File("target"), "karateWebinar"); | ||
//config.setBuildNumber("4444"); | ||
config.setBuildNumber(System.getProperty("buildNumber")); | ||
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config); | ||
reportBuilder.generateReports(); | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
webinar/src/test/java/caller/createBooking/createBookingCaller.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Feature: Create booking Caller | ||
|
||
Background: | ||
Given url baseUrl | ||
And path 'booking' | ||
And header Accept = 'application/json' | ||
* def dataGenerator = Java.type('helpers.DataGenerator') | ||
* def randomName = dataGenerator.generateRandomString(5) | ||
* print "randomName:", randomName | ||
|
||
@create_booking_caller | ||
Scenario: Create Booking | ||
* def requestBody = read('classpath:model/createUpdateBooking.json') | ||
And request requestBody | ||
When method post | ||
Then status 200 |
19 changes: 19 additions & 0 deletions
19
webinar/src/test/java/caller/createReqRes/createReqResCaller.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Feature: Create Req Res Caller | ||
|
||
Background: | ||
Given url reqResBaseUrl | ||
And path 'api/users' | ||
* def dataGenerator = Java.type('helpers.DataGenerator') | ||
* def randomName = dataGenerator.generateRandomString(5) | ||
* def jsRandomName = call read('classpath:helpers/randomDataGenerator.js') | ||
* def name = karate.get('__arg.name',jsRandomName) | ||
* print "name:", name | ||
|
||
@create_req_res_caller | ||
Scenario: Crete Req Res | ||
* def requestBody = read('classpath:model/createRegRes.json') | ||
* requestBody.name = name | ||
And request requestBody | ||
When method post | ||
Then status 201 | ||
|
12 changes: 12 additions & 0 deletions
12
webinar/src/test/java/caller/generateToken/createTokenCaller.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: Create Token Caller | ||
|
||
Background: | ||
Given url baseUrl | ||
And path 'auth' | ||
|
||
@create_token_caller | ||
Scenario: Create Token | ||
* def requestBody = {"username" : "admin","password" : "password123"} | ||
And request requestBody | ||
When method post | ||
Then status 200 |
18 changes: 18 additions & 0 deletions
18
webinar/src/test/java/features/getReqRes/getReqRes.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Feature: Get Req res Feature | ||
|
||
Background: | ||
* def nameFeature = 'kloia' | ||
* def createReqRes = call read('classpath:caller/createReqRes/createReqResCaller.feature@create_req_res_caller') | ||
* def id = createReqRes.response.id | ||
Given url reqResBaseUrl | ||
|
||
@get_req_res | ||
Scenario Outline: Get req res | ||
And path '/api/users', <id> | ||
When method get | ||
Then status 200 | ||
* print response | ||
Examples: | ||
| id | | ||
| 2 | | ||
| 3 | |
17 changes: 17 additions & 0 deletions
17
webinar/src/test/java/features/updateReqRes/updateReqRes.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Feature: | ||
|
||
Background: | ||
* def createReqRes = call read('classpath:caller/createReqRes/createReqResCaller.feature@create_req_res_caller') | ||
* def id = createReqRes.response.id | ||
Given url reqResBaseUrl | ||
And path '/api/users', 2 | ||
|
||
@update_req_res | ||
Scenario: | ||
#* def requestBody = createReqRes.requestBody | ||
* def requestBody = read('classpath:model/createRegRes.json') | ||
* requestBody.job = 'Engineer' | ||
And request requestBody | ||
When method put | ||
Then status 200 | ||
* print response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package helpers; | ||
|
||
import java.util.Random; | ||
|
||
public class DataGenerator { | ||
|
||
public static String generateRandomString(int range) { | ||
String CHAR_LIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; | ||
StringBuilder randStr = new StringBuilder(); | ||
for (int i = 0; i < range; i++) { | ||
int number = new Random().nextInt(CHAR_LIST.length()); | ||
char ch = CHAR_LIST.charAt(number); | ||
randStr.append(ch); | ||
} | ||
return randStr.toString(); | ||
} | ||
|
||
public static String generateRandomInteger(int range) { | ||
String CHAR_LIST = "1234567890"; | ||
StringBuilder randStr = new StringBuilder(); | ||
for (int i = 0; i < range; i++) { | ||
int number = new Random().nextInt(CHAR_LIST.length()); | ||
char ch = CHAR_LIST.charAt(number); | ||
randStr.append(ch); | ||
} | ||
return randStr.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function generateRandomName() { | ||
const names = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank", "Grace", "Henry", "Isabella", "James", "Kate", "Liam", "Mia", "Nora", "Oliver", "Penelope", "Quentin", "Riley", "Samantha", "Thomas", "Ursula", "Victoria", "William", "Xander", "Yara", "Zachary"]; | ||
const randomIndex = Math.floor(Math.random() * names.length); | ||
return names[randomIndex]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function fn() { | ||
var env = karate.env; // get system property 'karate.env' | ||
karate.log('karate.env system property was:', env); | ||
if (!env) { | ||
env = 'dev'; | ||
} | ||
var config = { | ||
env: env, | ||
myVarName: 'someValue', | ||
baseUrl: 'https://restful-booker.herokuapp.com/', | ||
reqResBaseUrl:'https://reqres.in/' | ||
}; | ||
|
||
var generalTokenResult = karate.callSingle('classpath:caller/generateToken/createTokenCaller.feature@create_token_caller',config); | ||
config.generalToken = generalTokenResult.response.token; | ||
karate.configure('headers',{'Content-Type':'application/json'}); | ||
|
||
karate.configure('connectTimeout', 50000); | ||
karate.configure('readTimeout', 50000); | ||
return config; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>target/karate.log</file> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="com.intuit" level="INFO"/> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
<appender-ref ref="FILE" /> | ||
</root> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "morpheus", | ||
"job": "leader" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"firstname": "Jim", | ||
"lastname": "Brown", | ||
"totalprice": 111, | ||
"depositpaid": true, | ||
"bookingdates": { | ||
"checkin": "2018-01-01", | ||
"checkout": "2019-01-01" | ||
}, | ||
"additionalneeds": "Breakfast" | ||
} |