As the title suggests, I wish to run some certain configuration / environment setup steps before a scenario outline. I know there is Background
to do this for scenarios, but Behave splits a scenario outline into multiple scenarios and thus runs the background for every input in the scenario outline.
This is not what I want. For certain reasons I cannot provide the code I am working with however I will write up an example feature file.
Background: Power up module and connect
Given the module is powered up
And I have a valid USB connection
Scenario Outline: Example
When I read the arduino
Then I get some <'output'>
Example: Outputs
| 'output' |
| Hi |
| No |
| Yes |
What would happen in this case is Behave would power cycle and check USB connection for each output Hi
, No
, Yes
resulting in three power cycles and three connection checks
What I want is for Behave to power cycle once and check the connection once and then run all three tests.
How would I go about doing this?
You can run a feature file by using -i or --include flags and then the name of the feature file. For more information check the documentation for command line arguments. There's a lot of useful information hidden in their appendix section. NOTE: At the time I'm writing this it won't work with Python 3.6 and Behave 1.2.
Advertisements. A Scenario Outline is used if we have a group of similar criteria and the results are to be passed in a Scenario. A Scenario Outline is accompanied with an Examples table. A Scenario Outline can have multiple Examples tables.
Your best bet is probably to use the before_feature
environment hook and either a)
tags on the feature and/or b) the feature name directly.
For example:
some.feature
@expensive_setup
Feature: some name
description
further description
Background: some requirement of this test
Given some setup condition that runs before each scenario
And some other setup action
Scenario: some scenario
Given some condition
When some action is taken
Then some result is expected.
Scenario: some other scenario
Given some other condition
When some action is taken
Then some other result is expected.
steps/environment.py
def before_feature(context, feature):
if 'expensive_setup' in feature.tags:
context.execute_steps('''
Given some setup condition that only runs once per feature
And some other run once setup action
''')
alternate steps/environment.py
def before_feature(context, feature):
if feature.name == 'some name':
context.execute_steps('''
Given some setup condition that only runs once per feature
And some other run once setup action
''')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With