Skip to content
Go to file
Cannot retrieve contributors at this time
55 lines (40 sloc) 1.28 KB

Testing web apps using Puppeteer

Translations: Français


  • Puppeteer: npm install --save-dev puppeteer


The first step is setting up a helper to configure the environment:


const puppeteer = require('puppeteer');

module.exports = async (t, run) => {
	const browser = await puppeteer.launch();
	const page = await browser.newPage();
	try {
		await run(t, page);
	} finally {
		await page.close();
		await browser.close();

Usage example


const test = require('ava');
const withPage = require('./_withPage');

const url = '';

test('page title should contain "Google"', withPage, async (t, page) => {
	await page.goto(url);
	t.true((await page.title()).includes('Google'));

test('page should contain an element with `#hplogo` selector', withPage, async (t, page) => {
	await page.goto(url);
	t.not(await page.$('#hplogo'), null);

test('search form should match the snapshot', withPage, async (t, page) => {
	await page.goto(url);
	const innerHTML = await page.evaluate(form => form.innerHTML, await page.$('#searchform'));
You can’t perform that action at this time.