-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAPI Script............txt
More file actions
81 lines (55 loc) · 2.44 KB
/
Copy pathAPI Script............txt
File metadata and controls
81 lines (55 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//Check status code................................................................
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
//Multiple assertion..............
pm.test("multiple value check", function () {
responseJson=pm.response.json();
pm.expect(responseJson.data.id).to.eql(2);
pm.expect(responseJson.data.email).to.eql("janet.weaver@reqres.in");
pm.expect(responseJson.data.first_name).to.eql("Janet");
pm.expect(responseJson.data.last_name).to.eql("Weaver");
});
//Body content check.................................................................
var response = JSON.parse(responseBody);
tests["verify status"] = response.status == "success";
tests["verify name"] = response.data.name == "nayem";
tests["verify age"] = response.data.age == "26";
pm.test("Body content string", function(){
pm.expect(pm.response.text()).to.include("janet.weaver@reqres.in");
})
//HTTP Status code check...............................................................
pm.test("successful status code", function(){
pm.expect(pm.response.code).to.be.oneOf([200,201,401]);
})
//Header Check..........................................................................
pm.test("Test Header", function(){
pm.response.to.be.header("Content-Type","application/json; charset=utf-8");
})
pm.test("Test Header Content-Length", function(){
pm.response.to.be.header("Content-Length","122");
})
pm.test("Content type header check", function(){
pm.response.to.have.header("Content-Type");
})
pm.test("Content type value", function(){
pm.expect(pm.response.headers.get("Content-Type")).to.eql("application/json; charset=utf-8");
})
//Cookies Check...............................................................
tests["Cookie test"] = postman.getResponseCookie("Cookie_1").value;
pm.test("Cookies is present", function(){
pm.expect(pm.cookies.has("Cookie_1")).to.be.true;
})
pm.test("cookies value check", function(){
pm.expect(pm.cookies.get("Cookie_1")).to.eql("value");
})
//Check Response Body size................................................................
pm.test("check response Time", function(){
pm.expect(pm.response.responseSize).to.be.eql(1220);
})
var size=0;
for (var count in responseBody) {
if(responseBody.hasOwnProperty(count))
size += 1;
}
console.log("BODY SIZE = " + size);