:如何在Citrus框架中以两种不同的方法(在同一步骤中)重用相同的HTTP消息
:
;
黄瓜3.0.2
;
爪哇8
吃这个小黄瓜:
Scenario: Client has permission to access the action
Given that client has access to action
When the client calls the endpoint /some-endpoint/client/1/action/some-action
Then the client receives status code of 200
And the client receives a response with {"action" : "some-action", "permission": "AUTHORIZED"}
JAVA
代码:
@Then("the client receives status code of {int}")
public void the_client_receives_status_code_of(Integer statusCode) {
designer.http().client(httpClient).receive().response(HttpStatus.valueOf(statusCode))
.contentType("application/json;charset=UTF-8"):
}
@Then("the client receives a response with {string}")
public void the_client_receives_a_response_with(String payload) {
designer.http().client(httpClient).receive().response().payload(payload);
}
如果运行此代码,它将在方法中给出一个超时
the_client_receives_a_response_with
自从
希望收到第二条消息(
send
方法只调用了一次)。
这里的目标是将
超文本传输协议
代码,因此通过创建两个方法进行分离。如何重用方法中接收的消息
the_client_receives_status_code_of
?
为接收到的消息命名:
designer.http().client(httpClient).receive().response(HttpStatus.valueOf(statusCode)).name("currentMessage")
.contentType("application/json;charset=UTF-8");
但是尝试这样访问消息:
@CitrusResource
private TestContext testContext;
...
testContext.getMessageStore().getMessage("currentMessage");
退换商品
null
designer.echo("citrus:message(currentMessage)");
打印正确的消息。
那么,我如何访问Java代码中的消息,即访问消息以执行以下操作:
Assert.assertTrue(testContext.getMessageStore().getMessage("currentMessage").getPayload().equals(payload));