Scenario: [1:7]
Simple POST
ms: 549
>>
Background:
4
* url 'https://reqres.in/api'
0
5
* header Accept = 'application/json'
0
8
Given path '/users'
0
9
And request {"name": "iUser", "job": "coder"}
0
10
When method POST
544
23:55:08.235 request:
1 > POST https://reqres.in/api/users
1 > Accept: application/json
1 > Content-Type: application/json; charset=UTF-8
1 > Content-Length: 30
1 > Host: reqres.in
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_382)
1 > Accept-Encoding: gzip,deflate
{"name":"iUser","job":"coder"}
23:55:08.760 response time in milliseconds: 525
1 < 201
1 < Date: Fri, 11 Aug 2023 23:55:08 GMT
1 < Content-Type: application/json; charset=utf-8
1 < Content-Length: 80
1 < Connection: keep-alive
1 < X-Powered-By: Express
1 < Access-Control-Allow-Origin: *
1 < Etag: W/"50-jx+aA8BxF6j8MFRnERtKOrREj/o"
1 < Via: 1.1 vegur
1 < CF-Cache-Status: DYNAMIC
1 < Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=fmVFh2hF1NRfStcHNmr9h9jwA1axmh9oL4E%2BiSftzV2zY3KO2x4%2F9c9IxuMRp2OKXj4f5f3PNxeq0O1S9PxO87IAsEfUlUhjOLHBnUDkGiArKiDvg67cOi5pzw%3D%3D"}],"group":"cf-nel","max_age":604800}
1 < NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
1 < Server: cloudflare
1 < CF-RAY: 7f5468620b5d486f-DFW
{"name":"iUser","job":"coder","id":"814","createdAt":"2023-08-11T23:55:08.690Z"}
11
Then status 201
0
12
And print response
2
23:55:08.767 [print] {
"name": "iUser",
"job": "coder",
"id": "814",
"createdAt": "2023-08-11T23:55:08.690Z"
}
13
And match $.id == '#string'
1
Scenario: [2:15]
Simple POST with payload from file
ms: 584
>>
Background:
4
* url 'https://reqres.in/api'
11
5
* header Accept = 'application/json'
0
16
* def path = karate.properties['user.dir']
1
17
* def file = path + '/src/test/resources/payload/post.json'
1
18
* def body = read('file:' + file)
2
19
* set body.job = 'developer'
25
20
Given path '/users'
0
21
And request body
0
22
When method POST
535
23:55:08.282 request:
1 > POST https://reqres.in/api/users
1 > Accept: application/json
1 > Content-Type: application/json; charset=UTF-8
1 > Content-Length: 34
1 > Host: reqres.in
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_382)
1 > Accept-Encoding: gzip,deflate
{"name":"iUser","job":"developer"}
23:55:08.815 response time in milliseconds: 533
1 < 201
1 < Date: Fri, 11 Aug 2023 23:55:08 GMT
1 < Content-Type: application/json; charset=utf-8
1 < Content-Length: 84
1 < Connection: keep-alive
1 < X-Powered-By: Express
1 < Access-Control-Allow-Origin: *
1 < Etag: W/"54-J4dvjQ9DVHmGi4jzwYNquw5U0S8"
1 < Via: 1.1 vegur
1 < CF-Cache-Status: DYNAMIC
1 < Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=BNz%2F%2BcL%2BRAcvZ%2BvOHCv6xeyCgZ2ZjSXGOy%2B%2BpgbAc324RIJERLOSEtuzjDVmNddV7mtq9PHvgg5pYTbSzKlGaoN3Cce7mz1fDgS%2BfIUBnaD00PlIGl%2BMJ5zOKA%3D%3D"}],"group":"cf-nel","max_age":604800}
1 < NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
1 < Server: cloudflare
1 < CF-RAY: 7f5468626c514775-DFW
{"name":"iUser","job":"developer","id":"804","createdAt":"2023-08-11T23:55:08.747Z"}
23
Then status 201
0
24
And print response
7
23:55:08.822 [print] {
"name": "iUser",
"job": "developer",
"id": "804",
"createdAt": "2023-08-11T23:55:08.747Z"
}
25
And match $.id == '#string'
1