SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGSiddharth Sharma
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API TestingBruno Pedro
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsQASymphony
 
2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assuredEing Ong
 
B4USolution_API-Testing
B4USolution_API-TestingB4USolution_API-Testing
B4USolution_API-Testingb4usolution .
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with MockitoRichard Paul
 
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 frameworkMicha Kops
 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An IntroductionSam Brannen
 
An Introduction To Automated API Testing
An Introduction To Automated API TestingAn Introduction To Automated API Testing
An Introduction To Automated API TestingSauce Labs
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockitoshaunthomas999
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And MockingJoe Wilson
 
Extent Test report v3 with Appium/Selenium
Extent Test report v3 with Appium/SeleniumExtent Test report v3 with Appium/Selenium
Extent Test report v3 with Appium/SeleniumRaman Gowda Hullur
 
API Testing Presentations.pptx
API Testing Presentations.pptxAPI Testing Presentations.pptx
API Testing Presentations.pptxManmitSalunke
 
Performance testing presentation
Performance testing presentationPerformance testing presentation
Performance testing presentationBelatrix Software
 

Was ist angesagt? (20)

Rest assured
Rest assuredRest assured
Rest assured
 
API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNG
 
Api testing
Api testingApi testing
Api testing
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API Testing
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and Jenkins
 
2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured
 
Api Testing.pdf
Api Testing.pdfApi Testing.pdf
Api Testing.pdf
 
B4USolution_API-Testing
B4USolution_API-TestingB4USolution_API-Testing
B4USolution_API-Testing
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with Mockito
 
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
 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An Introduction
 
An Introduction To Automated API Testing
An Introduction To Automated API TestingAn Introduction To Automated API Testing
An Introduction To Automated API Testing
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
 
Api testing
Api testingApi testing
Api testing
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Extent Test report v3 with Appium/Selenium
Extent Test report v3 with Appium/SeleniumExtent Test report v3 with Appium/Selenium
Extent Test report v3 with Appium/Selenium
 
API Testing for everyone.pptx
API Testing for everyone.pptxAPI Testing for everyone.pptx
API Testing for everyone.pptx
 
API Testing Presentations.pptx
API Testing Presentations.pptxAPI Testing Presentations.pptx
API Testing Presentations.pptx
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Performance testing presentation
Performance testing presentationPerformance testing presentation
Performance testing presentation
 

Ähnlich wie 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 AppEngineRoman 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 APIJeremyOtt5
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock FrameworkEugene 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 KotlinDmitriy Sobko
 
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 mirageKrzysztof Bialek
 
Real World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsReal World Asp.Net WebApi Applications
Real World Asp.Net WebApi ApplicationsEffie Arditi
 
Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance testBryan 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 HMRJavier 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 Vaswanivvaswani
 
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.jsMek 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 applicationsLoiane 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.0Claire 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfSkillCertProExams
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Baileyhlharris
 
Causes of poverty in France presentation.pptx
Causes of poverty in France presentation.pptxCauses of poverty in France presentation.pptx
Causes of poverty in France presentation.pptxCamilleBoulbin1
 
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...Delhi Call girls
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoKayode Fayemi
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lodhisaajjda
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIINhPhngng3
 
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...Pooja Nehwal
 
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verifiedSector 62, Noida Call girls :8448380779 Noida Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verifiedDelhi Call girls
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Vipesco
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar TrainingKylaCullinane
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxraffaeleoman
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...amilabibi1
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatmentnswingard
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaKayode Fayemi
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfSenaatti-kiinteistöt
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalFabian de Rijk
 

Kürzlich hochgeladen (18)

AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
Causes of poverty in France presentation.pptx
Causes of poverty in France presentation.pptxCauses of poverty in France presentation.pptx
Causes of poverty in France presentation.pptx
 
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
 
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verifiedSector 62, Noida Call girls :8448380779 Noida Escorts | 100% verified
Sector 62, Noida Call girls :8448380779 Noida Escorts | 100% verified
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 

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