×
Anup Manekar
Delivery Director
Anup Manekar, as the Delivery Director at Nitor Infotech, has over 13 years' experience in the IT domain. He has proven expertise in building s... Read More

When it comes to test automation, Selenium is the only tool in the open-source space which relies on executing JavaScript inside the browser. It has largely helped companies achieve good coverage of automation. However, in most cases, there are concerns due to its flakiness, synchronization, and speed.

However, testing types and tools are evolving with rise of Node platform and JavaScript based apps. New development frameworks with inbuilt support of testing libraries (For e.g.: Jest for React, Protractor for Angular etc.) are the order of the day. Additionally, multiple libraries for continuous testing as well as end-to-end UI testing are surfacing, such as PhantomJS, Puppeteer, Cypress, PollyJS.

Among these, Puppeteer has opened new possibilities in the realm of test automation with exposure to Chrome Dev Tools API. Today when it comes to automated web testing, Selenium & Puppeteer are two names that come to the fore- the latter making all the noise for the right reasons.

In this blog, I will introduce you to Puppeteer and shed light on how you can leverage it to transform the process continuous testing.

What exactly is Puppeteer?

Puppeteer is a Node library used to enable Chrome browser testing. In other words, Puppeteer runs headless Chrome or Chromium instances by default, which is why they are always mentioned in tandem. Nowadays, with the dominant use of SaaS based applications, Puppeteer-based testing holds a pivotal place.

Puppeteer provides a simple API to control Chromium instances. Through it, common tasks such as typing inputs, clicking buttons, testing usability of web pages, and even web scraping can be carried out easily. Puppeteer is a Chrome team official platform, and uses the Chrome Remote Debug Protocol, just as with Chrome Dev Tools. This library supports modern JavaScript syntax available in Google Chrome.

How can you get started with Puppeteer?

Installation

To use Puppeteer in your project, run: npm i puppeteer# or “yarn add puppeteer”

You should note that when you install Puppeteer, it downloads a recent version of Chromium (~170MB Mac, ~282MB Linux, ~280MB Win), a guaranteed API fit.

Environment Variables

Puppeteer looks for certain environment variables to aid its operations. If these variables aren’t found in the environment during the installation step, a lower cased variant of these variables will be used from the npm config.

  • HTTP_PROXY, HTTPS_PROXY, NO_PROXY – Use this to define HTTP proxy settings and to download & run Chromium
  • PUPPETEER_SKIP_CHROMIUM_DOWNLOAD – Do not download bundled Chromium during installation step
  • PUPPETEER_DOWNLOAD_HOST – Overwrite URL prefix used to download Chromium

At this juncture, you should note that this includes the protocol and might even include path prefix. It defaults to https://storage.googleapis.com.

  • PUPPETEER_CHROMIUM_REVISION – Specify a certain version of Chromium you’d like Puppeteer to use.
  • PUPPETEER_EXECUTABLE_PATH – Specify an executable path to be used in puppeteer.launch.

Now, you need to be aware about the fact that Puppeteer is only guaranteed to work with the bundled Chromium, so make sure to use at your own risk.

Puppeteer-core

Since version 1.7.0, we publish the puppeteer-core package, a version of Puppeteer that does not download Chromium by default. The npm i puppeteer-core# or “yarn add puppeteer-core” Puppeteer-core is intended to be a lightweight version of Puppeteer. You can use it either to launch an existing browser installation or to connect to a remote one.

It is important to check that the version of puppeteer-core you install is compatible with the browser you intend to connect.

What are the Features of Puppeteer?

While Puppeteer’s ability to launch a headless browser is one feature that has gained it some fame, that is not the only feature which makes it a go-to-choice for test automation. It also has other unique features that make it enhance the software testing process, let’s take a quick look at some of them.

Easy Automation:  While there are other tools that can be used for web automation, Puppeteer comes out on top. This is because it works best for one browser only – the Headless Chrome browser, therefore it carries out web automation tasks in the most efficient way possible. Puppeteer is also compatible with popular unit testing libraries such as Mocha and Jasmine.

Screenshot Testing:  This is a vital feature for any automated web testing task. Screenshots help keep track of the result of interactions with elements on a web page. Libraries such as Puppeteer-screenshot tester also exist in Puppeteer that allow the comparing of screenshots generated while testing. Besides generating test screenshots, Puppeteer can also help generate PDFs from tested web pages.

Performance Testing:  Chrome provides De Tools that allows the recording of the performance timeline of web pages, and Puppeteer takes advantage of this too. With Puppeteer, timeline traces of websites can be captured to examine performance issues. Due to the Puppeteer’s high-level API control over Chrome Developers Tools Protocol, it gives users the ability to control service workers and test caching of websites.

As you can see, Puppeteer is all set to the transform the era of automated testing. The success of Puppeteer with Chrome cannot be reduced only to its efficiency; the fact that it is Google-backed is also the reason why it has been accepted and recognized globally. Additionally, this software offers a high-level API to control the Chrome browser via the Dev Tools protocol. Leveraging Puppeteer for automation, we can develop solutions to solve problems, whether it is for quality assurance, productivity enhancements or data aggregation.

The foundation of success in today’s digital world lies in successful adoption of agile principles and DevOps processes, which are in turn dependent on faster and reliable feedback from testing pipeline.

Reach out to us to learn more about software testing and read our performance testing capability document to learn how we helped a client conduct performance testing for a healthcare application.

subscribe image

Subscribe to our
fortnightly newsletter!

we'll keep you in the loop with everything that's trending in the tech world.

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. Accept Cookie policy