0% found this document useful (0 votes)
34 views17 pages

BUILDING BLOCKS First Test

This document discusses testing an API response. It outlines 12 test cases to check the response body, status, headers, and cookies. These include validating the JSON format, required fields, field values, response time, status code, headers, and cookies. Implementing these checks would automate what takes 7-10 minutes to do manually. The document then provides Postman code to implement the 12 test cases to validate the API response.

Uploaded by

Artur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views17 pages

BUILDING BLOCKS First Test

This document discusses testing an API response. It outlines 12 test cases to check the response body, status, headers, and cookies. These include validating the JSON format, required fields, field values, response time, status code, headers, and cookies. Implementing these checks would automate what takes 7-10 minutes to do manually. The document then provides Postman code to implement the 12 test cases to validate the API response.

Uploaded by

Artur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

BUILDING BLOCKS:

First Test
First test

https://swapi.co
First test

https://swapi.co
First test

https://swapi.co
First test

https://swapi.co
First test
What to check?

1. Response body, status, time

https://swapi.co 2. Headers
3. Cookies
First test

Response body cases:

1. Correct response format JSON


https://swapi.co 2. We have all the declared fields in the response.
3. Field value is not NULL
4. Field value is not empty
5. The field corresponds to a specific value.
First test

Response status, time cases:

https://swapi.co 1. Status code is 200


2. Status message is OK
3. Response time is less than 1000ms
First test
Response headers
cases:

1. There is a specific header


in the response.

https://swapi.co 2. The response has a


specific header with a
specific value.
First test Response cookies cases:

1. Cookie exists

https://swapi.co 2. Cookie has value


Total:
First test
12 cases

If we wrote a check list and passed on it all these checks,


it took us about 7-10 minutes of manual work.
https://swapi.co
But ...
First test

https://swapi.co
//1. Correct response format JSON
pm.test("Check response format JSON", function () {
First test pm.response.to.have.jsonBody()
});

//2. We have all the declared fields in the response.


pm.test("Check that we have all the declared fields", function () {
const jsonData = pm.response.json();
https://swapi.co //It is recommended to use to.have.property instead of to.
//include since the first one checks the key, and the second
//is only a match in the answer for the given word.
//pm.expect(pm.response.text()).to.include("people");
pm.expect(jsonData).to.have.property("people");
pm.expect(jsonData).to.have.property("planets");
pm.expect(jsonData).to.have.property("films");
pm.expect(jsonData).to.have.property("species");
pm.expect(jsonData).to.have.property("vehicles");
pm.expect(jsonData).to.have.property("starships");
});
//3. Field value is not NULL
pm.test("Check if value is not NULL", function () {
var jsonData = pm.response.json();
First test pm.expect(jsonData.people).not.equal(null);
pm.expect(jsonData.planets).not.equal(null);
pm.expect(jsonData.films).not.equal(null);
pm.expect(jsonData.species).not.equal(null);
pm.expect(jsonData.vehicles).not.equal(null);
pm.expect(jsonData.starships).not.equal(null);

https://swapi.co });

//4. Field value is not empty


pm.test("Check if value is not empty", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.people).not.equal("");
pm.expect(jsonData.planets).not.equal("");
pm.expect(jsonData.films).not.equal("");
pm.expect(jsonData.species).not.equal("");
pm.expect(jsonData.vehicles).not.equal("");
pm.expect(jsonData.starships).not.equal("");
});
//5. The field corresponds to a specific value.
pm.test("Check if field corresponds to a specific value", function () {
var jsonData = pm.response.json();
First test pm.expect(jsonData.people).to.eql("https://swapi.co/api/people/");
pm.expect(jsonData.planets).to.eql("https://swapi.co/api/planets/");
pm.expect(jsonData.films).to.eql("https://swapi.co/api/films/");
pm.expect(jsonData.species).to.eql("https://swapi.co/api/species/");
pm.expect(jsonData.vehicles).to.eql("https://swapi.co/api/vehicles/");
pm.expect(jsonData.starships).to.eql("https://swapi.co/api/starships/");

https://swapi.co });

//6. Status code is 200


pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

//7. Status message is OK


pm.test("Status code name has string", function () {
pm.response.to.have.status("OK");
});
First test //8. Response time is less than 1000ms
pm.test("Response time is less than 1000ms", function () {
pm.expect(pm.response.responseTime).to.be.below(1000);
});

//9. There is a specific header in the response.

https://swapi.co pm.test("Content-Type is present", function () {


pm.response.to.have.header("Content-Type");
});

//10. The response has a specific header with a specific value.


pm.test("Content-Type is application/json", function () {
pm.response.to.be.header("Content-Type", "application/json");
});
First test //11. Cookie exists
pm.test("Cookie exists", function () {
pm.cookies.has("__cfduid");
});

//12. Cookie has value


https://swapi.co pm.test("Cookie exists", function () {
try {
var MY_COOKIE = pm.cookies.get("__cfduid");
console.log(MY_COOKIE);
} catch(e) {
console.log("SOME PROBLEM WITH COOKIE ->" + e);
}
});

You might also like