Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Step Definitions in Cucumber

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 323
    Comment on it

    Cucumber is a command-line tool that reads specifications from plain-language text files but cucumber itself does not have any idea as how to execute the scenario steps. Cucumber needs step definition to convert Gherkin step into some desired activity.

     

    Whenever cucumber executes any step then it looks its respective step definition in the entire project and execute the code written inside the step definition.

     

    Step definition may contain a single line code or a multi-line code depending on the steps logic.

     

    Feature:

    Scenario:Verify the registration

     

      Given I am at Home Page

      Then I click Registration link

      And I enter valid data for Registration

      Then I should see Edit Profile page

      And I should see Terms and Conditions overlay

     

    Step Definitions of few steps:

     

    Then(/^I click Registration link$/) do

    @page = @page.click_registration_link

    end

     

    And(/^I enter valid data for Registration$/) do

    @Timestamp = @page.read_time_stamp

    @page = @page.enter_username("#{@Timestamp}_xxxxxxxxxxxx")

    @page = @page.enter_email("#{@Timestamp}_xxxxxxxxxxx@mailinator.com")

    @page = @page.enter_password("xxxxxxxxxxxx")

    @page = @page.enter_confirm_password("xxxxxxxxxxxxx")

    @page = @page.click_register_button

    end

     

    Then(/^I should see Edit Profile page$/) do

    pending

    end

     

    And(/^I should see Terms and Conditions overlay$/) do

    pending

    End

     

    In the above example as we can see that only single line code is associated with “I click Registration link” step but multiline code is associated with “I enter valid data for Registration”. If the same step is written with different Gherkin keywords in the Feature then also we do not have to re-write the steps again. Cucumber while reading the step definition ignore Gherkin keywords.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: