Cucumber Scenario Outline

Hi, I’m trying to use scenario outline, but I have some steps that I
want to execute once before start steps with < >.

Scenario Outline: Execute Steps
Given some steps that I want to run once
When…
Then…

Given like
Example:
| step | description |
| 1 | first |
| 2 | second |

I want to execute Given, When and Then once before start with Scenario
Outline Iterator. This steps are running for each row. How can I create
a subscenario or something like that?

There’s a way to do it?

On Thu, Jan 14, 2010 at 1:08 PM, Jonatas P.
[email protected]wrote:

| step | description |
| 1 | first |
| 2 | second |

I want to execute Given, When and Then once before start with Scenario
Outline Iterator. This steps are running for each row. How can I create
a subscenario or something like that?

Do you have a concrete example? That would make it easier to find a
good
solution.

There’s a way to do it?

Here are some approaches that might be worth looking into.

Given-When-Then statements are functions that can call each other. Have
a
look at this example (
http://wiki.github.com/aslakhellesoy/cucumber/calling-steps-from-step-definitions)
to see what I mean. When calling steps from a step definition, it’s a
good
idea to keep the step types consistent. In other words, avoid calling a
Then statement from a Given statement definition. Compound steps may
not be
what you need because they will run once for each iteration of the
Scenario
Outline.

If you want a set of Givens to run only once for the entire Scenario
Outline, use Background (
http://wiki.github.com/aslakhellesoy/cucumber/background). The
potential
downside here is Background statements are run before each Scenario
(Outline) in the Feature, thereby restricting the Scenarios you can use
in
the Feature.

Lastly, take a look at Tagged Hooks (
http://wiki.github.com/aslakhellesoy/cucumber/hooks). These can be used
if
you want some Ruby code to run before (or after) every Scenario with a
particular tag. A big downside here is there’s no indication, aside
from
the tag, that additional Ruby code is running. You can get the same
effect
using a Given statement, which is certainly clearer than a Hook.

Thanks Jacob!
Excelent explanation!
I think that Background do exactly what I want. :smiley:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs