2

I have four very similar sections on my application and am trying to group tests together that are similar enough using scenario outline to facilitate maintenance and am giving the section (page) they're to be under as a parameter. However, these tests when written individually contain a different amount of items under their datatable (but still doing the same assertions), so I was wondering if it's possible to have a different databable for each examples sections?

Something like:

Scenario Outline: Verify that the user is able to see the details recorded on the note 
And I navigate to the "<page>" screen
Then the following items are displayed for their respective fields

@page1
Examples:
Then the following items are displayed for their respective fields
  | field   | text       |
  | title   | My title   |
  | history | My history |

@page2
Then the following items are displayed for their respective fields
  | field   | text       |
  | comment | My comment |
  | details | My details |
  | status  | My status  |

Note I'm omitting the page parameter as not sure where it should go, as if doing something like the below would mean they would be run multiple times within each example

@page1
Examples:
Then the following items are displayed for their respective fields
  | page  | field   | text       |
  | page1 | title   | My title   |
  | page1 | history | My history |

I also can't have something like:

Scenario Outline: Verify that the user is able to see the details recorded on the note 
Then the following items are displayed for their respective fields

@page1
Examples:
Then the following items are displayed for their respective fields
  | field   | text  | item1 | item2 |

Because these amounts change, so I could have three items under the test for a page but two items on another one and maybe four on the other one.

I hope I'm being clear enough on what I'm trying to achieve?

Many thanks.

Francislainy Campos
  • 3,462
  • 4
  • 33
  • 81

1 Answers1

2

You're writing your scenarios very much like a test script where you describe each step. This doesn't work with Gherkin. It is not a programming language and trying to program in it is hard. Try to write down the behavior of the application instead.

Scenario: Details of the note can be seen on page1 and page2
  Given Claire has created a note
   | property | value    | 
   | title    | My title |
   | ect ....
  When she views the notes details
  Then on "Notes Overview" she can see:
   | field   | text       |
   | title   | My title   |
   | history | My history |
  And on "Note Details" she can see:
   | field   | text       |
   | comment | My comment |
   | details | My details |
   | status  | My status  |

In the Given step you create a user named Claire, open the app, and create the note. In the When step you navigate to the right page and in the Then steps you check if the right things are visible in the right fields.

M.P. Korstanje
  • 10,426
  • 3
  • 36
  • 58
  • Hi mp, thank for your reply. I agree with what you're saying about BDD but this was just a draft example as my question is mainly around how to be able to use the datatable under different examples sections on a scenario outline. Maybe using your example, title and history would be what a user would see but another user would see comment, details and status on another example section but both of them on the same scenario outline. That's what I mean by page1 and page2. Maybe can chat on slack if I'm not being very clear? – Francislainy Campos Mar 14 '20 at 13:30
  • 2
    @FrancislainyCampos: He is trying to tell you that a scenario outline is the wrong tool. Since each page seems to deal with a different entity, they should be separate scenarios. A scenario outline is meant to verify the *same* behavior given different input. You are testing different input **and** different behavior. – Greg Burghardt Mar 14 '20 at 16:35
  • Hi, thanks. Yes, we spoke outside here and learned what I'm trying to use it for doesn't seem to be really possible with Cucumber. – Francislainy Campos Mar 14 '20 at 17:23