【发布时间】:2019-12-25 14:17:34
【问题描述】:
我有一个测试类,其测试方法需要运行“n”次。数字 n 来自 API 响应。我尝试将“n”传递给测试方法的 invocationCount,但它说 invocationCount 只能接受一个常量值,而不是来自变量。
我试图浏览 IAnnotationTransformers 文档,但我无法理解我需要在测试中进行哪些更改才能实现它。
这里是代码
public class JourneySearch1PaxTest {
.....
@BeforeClass
public void setup() {
reqSpec = RestUtilities.getRequestSpecification();
authtoken = RestUtilities.createAuthToken();
// System.out.println("Auth_Token is " +authtoken);
reqSpec.header("Authorization", "Bearer " + authtoken);
reqSpec.basePath(Path.V2_APIS);
resSpec = RestUtilities.getResponseSpecification();
}
...few methods.....
@Test
public void GetNumbers() throws Exception {
Response response=
given()
//.log().all()
.spec(reqSpec)
.pathParams("service_name", ServiceName, "travel_date", TravelDate, "origin", Origin, "destination", Destination)
.when()
.get(EndPoints.SERVICE_DETAILS)
.then()
.log().all()
.spec(resSpec)
.extract().response()
JsonPath jsPath = RestUtilities.getJsonPath(response);
BBucket = jsPath.getString("data.inventory_details[1].remaining_capacity");
System.out.println("BBucketCapacity:" +BBucket);
BBucketTBL=(Integer.parseInt(BBucket)*Integer.parseInt(LoadCapacity)/100);
System.out.println("BBucketCapacityTBL:" +BBucketTBL);
}
@Test(invocationCount = BBucketTBL)
public void CreateBookings() throws IOException {
JSONObject jObject = PrepareJourneySearchRequestBody(Origin,Destination,TravelDate);
Response response =
given()
//.log().all()
.spec(reqSpec)
.body(jObject.toString())
.when()
.post(EndPoints.JOURNEY_SEARCH)
.then()
.spec(resSpec)
.extract().response();
JsonPath jsPath = RestUtilities.getJsonPath(response);
TariffCode = GetTariffCode(jsPath);
System.out.println("TariffCode = " +TariffCode);
JSONObject BookingObject = PrepareProvBookingRequestBody(Origin,Destination,TravelDate,ServiceName,TariffCode);
Response Bookingresponse=
given()
//.log().body()
.spec(reqSpec)
.body(BookingObject.toString())
.when()
.post(EndPoints.BOOKING)
.then()
.spec(resSpec)
//.log().body()
.extract().response();
JsonPath jsP = RestUtilities.getJsonPath(Bookingresponse);
BookingNumber = jsP.get("data.booking.booking_number");
float TotalPrice=jsP.get("data.booking.total_price");
System.out.println("Booking number from create: " + BookingNumber);
System.out.println("Price from create: " + TotalPrice);
}
}
谁能帮我理解如何让 CreateBookings() 测试方法上的 invocationCount 接受 BBucketTBL 值的值。
【问题讨论】:
标签: testng rest-assured