If/How can Cucumber read parameter from steps ahead?

30 views Asked by At

I have a large test set written with Gherkin. I want to verify the test data is available at the run time but ı don't want to change BDD steps at all test cases. What I am trying to do is to run some methods before running my test by using parameters given in the next steps. How can we get parameters from next step, or can we?

Here is an example test case:

  Scenario: Book a Hotel Room
    Given Home Page opened successfully
    When I search booking options by dataTable on Hotel Search Component
      | RoomType | DaysToCheckIn | DaysToCheckOut | Guests  |
      | SEA_SIDE | 20            | 25             | ADULT:2 |
    And I select any room with price total is less than USD 1500.00
    And I complete payment with CREDIT_CARD option
    Then Verify reservation details

In the "Home Page opened successfully" step, ı want to be able to read the search and select criterias. With these criterias i want to find if there is any availability at requested date and change the dates or create a mock room if neccessary.

I want to use "preferences" ,"currency" and "amount" parameters given in later steps StepDefinitions at findAvailableReservationData() method.


    @And(" Home Page opened successfully")
    public void openHomePage() {
        Assertions.assertTrue(homePage.isAt(),
            "There is a problem for opening home page");
        homePage.findAvailableReservationData(preferences, currency, amount);
    }

    @And("I search booking option by given preferences on Hotel Search Component")
    public void searchRoom(Preferences preferences) {
        bookerAvailabilityTab.searchRoomsBy(preferences);
    }

    @And("I select room with price total is less than {currency} {int}")
    public void selectRoomByPriceLimit(Currency currency, int amount) {
        roomAvailabilityPage.selectRoomByPriceLimit(currency, amount);
    }

    @And("I complete payment with CREDIT_CARD option")
    public void completePayment(PaymentType paymentType) {
        paymentPage.completePaymentWith(paymentType);
    }

    @And("Verify reservation details")
    public void verifyReservation() {
        thankYouPage.verifyReservation();
    }

I couldn't find anything if this is possible or not. Does anybody knows what to do about this issue?

0

There are 0 answers