RestAssured-SDET QA
RestAssured-SDET QA
-----------------
1. Java9 + & Eclispe
2. TestNG
3. Maven (comes with Eclipse)
Dependencies
-----------------
rest-assured
json-path
json
gson
testng
scribejave-apis
json-schema-validator
xml-schema-validator
HTTP Requests
-----------------
GET
POST
PUT
DELETE
PATCH
GET Users:
https://reqres.in/api/users?page=2
POST Users:
https://reqres.in/api/users
{
"name": "morpheus",
"job": "leader"
}
UPDATE User:
https://reqres.in/api/users/2
{
"name": "morpheus",
"job": "zion resident"
}
DELETE User:
https://reqres.in/api/users/2
204
4 Different Ways to Create Request Body
--------------------------------------------
1. HashMap
2. Using org.json
3. POJO (Plain Old Java Object)
Create a new POJO class.
Create a class getters and setters.
4. External JSON File
Create a new 'body.json' file.
File f = new File(".\\body.json");
FileReader fr = new FileReader(f);
JSONTokener jt = new JSONTokener(fr);
JSONObject data = new JSONObject(jt);
http://reqres.in/api/users?page=2&id=5
Header
.header("Content-Type", "")
Headers myheaders = res.getHeaders();
for(Header k:myheaders)
{
System.out.println(k.getName()+" "+k.getValue());
}
Response res=given()
.contentType(ContentType.JSON)
.when()
.get("http://localhost:3000/store");
Assert.assertEquals(res.getStatusCode(), 200);
Assert.assertEquals(res.header("Content-Type"), "application/json");
boolean status=false;
for(int i=0; i<jo.getJSONArray("book").length(); i++)
{
String bookTitle =
jo.getJSONArray("book").getJSONObject(i).get("title").toString();
if(bookTitle.equals("Moby Dick"))
{
status=true;
break;
}
Assert.assertEquals(status, true);
double totalprice = 0;
for(int k=0; k<jo.getJSONArray("book").length(); k++)
{
String bookPrice =
jo.getJSONArray("book").getJSONObject(k).get("price").toString();
totalprice = totalprice+Double.parseDouble(bookPrice);
}
http://restapi.adequateshop.com/swagger/ui/index
https://fakerestapi.azurewebsites.net/index.html
https://thetestrequest.com/authors.xml
Authorization
-------------
It is like the user is valid. But, whether the user has the permission or access.
Authentication
----------------
It will check whether the user is valid or not. Valid credentials or not.
Secret key 1:
EGoMwONbJCjARU_FsX5rPry4rKd7juKAUFGj6YGEl4iKoOUFdiYQSppTcO_g4LP8EiJyifAnRO1dmpua
5. API Key
6. Preemptive
Faker library
Chaining
------------
It is a process wherein we send a request and the data or response that we receive
now can be used to create another request to fetch further data or response.
GoRest
Create User --> Get User --> Update User --> Delete User
context.getSuite().getAttribute()
Once the suite is defined globally. It is anyway accessible by the local method.
Framework Development
------------------------
When we try to automate many test cases and maintain all project related files.
Objective of Designing an Automation Framework:
Reusability, Maintainability, Readability
3. Design Framework
4. Development
5. Execution + CI
1. Development
2. Execution
3. CI
Routes: It is like a single class where all the URLs are maintained for all
the modules.
We'll create class for each and every module.
Test Cases: Creating test cases for the modules. User Tests, Store Tests, Pet
Tests. Once the Test cases are ready, they'll be executed by the TestNG file. And
then later we'll run through pom.xml.
Payload--> Creating the required data. (POJO classes are required.)User, Store and
Pet.
Utilities--> DataProviders
Extent Report
XL Utility
---------------------------------------
Pre-Requisites
Step 1: Create a Maven project.