0

I'm a VERY new to Playwright and am trying to enable the trace. I am trying to follow the documentation but am receiving an error:

ERROR [100%] test setup failed page =

@pytest.fixture()
def set_up_tear_down(page) -> None:
  browser = chromium.launch()

E NameError: name 'chromium' is not defined

conftest.py:7: NameError

Process finished with exit code 1

Any assistance would be appreciated.

conftest.py

import pytest
from playwright.sync_api import sync_playwright


@pytest.fixture()
def set_up_tear_down(page) -> None:
    browser = chromium.launch()
    context = browser.new_context()
    # Start tracing before creating / navigating a page.
    page.set_viewport_size({"width": 1536, "height": 800})
    page.goto("google.com")
    # Stop tracing and export it into a zip archive.
    context.tracing.stop(path="trace.zip")
    yield page

1 Answer 1

0

You're getting E NameError: name 'chromium' is not defined because you don't have the playwright fixture in the set_up_tear_down(page) fixture.

Just add it like below and you won't get that error:

import pytest
from playwright.sync_api import sync_playwright


@pytest.fixture()
def set_up_tear_down(playwright, page) -> None:
    chromium = playwright.chromium
    browser = chromium.launch()
    context = browser.new_context()
    # Start tracing before creating / navigating a page.
    page.set_viewport_size({"width": 1536, "height": 800})
    page.goto("google.com")
    # Stop tracing and export it into a zip archive.
    context.tracing.stop(path="trace.zip")
    yield page

Please have a look at the documentation for pytest fixtures and the Browser class for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.