简体   繁体   中英

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?

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

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 ~

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM