topic này mình sẽ tiếp tục với POST request, đầu tiên mình tạo một file có tên là Post-Demo.feature có nội dung như dưới đây:
Code: Select all
@auth
Feature: Authentication
Background:
* url 'http://restful-booker.herokuapp.com'
Scenario: Create token
Given path 'auth'
And request { "username" : "admin" , "password" : "password123" }
When method post
Then status 200
* print response.token
Code: Select all
10:21:43.239 [main] INFO com.intuit.karate - karate.env system property was: null
10:21:43.615 [main] DEBUG com.intuit.karate - request:
1 > POST http://restful-booker.herokuapp.com/auth
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 45
1 > Content-Type: application/json; charset=UTF-8
1 > Host: restful-booker.herokuapp.com
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_181)
{"username":"admin","password":"password123"}
10:21:44.477 [main] DEBUG com.intuit.karate - response time in milliseconds: 862
1 < 200
1 < Accept-Ranges: none
1 < Connection: keep-alive
1 < Content-Length: 27
1 < Content-Type: application/json; charset=utf-8
1 < Date: Wed, 28 Nov 2018 03:21:46 GMT
1 < Etag: W/"1b-tS/rSisH1WmRV+W8v2hSKW7O/oc"
1 < Server: Cowboy
1 < Via: 1.1 vegur
1 < X-Powered-By: Express
{"token":"7b4b7b96bca29c3"}