API Testing Brief Notes
API Testing Brief Notes
Agenda:
Project Application:
- Front End(UI)
- Backend(Database)
- Service(API)
Web Service:
- You Speak in English and the Chef who is present inside kitchen speaks German & you
don‘t know/understand each other in that case here is a person who make sure two
applications communicate with each other & whatever response you have to get from the
server or whatever response a server has to get from a client is in a format where two
entities can understand & communicate with each other
Waiter (API)
Web Service:
What is API?
Request
Response
Medium: HTTP
Format: XML/JSON
- SOAP Service
- REST Service
08/04/2022:
<definition>:
<types>:
- WSDL <types> element take care of defining the data types that are used by
the web service
- WSDL allows the types to be defined in separate elements so that the types
are reusable with multiple web services
<message>:
- The <message > element describes the data being exchanged between the
web service providers and consumers
- Each Web Service has two Messages: Input and Output
<portType>:
- <portType> can combine one request and one response message into a
single request/response operation. This is most commonly used in SOAP
Services.
- A PortType can define multiple operations.
<binding>:
- The <binding> element provides specific details on how a portType
operation will actually be transmitted over the web.
- The bindings can be made available via multiple transports including HTTP
GET,HTTP POST or SOAP.
WSDL WSDL
UDDI
WSDL WSDL
Web Services:
- SOAP Service
- REST Service
SOAP Web Service:
- A web service that complies to a SOAP web service specifications is a SOAP Service
What are these Specifications?
- Basic Standards/Specifications: SOAP,WSDL,UDDI
09/04/2022:
https://www.soapui.org/downloads/soapui/
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Add>
<tem:intA>?</tem:intA>
<tem:intB>?</tem:intB>
</tem:Add>
</soapenv:Body>
</soapenv:Envelope>
Envelope: (Mandatory)
Header: (Optional)
- Contains any optional attributes of the message used in Processing the message
Body: (Mandatory)
Fault: (Optional)
- An optional fault element that provides information about errors that occurred while processing
the message.
- When an error occurs during processing the response to a SOAP Message is called a SOAP fault
element in the body of the message, and the fault is returned to sender of the SOAP message.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
at System.Xml.XmlConvert.ToInt32(String s)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read1_Add()
at
Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationRea
der reader)
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</faultstring>
<detail/>
</soap:Fault>
</soap:Body>
</soap:Envelope>
API Testing:
2 Types of Web Services
- SOAP Service(SOAPUI Tool)
- REST Service(Soapui and Postman)
Request
Paytm – UI/ GUI Service Travels- Travels agency/ IRCTC main Server
Parameter Provide-Service/
Values
IRCTC - Service
Response
7.2 Verify the SOAP Service by passing two digit number EC=Two digits numbers should be
added=Pass
7.3 Verify the SOAP Service by passing Four/Five digit number EC=Four/Five digits
numbers should be added=Pass
7.4 Verify the SOAP Service by passing one digit number at 1st place and two digit number at 2nd
place one digit number at 1st place and two digit number at 2nd place should be added=Pass
7.5 Verify the SOAP Service by Passing zero at both placeEC =Zero number should be
added=Pass
7.6 Verify the SOAP Service by Passing both digits as –ve numbersEC=Negative numbers
should be added=Pass
8.2 Verify the SOAP Service by passing String/Fractional digit numberEC=Number should not be
added=Pass
8.3 Verify the SOAP Service by passing Null/Blank valuesEC=Should not be added=Pass
8.4 Verify the SOAP service by Passing wrong WSDL fileEC=Pass
13/04/2022:
Xpath Assertion:
Ex: https://ws.footballpool.dataaccess.eu/info.wso?WSDL
How to Run Test Suite in SOAP UI?
Sequential:
Parallel:
How to generate Documentation in SOAP UI?
14/04/2022:
GET Method:
8.4 Verify by Passing wrong URL/URI in GET Method EC=Status Code-404- Not Found & GET
Method will not show the response=Pass
REST Terminologies:
HTTP Methods which are commonly used to communicate with REST API‘s are: GET, POST,
PUT, PATCH, DELETE
GET: The GET is used to extract infromation from the given server using a given URI.While
using GET request, it should only extract data and should have no other effect on data. No
Payload/Body requred.
POST: A post request is used to send data to the server, for example,Customer information,File
Upload,etc using HTML forms.
PUT: Replaces all current representations of the target resourse with uploaded content
Resourses:
Google.com/maps
Google.com/images
Google.com/search
Path Parameters: are variable parts of the URL Path.They are typically used to point to a
specific resourse within a collection,such as user ider identified by ID
https://www.google.com/images/1123343
https://www.google.com/docs/1123343
https://www.amazon.com/orders/112
Query Parameters:
https://www.amazon.com/orders?sort_by=2/20/2022
POST Method/Request:
POST Method Service-URL/URI=https://reqres.in/api/register
Body Payload:
{
"email": "[email protected]",
"password": "pistol"
}
Unit Testing Document
Time Taken for the Response=5Sec
Username & Password(Basic Auth)/API Key/Bearer Token-dalablfblf
Test Cases:
1. Validating REST Response=Pass
7.1 Verify the POST Method/Request by Passing [email protected] with Password=>EC=For this
email ID and Password will be inserted in the server.=Pass
7.2 Verify the POST Method/Request by Passing [email protected] with Password=>EC=For this
email ID and Password will be inserted in the server.=Pass
7.3 Verify the POST Method/Request by Passing [email protected] with Password=>EC=For this
email ID and Password will be inserted in the server.=Pass
7.4 Verify the POST Method/Request by Passing [email protected] with Password=>EC=For this
email ID and Password will be inserted in the server.=Pass
7.5 Verify the POST Method/Request by Passing [email protected] with Password=>EC=For
this email ID and Password will be inserted in the server.=Pass
7.6 Verify the POST Method/Request by Passing [email protected] with Password=>EC=For this
email ID and Password will be inserted in the server.=Pass
8.2 Verify the POST Method by Passing Null/Blank email id=>EC=400-Bad Request=Pass
8.4 Verify POST Method /Request by Passing invalid email domain [email protected] =EC=400-
Bad Request=Pass
8.5 Verify POST Method/Request by Passing valid id(id=1) with Password=EC=400-Bad Request=Pass
{
"name": "morpheus",
"job": "zion resident"
}
Agenda: JSON Path Count, JSON Path Existence, JSON Path Match,
Postman
https://jsonpathfinder.com/
JSON Path Existence: Boolean O/P
JSON Path Match:
Postman Tool: for Testing REST Services
https://www.postman.com/downloads/##
What is Collection?
7.2 Verify by Passing parameter as 2 in GET Method=>EC=Status Code-200-OK & GET Method will show
the response=Pass
7.3 Verify by Passing parameter as 3 in GET Method=>EC=Status Code-200-OK & GET Method will show
the response=Pass
7.4 Verify by Passing parameter as 10/100/1000 in GET Method=>EC=Status Code-200-OK & GET
Method will show the response=Pass
8. Validating Negative Test Cases!
8.1 Verify by Passing parameter as a decimal values in GET Method=>EC=Status Code-400-Bad Request
& GET Method will not show the response=Fail-Defect
8.2 Verify by Passing parameter as Null/Blank Values in GET Method=>EC=Status Code-400-Bad Request
& GET Method will not show the response=Fail-Defect
8.5 Verify by Passing wrong Authorization/Bearer Token/API Key in GET Method=>EC=Status Code-401-
Un-Authorization & GET Method will not show the response.
8.6 Verify by changing GET Method into another Method=>EC=Status Code-405-Method not Allowed &
GET Method will not show the response=Fail-Defect
POST Method/Request:
POST Method Service-URL/URI=https://reqres.in/api/register
Body/Payload-
{
"email": "[email protected]",
"password": "pistol"
}
Username& Password(Basic Auth)/API Key/Barrier token-tcaabfj bjf lekf lklfl
Time taken for the response=60sec
Unit Testing Documents
Test Cases:
7.3 Verify POST method/ request by passing ―[email protected]‖ with password EC=
For these email id password will be inserted in serve=Pass
7.4 Verify POST method/ request by passing ―[email protected]‖ with password EC=
For these email id password will be inserted in serve=Pass
8.3 Verify POST method/ request by passing only email id ― [email protected]‖ without
password EC= 400-Bad request=Pass
8.4 Verify POST method/ request by passing invalid email id ― [email protected]‖
EC= 400-Bad request=Pass
8.5 Verify POST method/ request by passing valid id (id= 1) with password EC= 400-Bad
request=Pass
8.6 Verify POST method/ request by passing wrong URL/URI EC= 404-Not found=Pass
8.7 Verify POST method/ request by passing wrong authorization/ API Key/ barrier token
EC= 401-Un- authorization
8.8 Verify by changing POST method/ request into another method/ request EC= 405-Not
method=Fail-Defect
Practice API: Assignment 1
Resource: /maps/api/place/add/json
Sample Body :
{
"location": {
"lat": -38.383494,
"lng": 33.427362
},
"accuracy": 50,
"types": [
"shoe park",
"shop"
],
"website": "http://google.com",
"language": "French-IN"
}
Sample Response:
{
"status": "OK",
"place_id": "928b51f64aed18713b0d164d9be8d67f",
"scope": "APP",
"reference": "736f3c9bec384af62a184a1936d42bb0736f3c9bec384af62a184a1936d42bb0",
"id": "736f3c9bec384af62a184a1936d42bb0"
}
Google Maps Delete API (POST):
This API Will delete existing place from Server
Complete URL:
https://rahulshettyacademy.com/maps/api/place/delete/json?key=qaclick123
Resource: /maps/api/place/delete/json
Sample Body :
{
"place_id":"928b51f64aed18713b0d164d9be8d67f"
Sample Response
{
"status": "OK"
Complete URL :
http://rahulshettyacademy.com/maps/api/place/get/json?place_id=xxxx&key=qaclick123
Base URL: https://rahulshettyacademy.com
Resource: /maps/api/place/get/json
Query Parameters: key, place_id //( place_id value comes from Add place response)
"location":{
"lat" : -38.383494,
"lng" : 33.427362
},
"accuracy":50,
"name":"Frontline house",
"language" : "French-IN"
Complete URL :
http://rahulshettyacademy.com/maps/api/place/get/json?place_id=xxxx&key=qaclick123
Sample Request:
{
"place_id":"8d2573bdf6ceec0e474c5f388fa917fb",
"address":"70 Summer walk, USA",
"key":"qaclick123"
"location":{
"lat" : -38.383494,
"lng" : 33.427362
},
"accuracy":50,
"name":"Frontline house",
"phone_number":"(+91) 983 893 3937",
"address" : "29, side layout, cohen 09",
"types": ["shoe park","shop"],
"website" : "http://google.com",
"language" : "French-IN"
Real API:
2. Verify the Weather API for Mumbai City of Maharashtra=>EC=Weather Information should return and
Status Code=200-OK= Pass
3. Verify the Weather API for Nasik City of Maharashtra=>EC=Weather Information should return and
Status Code=200-OK= Pass
4. Verify the Weather API for Delhi City of Delhi=>EC=Weather Information should return and Status
Code=200-OK= Pass
5. Verify the Weather API for Goa City of Goa=>EC=Weather Information should return and Status
Code=200-OK=Pass
6. Verify the Weather API for Deoni Village of Maharashtra=>EC=Weather Information should not return
and Status Code=404-Not Found= Pass
8. Verify the Weather API for Null/Blank city name=>EC=Weather Information should not return and
Status Code=400-Bad Request= Pass
9. Verify the Weather API by passing Country name=>EC=Weather Information should not return and
Status Code=400-Bad Request= Fail-Defect
10. Verify the Weather API by passing Invalid City/State Name=>EC=Weather Information should not
return and Status Code=404= Pass
11. Verify the Weather API by passing Invalid URL/URI=>EC=Weather Information should not return and
Status Code=404= Pass
12. Verify the Weather API by passing Invalid API Key=>EC=Weather Information should not return and
Status Code=401=Pass
Variables:(POSTMAN)
2 Types: Global Variables & Environment Variable (Local Variable)
Variables enable you to store and reuse values in your requests and scripts. By storing a value in a
variable, you can reference it throughout your collections, environments, and requests. If you need
to update the value, you only have to change it in one place.
Global variables enable you to access data between collections, requests, test scripts, and
environments. Global variables are available throughout a workspace.
Environment variables enable you to tailor your processing to different environments, for
example local development versus testing or production. Only one environment can be active at a
time.
How to Add Environments?
How to Access response from one method into another Method?
Create new Collection and Add one GET Method: List Users-Gives list of users in the response
URL/URI: https://reqres.in/api/users?page=2
URL/URI: https://reqres.in/api/users/2
Body/Payload: Give the below details in body-> raw-Select JSON from dropdown
"name": "morpheus",
"job": "zion resident"
}
Save and Send
Go to new-Add Environment---APIChaining
"name": "{{Username}}",
"job": "zion resident"
}
Send request and Make Sure you are using Mentioned Environment above
Step 3: Add Script to fetch value from response from 1st API
Go to Tests=>>>
bodyData=JSON.parse(responseBody)
value=bodyData.data[0].first_name
console.log(value)
pm.environment.set("Username1", value);
nd
Note: The value is nothing but the value which we are getting and we will be using in 2
request.
pm.environment.set("Username2", value);This statement is setting Environment Variable and
the value of this environment variable is used in second method(PUT)
Step 4: Value coming from response of 1st method will be fetched in 2nd method.
Step 5: Run the second request and Validate now go to Environment and check if the value is correct
How to Run Collection?
How to Skip any Request?
What is idempotent?
Idem potency means that multiple identical requests will have the same outcome. So it does not matter
if a request is sent once or multiple times. The following HTTP methods are idempotent: GET, HEAD,
OPTIONS, TRACE, PUT and DELETE
PUT Patch
HTTP PUT is said to be idempotent, So if you HTTP PATCH is basically said to be non-
send retry a request multiple times, that idempotent. So if you retry the request N
should be equivalent to a single request times, you will end up having N resources
modification with N different URIs created on the server.
Questions-
5. What are different type of method as GET, POST, PUT, PATCH, DELETE
9. What is RestAssured?-
Ans - API service then I will use RestAssured library for doing Automation.
2. In Collection if one requests you want to skip .So how will you do it?
7. What is JSON?
Websites:
https://reqres.in/
https://gorest.co.in/
----------------------------------------Thank You & ALL THE BEST for Preparations----------------------------------------