run background before scenario outline, but just one time

2,632 views
Skip to first unread message

Jon Kruger

unread,
Nov 3, 2010, 3:59:02 PM11/3/10
to Cukes
If I have a Background section and a Scenario Outline, the Background
runs once before each example in the scenario outline. Is there a
hook that before the Scenario Outline, but not before each example? I
have a Scenario Outline for a search screen that has lots of examples,
but since the tests don't modify the data, there's no reason for me to
recreate it for each example.

Jon

Matt Wynne

unread,
Nov 3, 2010, 7:40:15 PM11/3/10
to cu...@googlegroups.com

Why are you using a scenario outline then? Just use a table in your Then step:

Then all these things should be true:
| this |
| that |
| the other |

> Jon
>
> --
> You received this message because you are subscribed to the Google Groups "Cukes" group.
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cukes?hl=en.
>

cheers,
Matt

http://blog.mattwynne.net
+44(0)7974 430184

Jon Kruger

unread,
Nov 3, 2010, 8:13:39 PM11/3/10
to cu...@googlegroups.com
Because the "When" can vary per example.  

Matt Wynne

unread,
Nov 5, 2010, 2:50:54 PM11/5/10
to cu...@googlegroups.com
Please don't top-post, it breaks the flow of the conversation.

On 4 Nov 2010, at 00:13, Jon Kruger wrote:

On Wed, Nov 3, 2010 at 7:40 PM, Matt Wynne <ma...@mattwynne.net> wrote:

On 3 Nov 2010, at 19:59, Jon Kruger wrote:

> If I have a Background section and a Scenario Outline, the Background
> runs once before each example in the scenario outline.  Is there a
> hook that before the Scenario Outline, but not before each example?  I
> have a Scenario Outline for a search screen that has lots of examples,
> but since the tests don't modify the data, there's no reason for me to
> recreate it for each example.
>

Why are you using a scenario outline then? Just use a table in your Then step:

Then all these things should be true:
  | this |
  | that |
  | the other |

Because the "When" can vary per example.  

Okay I see.

There isn't a feature in Cucumber that does what you want. Why do you want to run the setup just once? Is it slow to set up the data?

One suggestion would be to do all the test cases in a single scenario:

Given I have set up the complex data
Then I should be able to perform the following searches:
  | search term | result                  |
  | foo               | foo, food, corfoo |
  | bar               | bar, candy bar    |

Might not be possible for your purpose but food for thought.
Reply all
Reply to author
Forward
0 new messages