我有一个场景: 调用API - 捕获响应 - 从响应中获取ID并调用另一个API,该API从响应1获取输入ID。
前:
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)'我收到了错误。
答案 0 :(得分:1)
由于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