SlideShare une entreprise Scribd logo
1  sur  37
REST API testing with 
SpecFlow 
Aistė Stikliūtė @ Visma Lietuva
Agenda 
Why SpecFlow REST API How to 
Details & tips Live demo 
Bonus: 
other uses of 
SpecFlow
Why SpecFlow 
• SoapUI? 
• Fitnesse? 
• Cucumber?
Why not… 
 SoapUI 
 Free version issues 
 Tests less easy to read 
 Thought there was no CI 
 Fitnesse 
 Works poorly with .NET 
 Wiki markup and tables interface is tiring 
 Cucumber 
 Yes – SpecFlow is Cucumber for .NET!
Continuous integration
BDD / Gherkin language 
GIVEN book with ISBN “1-84356-028-3” is in the system 
AND it’s available quantity is 9 
WHEN I add a book with ISBN “1-84356-028-3” 
THEN the book is successfully added to the list 
AND available qty. for book with ISBN “1-84356-028-3” is 10
The environment 
Same tool as 
for GUI tests 
(Visual Studio, 
C#) 
Same solution 
as GUI tests 
and even the 
whole system 
Convenient! 
Developers are 
integrated!
Rest API 
• What it is 
• Examples 
• Why test it
REST API 
 Web architectural style with a set of constraints 
 Web service APIs that adhere to the constraints - RESTful 
Frontend 
REST API 
Backend 
External 
system(s) 
External 
system(s)
Rest API: typically used HTTP methods 
Resource GET PUT POST DELETE 
Collection URI, 
such as 
http://example.com/res 
ources 
List 
collection's 
members 
Replace 
collection with 
another 
collection 
Create new 
entry in the 
collection 
Delete the 
entire 
collection 
Element URI, 
such as 
http://example.com/res 
ources/item17 
Retrieve 
the member 
of the 
collection 
Replace the 
member of the 
collection 
Not generally 
used 
Delete the 
member of the 
collection
Example 1 
Request 
 GET https://eshop.com/books/14765 
Response 
 Status: 200 OK 
{ 
"id": “14765", 
“title": “Game of Thrones", 
“author": “George R. R. Martin", 
“isbn": "1-84356-028-3", 
“availableQty": “4" 
}
Example 2 
Request 
 POST https://eshop.com/books 
{ 
“title": “501 Spanish Verbs", 
“author": “C. Kendris", 
“isbn": "1-84750-018-7", 
“availableQty": “10" 
} 
Response 
 Status: 200 OK 
{ 
“id": “78953“ 
}
Example 3 
Requests 
 DELETE 
https://eshop.com/book/84523 
 GET https://eshop.com/admin 
 PUT https://eshop.com/book/24552 
{ [some wrong data] } 
Responses 
 Status: 200 OK 
 Status: 401 Unauthorized 
 Status: 500 Internal Server Error
Why test Rest API? 
 If used by external applications: this is your UI! 
 As your system layer: 
 Can help find / isolate problems: 
Security 
Performance 
Robustness 
Functionality 
 May be more simple to test / automate than GUI tests
How to… 
…write tests
Step 1: know what your API should do 
 Documentation 
 Talk to developers 
 Browser’s Developer tools 
 REST client (e.g. Postman on Chrome)
Dev tools + REST client
Step 2: write your test scenarios 
 ListBooks.feature 
Scenario: There are no books in the system 
Given there are no books in the system 
When I retrieve list of all books 
Then I get empty list 
Scenario: There are less books than fit into 1 page 
Scenario: There are more books than fit into 1 page 
Scenario: Sort books 
Scenario: Search for a book
Step 3: generate scenario steps 
[Given(@”there are no books in the list”)] 
public void GivenThereAreNoBooksInTheList() 
{ 
ScenarioContext.Current.Pending(); 
}
Step 4: implement scenario steps 
 Here‘s where the Rest API calls go! 
 Plain C# can be used or libraries // I use RestSharp 
 Structure your project
Project structure 
 Features: all features, can have subfolders 
 Steps: bindings of features to actions 
 Actions: where things happen 
 Helpers: among others, RestHelper.cs 
 Model: classes matching our API data format 
 App.config: holds base URI
A quick look into code: Steps & Actions 
Steps 
Actions
A quick look into code: Model
A quick look into code: RestHelper.cs
Step 5: run tests
Step 6: add to Continuous Integration
Details & Tips
Hooks (event bindings) 
 Before / after test run  static 
 Before / after feature  static 
 Before / after scenario 
 Before / after scenario block (given / when / then) 
 Before / after step
Step scope and reusing 
 Steps are global! 
 Naming: “when I update it”  “when I update the book” 
 Scoped bindings: 
[Scope(Tag="my tag", Feature=“my feature", Scenario=“my scenario")] 
 Reusing step in other steps 
[Given(@"(.*) is logged in")] 
public void GivenIsLoggedIn(string name) { 
Given(string.Format("the user {0} exists", name)); 
Given(string.Format("I log in as {0}", name)); 
}
Table and multiline step arguments
Live Demo
Bonus 
Other uses of SpecFlow
Behaviour / 
Business Driven Development 
1. PO / QA writes scenarios 
2. Developer writes unit/integration tests 
3. Developer writes code until tests pass
Driving Selenium tests 
Scenario: Successful login 
Given I am at http://eshop.com/login 
When I login with user “John” and password “Password1” 
Then I am redirected to http://eshop.com/main 
Scenario: Successful login 
Given I am in login page 
When I login with correct credentials 
Then I am redirected to main page
SpecFlow & Selenium 
using scoped bindings 
[When(@"I perform a simple search on '(.*)'", Scope(Tag = “api"))] 
public void WhenIPerformASimpleSearchOn(string searchTerm) { 
var api = new CatalogApi(); 
actionResult = api.Search(searchTerm); 
} 
[When(@"I perform a simple search on '(.*)'"), Scope(Tag = "web")] 
public void PerformSimpleSearch(string title) { 
selenium.GoToThePage("Home"); selenium.Type("searchTerm", title); 
selenium.Click("searchButton"); 
}
Test case management / Test reporting 
 One functional test suite? 
 Manual 
 Automated API 
 Automated GUI 
 One report with test list that can be read by 
 POs and manual QAs 
 management 
 customer
Thank you! 
Time for questions 

Contenu connexe

Tendances

API Test Automation
API Test Automation API Test Automation
API Test Automation SQALab
 
API Testing. Streamline your testing process.
API Testing. Streamline your testing process.API Testing. Streamline your testing process.
API Testing. Streamline your testing process.Andrey Oleynik
 
Ppt of soap ui
Ppt of soap uiPpt of soap ui
Ppt of soap uipkslide28
 
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
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumberNibu Baby
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API TestingBruno Pedro
 
Functional Tests Automation with Robot Framework
Functional Tests Automation with Robot FrameworkFunctional Tests Automation with Robot Framework
Functional Tests Automation with Robot Frameworklaurent bristiel
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberKMS Technology
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkinArati Joshi
 
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
 
4 Major Advantages of API Testing
4 Major Advantages of API Testing4 Major Advantages of API Testing
4 Major Advantages of API TestingQASource
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptWojciech Dzikowski
 
API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)Peter Thomas
 

Tendances (20)

API Test Automation
API Test Automation API Test Automation
API Test Automation
 
API Testing. Streamline your testing process.
API Testing. Streamline your testing process.API Testing. Streamline your testing process.
API Testing. Streamline your testing process.
 
Ppt of soap ui
Ppt of soap uiPpt of soap ui
Ppt of soap ui
 
Soap UI and postman
Soap UI and postmanSoap UI and postman
Soap UI and postman
 
Cucumber & gherkin language
Cucumber & gherkin languageCucumber & gherkin language
Cucumber & gherkin language
 
Tosca explained
Tosca explainedTosca explained
Tosca explained
 
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
 
Test Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and CucumberTest Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and Cucumber
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
 
Appium
AppiumAppium
Appium
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API Testing
 
Functional Tests Automation with Robot Framework
Functional Tests Automation with Robot FrameworkFunctional Tests Automation with Robot Framework
Functional Tests Automation with Robot Framework
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using Cucumber
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkin
 
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
 
4 Major Advantages of API Testing
4 Major Advantages of API Testing4 Major Advantages of API Testing
4 Major Advantages of API Testing
 
Automation testing
Automation testingAutomation testing
Automation testing
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
 
API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)
 

En vedette

Presentation for soap ui
Presentation for soap uiPresentation for soap ui
Presentation for soap uiAnjali Rao
 
SOAP-UI The Web service Testing
SOAP-UI The Web service TestingSOAP-UI The Web service Testing
SOAP-UI The Web service TestingGanesh Mandala
 
Soa testing soap ui (2)
Soa testing   soap ui (2)Soa testing   soap ui (2)
Soa testing soap ui (2)Knoldus Inc.
 
Getting Started with API Security Testing
Getting Started with API Security TestingGetting Started with API Security Testing
Getting Started with API Security TestingSmartBear
 
Testing Agile Web Services from soapUI
Testing Agile Web Services from soapUITesting Agile Web Services from soapUI
Testing Agile Web Services from soapUIPLM Mechanic .
 
An introduction to api testing | David Tzemach
An introduction to api testing | David TzemachAn introduction to api testing | David Tzemach
An introduction to api testing | David TzemachDavid Tzemach
 
Automate REST API Testing
Automate REST API TestingAutomate REST API Testing
Automate REST API TestingTechWell
 
Testing web services
Testing web servicesTesting web services
Testing web servicesTaras Lytvyn
 
Web Services Automated Testing via SoapUI Tool
Web Services Automated Testing via SoapUI ToolWeb Services Automated Testing via SoapUI Tool
Web Services Automated Testing via SoapUI ToolSperasoft
 

En vedette (13)

Presentation for soap ui
Presentation for soap uiPresentation for soap ui
Presentation for soap ui
 
SOAP-UI The Web service Testing
SOAP-UI The Web service TestingSOAP-UI The Web service Testing
SOAP-UI The Web service Testing
 
Soa testing soap ui (2)
Soa testing   soap ui (2)Soa testing   soap ui (2)
Soa testing soap ui (2)
 
Getting Started with API Security Testing
Getting Started with API Security TestingGetting Started with API Security Testing
Getting Started with API Security Testing
 
Testing soapui
Testing soapuiTesting soapui
Testing soapui
 
Testing Agile Web Services from soapUI
Testing Agile Web Services from soapUITesting Agile Web Services from soapUI
Testing Agile Web Services from soapUI
 
An introduction to api testing | David Tzemach
An introduction to api testing | David TzemachAn introduction to api testing | David Tzemach
An introduction to api testing | David Tzemach
 
Automate REST API Testing
Automate REST API TestingAutomate REST API Testing
Automate REST API Testing
 
Api testing
Api testingApi testing
Api testing
 
Soap ui
Soap uiSoap ui
Soap ui
 
Testing web services
Testing web servicesTesting web services
Testing web services
 
Learn SoapUI
Learn SoapUILearn SoapUI
Learn SoapUI
 
Web Services Automated Testing via SoapUI Tool
Web Services Automated Testing via SoapUI ToolWeb Services Automated Testing via SoapUI Tool
Web Services Automated Testing via SoapUI Tool
 

Similaire à REST API testing with SpecFlow

Examiness hints and tips from the trenches
Examiness hints and tips from the trenchesExaminess hints and tips from the trenches
Examiness hints and tips from the trenchesIsmail Mayat
 
Bridging the gap from Wikipedia to scholarly sources: a simple discovery solu...
Bridging the gap from Wikipedia to scholarly sources: a simple discovery solu...Bridging the gap from Wikipedia to scholarly sources: a simple discovery solu...
Bridging the gap from Wikipedia to scholarly sources: a simple discovery solu...Valerie Forrestal
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with SolrErik Hatcher
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with SolrErik Hatcher
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101Samantha Geitz
 
SharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewSharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewRob Windsor
 
Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)Julian Hyde
 
Start testing your extension NOW
Start testing your extension NOWStart testing your extension NOW
Start testing your extension NOWJan Helke
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTPMykhailo Kolesnyk
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxMichael Hackstein
 
SPTechCon 2014 How to develop and debug client side code in SharePoint
SPTechCon 2014 How to develop and debug client side code in SharePointSPTechCon 2014 How to develop and debug client side code in SharePoint
SPTechCon 2014 How to develop and debug client side code in SharePointMark Rackley
 
Apache Lucene: Searching the Web and Everything Else (Jazoon07)
Apache Lucene: Searching the Web and Everything Else (Jazoon07)Apache Lucene: Searching the Web and Everything Else (Jazoon07)
Apache Lucene: Searching the Web and Everything Else (Jazoon07)dnaber
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Tips and Tricks for Building Visual Studio Workflows
Tips and Tricks for Building Visual Studio WorkflowsTips and Tricks for Building Visual Studio Workflows
Tips and Tricks for Building Visual Studio WorkflowsMalin De Silva
 
Powershell Training
Powershell TrainingPowershell Training
Powershell TrainingFahad Noaman
 
Drupal & Summon: Keeping Article Discovery in the Library
Drupal & Summon: Keeping Article Discovery in the LibraryDrupal & Summon: Keeping Article Discovery in the Library
Drupal & Summon: Keeping Article Discovery in the LibraryKen Varnum
 

Similaire à REST API testing with SpecFlow (20)

Examiness hints and tips from the trenches
Examiness hints and tips from the trenchesExaminess hints and tips from the trenches
Examiness hints and tips from the trenches
 
Bridging the gap from Wikipedia to scholarly sources: a simple discovery solu...
Bridging the gap from Wikipedia to scholarly sources: a simple discovery solu...Bridging the gap from Wikipedia to scholarly sources: a simple discovery solu...
Bridging the gap from Wikipedia to scholarly sources: a simple discovery solu...
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 
Rest web services
Rest web servicesRest web services
Rest web services
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
 
SharePoint 2010 Application Development Overview
SharePoint 2010 Application Development OverviewSharePoint 2010 Application Development Overview
SharePoint 2010 Application Development Overview
 
MVS: An angular MVC
MVS: An angular MVCMVS: An angular MVC
MVS: An angular MVC
 
Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)
 
