top of page
Writer's pictureCraig Risi

The Pros and Cons of different UI automation test tools - Puppeteer


In my previous post, we spoke about one of the most exciting newcomers to the UI automation game in Playwright. Today, I want to briefly discuss the precursor to Playwright – Puppeteer. And while it’s easy to dismiss a testing tool for a new version of it that addresses some of the tool's initial deficiencies, Puppeteer is still a solid tool in its own right and one that still deserves attention in the test automation community.


Playwright has largely been the brainchild of Microsoft, but much like Microsoft has evolved its browser technology to be based on the Chromium engine, initially developed by Google, so is it the case on the test automation front, as Puppeteer was actually created by the Google Chrome team and was first released in 2017.

What the internal puppeteer architecture looks like


Puppeteer was built on top of the Chrome DevTools Protocol, which provides a high-level API to control the Chrome browser. Like Cypress, it allows Puppeteer to interact with web pages directly rather than operate outside of the browser and be able to better manipulate the different web elements. Unlike the other testing tools, however, Puppeteer can do this in a headless format without needing to fully render the website, which saved a lot of time in execution. It does this by using its API to manipulate the status of objects and being able to determine their final result. This also allows Puppeteer to mock certain dependencies as well and provide a high level of coverage in its automation tests.


In addition to its testing capabilities, Puppeteer also quickly gained popularity for its web scraping capabilities. Developers found that they could use Puppeteer to automate the process of extracting data from websites, which saved them a significant amount of time and effort.

While most of the benefits of Puppeteer derive from its headless format it is possible to switch this off and allow for fully rendered sites should there be complex elements that may require this to verify how it looks or to get a better visual snapshot of the overall web application.


As with Selenium, Cypress, and Playwright – Puppeteer is a web-only automation framework and so interreacts outside of the browser cannot be verified. And whereas the likes of Selenium may have some drivers which can assist with things like basic Windows tasks or DB checks, Puppeteer can only do this if there is an API or command that can be initiated directly from the browser to verify this functionality.


Where Puppeteer perhaps differs the most from Playwright is that it uses an HTTP connection as opposed to a WebSocket connection, which means it is more susceptible to flakiness in dealing with asynchronous communication. And while it doesn’t run in parallel directly, it can easily do so with the use of other tools.


Pros:

  • User-friendly API: Puppeteer provides a simple and easy-to-use API that makes it easy to write and maintain test scripts.

  • Supports Headless mode: Puppeteer can run in headless mode, which means that it can run tests without the need for a graphical user interface, making it faster and more efficient.

  • Supports multiple browsers: Puppeteer can be used to automate tests on multiple browsers, including Chrome, Firefox, and Safari.

  • Supports screenshots and PDF generation: Puppeteer makes it easy to capture screenshots and generate PDFs of web pages, which can be useful for testing purposes.

  • Supports parallel testing: Puppeteer can be used in conjunction with other tools, such as Jest or Mocha, to run tests in parallel, which can significantly reduce the time it takes to run tests.

Cons:

  • Limited cross-browser testing: While Puppeteer can automate tests on multiple browsers, it only supports the latest version of each browser, which can be limiting if you need to test on older versions.

  • Requires knowledge of Node.js: Puppeteer is a Node.js library, which means that developers need to have a good understanding of Node.js to use it effectively.

  • May not be suitable for non-web applications: Puppeteer is primarily designed for web applications, so it may not be the best choice for testing non-web applications.

  • Slow performance on complex web pages: Puppeteer's performance can suffer when working with complex web pages, especially if the page contains a lot of dynamic content.

  • May require additional tools for end-to-end testing: While Puppeteer can be used for end-to-end testing, it may require additional tools, such as a testing framework or a CI/CD pipeline, to be effective.

When to select Puppeteer:

This part is pretty similar to my previous post on Playwright, as the two tools share a lot of common libraries and design approaches, meaning that they will likely suit the same type of organizations.

  • When you need high automated execution speed in your pipelines

  • If your existing test automation struggles with a lot of flakiness and you need to improve the authenticity of your test results

  • If you need to transition to a pipeline-based CI testing tool but have a lot of existing Selenium scripts

  • If you have a technical testing team that understands coding fundamentals.

Puppeteer is an important tool in the web automation space, whose headless functionality provides a useful benefit to many test automation engineers. Playwright might be the new toy that is getting people excited, but much like how Google’s Chrome still delivers some extra features outside of Edge’s efficiency, Puppeteer still has something to offer its Microsoft counterpart.

Comments


Thanks for subscribing!

bottom of page