Karate DSL: Gửi một request GET như thế nào?

Chuyên mục cung cấp giải pháp kiểm thử tự động và giúp các bạn tìm hiểu sâu hơn về cách viết chương trình kiểm thử cho từng loại dự án riêng của mình.
Forum rules
Chỉ thảo luận các vấn đề liên quan đến kiểm thử tự động
Post Reply
cuhavp
Jr. Tester
Posts: 61
Joined: Mon 21 Jan, 2013 3:52 pm
Contact:

Karate DSL: Gửi một request GET như thế nào?

Post by cuhavp »

Mình tiếp tục với Series Karate DSL, sau phần bắt đầu làm việc với Karate DSL
topic này mình sẽ làm một ví dụ đơn giản, viết 1 scenario để gửi một GET request

Bạn tạo một file Get-Demo.feature với nội dung như dưới đây:

Code: Select all

@booking
Feature: booking ids
  Return the ids of all the bookings that existing within the API.
  Can take optional query strings to search and return a subset of booking ids.

  Background:
    * url 'http://restful-booker.herokuapp.com'

  Scenario: get all
    Given path 'booking'
    When method get
    Then status 200
    And match each response == { bookingid: '#number'}
Rồi để run nó bản Click chuột phải >> Run Feature : Get-Demo và kết quả là :

Code: Select all

10:17:32.599 [main] INFO  com.intuit.karate - karate.env system property was: null 
10:17:32.977 [main] DEBUG com.intuit.karate - request:
1 > GET http://restful-booker.herokuapp.com/booking
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Host: restful-booker.herokuapp.com
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_181)

10:17:34.094 [main] DEBUG com.intuit.karate - response time in milliseconds: 1116
1 < 200
1 < Accept-Ranges: none
1 < Connection: keep-alive
1 < Content-Length: 162
1 < Content-Type: application/json; charset=utf-8
1 < Date: Wed, 28 Nov 2018 03:17:36 GMT
1 < Etag: W/"a2-wj5+ACNAorUHyr/ARRCoPr05tSE"
1 < Server: Cowboy
1 < Via: 1.1 vegur
1 < X-Powered-By: Express
[{"bookingid":6},{"bookingid":8},{"bookingid":2},{"bookingid":1},{"bookingid":4},{"bookingid":9},{"bookingid":10},{"bookingid":5},{"bookingid":3},{"bookingid":7}]




Post Reply

Return to “Automation Framework”