Getting Started with Puppeteer
Explore how Puppeteer facilitates automated web testing through its browser and context management. Learn key concepts like JavaScript promises, asynchronous scripting, and file upload automation. Understand Puppeteer's integration with test runners like Jest and Mocha to enhance your front-end testing workflow.
We'll cover the following...
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.
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();
})();The preceding code snippet navigates to ...