Rayrun

How do I run a headed test in Playwright without XServer?

Answer

To run a headed test in Playwright without XServer, you'll need to use the --headed option and set up a virtual display using Xvfb (X virtual framebuffer). Xvfb creates a virtual display in memory, allowing applications to run in an X11 environment without a physical display.

First, install Xvfb on Ubuntu or Debian-based systems:

sudo apt-get update
sudo apt-get install xvfb

Next, start Xvfb and configure the virtual display:

Xvfb :99 -screen 0 1024x768x16 &
export DISPLAY=:99

This command starts Xvfb on display number 99 with a 1024x768 resolution and 16 bits per pixel color depth. The export DISPLAY=:99 command sets the DISPLAY environment variable for applications to find the virtual display.

With Xvfb running, you can execute your @playwright/test headed tests without XServer:

npx playwright test my-test.spec.ts --headed

This command runs the my-test.spec.ts file in a headed browser, allowing you to see the browser window during test execution. By using Xvfb, you can run headed tests on servers without X11 installed, such as headless Linux servers.

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].