![](/img/trans.png)
[英]Karate API Testing - Passing variable from one feature file to another
[英]Karate API Testing - How to use a variable (output from response) from API 1 to another API in same feature
我有一個場景:調用 API - 捕獲響應 - 從響應中獲取 ID 並調用另一個從響應 1 獲取輸入 ID 的 API。
前任 :
Feature: test graphql end point
Background:
* url baseUrl + '/graphql'
Scenario: Create Org Call
Given text query =
"""
mutation {
test: createOrganization(
name: "Org Name"
)
{
Id
name
}
}
"""
And request { query: '#(query)' }
When method post
Then status 200
* def res = response
* def id = res.data.test.Id
* print 'response:', response
* print 'Id:', id
Given text query =
"""
mutation {
createBackendHistory(orgId: '#(id)') {
orgId
}
}
"""
And request { query: '#(query)' }
When method post
Then status 200
如何傳遞值(來自調用 1 的 ID)是 createBackendHistory API
當我嘗試 orgId: '#(id)' 我收到錯誤。
由於query
是text
您不能使用#()
嵌入表達式。 請參考文檔: https : //github.com/intuit/karate#replace
嘗試這個:
Given text query =
"""
mutation {
createBackendHistory(orgId: '<id>') {
orgId
}
}
"""
And replace query.id = id
And request { query: '#(query)' }
When method post
Then status 200
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.