0
我是REST Assured框架的新手。我寫了下面的代碼。它工作正常。如何訪問其他測試中的變量RESt保證
private static String result;
@Test
public void getStudentById() {
Response response =
given().
header("authToken",userToken).
pathParam("SNum", "A123").
when().
get("/students/{SNum}").
then().
contentType(ContentType.JSON).
body("firstName",equalTo("JOHN")).
extract().
response();
result = response.print();
System.out.println("Response************************" + result);
}
@Test
public void StTest() {
System.out.println("Response************************" + result);
}
在我收到的響應JSON數據
{"list":
[
{
"id": 0,
"SNum": "A123",
"title": "Mr",
"firstName": "JOHN",
"lastName": "Doe"
},
{
"id":1 ,
"SNum": "A12",
"title": "Mr",
"firstName": "James",
"lastName": "Pesr"
}
]
}
在這裏,我需要id
在第二次測試。所以我在第二次測試中打印結果變量,但它變得null
。如何在第二次測試中獲得結果變量。
你想用id做什麼?獲取第一個id並斷言它等於某個值,或者您想要聲明您的列表包含某個id或包含幾個id? –