How to skip steps in background of Behave BDD?

hudrogen

I'm using Python & Behave BDD for automation.

As I know, background runs before each scenario, but I need background to run before scenarios only with @need_background tag. How can I achieve this?

I have tried to get current scenario tag and if tag != need_background then skip background's steps. But behave doesn't have a method for skipping background steps as far as I am aware.

Chong

Since the scenarios are not sharing the same background, why not moving the special one to other feature files or just not using background.

But if you still want to use background section, I would recommend:

Firstly, Add a hook to your environment.py

def before_scenario(context, scenario):
if 'need_background ' in scenario.tags:
    context.if_background = True
else:
    context.if_background = False    

Then combine all your steps in background as one step

@given('all background steps are done')
def step_impl(context):
if context.if_background:
    context.context.execute_steps('''
        steps in background
    ''')
else:
    pass

Now, if your feature file is:

Feature: Background with condition
Background:
Given all background steps are done

Scenario: run without background
# steps of the scenario you don't need background

@need_background 
Scenario: run with background
# steps of the scenario you need background

I think it might meet your requirements

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I skip a test in the behave python BDD framework?

From Dev

behave(BDD) AmbiguousStep Error

From Dev

How can I see print() statements in behave (BDD)

From Dev

Behave: How to import steps from another file?

From Dev

Serenity BDD with jUnit how to inject steps into setup method?

From Dev

How to skip 10 steps in Bootstrap Tour?

From Dev

How to skip specific Execution Plan Steps?

From Dev

How to create several implementation for the same named steps (behave)

From Dev

How can I get code coverage data from Python BDD functional tests using Behave?

From Dev

Does Behave (BDD) work with Python 3.4?

From Dev

Skip steps in fsevents queue

From Dev

Behave, multiple steps with same name

From Dev

Skip a behave step in the step implementation

From Dev

How to output Cucumber background steps before each scenario?

From Dev

How to automatically start and advance a few steps in an application in background in linux?

From Dev

How to automatically start and advance a few steps in an application in background in linux?

From Dev

How BDD complements TDD

From Dev

Debugging python-behave steps with Pycharm

From Dev

How to do BDD in a winforms app

From Dev

Skip Jenkins Pipeline Steps If Node Is Offline

From Dev

Highcharts skip non-provided steps in a series

From Dev

Why does my loop skip even steps?

From Dev

Java Calculate Max Steps of Stairs and skip stair

From Dev

Get the steps in background with iOS 7

From Dev

Make the contents of a div behave like a fixed background

From Dev

How Scala Traits behave?

From Dev

How kafka partitions behave

From Dev

Behave ImportError: No module named features.steps.pages.home_page

From Dev

BDD Behave Selenium Python error no module named pages when i run my feature test

Related Related

  1. 1

    How do I skip a test in the behave python BDD framework?

  2. 2

    behave(BDD) AmbiguousStep Error

  3. 3

    How can I see print() statements in behave (BDD)

  4. 4

    Behave: How to import steps from another file?

  5. 5

    Serenity BDD with jUnit how to inject steps into setup method?

  6. 6

    How to skip 10 steps in Bootstrap Tour?

  7. 7

    How to skip specific Execution Plan Steps?

  8. 8

    How to create several implementation for the same named steps (behave)

  9. 9

    How can I get code coverage data from Python BDD functional tests using Behave?

  10. 10

    Does Behave (BDD) work with Python 3.4?

  11. 11

    Skip steps in fsevents queue

  12. 12

    Behave, multiple steps with same name

  13. 13

    Skip a behave step in the step implementation

  14. 14

    How to output Cucumber background steps before each scenario?

  15. 15

    How to automatically start and advance a few steps in an application in background in linux?

  16. 16

    How to automatically start and advance a few steps in an application in background in linux?

  17. 17

    How BDD complements TDD

  18. 18

    Debugging python-behave steps with Pycharm

  19. 19

    How to do BDD in a winforms app

  20. 20

    Skip Jenkins Pipeline Steps If Node Is Offline

  21. 21

    Highcharts skip non-provided steps in a series

  22. 22

    Why does my loop skip even steps?

  23. 23

    Java Calculate Max Steps of Stairs and skip stair

  24. 24

    Get the steps in background with iOS 7

  25. 25

    Make the contents of a div behave like a fixed background

  26. 26

    How Scala Traits behave?

  27. 27

    How kafka partitions behave

  28. 28

    Behave ImportError: No module named features.steps.pages.home_page

  29. 29

    BDD Behave Selenium Python error no module named pages when i run my feature test

HotTag

Archive