Gavi
Gavi

Reputation: 1478

Cucumber same sentence different scenarios

I'm working with a java Spring Boot 2 application on which I'm using cucumber and gherkin.

I'm not understanding how to manage the situations in which the same sentence represents a different action.

Given the following sentence

And the user fills the field email with '[email protected]'

The problem is that the field "email" is in the signUp page and in the signIn page.

When I write the implementation of this sentence how can I understand whether I need to fill the signUp page or signIn page?

Searching on google I'm not finding anything about that, maybe there're some anti-pattern in my sentence?

Are there some real examples, in order to understand better?

Thank you

Upvotes: 1

Views: 648

Answers (2)

diabolist
diabolist

Reputation: 4099

The anti-pattern is that you are using your feature/scenarios to describe HOW you are doing something rather than having you feature/scenarios describe WHAT you are doing and WHY its important. You can push the details of HOW you do things into the bodies of step definitions, or better yet into helper methods that step definitions can call.

From your example you clearly have two scenarios

  • user signs up (I prefer to use 'register' here)
  • user signs in

So

Scenario: Sign up
  When I sign up
  Then I should be signed up

Scenario: Sign in
  When I sign in
  Then I should be signed in

And down the stack some helper method (mine are in Ruby)

def sign_up(new_user: )
  visit sign_up_page
  fill_in :email, with new_user.email
  fill_in :password, with new_user.password
  fill_in :confirmation, with new_user.password
  ...
  submit_form
end

def sign_in(user: )
  visit sign_in_page
  fill_in :email, with user.email
  fill_in :password, with user.password
  submit_form
end

Working this way you have a clear differentiation between sign_in and sign_up and no possibility of using the wrong step definition.

Upvotes: 2

MikeJRamsey56
MikeJRamsey56

Reputation: 2819

What's wrong with,

And the user fills the field email with '[email protected]' on the 'signUp' page

And the user fills the field email with '[email protected]' on the 'signIn' page'

?

Upvotes: 2

Related Questions