Puppeteer is a popular framework for running headless tests on Chrome and Chromium browsers.
Puppeteer is a popular framework for running headless tests on Chrome and Chromium browsers.
It uses the Chrome Devtools protocol to automate the headless browser.
Installing Puppeteer
To install Puppeteer, just use yarnor npm:
npm i --save puppeteer
By default, installing Puppeteer will also install a Chromium.Se build you want to use only the cloud, you might consider installing Puppeteer without the packaged Chromium build, called puppeteer-core:
npm i puppeteer-core
Running your first Puppeteer test
To run your first test, use this example:
Chrome
const puppeteer = require('puppeteer')
const browser = await puppeteer.connect({
browserWSEndpoint: 'wss://chrome.headlesstesting.com?token=[YOUR-TOKEN]'
})
const page = await browser.newPage()
await page.goto('https://headlesstesting.com')
await page.screenshot({ path: 'screenshot.png' })
browser.close()
This example will launch a Chrome Headless browser, navigate HeadlessTesting.com, and save a PNG screenshot.
Update your existing Puppeteer scripts
With a Puppeteer test, you will usually start a browser with await puppeteer.launch()
To start using the service, simply replace this line with the browser endpoint:
Before
const browser = await puppeteer.launch()
After
const browser = await puppeteer.connect({
browserWSEndpoint: 'wss://chrome.headlesstesting.com?token=[YOUR-TOKEN]'
})
Debugging Tips
Below are some tips on how to debug your Puppeteer scripts.
Detailed Record
To see the records 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 slowOption, you can slow down each operation during the Puppeteer session.To see the result, specify these options:
const browser = await puppeteer.connect({
browserWSEndpoint: 'wss://chrome.headlesstesting.com?token=[YOUR-TOKEN]&screenRecorder=true',
headless: false,
slowMo: 250 // slow down by 250ms
System requirements:
CPU: 1.8 GHz dual core processor
RAM: 2 GB
HDD / SSD: 50 GB of free space on the main drive
Operating system: Microsoft Windows 8 32-bit, Microsoft Windows 7 32-bit and Microsoft Windows Vista 32-bit
Resolution: 1024×768
You don't know what software you need or you haven't found what you were looking for? We have a team ready to help you choose the right software for your company.