Playwright Testing


Playwright is a Node library written by Microsoft to automate browsers. It is created by the same team that originally built Puppeteer at Google.

Installing Playwright

To install Playwright, you can use yarn or npm:

npm i --save playwright

Running your first Playwright test

To run your first test, please use this example:


const pw = require('playwright');

(async () => {
  const browser = await pw.chromium.connect({
    wsEndpoint: 'wss://chrome.headlesstesting.com?token=[YOUR-TOKEN]&browserVersion=dev',
  });
  const context = await browser.newContext();
  const page = await context.newPage();

  await page.goto('https://headlesstesting.com/');
  await page.screenshot({ path: 'screenshot.png' });

  await browser.close();
})();

This example will start a Chrome Headless Browser, navigate to HeadlessTesting.com and save a PNG screenshot.

If you are using the latest version of Playwright then we suggest you specify browserVersion=dev.

This will add some delay to the start of your test, since we first need to download and install the latest browser version before your test can start.


See our compatibility overview to know which browserVersion is compatible with which Playwright version.

const pw = require('playwright');

(async () => {
  const browser = await pw.chromium.connect({
    wsEndpoint: 'wss://edge.headlesstesting.com?token=[YOUR-TOKEN]',
  });
  const context = await browser.newContext();
  const page = await context.newPage();

  await page.goto('https://headlesstesting.com/');
  await page.screenshot({ path: 'screenshot.png' });

  await browser.close();
})();

This example will start a Microsoft Edge Headless Browser, navigate to HeadlessTesting.com and save a PNG screenshot.

Updating your existing Playwright scripts

With a Playwright test, you'll usually start a browser with await pw.chromium.launch()


To start using our service, simply replace this line with our browser endpoint:


Before

const browser = await pw.chromium.launch();

After

await pw.chromium.connect({
    wsEndpoint: 'wss://chrome.headlesstesting.com?token=[YOUR-TOKEN]&browserVersion=dev',
});

Browser Compatibility

You'll need to specify a different browserVersion, depending on the Playwright version you are using:


Chrome:

browserVersion Playwright Version
83 or leave blank v1.0.2
dev v1.0.2
beta v1.0.2
81 v0.10.0

Firefox

Currently, Firefox is not working very well with Playwright.
Once we have a stable solution, we will update the section of this page.


Edge

browserVersion Playwright Version
80 or leave blank v0.9.24