Features

Puppeteer Testing

Puppeteer is an automation framework which uses the Chrome Devtools protocol to automate a browser.


Please see the documentation below on how to run Puppeteer tests on Chrome and Microsoft Edge browsers in the TestingBot cloud.

Installing Puppeteer

To install Puppeteer, simply use yarn or npm:

npm i --save puppeteer

By default, installing Puppeteer will also install a Chromium build.
If you want to only use our cloud, you might consider installing Puppeteer without the bundled Chromium build, called puppeteer-core:


npm i puppeteer-core

Running your first Puppeteer test

To run your first test, please use this example:


const puppeteer = require('puppeteer')

const browser = await puppeteer.connect({
  browserWSEndpoint: 'wss://cloud.testingbot.com?key=api_key&secret=api_secret&browserName=chrome&browserVersion=latest'
})

const page = await browser.newPage()
await page.goto('https://testingbot.com')
await page.screenshot({ path: 'screenshot.png' })
browser.close()

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

const puppeteer = require('puppeteer')

const browser = await puppeteer.connect({
  browserWSEndpoint: 'wss://cloud.testingbot.com?key=api_key&secret=api_secret&browserName=edge&browserVersion=latest'
})

const page = await browser.newPage()
await page.goto('https://testingbot.com')
await page.screenshot({ path: 'screenshot.png' })
browser.close()

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

Updating your existing Puppeteer scripts

With a Puppeteer test, you'll usually start a browser with await puppeteer.launch()


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


Before

const browser = await puppeteer.launch()

After

const browser = await puppeteer.connect({
  browserWSEndpoint: 'wss://cloud.testingbot.com?key=api_key&secret=api_secret&browserName=chrome&browserVersion=latest'
})

Specifying browser and version

To specify on which browser and version your Puppeteer test should run, you can include both a browserName and browserVersion in the browserWSEndpoint URL.

Select a browser & version

Debugging Tips

Below are some tips on how to debug your Puppeteer scripts.


Verbose Logging

To see logs of what Puppeteer is sending and receiving, you can use this environment variable: env DEBUG="puppeteer:*"

DEBUG="puppeteer:*" node puppeteer.js

Slow Motion option

With the slowMo option you can slow down each operation during the Puppeteer session.
To see the result, please specify these options:


const puppeteer = require('puppeteer')

const browser = await puppeteer.connect({
  browserWSEndpoint: 'wss://cloud.testingbot.com?key=api_key&secret=api_secret&browserName=edge&browserVersion=latest',
  headless: false,
  slowMo: 250 // slow down by 250ms
})

const page = await browser.newPage()
await page.goto('https://testingbot.com')
await page.screenshot({ path: 'screenshot.png' })
browser.close()

Puppeteer Framework examples

  • Jest

    Jest-Puppeteer allows you to run tests with Jest on browsers controlled with Puppeteer.

  • Chromedp

    chromedp is a Golang framework to use with Puppeteer.

  • PyTest

    pytest-pyppeteer is a Python framework to use with Puppeteer.

  • WebdriverIO

    WebdriverIO is an Automation Test Framework for Node.js.