Skip to content

Latest commit

 

History

History
55 lines (40 loc) · 1.26 KB

puppeteer.md

File metadata and controls

55 lines (40 loc) · 1.26 KB

Testing web apps using Puppeteer

Translations: Français

Dependencies

Setup

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

./test/_withPage.js

importpuppeteerfrom'puppeteer';module.exports=async(t,run)=>{constbrowser=awaitpuppeteer.launch();constpage=awaitbrowser.newPage();try{awaitrun(t,page);}finally{awaitpage.close();awaitbrowser.close();}}

Usage example

./test/main.js

importtestfrom'ava';importwithPagefrom'./_withPage';consturl='https://google.com';test('page title should contain "Google"',withPage,async(t,page)=>{awaitpage.goto(url);t.true((awaitpage.title()).includes('Google'));});test('page should contain an element with `#hplogo` selector',withPage,async(t,page)=>{awaitpage.goto(url);t.not(awaitpage.$('#hplogo'),null);});test('search form should match the snapshot',withPage,async(t,page)=>{awaitpage.goto(url);constinnerHTML=awaitpage.evaluate(form=>form.innerHTML,awaitpage.$('#searchform'));t.snapshot(innerHTML);});
close