Features

Playwright Testing

Playwright is a NodeJS library written by Microsoft to automate browsers with the DevTools protocol. Its syntax is very similar to Puppeteer.

Installing Playwright

To install Playwright, simply use yarn or npm:


npm i --save playwright

By default, installing Playwright will also install one or more browsers.
If you only want to use the TestingBot cloud, you might consider installing Playwright without the bundled browsers, called playwright-core:


npm i playwright-core

Running your first Playwright test

To run your first test, please use this example:


const pw = require('playwright');

(async () => {
  const browser = await pw.chromium.connectOverCDP({
    wsEndpoint: 'wss://cloud.testingbot.com?key=api_key&secret=api_secret&browserName=chrome&browserVersion=latest',
  });
  const context = await browser.newContext();
  const page = await context.newPage();

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

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

This example will start a Chrome Browser, navigate to testingbot.com and save a PNG screenshot of the webpage.

const pw = require('playwright');

(async () => {
  const browser = await pw.chromium.connectOverCDP({
    wsEndpoint: 'wss://cloud.testingbot.com?key=api_key&secret=api_secret&browserName=edge&browserVersion=latest',
  });
  const context = await browser.newContext();
  const page = await context.newPage();

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

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

This example will start a Microsoft Edge Browser, navigate to testingbot.com and save a PNG screenshot of the webpage.

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.connectOverCDP({
    wsEndpoint: 'wss://cloud.testingbot.com?key=api_key&secret=api_secret&browserName=edge&browserVersion=latest',
});