Search code examples
selenium-webdriverautomated-testscucumbercucumber-java

Cucumber step not binding with step definitions when using Example block


I am using cucumber with java. When i am trying to pass value from Example block steps are not binding with the step definitions. Throwing steps undefined step reference error on feature file.

Feature File code:

Scenario Outline: Verify "Create your account" button on the Profile screen for Guest user
    Given I launched the app
    When I skip the On-boarding flow
    And I tap on continue with free lessons button
    And I tap on Profile tab
    Then the output should be <output>
    Then I should be able to see <text> on profile screen
    And I enter Username as <username> and Password as <username>
    And I tap create your account button on profile screen
    Then I should redirected to Create your account screen

    Examples:
    |  text      | output | username |   pwd    |
    |Register now|   5000 |    sam   | willis   |

Step Definition code that i tried:

@Then("I should be able to see {string} on profile screen")
    public void i_should_be_able_to_see_register_now_to_save_your_xp_and_access_your_full_profile_on_profile_screen(String text) {
        profile = new Profile();
        Assert.assertTrue(profile.verifyLevelTagForGuestUser(text));
    }

    @Then("I should be able to see <text> on profile screen")
    public void iShouldBeAbleToSeeTextOnProfileScreen(String output) {
        profile = new Profile();
        Assert.assertTrue(profile.verifyLevelTagForGuestUser(output));
    }

    @When("^I enter Username as \"([^\"]*)\" and Password as \"([^\"]*)\"$")
    public void I_enter_Username_as_and_Password_as(String arg1, String arg2) {

    }

    @And("I enter Username as <username> and Password as <username>")
    public void iEnterUsernameAsUsernameAndPasswordAsUsername() {
    }

Any help would be appreciated.

Step definition image:

Step definition image


Solution

  • Your program is Throwing steps undefined step reference error on feature file as you have duplicate column headers with text as username.

    |  text      | output | username | username |
    

    You may like to change it as:

    |  text      | output | username | password |