-
Notifications
You must be signed in to change notification settings - Fork 1
/
PostMan Script
95 lines (62 loc) · 1.86 KB
/
PostMan Script
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
82
83
84
85
86
console.log(pm.response.code);
console.log(pm.response.responseTime)
console.log("Check global veriable :" + pm.globals.get("url"));
console.log("Check global veriable :" + pm.variables.get("url"));
console.log("Check local veriable :" + pm.variables.get("localVerable"));
console.log("Check enviroment veriable :" + pm.environment.get("userid"));
console.log("Check enviroment veriable :" + pm.variables.get("userid"));
postman.setNextRequest("Login User");
postman.setNextRequest("null")
var jsonData = pm.response.json();
pm.environment.set("userid", jsonData.id);
var schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"email": {
"type": "string"
},
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"avatar": {
"type": "string"
}
},
"required": [
"id",
"email",
"first_name",
"last_name",
"avatar"
]
}
},
"required": [
"data"
]
}
var json = pm.response.json();
pm.test("schema is valid", function(){
pm.expect(tv4.validate(json, schema)).to.be.true;
})
postman - how to generate random number in specific range?
-----------------------------------------------------------------
pm.globals.set('randomNumber', Math.floor(Math.random() * 10));
----------------------------------------------------------
pm.variables.set("name", "postman");
console.log(pm.variables.get("name"));
let varURL = pm.variables.get("url");
console.log("request url : " + varURL);
let globalVAR = pm.globals.get("env");
console.log(globalVAR);
------------------------------------------------------------