App & Browser Testing Made Easy

Give your users a seamless experience by testing on 3000+ real devices and browsers. Don't compromise with emulators and simulators

Get Started free
Home Guide Puppeteer vs Selenium: Core Differences

Puppeteer vs Selenium: Core Differences

By Neha Vaidya, Community Contributor -

Even though both Puppeteer and Selenium serve the same purpose of facilitating automation testing, a comparison of them is helpful for developers and testers seeking to choose the right tool for their requirements, whether project-based or long-term.

This article will explore their strengths as automation test frameworks and allow readers to make an informed choice between them. 

Introduction to Puppeteer

Puppeteer Logo

Puppeteer is a Node library that provides a high-level API to control headless Chrome over the DevTools Protocol. Also known as a Headless Chrome Node API, it is useful for automating the Chrome browser to run website tests.

Fundamentally, Puppeteer is an automation tool and not a test tool. This simply means it is incredibly popular for use cases such as scraping, generating PDFs, etc.

Puppeteer uses Chrome DevTools protocol and the debugger protocol for Selenium is JSONWire. Both are used to perform clicks. In the case of practice Puppeteer and Selenium, use the same code for performing clicks.

Prominent Features of Puppeteer

The most prominent features supported by Puppeteer are as follows:

  1. Screenshot Testing
  2. Performance Testing
  3. Web Scraping
  4. Easy Automation

Limitations of Puppeteer

The complexity and automation context are changing with each passing day and hence, one tool might not be the solution for all. Puppeteer has some limitations like, it supports only Chrome browser. Puppeteer for Firefox is a work in progress.

Introduction to Selenium

Selenium automates browsers. Primarily, it is for automating web applications for testing purposes but is certainly not limited to just that. It supports numerous features that are helpful for automation testing. 

Selenium Logo
Selenium supports multiple programming languages and platforms. It also supports testing on multiple major browsers in global usage.

Now, let’s understand the pros and cons of Selenium

Pros of Selenium:

  1. Open source and freely available
  2. Integrated with CI, and Agile
  3. Supports cross-browser, a wide range of OS and programming languages
  4. Has huge community support along with a large library and extensions

Cons of Selenium:

  1. Steep learning curve
  2. Doesn’t support built-in image comparison

Explore the various features of Selenium with this Selenium WebDriver tutorial. 

Try Selenium Testing for Free

Market Trends on Selenium and Puppeteer

The image below depicts that Selenium’s popularity is long-established and keeps growing. That doesn’t imply that Puppeteer is not popular. It is especially popular when it comes to automating the Chrome Browser.

Both are unique in their own ways Selenium does take an edge over Puppeteer in terms of overall popularity and usage.

Puppeteer vs SeleniumSource

Setup and Test Implementation of Puppeteer and Selenium

Selenium and Puppeteer are the two automation testing tools that can be directly installed using npm.

  • To install Selenium, type the following command in the terminal:
npm install selenium-webdriver

Another way is to study and use the Selenium Installation here. 

Here, creating a driver and using it is easy—the syntax is verbose compared to the alternatives but still pretty straightforward:

The example below located the Yahoo sign up page using the Xpath locator.

driver.get("https://login.yahoo.com/account/create");
driver.findElement(By.xpath("//input[@id='usernamereg-firstName']")).sendKeys("Your-Name"); // Will send values to First Name tab
driver.findElement(By.xpath("//input[@id='usernamereg-lastName']")).sendKeys("Your-Last_name"); //xpath for last name box
driver.findElement(By.xpath("//input[@id='usernamereg-yid']")).sendKeys("email@yahoo.com"); //xpath for email box

  • Now, on to Puppeteer. To install Puppeteer, type the command below in the terminal:
npm install puppeteer

Now, let’s locate the same sign-up page using the Puppeteer syntax:

await page.goto(‘https://login.yahoo.com/account/create’);

await page.click(‘button’);

await page.type(‘#sign-up’, ‘your_name’);

await page.type(‘[type=email]’, ‘your_email’);

People also read: How to Build and Execute Selenium Projects


Puppeteer vs Selenium: Core Differences

PuppeteerSelenium
Puppeteer was developed by Google and runs the script on ChromiumSelenium is the node.js library that is used to automate Chrome. This library is open-source and provides a high-level API to control Chrome
Is a Node.js libraryIs a web framework for testing web applications
Works only with Chrome or Chromium and does not support other browsers.  Supports multiple browsers like Chrome, IE, Firefox, Safari, etc. Cross-platform support is provided across all the available browsers
Was released in 2017Was released in 2004
Supports only Node.jsSupports multiple languages like Python, Ruby, Javascript, Java, etc.
Supports only web automationSupports web automation and mobile automation
Screenshot can be taken of both PDFs and imagesScreenshot can be taken of both PDFs and images only in Selenium 4

Selenium or Puppeteer: Which is the preferred one?

Considering all the above factors, Puppeteer is the go-to tool if devs and testers are specifically working with Google Browser alone. 

But considering the fact that cross-browser testing must be conducted across platforms and using multiple programming languages, Selenium is the best fit for automation testing. It comes with library support for multiple programming languages, drivers for different browsers, and more.

It is not always about cross-browser support or platform support, sometimes other functionalities like record and playback for testing web applications matter a lot. That’s something Selenium supports. The code can be re-used, and also it is loaded with packages and test suites. It is considered to be a tool that is the best fit for Automation testing. As ease of access and configuration is pretty simple, one doesn’t have to download Selenium like a piece of software. But they might need some of its components to run tests on automated browser instances on their own device.

To get a hang of this, simply head over to Automate Documentation. Pick a language and/or framework you typically work with. Follow the steps to install the components required, and run a couple of sample tests. It is easy to acquire a functional understanding of Selenium automation testing in no time.

Ready to test websites on real browsers and devices? Take a look at BrowserStack Automate, which offers instant access to a cloud Selenium Grid and 2000+ browsers and real desktop and mobile devices.

Try running the code detailed above using Selenium. Bear in mind that Selenium tests must be run on a real device cloud to get completely accurate results. BrowserStack’s cloud Selenium grid of 2000+ real browsers and devices allows testers to automated visual UI tests in real user conditions. Simply sign up, select a device-browser-OS combination, and start running tests for free.

Tags
Automation Testing Selenium

Featured Articles

Choosing the Right Automation Tool: Appium vs Selenium

Cypress vs Selenium: Key Differences

App & Browser Testing Made Easy

Seamlessly test across 20,000+ real devices with BrowserStack