Start testing your extension NOW
Start testing your extension NOWStart testing your extension NOW
Start testing your extension NOW
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTP
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB Foxx
 
Elasticsearch
ElasticsearchElasticsearch
Elasticsearch
 
SPTechCon 2014 How to develop and debug client side code in SharePoint
SPTechCon 2014 How to develop and debug client side code in SharePointSPTechCon 2014 How to develop and debug client side code in SharePoint
SPTechCon 2014 How to develop and debug client side code in SharePoint
 
Apache Lucene Searching The Web
Apache Lucene Searching The WebApache Lucene Searching The Web
Apache Lucene Searching The Web
 
Apache Lucene: Searching the Web and Everything Else (Jazoon07)
Apache Lucene: Searching the Web and Everything Else (Jazoon07)Apache Lucene: Searching the Web and Everything Else (Jazoon07)
Apache Lucene: Searching the Web and Everything Else (Jazoon07)
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Tips and Tricks for Building Visual Studio Workflows
Tips and Tricks for Building Visual Studio WorkflowsTips and Tricks for Building Visual Studio Workflows
Tips and Tricks for Building Visual Studio Workflows
 
Powershell Training
Powershell TrainingPowershell Training
Powershell Training
 
Drupal & Summon: Keeping Article Discovery in the Library
Drupal & Summon: Keeping Article Discovery in the LibraryDrupal & Summon: Keeping Article Discovery in the Library
Drupal & Summon: Keeping Article Discovery in the Library
 

