SlideShare a Scribd company logo
API Testing - The
Power of Libraries
Anuradha Raman
Anuradha Raman
★ Lead Automation Test Engineer
@Kissflow
★ 10+ years of experience in
software testing
★ Test Tribe champion for the
Chennai Chapter
Outline
➢ API Test Strategy
➢ Designing test scenarios for API testing
➢ Writing tests in Postman using different libraries
API Testing
Objectives:
● To ensure that the business logic implementation is working correctly as
expected
● To ensure that the implementation is working as specified according to the
requirements specification (API documentation)
● To prevent regressions between code merges and releases
API Testing - Scenarios
Positive Scenario
Negative Scenario
Flow Based - Series of requests which are common user actions or use
cases
Test every single API for
different sets of valid and
invalid input test data
Postman - A collaboration platform for
API development
● Collaborate in real-time with built-in version control
● Directly send REST, SOAP, and GraphQL requests
● Generate beautiful, machine-readable documentation
● Provide a shared context for building and consuming APIs
● Simulate endpoints and responses without having to set up a backend server
API Testing in Postman
a. Request level
Functional -> Request-Response Validation
Automated -> Code snippets -> Basic response code and response
object validation
a. Collection level tests
b. Schema validation test (https://ajv.js.org/)
pm.test("Response uses a valid schema", function() {
pm.expect(ajv.validate(cam, SCHEMA_STORED_AS_A_VARIABLE)).to.be.true;
});
Writing Tests in Postman
➔ Pre Request Tab (before)
➔ Tests (after)
➔ Assertions
◆ Parse the response body
◆ Write test script
Javascript code can be
written in both these places
JSON - JavaScript object notation
JSON String:
‘{
“Name”:”value”,
“array”: [ ]
}’
★ Data is in name value pairs
★ Data is separated by commas (,)
★ Curly braces holds objects
★ Square braces holds arrays
https://jsonpath.
herokuapp.com/
Variables
- Dynamic Variables using Faker library
(https://www.npmjs.com/package/faker)
- Generate mock/dummy test data for each run
- Some interesting dummy variables to note :
- Random filenames,
- images,
- catchphrases,
- To use in pre request and tests tab
pm.variables.replaceIn.(“{{$randomFirstname}}”)
Chai
Chai Assertion Library BDD: Default library in postman for assertions
This syntax provides options to optimize how readable (expect and should)
your tests are to you and your collaborators
const jsonData = pm.response.json(); -->Parsing the response body
pm.test("response data not null", function () {
pm.expect(jsonData.page).to.be.an('number');
pm.expect(jsonData.per_page).to.be.an('number');
pm.expect(jsonData.total_count).to.be.an('number');
pm.expect(jsonData.data.length).to.be.above(0);
})
Chai Assertion
Cheerio - Moment - Lodash
Cheerio - To parse HTML
response
Moment - working with dates Lodash - for loop
● To parse and retrieve the value
from an HTML response, we will
use the cheerio JavaScript library
● Simple library for working with the
DOM model.
● Cheerio wraps around parse5
parser and can optionally use
htmlparser2.
https://cheerio.js.org/
https://blog.logrocket.com/parsing-html-
nodejs-cheerio/
https://github.com/cheeriojs/cheerio
● To work with “dates” in Postman
● Can be used to manage test data in
pre requests tab or even query
params
https://momentjs.com/docs/
● Use with pm.expect() =>iterating
through response data, to help
assert that a certain value is
present.
● create some dynamic data to use in
our requests => The ‘_.random()’
Lodash function syntax
(_random(1000))
https://lodash.com/docs/4.17.15#forEach
Debugging Test Failures
● console.log(),
● console.info(),
● console.warn()
● and console.error()
=> Debug statements with test assertions,
=> Examine the content of the HTTP requests and responses, as well as Postman data
items such as variables
Automated tests in Postman
1. Workflows/End to End Testing/User Journey
2. Workflows=>Collection of API Requests. Automating workflows with the
collection runner
3. Default execution of requests in a Postman collection is sequential/linear
4. Configure which request to run next using pm.setNextRequest();
5. Loop over current request => Set name of current request to setNextRequest
6. Stop the run => pm.setNextRequest(null);
A perfect working API leads to the perfect working application
Thank you

More Related Content

What's hot

Types of test tools
Types of test toolsTypes of test tools
Types of test tools
Vaibhav Dash
 
Keyword-driven Test Automation Framework
Keyword-driven Test Automation FrameworkKeyword-driven Test Automation Framework
Keyword-driven Test Automation Framework
Mikhail Subach
 
Load Testing and JMeter Presentation
Load Testing and JMeter PresentationLoad Testing and JMeter Presentation
Load Testing and JMeter Presentation
Neill Lima
 
Performance testing with Jmeter
Performance testing with JmeterPerformance testing with Jmeter
Performance testing with Jmeter
Prashanth Kumar
 
Final Automation Testing
Final Automation TestingFinal Automation Testing
Final Automation Testing
priya_trivedi
 
Loadrunner interview questions and answers
Loadrunner interview questions and answersLoadrunner interview questions and answers
Loadrunner interview questions and answers
Garuda Trainings
 
Performance Bottleneck Identification
Performance Bottleneck IdentificationPerformance Bottleneck Identification
Performance Bottleneck Identification
Mustufa Batterywala
 
Performance Testing With Jmeter
Performance Testing With JmeterPerformance Testing With Jmeter
Performance Testing With Jmeter
Adam Goucher
 
Load Testing & Apache JMeter
Load Testing & Apache JMeterLoad Testing & Apache JMeter
Load Testing & Apache JMeter
WO Community
 
Performance testing jmeter
Performance testing jmeterPerformance testing jmeter
Performance testing jmeter
Bhojan Rajan
 
Testing_with_TestComplete
Testing_with_TestCompleteTesting_with_TestComplete
Testing_with_TestComplete
Samanuru G Chakravarthy
 
Performance Requirement Gathering
Performance Requirement GatheringPerformance Requirement Gathering
Performance Requirement Gathering
Atul Pant
 
Web and load testing with Visual Studio 2010 Ultimate
Web and load testing with Visual Studio 2010 UltimateWeb and load testing with Visual Studio 2010 Ultimate
Web and load testing with Visual Studio 2010 Ultimate
Abhimanyu Singhal
 
Performance testing using jmeter
Performance testing using jmeterPerformance testing using jmeter
Performance testing using jmeter
Rachappa Bandi
 
Automation framework
Automation framework Automation framework
Automation framework
ITeLearn
 
Software testing tools
Software testing toolsSoftware testing tools
Software testing tools
Software Testing Books
 
JMeter Database Performace Testing - Keytorc Approach
JMeter Database Performace Testing - Keytorc ApproachJMeter Database Performace Testing - Keytorc Approach
JMeter Database Performace Testing - Keytorc Approach
Keytorc Software Testing Services
 
Performance testing interview questions and answers
Performance testing interview questions and answersPerformance testing interview questions and answers
Performance testing interview questions and answers
Garuda Trainings
 
Build Your Custom Performance Testing Framework
Build Your Custom Performance Testing FrameworkBuild Your Custom Performance Testing Framework
Build Your Custom Performance Testing Framework
TechWell
 
WSO2 Test Automation Framework : Approach and Adoption
WSO2 Test Automation Framework : Approach and AdoptionWSO2 Test Automation Framework : Approach and Adoption
WSO2 Test Automation Framework : Approach and Adoption
WSO2
 

What's hot (20)

Types of test tools
Types of test toolsTypes of test tools
Types of test tools
 
Keyword-driven Test Automation Framework
Keyword-driven Test Automation FrameworkKeyword-driven Test Automation Framework
Keyword-driven Test Automation Framework
 
Load Testing and JMeter Presentation
Load Testing and JMeter PresentationLoad Testing and JMeter Presentation
Load Testing and JMeter Presentation
 
Performance testing with Jmeter
Performance testing with JmeterPerformance testing with Jmeter
Performance testing with Jmeter
 
Final Automation Testing
Final Automation TestingFinal Automation Testing
Final Automation Testing
 
Loadrunner interview questions and answers
Loadrunner interview questions and answersLoadrunner interview questions and answers
Loadrunner interview questions and answers
 
Performance Bottleneck Identification
Performance Bottleneck IdentificationPerformance Bottleneck Identification
Performance Bottleneck Identification
 
Performance Testing With Jmeter
Performance Testing With JmeterPerformance Testing With Jmeter
Performance Testing With Jmeter
 
Load Testing & Apache JMeter
Load Testing & Apache JMeterLoad Testing & Apache JMeter
Load Testing & Apache JMeter
 
Performance testing jmeter
Performance testing jmeterPerformance testing jmeter
Performance testing jmeter
 
Testing_with_TestComplete
Testing_with_TestCompleteTesting_with_TestComplete
Testing_with_TestComplete
 
Performance Requirement Gathering
Performance Requirement GatheringPerformance Requirement Gathering
Performance Requirement Gathering
 
Web and load testing with Visual Studio 2010 Ultimate
Web and load testing with Visual Studio 2010 UltimateWeb and load testing with Visual Studio 2010 Ultimate
Web and load testing with Visual Studio 2010 Ultimate
 
Performance testing using jmeter
Performance testing using jmeterPerformance testing using jmeter
Performance testing using jmeter
 
Automation framework
Automation framework Automation framework
Automation framework
 
Software testing tools
Software testing toolsSoftware testing tools
Software testing tools
 
JMeter Database Performace Testing - Keytorc Approach
JMeter Database Performace Testing - Keytorc ApproachJMeter Database Performace Testing - Keytorc Approach
JMeter Database Performace Testing - Keytorc Approach
 
Performance testing interview questions and answers
Performance testing interview questions and answersPerformance testing interview questions and answers
Performance testing interview questions and answers
 
Build Your Custom Performance Testing Framework
Build Your Custom Performance Testing FrameworkBuild Your Custom Performance Testing Framework
Build Your Custom Performance Testing Framework
 
WSO2 Test Automation Framework : Approach and Adoption
WSO2 Test Automation Framework : Approach and AdoptionWSO2 Test Automation Framework : Approach and Adoption
WSO2 Test Automation Framework : Approach and Adoption
 

Similar to API Testing - The power of libraries (chai, cheerio.js ,lodash and moment.js)

Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
coreygoldberg
 
A smarter Pig: Building a SQL interface to Apache Pig using Apache Calcite
A smarter Pig: Building a SQL interface to Apache Pig using Apache CalciteA smarter Pig: Building a SQL interface to Apache Pig using Apache Calcite
A smarter Pig: Building a SQL interface to Apache Pig using Apache Calcite
Julian Hyde
 
Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLGetting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQL
Morgan Dedmon
 
API testing - Japura.pptx
API testing - Japura.pptxAPI testing - Japura.pptx
API testing - Japura.pptx
TharindaLiyanage1
 
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-AirflowPyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
Chetan Khatri
 
StackMate - CloudFormation for CloudStack
StackMate - CloudFormation for CloudStackStackMate - CloudFormation for CloudStack
StackMate - CloudFormation for CloudStack
Chiradeep Vittal
 
SamzaSQL QCon'16 presentation
SamzaSQL QCon'16 presentationSamzaSQL QCon'16 presentation
SamzaSQL QCon'16 presentation
Yi Pan
 
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...
Flink Forward SF 2017: Malo Deniélou -  No shard left behind: Dynamic work re...Flink Forward SF 2017: Malo Deniélou -  No shard left behind: Dynamic work re...
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...
Flink Forward
 
GraphConnect 2014 SF: From Zero to Graph in 120: Scale
GraphConnect 2014 SF: From Zero to Graph in 120: ScaleGraphConnect 2014 SF: From Zero to Graph in 120: Scale
GraphConnect 2014 SF: From Zero to Graph in 120: Scale
Neo4j
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
NLJUG
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
Peter Hendriks
 
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by ScyllaScylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
ScyllaDB
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databases
Raimonds Simanovskis
 
Big Data, Analytics and Machine Learning on AWS Lambda - SRV402 - re:Invent 2017
Big Data, Analytics and Machine Learning on AWS Lambda - SRV402 - re:Invent 2017Big Data, Analytics and Machine Learning on AWS Lambda - SRV402 - re:Invent 2017
Big Data, Analytics and Machine Learning on AWS Lambda - SRV402 - re:Invent 2017
Amazon Web Services
 
Nexthink Library - replacing a ruby on rails application with Scala and Spray
Nexthink Library - replacing a ruby on rails application with Scala and SprayNexthink Library - replacing a ruby on rails application with Scala and Spray
Nexthink Library - replacing a ruby on rails application with Scala and Spray
Matthew Farwell
 
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
François-Guillaume Ribreau
 
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
Amazon Web Services
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
Wolfram Arnold
 
GraphQL the holy contract between client and server
GraphQL the holy contract between client and serverGraphQL the holy contract between client and server
GraphQL the holy contract between client and server
Pavel Chertorogov
 
Gohan
GohanGohan
Gohan
Nachi Ueno
 

Similar to API Testing - The power of libraries (chai, cheerio.js ,lodash and moment.js) (20)

Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
 
A smarter Pig: Building a SQL interface to Apache Pig using Apache Calcite
A smarter Pig: Building a SQL interface to Apache Pig using Apache CalciteA smarter Pig: Building a SQL interface to Apache Pig using Apache Calcite
A smarter Pig: Building a SQL interface to Apache Pig using Apache Calcite
 
Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLGetting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQL
 
API testing - Japura.pptx
API testing - Japura.pptxAPI testing - Japura.pptx
API testing - Japura.pptx
 
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-AirflowPyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
 
StackMate - CloudFormation for CloudStack
StackMate - CloudFormation for CloudStackStackMate - CloudFormation for CloudStack
StackMate - CloudFormation for CloudStack
 
SamzaSQL QCon'16 presentation
SamzaSQL QCon'16 presentationSamzaSQL QCon'16 presentation
SamzaSQL QCon'16 presentation
 
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...
Flink Forward SF 2017: Malo Deniélou -  No shard left behind: Dynamic work re...Flink Forward SF 2017: Malo Deniélou -  No shard left behind: Dynamic work re...
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...
 
GraphConnect 2014 SF: From Zero to Graph in 120: Scale
GraphConnect 2014 SF: From Zero to Graph in 120: ScaleGraphConnect 2014 SF: From Zero to Graph in 120: Scale
GraphConnect 2014 SF: From Zero to Graph in 120: Scale
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
 
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by ScyllaScylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databases
 
Big Data, Analytics and Machine Learning on AWS Lambda - SRV402 - re:Invent 2017
Big Data, Analytics and Machine Learning on AWS Lambda - SRV402 - re:Invent 2017Big Data, Analytics and Machine Learning on AWS Lambda - SRV402 - re:Invent 2017
Big Data, Analytics and Machine Learning on AWS Lambda - SRV402 - re:Invent 2017
 
Nexthink Library - replacing a ruby on rails application with Scala and Spray
Nexthink Library - replacing a ruby on rails application with Scala and SprayNexthink Library - replacing a ruby on rails application with Scala and Spray
Nexthink Library - replacing a ruby on rails application with Scala and Spray
 
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
 
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
GraphQL the holy contract between client and server
GraphQL the holy contract between client and serverGraphQL the holy contract between client and server
GraphQL the holy contract between client and server
 
Gohan
GohanGohan
Gohan
 

Recently uploaded

Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
FODUU
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 

Recently uploaded (20)

Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 

API Testing - The power of libraries (chai, cheerio.js ,lodash and moment.js)

  • 1. API Testing - The Power of Libraries Anuradha Raman
  • 2. Anuradha Raman ★ Lead Automation Test Engineer @Kissflow ★ 10+ years of experience in software testing ★ Test Tribe champion for the Chennai Chapter
  • 3. Outline ➢ API Test Strategy ➢ Designing test scenarios for API testing ➢ Writing tests in Postman using different libraries
  • 4. API Testing Objectives: ● To ensure that the business logic implementation is working correctly as expected ● To ensure that the implementation is working as specified according to the requirements specification (API documentation) ● To prevent regressions between code merges and releases
  • 5. API Testing - Scenarios Positive Scenario Negative Scenario Flow Based - Series of requests which are common user actions or use cases Test every single API for different sets of valid and invalid input test data
  • 6. Postman - A collaboration platform for API development ● Collaborate in real-time with built-in version control ● Directly send REST, SOAP, and GraphQL requests ● Generate beautiful, machine-readable documentation ● Provide a shared context for building and consuming APIs ● Simulate endpoints and responses without having to set up a backend server
  • 7. API Testing in Postman a. Request level Functional -> Request-Response Validation Automated -> Code snippets -> Basic response code and response object validation a. Collection level tests b. Schema validation test (https://ajv.js.org/) pm.test("Response uses a valid schema", function() { pm.expect(ajv.validate(cam, SCHEMA_STORED_AS_A_VARIABLE)).to.be.true; });
  • 8. Writing Tests in Postman ➔ Pre Request Tab (before) ➔ Tests (after) ➔ Assertions ◆ Parse the response body ◆ Write test script Javascript code can be written in both these places
  • 9. JSON - JavaScript object notation JSON String: ‘{ “Name”:”value”, “array”: [ ] }’ ★ Data is in name value pairs ★ Data is separated by commas (,) ★ Curly braces holds objects ★ Square braces holds arrays https://jsonpath. herokuapp.com/
  • 10. Variables - Dynamic Variables using Faker library (https://www.npmjs.com/package/faker) - Generate mock/dummy test data for each run - Some interesting dummy variables to note : - Random filenames, - images, - catchphrases, - To use in pre request and tests tab pm.variables.replaceIn.(“{{$randomFirstname}}”)
  • 11. Chai Chai Assertion Library BDD: Default library in postman for assertions This syntax provides options to optimize how readable (expect and should) your tests are to you and your collaborators const jsonData = pm.response.json(); -->Parsing the response body pm.test("response data not null", function () { pm.expect(jsonData.page).to.be.an('number'); pm.expect(jsonData.per_page).to.be.an('number'); pm.expect(jsonData.total_count).to.be.an('number'); pm.expect(jsonData.data.length).to.be.above(0); }) Chai Assertion
  • 12. Cheerio - Moment - Lodash Cheerio - To parse HTML response Moment - working with dates Lodash - for loop ● To parse and retrieve the value from an HTML response, we will use the cheerio JavaScript library ● Simple library for working with the DOM model. ● Cheerio wraps around parse5 parser and can optionally use htmlparser2. https://cheerio.js.org/ https://blog.logrocket.com/parsing-html- nodejs-cheerio/ https://github.com/cheeriojs/cheerio ● To work with “dates” in Postman ● Can be used to manage test data in pre requests tab or even query params https://momentjs.com/docs/ ● Use with pm.expect() =>iterating through response data, to help assert that a certain value is present. ● create some dynamic data to use in our requests => The ‘_.random()’ Lodash function syntax (_random(1000)) https://lodash.com/docs/4.17.15#forEach
  • 13. Debugging Test Failures ● console.log(), ● console.info(), ● console.warn() ● and console.error() => Debug statements with test assertions, => Examine the content of the HTTP requests and responses, as well as Postman data items such as variables
  • 14. Automated tests in Postman 1. Workflows/End to End Testing/User Journey 2. Workflows=>Collection of API Requests. Automating workflows with the collection runner 3. Default execution of requests in a Postman collection is sequential/linear 4. Configure which request to run next using pm.setNextRequest(); 5. Loop over current request => Set name of current request to setNextRequest 6. Stop the run => pm.setNextRequest(null);
  • 15.
  • 16.
  • 17.
  • 18. A perfect working API leads to the perfect working application

Editor's Notes

  1. A basic guideline is to identify the most common parameters and conditions that an end developer will use when calling the APIs and test these scenarios extensively. Validate integration between services Reliable Code Need for API tests Sweet spot of the Testing pyramid Shift left Agile Practices
  2. Happy - check basic functionality and the acceptance criteria of the API Negative - gracefully handle problem scenarios with both valid user input and invalid user input
  3. The awesome thing about this tool is that it simplifies each step of building an API and it also makes collaboration seamless for building faster APIs. Automate functional tests Check API performance and response times at scheduled intervals
  4. You can store the schema to be validated against as a collection variable and write various tests for the possible responses for an API.
  5. The `Pre-request Script` and `Tests` tabs are basically little JavaScript IDE’s and they give us the ability to write small scripts, to assist us with things like creating test data or managing the response data that we receive from an API endpoint
  6. Derived from Java script object notation With JavaScript you can create an object and assign data to it, like this: It is a common mistake to call a JSON object literal "a JSON object". JSON cannot be an object. JSON is a string format. You can access object values by using dot (.) notation: You can also access object values by using bracket ([]) notation: You access array values by index:
  7. The sole purpose of a test is to identify that for a situation given parameters of the system are as expected. To force that the parameters of the system are correct we assert the expected values with the actual values during a test run. Assertions are used to assert that expected and actual values during a test run match. If they don't match, the test fails with the output pointing directly to the failure.
  8. Cheerio can parse nearly any HTML or XML document. Lodash - to check that the specific property of each object in the array
  9. you can override this behavior using a built-in function.as the name suggests, allows you to specify which request runs next. Exit the loop with proper logic in place to avoid indefinite run