Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does if else concept available in feature file (Gherkin language)?

Is there anyway where we can use if/else concept in feature file? For example:

  Scenario: User should be able to check login page
  Given I am on login page
  When I click on SignIn button 
  Then I should be in home page 
  If yes
  Then I will create a new profile
  Else
  Then I will logout from page 
like image 351
user1553680 Avatar asked May 14 '15 09:05

user1553680


2 Answers

Not that I am aware of. Gherkin (and cucumber) are best used when they specify discreet business cases though, and should be repeatable, else they get hard to follow and test. It looks like you have two stories here at least:

Scenario: A new user should be asked to sign in
  Given I am a new user
  And I navigate to the login page
  When I click on SignIn button
  I should not be able to get to the home page

Scenario: An existing user should be able to log in
  Given I am an existing user
  And I navigate to the login page
  And I submit valid credentials
  When I click on SignIn button
  I should be taken to the home page
like image 86
Jon Bates Avatar answered Sep 20 '22 23:09

Jon Bates


No you can't and you shouldn't. Feature files are for business behaviour, not programming.

From your scenario I think you are trying to deal with different behaviour, depending on whether you are registered or not. To do this you would write two scenarios

Given I am registered
When I 
Then I should ....

Given I am a new user
When I ...
Then I should be asked to register

Notice how these scenarios don't describe 'how' anything is done. Anything like `I click on foo' in feature is a smell and should be avoided.

like image 28
diabolist Avatar answered Sep 17 '22 23:09

diabolist