![](/img/trans.png)
[英]How to continue execution of steps in Pytest BDD with scenario outline
[英]How to stop pytest_bdd from performing the teardown steps after each iteration of a Gherkin Scenario Outline?
我有以下小黄瓜场景大纲:
Scenario: Links on main page
When I visit the main page
Then there is a link to "<site>" on the page
Examples:
|site |
|example.com |
|stackoverflow.com|
|nasa.gov |
和各自的test.py:
from pytest_bdd import scenario, given, when, then
@scenario("test.feature", "Links on main page")
def test_links():
pass
在我的conftest.py
中,我分别在启动/拆卸时执行登录和注销:
@pytest.fixture(autouse=True, scope="function")
def login_management(driver, page_url, logindata):
login()
yield
logout()
但是,我不希望浏览器在检查每个链接之间注销并登录 - 我宁愿在访问一个页面时检查所有链接。 我也宁愿保留这种表格语法,而不是编写十几个步骤来调整
And there is a link to "example.com"
And there is a link to "stackoverflow.com"
And there is a link to "nasa.gov"
有什么方法可以表明仅针对此测试,此大纲中的所有场景都应该在没有拆解的情况下执行吗?
场景大纲只是编写多个单独场景的一种紧凑方式。 Cucumber 和其他测试框架致力于隔离每个单独的测试/场景,以防止一个测试/场景破坏其他测试/场景的副作用。 如果你尝试绕过这个,你最终可能会得到一个非常不稳定的测试套件,它偶尔会失败,这是基于测试/场景的运行顺序,而不是测试/场景因合理原因而失败。
所以你试图做的事情违反了测试的基本规则,你真的应该避免这样做。
如果您想更有效地测试您的链接,请将它们组合在一起并给它们命名。 然后一步测试它们并摆脱你的场景大纲,例如
Scenario: Main page links
When I visit the main page
Then I should see the main page links
Then "I should see the main page links" do
expect(page).to have_link("example.com")
expect(page).to have_link("nasa.gov")
...
end
现在您有了一个简单的场景,只需登录一次并运行得更快。
注意:示例在 ruby (ish) 中,但无论使用哪种语言,原则都适用。
一般来说,我会建议避免场景大纲,你真的根本不需要使用它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.