I’m using pytest-playwright
running in a debian container and trying to follow their docs.
playwright 1.43.0
pytest-playwright 0.5.0
I just ran
pip install pytest-playwright
playwright install
playwright install-deps
Basic tests from the docs:
import re
from playwright.sync_api import Page, expect
def test_has_title(page: Page):
page.goto("https://playwright.dev/")
# Expect a title "to contain" a substring.
expect(page).to_have_title(re.compile("Playwright"))
def test_get_started_link(page: Page):
page.goto("https://playwright.dev/")
# Click the get started link.
page.get_by_role("link", name="Get started").click()
# Expects page to have a heading with the name of Installation.
expect(page.get_by_role("heading", name="Installation")).to_be_visible()
I run pytest -vv --tracing on
to generate traces.
Try to view them: playwright show-trace blah/trace.zip
Get this error:
playwright show-trace test-results/test-basic-py-test-get-started-link-chromium/trace.zip
pw:browser <launching> /root/.cache/ms-playwright/chromium-1112/chrome-linux/chrome --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,HttpsUpgrades,PaintHolding --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --no-sandbox --app=data:text/html, --window-size=1280,800 --test-type= --user-data-dir=/tmp/playwright_chromiumdev_profile-PiCNtL --remote-debugging-pipe about:blank +0ms
pw:browser <launched> pid=1940 +7ms
pw:browser [pid=1940][err] [0509/143817.126425:WARNING:stack_trace_posix.cc(918)] Failed to open file: /mnt/lima-rosetta/rosetta +53ms
pw:browser [pid=1940][err] Error: Success +1ms
pw:browser [pid=1940][err] [0509/143817.232732:WARNING:stack_trace_posix.cc(918)] Failed to open file: /mnt/lima-rosetta/rosetta +103ms
pw:browser [pid=1940][err] Error: Success +0ms
pw:browser [pid=1940][err] [0509/143817.232738:WARNING:stack_trace_posix.cc(918)] Failed to open file: /mnt/lima-rosetta/rosetta +1ms
pw:browser [pid=1940][err] Error: Success +0ms
pw:browser [pid=1940][err] [1940:1955:0509/143817.346236:ERROR:bus.cc(407)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory +111ms
pw:browser [pid=1940][err] [1940:1940:0509/143817.352343:ERROR:ozone_platform_x11.cc(243)] Missing X server or $DISPLAY +6ms
pw:browser [pid=1940][err] [1940:1940:0509/143817.352359:ERROR:env.cc(258)] The platform failed to initialize. Exiting. +1ms
pw:browser [pid=1940] <gracefully close start> +36ms
pw:browser [pid=1940] <kill> +2ms
pw:browser [pid=1940] <will force kill> +0ms
pw:browser [pid=1940] <process did exit: exitCode=1, signal=null> +1ms
pw:browser [pid=1940] starting temporary directories cleanup +0ms
pw:browser [pid=1940] finished temporary directories cleanup +6ms
pw:browser [pid=1940] <gracefully close end> +0ms
Error: Protocol error (Browser.getVersion): Internal server error, session closed.
Error about Missing X server or $DISPLAY +6ms
doesn’t make sense because it runs headless by default: https://playwright.dev/python/docs/test-runners
I read somewhere maybe I need to disable the gpu but I see no options for that. I’m using the pytest plugin which I think means I should not be creating a browser context myself in code correct?
I tried to disable the GPU like this but I’m not sure if its correct because they have no official examples of how to properly use browser_type_launch_args: https://playwright.dev/python/docs/test-runners
@pytest.fixture(scope="session")
def browser_type_launch_args(browser_type_launch_args):
return {**browser_type_launch_args, "args": ["--disable-gpu"]}
I’m just trying to use pytest-playwright with their most basic examples.