如何在以后的步骤中基于布尔声明重新运行先前的黄瓜步骤?

时间:2018-09-21 10:10:10

标签: cucumber cucumber-java jdbi

我是一名学习使用黄瓜的测试人员,并具有如下的场景

Given a standard party
And a flight from "UK" to "Europe"
When I search
And I receive search results
Then I can book my holiday

在第二步的步骤定义中,我使用JDBI查询数据库,并接收一个数据集,该数据集可以进行迭代并将其用作向其发送请求的API中的步骤3的搜索数据。在查询的前2或3行中不接收任何结果是很常见的。这对我没有用,因为该场景并未真正测试是否返回结果(尽管显然是有效的场景)。

我真正想要的是获得结果,然后断言我可以预订-在该步骤Def中检查了正确的价格等。...

所以,如果

And I receive search results

等于false,如何返回

And a flight from.....

...以便我可以尝试下一行数据。

然后,我的查询是在“黄瓜步骤定义”的上下文中进行的,鉴于for循环位于较早的步骤中,这是最佳/惯用的方法是什么?

在这种情况下重试是否有共同的惯例?我不能简单地再次调用基础搜索方法,因为我有很多搜索步骤Def方法都粘贴到了步骤上,并且“我接收...”中接收响应对象的对象没有上一步的概念。

从“英国”飞往“欧洲”的航班:

 @And("^a flight from \"([^\"]*)\" to \"([^\"]*)\"$")
public void aFlightFromContinentOneToContinentTwo(String continentOne, String continentTwo) {

    airportsAndDates = searchWorld.airportsAndDates();

    supplierCode = supplierCredentials.getSupplierCode();
    ReposMasterConnection rm = new ReposMasterConnection();

    origins = getContinentOne(continentOne);
    destinations = getContinentTwo(continentTwo);

    rm.initialiseDatabaseConnection();

    List<FlightDataBean> dataSet = rm.lastFlightBookedResultsByRegion(supplierCode, origins, destinations);

    for (FlightDataBean i : dataSet) {
        String startDate = i.getStartDate();
        String endDate = i.getEndDate();
        String origin = i.getOrigin();
        String destination = i.getDestination();

        String start = getStartDate(startDate);
        String end = getEndDate(endDate);

        if (startDate != null) {

            DateRange dateRange = new DateRange()
                    .withStartDate(start)
                    .withEndDate(end);

            airportsAndDates.
                    withDepartureDateRange(dateRange).
                    withDepartureAirports(departureAirportList(origin)).
                    withDestinationChoice(destinationChoice(destinationAirportList(destination)));
        }
    }
}

当我搜索... //发布请求的另一个Stepdef

然后我收到搜索结果:

@Then("^I receive search results$")
public void iReceiveSearchResults() {

    response = given().contentType(ContentType.XML).body(packageAvailRequest).when().post().then().extract().response();
    String status = requestWorld.getAppRequest().getAvailabilityResponseObject().getSearchResponseStatus(response);

    requestWorld.getAppRequest().getAvailabilityResponseObject().setResponse(response);

    errorMessage = requestWorld.getAppRequest().getFirstBasketResponseObject().getError(response);
    warningMessage = requestWorld.geAppRequest().getFirstBasketResponseObject().getWarning(response);

    if (errorMessage != null && !errorMessage.isEmpty()) {
        scenario.write("Error: " + errorMessage);
    }
    if (warningMessage != null && !warningMessage.isEmpty()) {
        scenario.write("Warning: " + warningMessage);
    }

    assertEquals("true", status);
}

很显然,我不需要在“与”步骤中为每个循环添加一个,而是有某种方式将光标移动到数据的下一行。

0 个答案:

没有答案