Wednesday, 25 April 2018

Cucumber: Generate source code from feature file

In my previous post, I explained how to install ‘cucumber-eclipse’ plugin. By using this plugin, we can generate source code from a feature file.

Right click on feature file -> Run As -> Cucumber Feature

It generates below output in the console.
As you see the output, it generates skeleton method definitions.

Feature: Login
 Login should be quick and friendly.

  Scenario: Successful Login                                          # C:/Users/krishna/miscellaneous/cucumber_tutorial/src/test/java/com/sample/features/Login.feature:5
 Users should be logged in successfully by providing correct username and password.
    Given I have chosen to Login                                      # null
    When I log in with user name "krishna" and password "password123" # null
    Then I should be logged in successfully                           # null
    And I should see a personalized greeting message                  # null

1 Scenarios (1 undefined)
4 Steps (4 undefined)
0m0.018s


You can implement missing steps with the snippets below:

@Given("^I have chosen to Login$")
public void i_have_chosen_to_Login() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I log in with user name \"([^\"]*)\" and password \"([^\"]*)\"$")
public void i_log_in_with_user_name_and_password(String arg1, String arg2) throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I should be logged in successfully$")
public void i_should_be_logged_in_successfully() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I should see a personalized greeting message$")
public void i_should_see_a_personalized_greeting_message() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}


Previous                                                 Next                                                 Home

No comments:

Post a Comment