gpt4 book ai didi

Karate API 测试 - 如何在同一功能中使用从 API 1 到另一个 API 的变量(响应输出)

转载 作者:行者123 更新时间:2023-12-01 01:46:46 25 4
gpt4 key购买 nike

我有一个场景:
调用 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)' 我收到错误。

最佳答案

querytext您不能使用 #()嵌入表达式。请引用文档: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

关于 Karate API 测试 - 如何在同一功能中使用从 API 1 到另一个 API 的变量(响应输出),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48213144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com