DEV Community

Cover image for Puppeteer Web Automation
Deepa Subramanian
Deepa Subramanian

Posted on • Updated on

Puppeteer Web Automation

What is Puppeteer?

Google launched puppeteer in 2017. Puppeteer is a powerful library which provides an API to control headless Chrome or Chromium over the DevTools Protocol.

What can it do?

Puppeteer can be used for automating all the manual or GUI interactions. When it comes to debugging, this tool becomes any developer's choice.

How does it work?

Alt Text

Why choose Puppeteer?

  1. Puppeteer requires zero setup. Comes with chromium version making it very easy to start with.
  2. It has event-driven architecture which removes potential flakiness. So, there’s no need to add unnecessary wait and sleep times.
  3. Puppeteer runs headless by default which makes it super fast.
  4. Puppeteer v1.5.0 also exposes browser contexts, making it possible to efficiently parallelize test execution.
  5. Run in a Docker container or serverless environment.
  6. Intercept network requests.
  7. Dev tools can be used to capture performance info and can run commands in the console.
  8. Test a Chrome extension.
  9. Analyze JS bundle using the analyzer available.
  10. Emulate mobile viewports.
  11. Speed: Puppeteer has almost zero performance overhead over an automated page.
  12. Security: Puppeteer operates off-process with respect to Chromium, making it safe to automate potentially malicious pages.
  13. Stability: Puppeteer should not be flaky and should not leak memory.
  14. Simplicity: Puppeteer provides a high-level API that’s easy to use, understand, and debug.

How it can be used for test automation?

Using Puppeteer you can launch web pages, make UI navigations, take screenshots and generate pdf's. Pupetteer can be used with testing framework such as Jest, Mocha or make your own test framework too! It works well with Chai assertion library.

What ways this tool could help your team?

Puppeteer is the go-to tool for automation if speed and performance of automated tests are more important than portability and compatibility.

Summary

  • Puppeteer works seamlessly with single-page applications.
  • It creates an up-to-date, automated testing environment by directly in the latest version of Chrome using the latest JavaScript and browser features.
  • Supports FireFox(beta).
  • Supports parallel execution.
  • Crawl a SPA (Single-Page Application) and generate pre-rendered content (i.e. "SSR" (Server-Side Rendering)).
  • Capture a timeline trace of your site to help diagnose performance issues.
  • If you are looking for Speed, stability, security and simple tool, then puppeteer is the best choice.

Puppeteer does not support the following

  1. Cross browser compatibility testing
  2. Does not support licensed formats such as AAC or H.264 media formats
  3. Puppeteer does not support HTTP Live Streaming (HLS).
  4. Does not support multiple languages, supports only JavaScript.

More details about test frame work and tests:
Jest framework - https://github.com/sdkdeepa/pptr-testframework
Mocha-chai - https://github.com/sdkdeepa/pptr-mocha.

Discussion (0)