Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fixture 'page' not found - pytest playwright

I started learning playwright and from documentation (https://playwright.dev/python/docs/intro) tried to to run the following sample code:

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"))

While running using command pytest, throwing following error:

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 module (0.3.0) is installed. confirmed with pip list command
  • Restarted Widows Machine
  • playwright version - 1.27.1
  • pytest - 6.2.1 (tried with 7.* as well)

Still getting the issue. please help.

like image 854
Naveen Kumar R B Avatar asked Aug 08 '26 06:08

Naveen Kumar R B


1 Answers

You need to install the pytest wrapper pytest-playwright that provides default support for fixtures for all browsers like chromium, firefox and webkit.

$ pip install pytest-playwright
like image 148
prabhakar Avatar answered Aug 09 '26 19:08

prabhakar