Thursday 26 April 2018

Cucumber: Generate method names in camel case

Use the option ‘--snippets camelcase’.

Ex
java -cp "jars/*" cucumber.api.cli.Main -p pretty --snippets camelcase .

For the below feature file.

Login.feature
Login.feature
Feature: Login

 Login should be quick and friendly.
 
 Scenario: Successful Login
  Users should be logged in successfully by providing correct username and password.
  
  Given I have chosen to Login
  When I log in with correct "username" and "password"
  Then I should be logged in successfully
  And I should see a personalized greeting message

Go to the directory, where the .feature file is located and execute below command.
java -cp "jars/*" cucumber.api.cli.Main -p pretty --snippets camelcase .

I got below kind of method signatures.

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

@When("^I log in with correct \"([^\"]*)\" and \"([^\"]*)\"$")
public void iLogInWithCorrectAnd(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 iShouldBeLoggedInSuccessfully() 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 iShouldSeeAPersonalizedGreetingMessage() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}


How to generate camelCase method names in Eclipse?
By adding the argument '--snippets camelcase', you can generate method names in camel case.

Right click on the feature file -> Run As -> Run Configuration.

Go to ‘Arguments’ tab and add the argument '--snippets camelcase' and run.

You can able to see below output in the console.

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.020s


You can implement missing steps with the snippets below:

@Given("^I have chosen to Login$")
public void iHaveChosenToLogin() 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 iLogInWithUserNameAndPassword(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 iShouldBeLoggedInSuccessfully() 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 iShouldSeeAPersonalizedGreetingMessage() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}



Previous                                                 Next                                                 Home

No comments:

Post a Comment