【发布时间】:2022-11-28 08:23:47
【问题描述】:
我开始学习剧作家,并从文档 (https://playwright.dev/python/docs/intro) 尝试运行以下示例代码:
import re
from playwright.sync_api import Page, expect
def test_pp(page: Page):
page.goto("https://playwright.dev/")
# Expect a title "to contain" a substring.
expect(page).to_have_title(re.compile("Playwright"))
# create a locator
get_started = page.locator("text=Get Started")
# Expect an attribute "to be strictly equal" to the value.
expect(get_started).to_have_attribute("href", "/docs/intro")
# Click the get started link.
get_started.click()
# Expects the URL to contain intro.
expect(page).to_have_url(re.compile(".*intro"))
使用命令pytest 运行时,抛出以下错误:
file D:\play_wright\test\test_sample.py, line 5
def test_pp(page: Page):
E fixture 'page' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
D:\play_wright\test\test_sample.py:5
-
pytest-playwright模块 (0.3.0) 已安装。用pip list命令确认 - 重新启动 Windows 机器
- 编剧版 - 1.27.1
- pytest - 6.2.1(也尝试过 7.*)
仍然有问题。请帮忙。
【问题讨论】:
标签: python pytest playwright playwright-python