What to choose? Selenium or Puppeteer
By: Lakmal Liyanage
Tags: Test Automation, QA, Puppeteer, Web Automation, Selenium

What is the most suitable tool for a browser automation project?

Lets talk about it focusing on installation, test stability, features comparison and test speed.

Introduction

Selenium

It has been around for a while now, since 2004 which is longest compared to puppeteer. This is the most popular and widely used browser automation tool which is support almost all the browsers currently out there and wide range of programming languages. (Java, JavaScript, C#, etc…)

Puppeteer

Puppeteer is released in 2017 which is much newer than selenium. It is developed and maintained by Google. This can be only used with Chromium based browsers. Which are Chrome and Chromium. Also technically it should support for newly released MS Edge which is based on chromium. (haven’t check yet). Puppeteer supports only Javascript.

Installation

Assuming working with Javascript and Node.js, Chrome are already installed.

Selenium

Run npm install selenium-webdriver Download chrome driver version which is compatible with installed chrome version if not this won’t work. Update system PATH to add chrome driver location

Puppeteer

Just run npm install puppeteer . This will install puppeteer and download it's compatible chromium (base of chrome) browser by it self.

Feature comparison

Lets check simple example. If you used selenium before for sure you have encountered ElementNotInteractableError: element not interactable error. Way to fix this issue is add driver.sleep after action/navigation as follows.

await driver.get("https://google.com”);

await driver.sleep(2000);

This will fix the issue but it makes test slower. For sure you have to use this multiple times on your tests/test suits. Puppeteer has overcome this issue by passing optional parameter to page.goto() function as follows.

await page.goto("https://google.com”, { waitUntil: "networkidle0" });

This will pause code execution for maximum 500ms until all network interactions are completed. [more info https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#pagegotourl-options ]

Test Stability

When running test with selenium there are most common set of failures

ElementNotInteractableError

WebDriverError: chrome not reachable

Error: Server terminated early with status 1

We already discuss how to fix first issue on feature comparison. The second and third issue can caused due to incompatible version of chrome driver. For now haven’t seen any noticeable issues on Puppeteer.

Test Speed

As discussed above on feature comparison section adding explicit timeouts on selenium tests introduce unnecessary slowness to the tests. Puppeteer tests are faster compared to selenium since it doesn’t required explicit timeouts. Puppeteer tests are more reliable since its directly interacting with chrome rather than going through bridging web driver as Selenium.

What to use?

Even though Puppeteer has advantages that we discussed Selenium still has cross browser compatibility and multiple language advantage. Also Selenium has more community support than Puppeteer. But Puppeteer will be the next level of browser test automation tool.

Hope this helps you to make decision what to use when rather than directly using most popular tool.

Happy Testing !!!!