这就是我如何编写SeleniumBase/pytest-bdd测试的方式:
ddg.feature
Feature: Browse DuckDuckGo
Going to DuckDuckGo webpage.
Scenario: I can see the title
When I go to DuckDuckGo webpage
Then Duck is present in the titletest_ddg.py
from seleniumbase import BaseCase
from pytest_bdd import scenarios, when, then
scenarios("./ddg.feature")
class MyTestClass(BaseCase):
@when("I go to DuckDuckGo webpage")
def go_to_ddg(self):
self.open('https://duckduckgo.com/')
@then("Duck is present in the title")
def is_title_present(self):
assert 'Duck' in self.get_title()然而,这是行不通的。函数无法查看何时和随后的描述符。
如果可能的话,你知道怎么做吗?
发布于 2021-03-23 09:01:20
您需要使用SeleniumBase作为pytest工具,而不是直接继承BaseCase。参见“sb pytest夹具”一节
因此-在您的示例中-您不需要导入BaseCase,您应该使用"sb“而不是"self”。
另一个例子:功能/网站特性
@homepage
Feature: Homepage
Scenario: Homepage this and that
Given the browser is at the homepage
When the user clicks this
Then that is shown步骤防御/主页_test.py
from pytest_bdd import scenarios, given, when then
from .pom import *
# Constants
PAGE = 'https://seleniumbase.io'
# Scenarios
scenarios('../features/homepage.feature')
# Given Steps
@given('the browser is at the homepage')
def the_browser_is_at_the_homepage(sb):
"""the browser is at the homepage."""
sb.get(PAGE)
# When Steps
@when('the user clicks this')
def the_user_clicks_this(sb):
"""the user clicks this."""
sb.click(Menu.this)
# Then Steps
@then('that is shown')
def that_is_shown(sb):
"""that is shown."""
sb.assert_text('The sb pytest fixture',SyntaxPage.that)梯级防御/防撞
class Menu():
this = "//nav//a[contains(text(),'Syntax Formats')]"
class SyntaxPage():
that = "(//h3)[4]"https://stackoverflow.com/questions/66115961
复制相似问题