3

I have recently seen a cucumber scenario outline like this. sorry for my bad example below. But the format is in this way. I really wonder if this type of format is supported by cucumber? The nested Data tables. Has any one used this type of nested Data table? If yes is this the below format?

        Scenario Outline: Hello World
     Given I am logged in as <user>
     When I search for <searchTerm>
     Then I add the following to my basket:
        | <item1> |teapot|
        | <item2> |Yorkshire tea|

Examples:
| user | searchTerm |
| Adam | Tea        |

Can i make a data table like above

npp
  • 45
  • 2
  • 6

2 Answers2

4

Updated Answer!!

As @kayle mentioned in his answer.. You can write following test scenario's

Scenario Outline: Hello World
     Given I am logged in as <user>
     When I search for <searchTerm>
     Then I add the following to my basket:
         | Teapot        |
         | Yorkshire tea |

Examples:
| user | searchTerm |
| Adam | Tea        |

or

Scenario Outline: Hello World
     Given I am logged in as <user>
     When I search for <searchTerm>
     Then I add the following to my basket:
        | <item1> |
        | <item2> |

Examples:
| user | searchTerm | item1 | item2        |
| Adam | Tea        | Teapot| Yorkshire tea|

the second scenario will be useful if you want to add different items for each user. for example:

Scenario Outline: Hello World
     Given I am logged in as <user>
     When I search for <searchTerm>
     Then I add the following to my basket:
        | <item1> |
        | <item2> |

Examples:
| user | searchTerm | item1         | item2  |
| Adam | Tea        | Yorkshire tea | Teapot |
| Tom  | Books      | book1         | book2  |

Hope it's clear!!

Ranjith's
  • 4,508
  • 5
  • 24
  • 40
4

That's not quite how they work.

The nested data tables are used by the step that the table is joined to. It's usually used to do multiple of the same thing, using the data table on the inside as an array. This can include headers, or no headers - depending on how you have written your step. Remember - it's all about communication.

As an example:

Scenario Outline: Hello World
 Given I am logged in as <user>
 When I search for <searchTerm>
 Then I add the following to my basket:
    | <item1> |
    | <item2> |

Examples:
| user | searchTerm | item1  | item2         |
| Adam | Tea        | teapot | Yorkshire tea |
KyleFairns
  • 2,947
  • 1
  • 15
  • 35
  • Thank you for the answer Kyle. Its clear, but i have got another question after reading this answer. I have updated my question again. – npp May 26 '17 at 11:02
  • The angle brackets are really placeholders. You could do this and treat item1 and item2 as a sort of header column, but because you wouldn't be doing the replacement of item1 and item2, all of your scenarios running from your examples table will use "teapot" and "Yorkshire tea". If that's what you require, then it'll work well for you. – KyleFairns May 26 '17 at 11:29
  • Hi Kyle, Is there any best place i find the template for this type of scenario outlines? I am fishing all over the internet. I can find a normal scenario outline. – npp May 30 '17 at 22:11
  • If by normal scenario outline, you mean a scenario without a table, then remove the examples table, and change the line "Scenario Outline: " to "Scenario: " – KyleFairns May 30 '17 at 22:14
  • Sorry if was unclear. Its not about normal scenario. Its the datatable inside the cucumber scenario. For example the Item1 and item2 are placed inside the scenario outline and there is no name header. I want to know how does it work. Is it the program only that takes the item1 and item2 values? I can see item1 and item2 are not used in the scenario – npp May 31 '17 at 08:15
  • If needed, I should be able to post some code for the JavaScript and Ruby frameworks, to show you how I would use the data table in the step definition. I don't know the Java framework as well as these yet (it is on my to do list) - but it should show you pretty much how to use them, as the JS, Ruby and Java frameworks are developed by the same team. – KyleFairns May 31 '17 at 08:59
  • That sounds great Kyle. how to connect please? – npp May 31 '17 at 09:05
  • Got this link http://www.thinkcode.se/blog/2014/06/30/cucumber-data-tables – npp May 31 '17 at 10:55