Api Testing
Api Testing
DAY 1:::::
Types of APIs:
1. Simple Object Access Protocol (SOAP): It is a messaging protocol that
allows programs that run on disparate operating systems or services like frontend
or backend to communicate
using Hypertext Transfer Protocol(HTTP) and its
Extensible Markup Language(XML).
All Web Services are APIs, but not all APIs are web services. Web service is an API
wrapped in HTTP. A Web Service needs a network while an API doesn't need a network
for its operation.
REST API Methods:
GET
POST
PUT
DELETE
These requests are also called HTTP requests.
URI: Uniform Resource Identifier
URL: Uniform Resource Locator
URN: Uniform Resource Name
COOKIE & TOKEN(IN HTTP): When the server receives an HTTP request in the response,
it can send a Set-Cookie header. The browser puts it into the cookie jar, and the
cookie will
be sent along with every request made to the same origin in the Cookie
HTTP header.
Tokens are most widely used in REST APIs. JSON Web Token, kind of unique
string that can identify and its permission level.
DAY 2:::::
POSTMAN: It is an API testing tool. We can do manual testing of APIs using Postman.
Workspace: It is an area where we can maintain all our files.
Dynamic Variables:
{{$guid}}:
{{$timestamp}}:
{{$randomInt}}:
Data Variable:
Collection Runner lets us import a CSV or a JSON file, and then
use the values from the data file inside HTTP requests and scripts.
Validations:
Status Code
Time
Size Data
Response Body(JSON/XML)
Cookies
Headers
DAY 3::::::
---> JSON-schema.org
https://jsonschema.net/#/
draft 07 or draft 06
{
"students":[
{
"sid":101,
"sname": "SSK",
"grad":"A"
},
{
"sid":102,
"sname": "NSK",
"grad":"B"
},
{
"sid":103,
"sname": "HSK",
"grad":"C"
}
]
}
student[0].sname ----> SSK
student[2].sid ----> 103
jsonpathfinder.com
jsonpath.com
postman.setNextRequest("Request Name");
postman.setNextRequest(null);
terminates execution
Newman: It is a command line Collection Runner for Postman. It allows you to run or
test a Postman Collection directly from the command line.
npm install -g newman
newman run yourcollection.json
GraphQL: It is a query language for APIs and a runtime for fulfilling those queries
with your existing data.
Overfetching:
Underfetching:
DAY 4:::::
Response Validations:
Status Code
Headers
Cookies
Response Time
Response Body
If you want to test for the status code being one of a set, include
them all in an array and use one of
Testing Headers
Testing Cookies
{
"id": 1,
"name": "John",
"location": "india",
"phone": "1234567890",
"courses": [
"Java",
"Selenium"
]
}
{
"id": 1,
"name": "John",
"location": "india",
"phone": "1234567890",
"courses": [
"Java",
"Selenium"
]
}
{
"id": 1,
"name": "John",
"location": "india",
"phone": "1234567890",
"courses": [
"Java",
"Selenium"
]
}
var schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"location": {
"type": "string"
},
"phone": {
"type": "string"
},
"courses": {
"type": "array",
"items": [
{
"type": "string"
},
{
"type": "string"
}
]
}
},
DAY 5::::
Pre-Request Scripts
1. Collection
2. Folder
3. Requests
Pre-Request Script---->Request---->Response---->Tests
console.log("pre-request script at collection level");
console.log("pre-request script at folder level");
console.log("pre-request script at request level");
Console:
Variable:
Something that contains data. Variables can be created in multiple levels.
Variables are classified into 5 types.
DAY 6::::
Chaining of API's
Response of one API becomes the request(or a part of the request) for a different
API.