我有一個父 URL,它回傳一個帶有 id 和 slug 的物件陣列,這是動態生成的,因為它取決于用戶(測驗環境)。獲取此資料后,如何從陣列中動態呼叫每個元素物件并發出另一個請求?
例子 :
Scenario: parent
Given url 'posts'
Then Status 200
* assert response.status == true
示例 url/posts 回傳物件陣列的資料:
[
{id: 6, slug: 'my-post-6'},
{id: 23, slug: 'example-test-23'},
{id: 133, slug: 'another-test-133'},
]
然后我想向每個物件發出一個 get 請求,如下所示: url 'posts/' data.slug
我怎樣才能做到這一點 ?
GET url 'posts/my-post-6'
// Validate schema
GET url 'posts/example-test-23'
// Validate schema
GET url 'posts/another-test-133'
// Validate schema
uj5u.com熱心網友回復:
空手道的call關鍵字在 JSON 物件陣列上自動回圈。參考檔案:https ://github.com/karatelabs/karate#data-driven-features
你可以試試這個簡單的例子:
Feature:
Scenario:
* def data = [{ slug: 'one'}, { slug: 'two'}]
* call read('@called') data
@called @ignore
Scenario:
* url 'https://httpbin.org/anything'
* path slug
* method get
這在未來的版本中會得到改進,請參閱:https ://github.com/karatelabs/karate/issues/1905 (現在在 1.3.0.RC2 中可用)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/516728.html
標籤:测试自动化测试空手道
上一篇:無法找到并單擊條件條款按鈕
下一篇:在AzurePipelines.yml檔案中使用(任務:DotNetCoreCLI@2)是否可以添加一個引數來重新運行失敗的測驗
