2

If you have a simple form, you enter your name, Gender and save it. When you select the Gender drop-down it will list [Male | Female].

So when writing test scenarios for the above, the typical way is to Write it in steps.

Precondition : User Loged in and Form Opened

Steps                                | Expected Result
------------------------------------------------------------------------
1 : User Enters the name             | Entered name should be there         
2 : User Clicks on Gender Drop-down  | Male and Female should be listed
3 : Users Selects a Gender           | Selected Gender should be there
4 : Clicks on Save                   | Information get saved.   

Following is one way to represent this is Cucumber.

Given User Loged in and Form Opened
When User Enters the name
Then Entered name should be there         
When User Clicks on Gender Drop-down
Then Male and Female should be listed
When Users Selects a Gender
Then Selected Gender should be there
When Clicks on Save 
Then Information get saved. 

Now How can we represent this in Cucumber? As I read you are not suppose to have multiple actions within the same scenario. If you add multiple testcases for each step above, the Testcases will grow exponentially. What is the best way to handle this?

ycr
  • 12,828
  • 2
  • 25
  • 45

3 Answers3

3

My approach would be to think about documenting in Gherkin (using principles of BDD) - the application behavior and not test cases. In fact, this article provides some good context around misconceptions of BDD.

With that said, even though you are trying to validate the above criteria in a single scenario, I would recommend at least splitting into 2, to keep your acceptance tests succinct, readable and maintainable.

Here's my attempt, at reformulating:

Scenario: Gender Dropdown values
Given a user is logged in
When the user clicks the Gender dropdown
Then Male and Female options are displayed

@EndtoEnd
Scenario Outline: Saving User information
Given a user is logged in
When the user enters a <Name> and selects a <Gender>
And Clicks on Save
Then the information gets saved

Examples:
|Name|Gender|
|Keith|Male|
|Jenn|Female|
||Female| # Negative
|Rob||    # Negative

Additionally, you can also think about throwing in some negative test scenarios as well.

rs79
  • 2,311
  • 2
  • 33
  • 39
0

If you need to test on cucumber with multiple data, you can go ahead and use the scenario outline feature, where you load the data in the examples after the scenarios.

Scenario Outline: User enters details and stores
Given User Loged in and Form Opened
When User Enters the <Name>        
And Users Enters the <Gender>
And Clicks on Save 
Then Information get saved. 
Then I Go back (In case view info)
Then I assert for <Name>
Then I assert for <Gender>

Examples:
|Name| |Gender|
|x|     |Male|
|y|     |female|
Emjey
  • 2,038
  • 3
  • 18
  • 33
0

Cucumber is not about testing how you do things, its about specifying why you do things. This scenario is all about how the user interacts with the form, its all about clicking on this and entering that, none of this has any place in scenarios.

Your scenario and question doesn't even tell us what you are trying to do, so I'll just have to make something up. Lets say you are trying to add a friend

Feature: Adding a friend

  Scenario: Add Alison
    Given I am logged in
    When I add Alison to my friends
    Then I should see Alison is my friend

and thats pretty much that. Note how none of the details about how you add a friend are captured in the scenario, thats not what Cucumber is for.

Now on the technical side lets explore how we get this scenario to actually add a friend. First of all the step definition

When 'I add Alison to my friends' do
  add_a_friend name: 'Alison' # perhaps add a gender param here
end

Notice how even the step definition doesn't know how to fill in the form.

Finally a helper method to actually do the work (done in Ruby cos its clearer)

module FriendStepHelper
  def add_a_friend(name:)
    # here is where we fill in the form and choose the gender
  end
end
World FriendStepHelper # makes add_a_friend visible to step def

So technically this is how you represent your problem in Cucumber you write WHY you doing things in using your scenarios and you push down HOW you do things to helper methods used by your step definitions

diabolist
  • 3,990
  • 1
  • 11
  • 15