SlideShare a Scribd company logo
Karate - powerful and simple framework
for REST API automation testing
SlideShare: http://b.link/karate
Roman Liubun’ | 22 Feb 2019
Experience
15 years overall exp. at automation
5+ years as automation expert
25+ projects in 9 companies
Now
Automation expert |
Trainer |
Roman Liubun’
Lviv | Ukraine
About me
Description
R&D project
Modern technologies
Small team of “seniors”
Frequent changes
No requirements
Main automation challenges
BDD tests as requirements
Testing alongside with development
Project
BDD scripts layer
Test logic layer
Business logic layer
Core (CRUD) layer
Typical API
automation
framework
Agenda?
Karate | Cucumber | REST-assured
Re-usable tests
Using JS, Java interop
Assertions, schema validation
DDT
Parallel execution & reporting
Live coding...
Summary
Karate
Author: Peter Thomas
Current version: 0.9.1
Initial release: ~2 years ago
Popularity: 1600+ stars on GitHub
Url: https://github.com/intuit/karate
Written on Java
Less code == less bugs
Scenario: create, retrieve a pet
Given pet endpoint is up
And request where name is ‘Wolf’
When we send post request
Then status is 200
And returned JSON with id, name
Scenario: create, retrieve a pet
Given url ‘http://mysite.io/v2/pet’
And request { name: ‘Wolf’ }
When method post
Then status 200
And match response ==
{ id:‘#number’, name:‘Wolf’ }
+ steps
+ business logic
+ pojos
CucumberKarate
and … that’s all :)
Simpler code == less bugs
public void createPetTest() {
given()
.contentType(ContentType.JSON)
.body("{"name": "Wolf"}")
.when()
.post("http://mysite.io/v2/pet")
.then().statusCode(200)
.body("id",
Matchers.instanceOf(Integer.class))
.body("name", equalTo("Wolf"));
}
Scenario: create, retrieve a pet
Given url ‘http://mysite.io/v2/pet’
And request { name: ‘Wolf’ }
When method post
Then status 200
And match response ==
{ id:‘#number’, name:‘Wolf’ }
REST-assuredKarate
If you need complexity
Scenario: update the pet
* def id = 5;
* def petJson = call read(‘genUserJson.js’) id
Given url ‘http://mysite.io/v2/pet’
And request petJson
When method put
Then status 200
And match response == { id:‘#(id)’, name:‘#(petJson.name)’ }
genUserJson.js
function(id) {
var result = {};
Result.id = id;
result.name = 'MyPet' + id;
return result;
}
DRY
Scenario: update pre-defined pet
* def createdPet = call read(‘createPet.feature’)
Given url ‘http://mysite.io/v2/pet’
And request { id:‘#(createdPet.response.id)’, name:‘newPetsName’ }
When method put
Then status 200
What about Java?
# Calling Java method from API test
* def uniqueId = Java.type(’utils.NumberUtils’).getUniqueId();
* def uniqueName = ‘TestUser’ + uniqueId
And request { name: ‘#(uniqueName)’ }
# Calling API test from Java method
public PetPojo createPet() {
Map<String, Object> pet;
pet = Runner.runFeature(getClass(), "get-pet.feature", null, true);
ObjectMapper mapper = new ObjectMapper();
return mapper.convertValue(pet, PetPojo.class);
}
Assertion capabilities
Scenario: create and retrieve a cat with ID
Given url ‘http://petstore.mysite.io/v2/pet’
And request { name:’KORAT’, id:’a9f7a56b-8d5c-455c-9d13-808461d17b91’ }
When method post
Then status 200
And match response == { name:’#regex [A-Z]{5}’, id:’#uuid’ }
Schema validation
* def subNode = { price:‘#string’, name:‘#regex[0-9X]’ }
* def isValidTime = read(‘time-validator.js’)
When method get
Then match response ==
"""
{
id: ‘#regex[0-9]+’,
odd: ‘#(subNode)’,
data: {
countryId: ‘#ignore’,
countryName: ‘#string’,
status: ‘#number? _ >= 0’,
time: ‘#? isValidTime(_)’
}
}
"""
Markers
#ignore
#null
#notnull
#present
#notpresent
#number
#uuid
#array
#object
#string
##string
#? EXPR
#[NUM] EXPR
#regex STR
DDT
@regression
Scenario Outline: create <name> cat with age = <age>
Given url ‘http://mysite.io/v2/pet’
And request { name: ‘<name>’, age: ‘<age>’ }
When method post
Then status 200
And match response == { id:’#number’, name:’<name>’, age:‘<age>’ }
# the single cell in the table can be any valid karate expression:
# csv, js, js function, json, variable, XPath or JsonPath.
Examples:
| read(‘kittens.csv’) |
kittens.csv
name,age
Bob,1
Wild,5
Nyan,3
Parallel execution
@KarateOptions ( tags = { "@regression", "~@ignore" } )
public class RegressionTests {
@Test
public void regressionTests() {
Results results = Runner.parallel(getClass(), 5, "target/reports");
assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
}
}
Reporting
Other cool features
JsonPath, XPath expressions
Reused for perf. testing (Gatling)
Embedded UI for step-by-step debug
Websocket support, async capability
GraphQL API testing capability
Built-in environment switcher
Integration with CI pipelines
API mock or test-doubles
Allure reporting support
Postman import (exp.)
… and many others
And...
Takeaways
PROS
Single layer tests
JSON, XML native support
Integration with Java, JS
Powerful assertion capabilities
Parallel execution
Great docs, demos, reporting
No programming skills are required
Many other features out of the box
CONS
Must learn a new DSL language
No “find usage”, auto renaming
No syntax error highlighting
Q&A Contacts
romlub
romlub
www.linkedin.com/in/romlub
SlideShare: http://b.link/karate

More Related Content

What's hot

How to earn a black belt in Graphql testing
How to earn a black belt in Graphql testingHow to earn a black belt in Graphql testing
How to earn a black belt in Graphql testing
Luca Pelosi
 
Testing RESTful web services with REST Assured
Testing RESTful web services with REST AssuredTesting RESTful web services with REST Assured
Testing RESTful web services with REST Assured
Bas Dijkstra
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
Micha Kops
 
Criando uma arquitetura para seus testes de API com RestAssured
Criando uma arquitetura para seus testes de API com RestAssuredCriando uma arquitetura para seus testes de API com RestAssured
Criando uma arquitetura para seus testes de API com RestAssured
Elias Nogueira
 
BDD for APIs
BDD for APIsBDD for APIs
BDD for APIs
Jason Harmon
 
Rest assured
Rest assuredRest assured
Rest assured
Varun Deshpande
 
Rest API Automation with REST Assured
Rest API Automation with REST AssuredRest API Automation with REST Assured
Rest API Automation with REST Assured
TO THE NEW Pvt. Ltd.
 
Postman.ppt
Postman.pptPostman.ppt
Postman.ppt
ParrotBAD
 
Postman & API Testing by Amber Race
Postman & API Testing by Amber RacePostman & API Testing by Amber Race
Postman & API Testing by Amber Race
Postman
 
API Testing
API TestingAPI Testing
API Testing
Bikash Sharma
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with Jest
Maayan Glikser
 
API Automation Testing Using RestAssured+Cucumber
API Automation Testing Using RestAssured+CucumberAPI Automation Testing Using RestAssured+Cucumber
API Automation Testing Using RestAssured+Cucumber
Knoldus Inc.
 
Test your microservices with REST-Assured
Test your microservices with REST-AssuredTest your microservices with REST-Assured
Test your microservices with REST-Assured
Michel Schudel
 
API Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj RollisonAPI Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj Rollison
TEST Huddle
 
Test Design and Automation for REST API
Test Design and Automation for REST APITest Design and Automation for REST API
Test Design and Automation for REST API
Ivan Katunou
 
Automated Test Framework with Cucumber
Automated Test Framework with CucumberAutomated Test Framework with Cucumber
Automated Test Framework with Cucumber
Ramesh Krishnan Ganesan
 
BDD with Cucumber
BDD with CucumberBDD with Cucumber
BDD with Cucumber
Knoldus Inc.
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
John Blum
 
Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?
BugRaptors
 
B4USolution_API-Testing
B4USolution_API-TestingB4USolution_API-Testing
B4USolution_API-Testing
b4usolution .
 

What's hot (20)

How to earn a black belt in Graphql testing
How to earn a black belt in Graphql testingHow to earn a black belt in Graphql testing
How to earn a black belt in Graphql testing
 
Testing RESTful web services with REST Assured
Testing RESTful web services with REST AssuredTesting RESTful web services with REST Assured
Testing RESTful web services with REST Assured
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
 
Criando uma arquitetura para seus testes de API com RestAssured
Criando uma arquitetura para seus testes de API com RestAssuredCriando uma arquitetura para seus testes de API com RestAssured
Criando uma arquitetura para seus testes de API com RestAssured
 
BDD for APIs
BDD for APIsBDD for APIs
BDD for APIs
 
Rest assured
Rest assuredRest assured
Rest assured
 
Rest API Automation with REST Assured
Rest API Automation with REST AssuredRest API Automation with REST Assured
Rest API Automation with REST Assured
 
Postman.ppt
Postman.pptPostman.ppt
Postman.ppt
 
Postman & API Testing by Amber Race
Postman & API Testing by Amber RacePostman & API Testing by Amber Race
Postman & API Testing by Amber Race
 
API Testing
API TestingAPI Testing
API Testing
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with Jest
 
API Automation Testing Using RestAssured+Cucumber
API Automation Testing Using RestAssured+CucumberAPI Automation Testing Using RestAssured+Cucumber
API Automation Testing Using RestAssured+Cucumber
 
Test your microservices with REST-Assured
Test your microservices with REST-AssuredTest your microservices with REST-Assured
Test your microservices with REST-Assured
 
API Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj RollisonAPI Testing: The heart of functional testing" with Bj Rollison
API Testing: The heart of functional testing" with Bj Rollison
 
Test Design and Automation for REST API
Test Design and Automation for REST APITest Design and Automation for REST API
Test Design and Automation for REST API
 
Automated Test Framework with Cucumber
Automated Test Framework with CucumberAutomated Test Framework with Cucumber
Automated Test Framework with Cucumber
 
BDD with Cucumber
BDD with CucumberBDD with Cucumber
BDD with Cucumber
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?
 
B4USolution_API-Testing
B4USolution_API-TestingB4USolution_API-Testing
B4USolution_API-Testing
 

Similar to Karate - powerful and simple framework for REST API automation testing

TDC São Paulo 2019 - Trilha DevTest - Karatê DSL - Automatizando testes de AP...
TDC São Paulo 2019 - Trilha DevTest - Karatê DSL - Automatizando testes de AP...TDC São Paulo 2019 - Trilha DevTest - Karatê DSL - Automatizando testes de AP...
TDC São Paulo 2019 - Trilha DevTest - Karatê DSL - Automatizando testes de AP...
Samuel Lucas
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Roman Kirillov
 
Mp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook gameMp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook gameMontreal Python
 
Evolution of the REST API
Evolution of the REST APIEvolution of the REST API
Evolution of the REST API
JeremyOtt5
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock Framework
Eugene Dvorkin
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
Dmitriy Sobko
 
Webauthn Tutorial
Webauthn TutorialWebauthn Tutorial
Webauthn Tutorial
FIDO Alliance
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
Rapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirageRapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirage
Krzysztof Bialek
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi Applications
Effie Arditi
 
Full Stack Unit Testing
Full Stack Unit TestingFull Stack Unit Testing
Full Stack Unit Testing
GlobalLogic Ukraine
 
Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance test
Bryan Liu
 
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
Javier Abadía
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
vvaswani
 
2012: ql.io and Node.js
2012: ql.io and Node.js2012: ql.io and Node.js
2012: ql.io and Node.js
Jonathan LeBlanc
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
Mek Srunyu Stittri
 
Serverless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applicationsServerless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applications
Loiane Groner
 
Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0
Claire Townend Gee
 
Testing swagger contracts without contract based testing
Testing swagger contracts without contract based testingTesting swagger contracts without contract based testing
Testing swagger contracts without contract based testing
Алексей Стягайло
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleRaimonds Simanovskis
 

Similar to Karate - powerful and simple framework for REST API automation testing (20)

TDC São Paulo 2019 - Trilha DevTest - Karatê DSL - Automatizando testes de AP...
TDC São Paulo 2019 - Trilha DevTest - Karatê DSL - Automatizando testes de AP...TDC São Paulo 2019 - Trilha DevTest - Karatê DSL - Automatizando testes de AP...
TDC São Paulo 2019 - Trilha DevTest - Karatê DSL - Automatizando testes de AP...
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
 
Mp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook gameMp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook game
 
Evolution of the REST API
Evolution of the REST APIEvolution of the REST API
Evolution of the REST API
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock Framework
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
 
Webauthn Tutorial
Webauthn TutorialWebauthn Tutorial
Webauthn Tutorial
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Rapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirageRapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirage
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi Applications
 
Full Stack Unit Testing
Full Stack Unit TestingFull Stack Unit Testing
Full Stack Unit Testing
 
Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance test
 
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
2012: ql.io and Node.js
2012: ql.io and Node.js2012: ql.io and Node.js
2012: ql.io and Node.js
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
 
Serverless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applicationsServerless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applications
 
Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0
 
Testing swagger contracts without contract based testing
Testing swagger contracts without contract based testingTesting swagger contracts without contract based testing
Testing swagger contracts without contract based testing
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 

Recently uploaded

Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Sebastiano Panichella
 
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Matjaž Lipuš
 
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
Howard Spence
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
OWASP Beja
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
Access Innovations, Inc.
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
khadija278284
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Sebastiano Panichella
 
Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
IP ServerOne
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
Vladimir Samoylov
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
Sebastiano Panichella
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
OECD Directorate for Financial and Enterprise Affairs
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
Faculty of Medicine And Health Sciences
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Orkestra
 

Recently uploaded (13)

Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
 
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
 
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
 
Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
 

Karate - powerful and simple framework for REST API automation testing

  • 1. Karate - powerful and simple framework for REST API automation testing SlideShare: http://b.link/karate Roman Liubun’ | 22 Feb 2019
  • 2. Experience 15 years overall exp. at automation 5+ years as automation expert 25+ projects in 9 companies Now Automation expert | Trainer | Roman Liubun’ Lviv | Ukraine About me
  • 3. Description R&D project Modern technologies Small team of “seniors” Frequent changes No requirements Main automation challenges BDD tests as requirements Testing alongside with development Project
  • 4. BDD scripts layer Test logic layer Business logic layer Core (CRUD) layer Typical API automation framework
  • 5. Agenda? Karate | Cucumber | REST-assured Re-usable tests Using JS, Java interop Assertions, schema validation DDT Parallel execution & reporting Live coding... Summary
  • 6. Karate Author: Peter Thomas Current version: 0.9.1 Initial release: ~2 years ago Popularity: 1600+ stars on GitHub Url: https://github.com/intuit/karate Written on Java
  • 7. Less code == less bugs Scenario: create, retrieve a pet Given pet endpoint is up And request where name is ‘Wolf’ When we send post request Then status is 200 And returned JSON with id, name Scenario: create, retrieve a pet Given url ‘http://mysite.io/v2/pet’ And request { name: ‘Wolf’ } When method post Then status 200 And match response == { id:‘#number’, name:‘Wolf’ } + steps + business logic + pojos CucumberKarate and … that’s all :)
  • 8. Simpler code == less bugs public void createPetTest() { given() .contentType(ContentType.JSON) .body("{"name": "Wolf"}") .when() .post("http://mysite.io/v2/pet") .then().statusCode(200) .body("id", Matchers.instanceOf(Integer.class)) .body("name", equalTo("Wolf")); } Scenario: create, retrieve a pet Given url ‘http://mysite.io/v2/pet’ And request { name: ‘Wolf’ } When method post Then status 200 And match response == { id:‘#number’, name:‘Wolf’ } REST-assuredKarate
  • 9. If you need complexity Scenario: update the pet * def id = 5; * def petJson = call read(‘genUserJson.js’) id Given url ‘http://mysite.io/v2/pet’ And request petJson When method put Then status 200 And match response == { id:‘#(id)’, name:‘#(petJson.name)’ } genUserJson.js function(id) { var result = {}; Result.id = id; result.name = 'MyPet' + id; return result; }
  • 10. DRY Scenario: update pre-defined pet * def createdPet = call read(‘createPet.feature’) Given url ‘http://mysite.io/v2/pet’ And request { id:‘#(createdPet.response.id)’, name:‘newPetsName’ } When method put Then status 200
  • 11. What about Java? # Calling Java method from API test * def uniqueId = Java.type(’utils.NumberUtils’).getUniqueId(); * def uniqueName = ‘TestUser’ + uniqueId And request { name: ‘#(uniqueName)’ } # Calling API test from Java method public PetPojo createPet() { Map<String, Object> pet; pet = Runner.runFeature(getClass(), "get-pet.feature", null, true); ObjectMapper mapper = new ObjectMapper(); return mapper.convertValue(pet, PetPojo.class); }
  • 12. Assertion capabilities Scenario: create and retrieve a cat with ID Given url ‘http://petstore.mysite.io/v2/pet’ And request { name:’KORAT’, id:’a9f7a56b-8d5c-455c-9d13-808461d17b91’ } When method post Then status 200 And match response == { name:’#regex [A-Z]{5}’, id:’#uuid’ }
  • 13. Schema validation * def subNode = { price:‘#string’, name:‘#regex[0-9X]’ } * def isValidTime = read(‘time-validator.js’) When method get Then match response == """ { id: ‘#regex[0-9]+’, odd: ‘#(subNode)’, data: { countryId: ‘#ignore’, countryName: ‘#string’, status: ‘#number? _ >= 0’, time: ‘#? isValidTime(_)’ } } """ Markers #ignore #null #notnull #present #notpresent #number #uuid #array #object #string ##string #? EXPR #[NUM] EXPR #regex STR
  • 14. DDT @regression Scenario Outline: create <name> cat with age = <age> Given url ‘http://mysite.io/v2/pet’ And request { name: ‘<name>’, age: ‘<age>’ } When method post Then status 200 And match response == { id:’#number’, name:’<name>’, age:‘<age>’ } # the single cell in the table can be any valid karate expression: # csv, js, js function, json, variable, XPath or JsonPath. Examples: | read(‘kittens.csv’) | kittens.csv name,age Bob,1 Wild,5 Nyan,3
  • 15. Parallel execution @KarateOptions ( tags = { "@regression", "~@ignore" } ) public class RegressionTests { @Test public void regressionTests() { Results results = Runner.parallel(getClass(), 5, "target/reports"); assertTrue(results.getErrorMessages(), results.getFailCount() == 0); } }
  • 17. Other cool features JsonPath, XPath expressions Reused for perf. testing (Gatling) Embedded UI for step-by-step debug Websocket support, async capability GraphQL API testing capability Built-in environment switcher Integration with CI pipelines API mock or test-doubles Allure reporting support Postman import (exp.) … and many others
  • 19. Takeaways PROS Single layer tests JSON, XML native support Integration with Java, JS Powerful assertion capabilities Parallel execution Great docs, demos, reporting No programming skills are required Many other features out of the box CONS Must learn a new DSL language No “find usage”, auto renaming No syntax error highlighting