【发布时间】:2018-07-21 10:49:48
【问题描述】:
我使用 restAssured 创建了两个 java 类 TestA.java、TestB.java,其中每个类都从 TestA.json 读取 json和 testB.json 并向端点 uri.TestA.java 发布请求,返回带有标签“customerID”的 json 响应,该响应将作为 标签之一的输入>TestB.json 并且每当我使用“TestB.java”发布请求时,必须从 TestB.json 中挑选客户 ID。我的代码是什么样的?有什么想法吗?
我的代码:
TestA.java
String requestBody = generateString("CreateCustomer.json");
RestAssured.baseURI = "https://localhost:8080";
Response res = given().contentType(ContentType.JSON)
.header("Content-Type", "application/json").header("checkXML", "N").body(requestBody).when()
.post("/restservices/customerHierarchy/customers").then().assertThat()
.statusCode(201).and().body("transactionDetails.statusMessage", equalTo("Success")).and().log().all()
.extract().response();
//converts response to string
String respose = res.asString();
JsonPath jsonRes = new JsonPath(respose);
CustomerID = jsonRes.getString("customerNodeDetails.customerId");
TestA.java response
{
"customerNodeDetails": {
"customerId": "81263"
},
现在我想将这个customerID 作为输入传递给testB.json 或testB.java,这是动态的。
TestB.json
"hierarchyNodeDetails": {
"**customerId**":"",
"accountNumber": "",
"startDate": "",
}
TestA.java 和 TestB.java 看起来几乎相同,除了 post uri
提前致谢
【问题讨论】:
标签: json rest-assured rest-assured-jsonpath