【问题标题】:python behave bdd framework. how to execute remaining step when a step failspython表现bdd框架。步骤失败时如何执行剩余步骤
【发布时间】:2020-06-23 00:19:50
【问题描述】:
我正在使用 python BDD 框架。即使一步失败,我也需要继续执行其余步骤。
Scenario Outline: Components
Given I load the website
When I go to "Dashboard" page
Then I see this component "<boxes>"
当上述场景的第二步失败时。即使上述步骤失败,我也希望继续下一步。我该如何继续
【问题讨论】:
标签:
python-3.x
cucumber
python-behave
【解决方案1】:
例如,您可以将标签 @runner.continue_after_failed_step 添加到您的场景中,并将以下代码添加到您的 environment.py 中:
from behave.model import Scenario
def before_scenario(context, scenario):
if "@runner.continue_after_failed_step" in scenario.effective_tags:
scenario.continue_after_failed_step = True
或者,如果您想在所有场景的步骤失败后继续执行,您可以简单地将其添加到您的 environment.py:
from behave.model import Scenario
def before_all(context):
userdata = context.config.userdata
continue_after_failed = userdata.getbool("runner.continue_after_failed_step", False)
Scenario.continue_after_failed_step = continue_after_failed
并将这些参数添加到根目录下的 behavior.ini 文件中:
[behave]
show_timings = false
[behave.userdata]
runner.continue_after_failed_step = true
如果您需要有关它的更多信息,可以在此处Behave Github 的行为项目中找到实现