我正在尝试测试以下两个 REST 调用:
请求 1
GET getLatestVersion
Response: {"version": 10}
请求 2
POST getVersionData (body={"version": 10})
Response: {"version": 10, data: [...]}
是否可以将请求 1 中的“版本”分配给一个变量以在同一测试中的请求 2 中使用?
@CitrusTest(name = "SimpleIT.getVersionTest")
public void getVersionTest() {
// Request 1
http()
.client("restClient")
.send()
.get("/getLatestVersion")
.accept("application/json");
http()
.client("restClient")
.receive()
.response(HttpStatus.OK)
.messageType(MessageType.JSON)
// Can the version be assigned to a variable here?
.payload("{\"version\":10}");
// Request 2
http()
.client("restClient")
.send()
.post("/getVersionData")
// Idealy this would be a Citrus variable from the previous response
.payload("{\"version\":10}")
.accept("application/json");
http()
.client("restClient")
.receive()
.response(HttpStatus.OK)
.messageType(MessageType.JSON)
.payload("\"version\": 10, data: [...]");
}