You are on page 1of 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