尝试在第一个方法之外验证一些JSON值。在第二种方法中,最好的方法是什么?
@When("^User sends API request with (.*) and no qualifiers and an State Code entry level T1.3$")
public void user_sends_API_request_with_no_qualifiers_and_an_entry_level_T(String path) {
response =
given()
.auth().oauth2(DomaniRx_RestAssuredOAuth2.access_token_code)
.queryParam("PhamacyID","12345")
.queryParam("Customer Set Type ID", "CustomerSetTypeValue")
.queryParam("PharmacyListIDShortName","Value")
.queryParam("DateFilled","04/17/2022")
.get(defaultURL+path)
.then()
.statusCode(200)
.extract().response();
}
@Then("^The Pharmacy ID in the response should match the (\d+) in the request T1.3$")
public void the_Pharmacy_ID_in_the_response_should_match_the_in_the_request_T(String PharmacyID) {
}
我不知道best
方式,但我认为实现这一目标的一种方法是将response
作为实例变量,然后您可以从同一类中的其他方法访问它。
如果你想在类外共享response
,那么使用类(静态)变量
你可以像下面这样给你的响应体分配一个变量:然后,您可以轻松地在其他方法上进行断言。您可以根据您的响应定义一个responsemmodel。它的名称可以更改。由你决定。
private ResponseModel response;
.
response =
given()
.auth().oauth2(DomaniRx_RestAssuredOAuth2.access_token_code)
.queryParam("PhamacyID","12345")
.queryParam("Customer Set Type ID", "CustomerSetTypeValue")
.queryParam("PharmacyListIDShortName","Value")
.queryParam("DateFilled","04/17/2022")
.get(defaultURL+path)
.then()
.statusCode(200)
.extract().response()
.jsonPath().getObject(".", ResponseModel .class);