These assertions work similary for cookies & headers.
See also:
Assert some property matches an exact literal value.
1link - name: get users
2link request:
3link path: /users
4link method: get
5link response:
6link headers:
7link - name: content-type
8link value: application/json
9link cookies:
10link - name: x-xsrf-token
11link value: 4f3b2209-3b75-4a8a-bd10-d0b8f02a9c07
Assert some property matches a regular expression.
1link - name: get users
2link request:
3link path: /users
4link method: get
5link response:
6link headers:
7link - name: content-type
8link value: !!js/regexp /json/
9link cookies:
10link - name: x-xsrf-token
11link value: !!js/regexp /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/
Write custom code to do your own assertions.
Functions context is bound to the spec context, so this.response
has all the relevant properties.
Properties:
response.body
response.statusCode
response.statusMessage
response.headers
response.body
response.duration
1link - name: get users
2link request:
3link path: /users
4link method: get
5link response:
6link status_code: 200
7link custom_validator:
8link run_type: inline
9link inline:
10link function: !!js/function >
11link function() {
12link var users = JSON.parse(this.response.body);
13link if (!users.length) {
14link throw new Error('no users found');
15link }
16link if (users[0].firstName !== 'john') {
17link throw new Error('first user in list is not john');
18link }
19link if (this.response.duration > 2000) {
20link throw new Error('request took longer than expected');
21link }
22link }
1link - name: get users
2link request:
3link path: /users
4link method: get
5link response:
6link status_code: 200
7link custom_validator:
8link run_type: module
9link module:
10link module_path: lib/helpers/path-to-a-file.js
11link function_name: validateUsersList