Automation API TM14 PDF
Automation API TM14 PDF
1. Early defect detection – Most of the time UI layer uses the REST Web services to fetch data
from back end and do the business validation
2. Contract validation – Suppose a scrum team changes some parameters related to a web
service that was developed in the last sprint and they failed to notify your team, so this situation
leads to a production defect of that functionality which you have not touched in the current sprint.
Validating contract is a necessary thing
3. Stops the further build – If a test failed in automation environment, it stops the further build
unless that error is rectified, which assured that only good build are passed to manual testers for
testing
4. Fast result – API Automation test jobs take very less time to complete one test testing cycle.
Very helpful in CICD (Continuous Integration, Continuous Deployment) environments
5. Reliable – If tests are passed without any issue then we can be sure that business layer is not
having any defect
Why API automation required?
RESTful services
● A Uniform Resource Locator (URL) that defines the location of the request
● An HTTP verb that describes what action should be taken
● HTTP headers that provide information to the server about the request
● A request body that provides further details for the request (this can
sometimes be empty)
● POST
○ Creates a new resource
● PUT
○ Modifies an existing resource
● PATCH
○ Modifies only the sent parameters
● GET
○ Read details of an existing resource
● DELETE
○ Delete an existing resource
REST resources
● Consider, for example, a web service for ordering books. Your data might be
organized into customers, which contain orders, which in turn contain individual
books. The resource URL might look like this:
○ http://server.test:8080/order_api/{customer_id}/{order_id}/{book_id}
● Sending a DELETE request to this URL might remove a book from an existing
order, while sending a GET request to this URL might retrieve the details of a
particular book (such as if it is on back order or out of stock).
Request/response headers
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
RESTful services - JSON
XML JSON
<Pet> {
<id>12345</id> "id": 12345,
<name>wantsomeDog</name> "name": "wantsomeDog",
<status>available</status> "status": "available"
</Pet> }
API Testing
● Postman
● SOAPUI
● Curl
● Runscope
● Cfix
API Testing - SWAGGER
● http://petstore.swagger.io/
● Swagger is a suite of API developer tools
● It describes an API in a common language, easy to
understand
● Can be used to design, document and write code
for an API
● Swagger-UI is used to interact with the APIs
API Testing - SWAGGER
● POST
● http://petstore.swagger.io/v2/pet
● -H "content-type: application/json"
● -H "api_key: special-key"
API Testing - SWAGGER - Add pet
● Exercises
○ Try to add a pet without specifying the status
element
○ Perform request after removing the first
bracket in JSON object
API Testing - Get pet by ID
● GET /pet/<petID>
● http://petstore.swagger.io/v2/pet/555
API Testing - SWAGGER - Get pet by ID
● Exercises
○ Perform request using an ID that does not exist
○ Try to execute call with empty value for ID
API Testing - SWAGGER - Update pet
● PUT
● Update an existing PET
API Testing - SWAGGER - Update pet
● Exercises
○ Perform update request using an ID that does
not exist
○ Execute request after removing a comma from
JSON object
API Testing - SWAGGER - Delete pet
DELETE /pet/<petId>
API Testing - Delete pet
● Exercises
○ Perform request using an ID that does not exist
○ Try to execute call with empty value for ID
API Testing - Postman
● https://www.getpostman.com
● Custom HTTP calls can be performed
● Response body, response status
● Create collections, call them anytime
● Write tests and save environment for later use
API Testing - Postman
API Testing - Postman
Environments
Session values
Variables
Environment variable
Setting
pm.environment.set(“variable_key”, “variable_value”);
Getting
var value = pm.environment.get(“variable_key”);
Global variables
Setting
pm.globals.set(“variable_key”, “variable_value”);
Getting
pm.globals.get(“variable_key”);
Clear
pm.globals.unset(“variable_key”);
Search for the variable across globals and the active environment
Step 7) Environment should now be exported to the same local directory as Collection.
Step 8) Now go back to command line and change the directory to where you have
saved the collection and environment.
cd C:\Users\Asus\Desktop\Postman Tutorial
Step 9) Run your collection using this command:
▪ Postman is currently one of the most popular tools used in API testing
▪ Accessibility, Use of Collections, Collaboration, Continuous Integration,
are some of the Key features to learn in Postman
▪ It's recommended you create an account in Postman, so your
collections are available online
▪ You can parameterize request in Postman
▪ You can create Tests to verify a postman request
▪ Collections can be run using Newman or Collection Runner
JENKINS
JENKINS
JENKINS DEMO
References and Recommended Reading
● REST
○ http://www.restapitutorial.com/lessons/whatisrest.html
● Swagger
○ https://swagger.io
● Postman
○ https://www.getpostman.com/
References and Recommended Reading
● Postman documentation
○ https://www.getpostman.com/docs/
● Postman test examples
○ https://www.getpostman.com/docs/postman/scripts/test_
examples
How to Use JMeter for Performance & Load Testing
https://www.guru99.com/jmeter-performance-
testing.html
Questions?