Yuya
Yuya

Reputation: 25

How to execute a scenario from a step in another scenario?

Below is the example I want to execute a scenario in another scenario. How can I do this?
I've already known that I execute the other steps by using execute_steps().

My environment: macOS v10.14.1, Docker v18.06.1-ce, Django v2.1.4, behave v1.2.6, behave-django v1.1.0

Scenario: scenarioA
    Given ~
    When ~
    Then ~

Scenario: scenarioB
    Given scenarioA is completed # I want to exexute scenarioA here.
    When ~
    Then ~

Is there an api to run the scenario from the name of the scenario?
Is there an api that gets scenarios from scenario names and divides them into steps?

Upvotes: 1

Views: 1876

Answers (2)

Thach Hoang
Thach Hoang

Reputation: 56

Unfortunately, you cannot call a scenario A from scenario B. Behave does not support anything like that. But What you want here is executing all steps defined in scenario A in the first step of scenario B. We simply do this by create a dedicated step in step file.

@given(‘all steps of scenario A is completed’) def step_execute_scenario_A(context): context.execute_steps(u‘’’ Given step~ A When step~ A Then step~ A ‘’’)

Scenario: scenarioB

Given all steps of scenario A is completed
When ~
Then ~

Upvotes: 1

Andrey Glazkov
Andrey Glazkov

Reputation: 2592

No. This behavior is done deliberately, to eliminate collisions in cases where scenarioA falls during a call by scenarioB.

Behave API has only one method to call another step from current step: execute_steps()

Official tutorial with exactly example: macro step

Upvotes: 0

Related Questions