1

Is it possible to somehow construct a Scenario which uses two different Example tables in different steps? Something like this:

Given I log in
When I view a page
Then I should see <goodText>
Examples:
|goodText|
|abc|
And I should not see <badText>
Examples:
|badText|
|xyz|

The scenario above doesn't work, also in reality there would be more rows to each table.

C0deAttack
  • 24,419
  • 18
  • 73
  • 81

2 Answers2

1

It looks like you're confusing tables with scenario examples. You can mix them, but from your example I'm not sure what you're trying to achieve. Why not just write:

Given I log in
When I view a page
Then I should see "abc"
But I should not see "xyz"

or if you wanted to check for multiple strings:

Given I log in
When I view a page
Then I should see the following text:
  | abc |
  | def |
But I should not see the following text:
  | xyz |
  | uvw |
Andy Waite
  • 10,785
  • 4
  • 33
  • 47
  • As mentioned there would be more rows in the table, not just the simple example I wrote. – C0deAttack Sep 29 '11 at 20:09
  • I've edited my post to illustrate how you could do that. No need for a scenario outline. – Andy Waite Sep 29 '11 at 20:21
  • Hmm, so how would I have access to 'abc', 'def', etc in my Step if I don't have the placeholder? – C0deAttack Sep 29 '11 at 20:36
  • If you run Cucumber against that feautre it will provide you with an outline step definition with one parameter, which will be representation of the table (a Cucumber::Ast::Table). – Andy Waite Sep 29 '11 at 20:41
  • Thanks for your help so far. I've implemented the step outline but I don't really understand what do to with the 'Cucumber::Ast::Table' parameter, how I'm supposed to access the table or the row. I can't even find any decent documentation about this either which is annoying! – C0deAttack Sep 29 '11 at 20:54
  • It's can be a bit tricky to understand, but if you just want the contents as an array then use table.raw.flatten. – Andy Waite Sep 29 '11 at 21:09
  • I Google the API for the Cucumber::Ast and tried to access some of the table's properties but I get this error - groovy.lang.MissingPropertyException: No such property: raw for class: Cucumber$$Ast$$Table_139611417 – C0deAttack Sep 29 '11 at 21:18
  • Just saw that you're using cuke4duke - I don't know anything about that sorry. – Andy Waite Sep 29 '11 at 21:23
  • Thanks for your help you lead me to the the answer, the way you've shown how to structure the scenario with a table, and NOT a scenario outline with examples got me there. – C0deAttack Sep 30 '11 at 14:03
0

You say that in reality there would be many more rows to the table; but of course a table can also have many columns.

Would this not work for you?

Given I log in
When I view a page
Then I should see <goodText>
But I should not see <badText>
Examples:
|goodText| badText |
|abc     | xyz     |
AlistairH
  • 3,139
  • 2
  • 21
  • 19
  • No because there isn't always a equal number of goodText and badText. I have worked it out though see comment in above answer. – C0deAttack Sep 30 '11 at 14:02