Citrus Framework - 可以从响应中分配 API 调用变量吗?
Citrus Framework - Can an API call variable be assigned from a response?
我想 POST 一个新对象并使用响应中的一个字段将我的 URI 映射到正确的 resourceId。我在路径中使用 @variable('resourceId')@,但它使用文字 URI 字符串来发出请求,而不是使用 POST 响应中的 resourceId 进行填充。
有什么方法可以让它发挥作用吗?谢谢。
Given message itemPostRequestSingle
And <itemPostRequestSingle> header Content-Type is "application/json;charset=utf-8"
And <itemPostRequestSingle> header citrus_http_method is "POST"
-----> And <itemPostRequestSingle> header citrus_request_path is "/path/@variable('resourceId')@/path"
And <itemPostRequestSingle> payload is
"""
[
{
"relativeId": "${relativeId2}"
}
]
"""
Given message itemPostResponseSingle
And <itemPostResponseSingle> header Content-Type is "application/json;charset=utf-8"
And <itemPostResponseSingle> header citrus_http_status_code is "201"
And <itemPostResponseSingle> header citrus_http_reason_phrase is "CREATED"
And <itemPostResponseSingle> payload is
"""
[
{
"relativeId": "${relativeId}"
},
{
"relativeId": "${relativeId2}"
}
]
"""
Scenario: Example
Given variables
| relativeId | citrus:randomString(10,false) |
| relativeId2 | citrus:randomString(10,false) |
When <ApiClient> sends message <PostRequest>
And <ApiClient> should receive Json message <PostResponse>
And <ApiClient> sends message <itemPostRequestSingle>
Then <ApiClient> should receive Json message <itemPostResponseSingle>
您混淆了 @variable('resourceId')@
等验证匹配器表达式和 ${resourceId}
等变量引用。
您的 itemPostRequestSingle
应该使用变量引用。您的 PostResponse
应该使用验证匹配器表达式,以便将 id 提取到变量 resourceId
.
所以想法是使用验证匹配表达式 @variable('resourceId')@
提取 resourceId
值,以便稍后在测试用例中使用 ${resourceId}
.[=18 引用变量=]
我想 POST 一个新对象并使用响应中的一个字段将我的 URI 映射到正确的 resourceId。我在路径中使用 @variable('resourceId')@,但它使用文字 URI 字符串来发出请求,而不是使用 POST 响应中的 resourceId 进行填充。
有什么方法可以让它发挥作用吗?谢谢。
Given message itemPostRequestSingle
And <itemPostRequestSingle> header Content-Type is "application/json;charset=utf-8"
And <itemPostRequestSingle> header citrus_http_method is "POST"
-----> And <itemPostRequestSingle> header citrus_request_path is "/path/@variable('resourceId')@/path"
And <itemPostRequestSingle> payload is
"""
[
{
"relativeId": "${relativeId2}"
}
]
"""
Given message itemPostResponseSingle
And <itemPostResponseSingle> header Content-Type is "application/json;charset=utf-8"
And <itemPostResponseSingle> header citrus_http_status_code is "201"
And <itemPostResponseSingle> header citrus_http_reason_phrase is "CREATED"
And <itemPostResponseSingle> payload is
"""
[
{
"relativeId": "${relativeId}"
},
{
"relativeId": "${relativeId2}"
}
]
"""
Scenario: Example
Given variables
| relativeId | citrus:randomString(10,false) |
| relativeId2 | citrus:randomString(10,false) |
When <ApiClient> sends message <PostRequest>
And <ApiClient> should receive Json message <PostResponse>
And <ApiClient> sends message <itemPostRequestSingle>
Then <ApiClient> should receive Json message <itemPostResponseSingle>
您混淆了 @variable('resourceId')@
等验证匹配器表达式和 ${resourceId}
等变量引用。
您的 itemPostRequestSingle
应该使用变量引用。您的 PostResponse
应该使用验证匹配器表达式,以便将 id 提取到变量 resourceId
.
所以想法是使用验证匹配表达式 @variable('resourceId')@
提取 resourceId
值,以便稍后在测试用例中使用 ${resourceId}
.[=18 引用变量=]