Dernier

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 

Dernier (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

REST API testing with SpecFlow

  • 1. REST API testing with SpecFlow Aistė Stikliūtė @ Visma Lietuva
  • 2. Agenda Why SpecFlow REST API How to Details & tips Live demo Bonus: other uses of SpecFlow
  • 3. Why SpecFlow • SoapUI? • Fitnesse? • Cucumber?
  • 4. Why not…  SoapUI  Free version issues  Tests less easy to read  Thought there was no CI  Fitnesse  Works poorly with .NET  Wiki markup and tables interface is tiring  Cucumber  Yes – SpecFlow is Cucumber for .NET!
  • 6. BDD / Gherkin language GIVEN book with ISBN “1-84356-028-3” is in the system AND it’s available quantity is 9 WHEN I add a book with ISBN “1-84356-028-3” THEN the book is successfully added to the list AND available qty. for book with ISBN “1-84356-028-3” is 10
  • 7. The environment Same tool as for GUI tests (Visual Studio, C#) Same solution as GUI tests and even the whole system Convenient! Developers are integrated!
  • 8. Rest API • What it is • Examples • Why test it
  • 9. REST API  Web architectural style with a set of constraints  Web service APIs that adhere to the constraints - RESTful Frontend REST API Backend External system(s) External system(s)
  • 10. Rest API: typically used HTTP methods Resource GET PUT POST DELETE Collection URI, such as http://example.com/res ources List collection's members Replace collection with another collection Create new entry in the collection Delete the entire collection Element URI, such as http://example.com/res ources/item17 Retrieve the member of the collection Replace the member of the collection Not generally used Delete the member of the collection
  • 11. Example 1 Request  GET https://eshop.com/books/14765 Response  Status: 200 OK { "id": “14765", “title": “Game of Thrones", “author": “George R. R. Martin", “isbn": "1-84356-028-3", “availableQty": “4" }
  • 12. Example 2 Request  POST https://eshop.com/books { “title": “501 Spanish Verbs", “author": “C. Kendris", “isbn": "1-84750-018-7", “availableQty": “10" } Response  Status: 200 OK { “id": “78953“ }
  • 13. Example 3 Requests  DELETE https://eshop.com/book/84523  GET https://eshop.com/admin  PUT https://eshop.com/book/24552 { [some wrong data] } Responses  Status: 200 OK  Status: 401 Unauthorized  Status: 500 Internal Server Error
  • 14. Why test Rest API?  If used by external applications: this is your UI!  As your system layer:  Can help find / isolate problems: Security Performance Robustness Functionality  May be more simple to test / automate than GUI tests
  • 16. Step 1: know what your API should do  Documentation  Talk to developers  Browser’s Developer tools  REST client (e.g. Postman on Chrome)
  • 17. Dev tools + REST client
  • 18. Step 2: write your test scenarios  ListBooks.feature Scenario: There are no books in the system Given there are no books in the system When I retrieve list of all books Then I get empty list Scenario: There are less books than fit into 1 page Scenario: There are more books than fit into 1 page Scenario: Sort books Scenario: Search for a book
  • 19. Step 3: generate scenario steps [Given(@”there are no books in the list”)] public void GivenThereAreNoBooksInTheList() { ScenarioContext.Current.Pending(); }
  • 20. Step 4: implement scenario steps  Here‘s where the Rest API calls go!  Plain C# can be used or libraries // I use RestSharp  Structure your project
  • 21. Project structure  Features: all features, can have subfolders  Steps: bindings of features to actions  Actions: where things happen  Helpers: among others, RestHelper.cs  Model: classes matching our API data format  App.config: holds base URI
  • 22. A quick look into code: Steps & Actions Steps Actions
  • 23. A quick look into code: Model
  • 24. A quick look into code: RestHelper.cs
  • 25. Step 5: run tests
  • 26. Step 6: add to Continuous Integration
  • 28. Hooks (event bindings)  Before / after test run  static  Before / after feature  static  Before / after scenario  Before / after scenario block (given / when / then)  Before / after step
  • 29. Step scope and reusing  Steps are global!  Naming: “when I update it”  “when I update the book”  Scoped bindings: [Scope(Tag="my tag", Feature=“my feature", Scenario=“my scenario")]  Reusing step in other steps [Given(@"(.*) is logged in")] public void GivenIsLoggedIn(string name) { Given(string.Format("the user {0} exists", name)); Given(string.Format("I log in as {0}", name)); }
  • 30. Table and multiline step arguments
  • 32. Bonus Other uses of SpecFlow
  • 33. Behaviour / Business Driven Development 1. PO / QA writes scenarios 2. Developer writes unit/integration tests 3. Developer writes code until tests pass
  • 34. Driving Selenium tests Scenario: Successful login Given I am at http://eshop.com/login When I login with user “John” and password “Password1” Then I am redirected to http://eshop.com/main Scenario: Successful login Given I am in login page When I login with correct credentials Then I am redirected to main page
  • 35. SpecFlow & Selenium using scoped bindings [When(@"I perform a simple search on '(.*)'", Scope(Tag = “api"))] public void WhenIPerformASimpleSearchOn(string searchTerm) { var api = new CatalogApi(); actionResult = api.Search(searchTerm); } [When(@"I perform a simple search on '(.*)'"), Scope(Tag = "web")] public void PerformSimpleSearch(string title) { selenium.GoToThePage("Home"); selenium.Type("searchTerm", title); selenium.Click("searchButton"); }
  • 36. Test case management / Test reporting  One functional test suite?  Manual  Automated API  Automated GUI  One report with test list that can be read by  POs and manual QAs  management  customer
  • 37. Thank you! Time for questions 

Notes de l'éditeur

  1. Client-server, stateless, cacheable, layered system, code on demand (client-side, optional), uniform interface: identification of resources, manipulation of resources, self-descriptive messages, hypermedia as the engine of the application state.
  2. If I don’t see it in the UI but can access through API – it’s not secured good enough! Unnecessary API calls made / too much info returned – performance Misuse of the API finds bugs (insert duplicate record  error retrieving list) Fields you don’t see in UI may be wrong, or just looking from another point of view helps find bugs
  3. In SpecFlow, test scenarios are grouped by features into dedicated feature files Good example why API needs to be tested. It may be implemented the way that API returns and error if there are no books, but it should be an empty list based on RESTful constraints. GUI might simply display no books if there‘s an error, so you will think all is good. Then you might also wonder if it‘s OK that API returns an error but API doesn‘t show it.
  4. Binding to feature is an anti-pattern, but there are other good uses to scoped bindings, like tags for differentiating between API and GUI tests Reusing like in this example is for making our steps shorter. In test console we’ll see inner steps. So far I haven’t used this as I found moving out Rest API calls to separate classes is enough, but I can see where it would make sense to use it.
  5. API testing is just one possible use of SpecFlow
  6. And in Steps all Webdriver logic can be placed. PageObject pattern can still be used at it’s fullest. For example, just the way we have Model classes, we can have Page classes. The slide shows the style that should not and should be used in scenarios.