...

/

Getting Started with Puppeteer

Getting Started with Puppeteer

Learn about Puppeteer essentials: PWA testing, HAR files, puppeteer-core, and asynchronous handling with promises.

PWA testing

Like the Playwright framework, Puppeteer also drives its automation through the Browser object, which then drills down into the multiple BrowserContext sessions that can operate on multiple pages, extensions, and frames.

Press + to interact
Google Puppeteer high-level architecture diagram
Google Puppeteer high-level architecture diagram

Since Google is the leader in PWAs and was the first technology provider to launch such application types, within this framework, we’ll be able to use built-in methods to test such application types. In the architecture diagram above, we can see the service workers support under the BrowserContext component within the web applications.

In this chapter, we’ll expand on the Puppeteer JavaScript class. Let’s look at the code below:

const puppeteer = require('puppeteer');
const PuppeteerHar = require('puppeteer-har');

(async () => {
  const browser = await puppeteer.launch({headless:false, args: ['--no-sandbox']});
  const page = await browser.newPage();

  const har = new PuppeteerHar(page);
  await har.start({ path: 'book_demo.har' });
  await page.goto('https://www.packtpub.com/');
  await har.stop();
  await browser.close();
})();
Capture HAR file with Puppeteer for the Packt Publishing website

The preceding code snippet navigates to ...