Scenario: [1:7]
Simple POST
ms: 475
>>
Background:
4
* url 'https://reqres.in/api'
1
5
* header Accept = 'application/json'
0
8
Given path '/users'
0
9
And request {"name": "iUser", "job": "coder"}
0
10
When method POST
462
23:37:50.364 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:37:50.806 response time in milliseconds: 442
1 < 201
1 < Date: Fri, 11 Aug 2023 23:37:50 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-61zugIMatUAImi1DIF41pgMg/6k"
1 < Via: 1.1 vegur
1 < CF-Cache-Status: DYNAMIC
1 < Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=VBaQv%2FgOMICXHVtmoJN6u6g7BseE%2FiISg%2FIEEgk52rS15lkiN0iFVrcgmdX31%2BlDdH1AwPDUitK2Qxvvx1uZJzAF1vFLEEHbezWeGMDX3kZcQrLG5BIjUNfSTg%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: 7f544f0b49bb38fd-IAD
{"name":"iUser","job":"coder","id":"513","createdAt":"2023-08-11T23:37:50.754Z"}
11
Then status 201
0
12
And print response
2
23:37:50.809 [print] {
"name": "iUser",
"job": "coder",
"id": "513",
"createdAt": "2023-08-11T23:37:50.754Z"
}
13
And match $.id == '#string'
9
Scenario: [2:15]
Simple POST with payload from file
ms: 455
>>
Background:
4
* url 'https://reqres.in/api'
0
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)
13
19
* set body.job = 'developer'
27
20
Given path '/users'
0
21
And request body
0
22
When method POST
410
23:37:50.399 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:37:50.802 response time in milliseconds: 403
1 < 201
1 < Date: Fri, 11 Aug 2023 23:37:50 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-Ibac5bzGeaMbD5HmbTFPh85JZYg"
1 < Via: 1.1 vegur
1 < CF-Cache-Status: DYNAMIC
1 < Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=ZdRQXIePFGAwqvXbSSrv%2FfZFoS8hP3mtQEfBJyHfA%2F%2B7l0W65KHTm05EkuH1njMGqdonmVV%2FBALPOFTCHIIWGinNwb%2F7l64D0aBAmTnk9a0PLklzKHN3QJodPw%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: 7f544f0b4bde8284-IAD
{"name":"iUser","job":"developer","id":"565","createdAt":"2023-08-11T23:37:50.754Z"}
23
Then status 201
0
24
And print response
1
23:37:50.814 [print] {
"name": "iUser",
"job": "developer",
"id": "565",
"createdAt": "2023-08-11T23:37:50.754Z"
}
25
And match $.id == '#string'
1