API Testing_NOTES
API Testing_NOTES
Agenda:
- What is Web Service?
- Basic Concept behind web service
- Why we use it?
- Why to test it?
Project Application:
- Front End(UI)
- Backend(Database)
- Service(API’s)
Web Service:
Waiter (API)
Web Service:
Request
Response
19/12/2023:
Medium: HTTP
Format/language: XML/JSON
UI: JS,Angular,ReactJS
API: Java,C#
Backend: MySQL,Oracle,SQL
API Testing-
2 Types Service
1. SOAP service(SOAP UI tool)
2. REST service(SOAP UI,POSTMAN)
Manual Testing: Postman,JMeter,Load Runner,SOAP UI
API Automation: Rest Assured=>Tool=>Java Library
Request
21/12/2023:
Query Parameters:
Request Body:
Response Attributes/tagnames:
Response Examle:
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
"id": 7,
"email": "michael.lawson@reqres.in",
"first_name": "Michael",
"last_name": "Lawson",
},
"id": 8,
"email": "lindsay.ferguson@reqres.in",
"first_name": "Lindsay",
"last_name": "Ferguson",
"avatar": "https://reqres.in/img/faces/8-image.jpg"
},
{
"id": 9,
"email": "tobias.funke@reqres.in",
"first_name": "Tobias",
"last_name": "Funke",
"avatar": "https://reqres.in/img/faces/9-image.jpg"
},
"id": 10,
"email": "byron.fields@reqres.in",
"first_name": "Byron",
"last_name": "Fields",
"avatar": "https://reqres.in/img/faces/10-image.jpg"
},
"id": 11,
"email": "george.edwards@reqres.in",
"first_name": "George",
"last_name": "Edwards",
"avatar": "https://reqres.in/img/faces/11-image.jpg"
},
"id": 12,
"email": "rachel.howell@reqres.in",
"first_name": "Rachel",
"last_name": "Howell",
"avatar": "https://reqres.in/img/faces/12-image.jpg"
],
"support": {
"url": "https://reqres.in/#support-heading",
"text": "To keep ReqRes free, contributions towards server costs are
appreciated!"
}
}
GET Method Service:
Sample Response:
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
"id": 7,
"email": "michael.lawson@reqres.in",
"first_name": "Michael",
"last_name": "Lawson",
},
"id": 8,
"email": "lindsay.ferguson@reqres.in",
"first_name": "Lindsay",
"last_name": "Ferguson",
"avatar": "https://reqres.in/img/faces/8-image.jpg"
},
"id": 9,
"email": "tobias.funke@reqres.in",
"first_name": "Tobias",
"last_name": "Funke",
"avatar": "https://reqres.in/img/faces/9-image.jpg"
},
"id": 10,
"email": "byron.fields@reqres.in",
"first_name": "Byron",
"last_name": "Fields",
"avatar": "https://reqres.in/img/faces/10-image.jpg"
},
"id": 11,
"email": "george.edwards@reqres.in",
"first_name": "George",
"last_name": "Edwards",
"avatar": "https://reqres.in/img/faces/11-image.jpg"
},
"id": 12,
"email": "rachel.howell@reqres.in",
"first_name": "Rachel",
"last_name": "Howell",
"avatar": "https://reqres.in/img/faces/12-image.jpg"
],
"support": {
"url": "https://reqres.in/#support-heading",
"text": "To keep ReqRes free, contributions towards server costs are
appreciated!"
}
}
22/12/2023:
Test Cases:
1. Validating REST Response=Pass
12/12/2023:
Snippets:
pm.response.to.have.status(200);
});
Response time is less than 200ms:
pm.expect(pm.response.responseTime).to.be.below
(5000);
});
Response Body: Contains String
pm.expect(pm.response.text()).to.include("linds
ay.ferguson@reqres.in");
});
Response Body: Is equal to String
pm.response.to.have.body({
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
"id": 7,
"email": "michael.lawson@reqres.in",
"first_name": "Michael",
"last_name": "Lawson",
"avatar": "https://reqres.in/img/
faces/7-image.jpg"
},
"id": 8,
"email": "lindsay.ferguson@reqres.in",
"first_name": "Lindsay",
"last_name": "Ferguson",
"avatar": "https://reqres.in/img/
faces/8-image.jpg"
},
"id": 9,
"email": "tobias.funke@reqres.in",
"first_name": "Tobias",
"last_name": "Funke",
"avatar": "https://reqres.in/img/
faces/9-image.jpg"
},
{
"id": 10,
"email": "byron.fields@reqres.in",
"first_name": "Byron",
"last_name": "Fields",
"avatar": "https://reqres.in/img/
faces/10-image.jpg"
},
"id": 11,
"email": "george.edwards@reqres.in",
"first_name": "George",
"last_name": "Edwards",
"avatar": "https://reqres.in/img/
faces/11-image.jpg"
},
"id": 12,
"email": "rachel.howell@reqres.in",
"first_name": "Rachel",
"last_name": "Howell",
"avatar": "https://reqres.in/img/
faces/12-image.jpg"
],
"support": {
"url": "https://reqres.in/#support-
heading",
});
});
Response Body: JSON value check:
pm.expect(jsonData.data[0].first_name).to.eql("
Michael");
});
Writing tests | Postman Learning Center
Expect / Should - Chai (chaijs.com)
7. Validating functionality by passing Test data (Re-Testing)
7.1 Verify by Passing parameter as 1 in GET Method=>EC=Status Code-200-OK & GET Method will show
the response=Pass
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.3 Verify by Passing parameter as a Character/String Values in GET Method=>EC=Status Code-400-Bad
Request & GET Method will not show the response= Fail-Defect
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
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
This method will register existing users and set password for them
Request Headers:
Query Parameters:
This operation do not require query parameters.
Request Body:
{
"email": "eve.holt@reqres.in",
"password": "pistol"
}
Response Attributes/tagnames:
Response Examle:
{
"id": 4,
"token": "QpwL5tke4Pnpja7X4"
POST Method/Request:
POST Method Service-URL/URI= https://reqres.in/api/register
Body/Payload-
{
"email": "eve.holt@reqres.in",
"password": "pistol"
}
Username& Password(Basic Auth)/API Key/Bearer token-tcaabfj bjf lekf lklfl
Time taken for the response=5sec
Unit Testing Documents
Sample Response:
"id": 4,
"token": "QpwL5tke4Pnpja7X4"
}
Response Status Code: 200-K
Test Cases:
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
Resource: /maps/api/place/add/json
Sample Body :
{
"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"
}
Sample Response:
{
"status": "OK",
"place_id": "928b51f64aed18713b0d164d9be8d67f",
"scope": "APP",
"reference": "736f3c9bec384af62a184a1936d42bb0736f3c9bec384af62a184a1936d42bb0",
"id": "736f3c9bec384af62a184a1936d42bb0"}
Google Maps get Place API (GET):
Resource: /maps/api/place/get/json
Query Parameters: key, place_id //( place_id value comes from Add place(POST) response)
"location":{
"lat" : -38.383494,
"lng" : 33.427362
},
"accuracy":50,
"name":"Frontline house",
"website" : "http://google.com",
"language" : "French-IN"
}
Google Maps Put Place API (PUT):
This API Will update existing place in Server with new values
Sample Request:
{
"place_id":"8d2573bdf6ceec0e474c5f388fa917fb",
"address":"70 Summer walk, USA",
"key":"qaclick123"
}
Sample Response for the Provided Place_Id
{
"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"
Resource: /maps/api/place/delete/json
25/12/2023:
Miscelleneous:
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.
Get data from response of one API and refer it in Another API
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
Step 2: Use environment variables to Parameterize values to be referred
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("Username", value);
Note: The value is nothing but the value which we are getting and we will be using in
2nd request.
pm.environment.set("Username", 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
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 information 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 required.
POST: A post request is used to send data to the server, for example,Customer information,File
Upload,etc using HTML forms.
“Name”: “Pramod”,
“Job”: “QA”
PUT: Replaces all current representations of the target resource with uploaded content
Resources:
Path Parameters: are variable parts of the URL Path.They are typically used to point to a
specific resource within a collection,such as user identified by ID
https://www.google.com/images/1123343
https://www.google.com/docs/1123343
https://www.amazon.com/orders/112
Query Parameters:
Query Parameter is used to sort/filter the resources
https://www.amazon.com/orders?sort_by=2/20/2022
URI=Base URL/Resource/(Query/Path)Parameters
27/12/2023
SOAP Webservice:
<definitions>:
<types>:
- WSDL <types> element takes care of defining the data types that are used by the web
service
- WSDL allows types to be defined in separate elements so that the types are reusable.
<message>:
- The <message> element describes the data being exchanged between the web service
provider and the consumer
- Each Web Service has two message: Input and Output
<portType>:
- <portType> can combine one request and one response message into single request
response operation
- A port Type can define multiple operations
<binding>:
http://www.dneonline.com/calculator.asmx?WSDL
https://ws.footballpool.dataaccess.eu/info.wso?WSDL
WSDL WSDL
UDDI
WSDL WSDL
SOAP: Simple Object Access Protocol
- SOAP is an XML based protocol for exchanging information between web services
- SOAP is Communication Protocol
- SOAP provides data transport for web services
- All information exchange happens over a common format: XML
- XML message has defined structure: SOAP Message
- SOAP Message Consists of: Envelope, Header, Body, Fault
Envelope :( Mandatory)
- The SOAP envelope indicates the start and end of the message so that the receiver knows
when an entire message has transmitted
- The SOAP Envelope solves the problem of knowing when you are done receiving a
message and are ready to process it.
- Every SOAP Message has a root Envelope Element
- Envelope element is mandatory part of SOAP Message.
Header :( Optional)
- Contains any optional attributes of the message used in processing the message, either at
an intermediary point or at the ultimate end point
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 a SOAP
fault element in the body of the message and the fault is returned to the sender of the
SOAP Message.
SOAP Message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Add>
<tem:intA>A</tem:intA>
<tem:intB>15</tem:intB>
</tem:Add>
</soapenv:Body>
</soapenv:Envelope>
SOAP Fault:
<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(XmlSerial
izationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String
encodingStyle, XmlDeserializationEvents events)
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>
https://www.soapui.org/downloads/soapui/
Test Cases:
1. Validating response
2. Validating Data and count of data in response
3. Validating Tagname/Attributes presents in responses
4. Validating Status code in responses
5. Validating Time taken for responses
6. Applying Assertion for verification
7. Functionality(Re-Testing)
8. NEGATIVE test cases !
Execution:
QA/Dev Env(Individually)=>It will be merged to the env where you all code resides==>Regression(To
make sure existing functionality is working as expected)
7. Validating the functionality by passing Test data (Re-Testing)
7.1 Verify the SOAP Service by passing one digit numbersEC (Expected) =One digit numbers
should be added=Pass
7.2 Verify the SOAP Service by passing two digit numbersEC=two digit numbers should be
added=Pass
7.3 Verify the SOAP Service by passing Three digit numbersEC=Three digit numbers should
be added=Pass
7.4 Verify the SOAP Service by passing Four/Five digit numbersEC=Four/Five digit numbers
should be added=Pass
7.5 Verify the SOAP Service by passing one digit number at 1st place and two digit numbers at
2nd placeEC= one digit number at 1st place and two digit numbers at 2nd place should be
added=Pass
7.8 Verify by passing one positive number and one negative numberEC=Should be
added=Pass
8.2 Verify the SOAP Service by passing Character/String digit numbersEC=Should not be added=Pass
8.3 Verify by passing the values beyond integer rangeEC=Should not be added=Pass
8.4 Verify the SOAP Service by passing Null/Blank valuesEC=Should not be added=Pass
8.5 Verify the SOAP Service by passing Wrong WSDLEC=Pass
Contains
Not Contains
Valid HTTP Status Code
Invalid HTTP Status Code
Response SLA
Xpath Assertion
Xquery Match
SOAP Fault
SOAP Request
SOAP Response
NOT SOAP Fault
Schema Compliance
Script Assertion
JSON Path Count
JSON Path Existence Match
JSON Path Match
How to run Test Suite in Parallel and Sequential?
Sequential: