![](/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.