Monday 30 April 2018

Gherkin: Adding comments to the feature file

Comments are used to document more information.

Comments in Gherkin are written using pound (#) symbol.

Login.feature

# This feature checks the login flow of the user.

Feature: Login

 Login should be quick and friendly. When user logged in with correct credentials, then he would be greeted with welcome message.
 If user session is expired, he should be reverted back to login page.

 # Check the happy Scenario 
 Scenario: Successful Login 
 User should be logged in successfully by providing correct username and password.
   
  Given I am registered user to the application 
  When I log in with user name "krishna" and password "password123" 
  Then I should be logged in successfully 
  And I should see a personalized greeting message 
 
 # Checks session expiration scenarion
 Scenario: Session Expired 
 User should be redirected to login page on session expiration
 
  Given I am the logged in user to the application 
  But My session is expired 
  When I try to interact with the application 
  Then I should be notified about session expiration 
  And I should be redirected to the login page

Cucumber generates below java code.

@Given("^I am registered user to the application$")
public void iAmRegisteredUserToTheApplication() 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();
}

@Given("^I am the logged in user to the application$")
public void iAmTheLoggedInUserToTheApplication() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Given("^My session is expired$")
public void mySessionIsExpired() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I try to interact with the application$")
public void iTryToInteractWithTheApplication() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I should be notified about session expiration$")
public void iShouldBeNotifiedAboutSessionExpiration() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I should be redirected to the login page$")
public void iShouldBeRedirectedToTheLoginPage() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}



Previous                                                 Next                                                 Home

No comments:

Post a Comment