nightmare, playwright, puppeteer, and selenium-webdriver are libraries used to automate web browsers for testing, scraping, and task automation. They allow developers to script interactions like clicking buttons, filling forms, and navigating pages programmatically. While selenium-webdriver is the legacy standard supporting many languages and browsers, puppeteer and playwright are modern Node.js-first tools built for Chromium and multi-browser support respectively. nightmare was an early high-level abstraction but is no longer actively maintained.
Automating browser interactions is a core requirement for modern web development, whether for end-to-end testing, web scraping, or generating screenshots. The ecosystem offers four major contenders: nightmare, playwright, puppeteer, and selenium-webdriver. While they all aim to control a browser, their architectures, maintenance status, and developer experiences differ significantly. Let's break down how they handle real-world engineering challenges.
Before writing a single line of code, you must know which tools are safe to bet on.
nightmare is effectively abandoned.
// nightmare: No longer receiving security patches or feature updates
// const Nightmare = require('nightmare');
// const nightmare = Nightmare({ show: true });
// Avoid this in production
playwright is actively maintained by Microsoft.
// playwright: Actively updated
// npm install playwright
const { chromium } = require('playwright');
puppeteer is actively maintained by the Chrome DevTools team.
// puppeteer: Actively updated
// npm install puppeteer
const puppeteer = require('puppeteer');
selenium-webdriver is actively maintained by the Selenium project.
// selenium-webdriver: Actively updated
// npm install selenium-webdriver
const { Builder } = require('selenium-webdriver');
Your choice often depends on which browsers your users actually use.
playwright supports three engines out of the box.
// playwright: Multi-browser support
const { chromium, firefox, webkit } = require('playwright');
const browser = await chromium.launch(); // Or firefox.launch() or webkit.launch()
const page = await browser.newPage();
puppeteer focuses on Chromium.
// puppeteer: Chromium focused
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch({ product: 'chrome' }); // 'firefox' is experimental
const page = await browser.newPage();
selenium-webdriver supports everything.
// selenium-webdriver: Requires external drivers
const { Builder, Browser } = require('selenium-webdriver');
// Must have chromedriver installed separately
const driver = await new Builder().forBrowser(Browser.CHROME).build();
nightmare supports Electron only.
// nightmare: Electron only
const Nightmare = require('nightmare');
const nightmare = Nightmare({ show: true });
// Limited to Electron's Chromium version
Flaky tests often happen because scripts run faster than the UI renders. How each library handles this defines your debugging time.
playwright has auto-waiting built in.
click() wait for elements to be visible and actionable automatically.sleep or waitFor calls.// playwright: Auto-waits before action
await page.click('button#submit'); // Waits for element to be stable
puppeteer requires explicit waiting.
// puppeteer: Manual wait required
await page.waitForSelector('button#submit');
await page.click('button#submit');
selenium-webdriver uses explicit waits via ExpectedConditions.
// selenium-webdriver: Explicit wait logic
const { until } = require('selenium-webdriver');
await driver.wait(until.elementLocated(By.id('submit')), 5000);
await driver.findElement(By.id('submit')).click();
nightmare chains actions implicitly.
// nightmare: Implicit chaining
await nightmare
.wait('button#submit')
.click('button#submit')
.end();
The way you write code affects how easy it is to maintain large test suites.
playwright uses a context and page model.
// playwright: Context isolation
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com');
puppeteer uses a browser and page model.
// puppeteer: Browser/Page model
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
selenium-webdriver uses a driver and element model.
// selenium-webdriver: Driver/Element model
const driver = await new Builder().forBrowser('chrome').build();
await driver.get('https://example.com');
const element = await driver.findElement(By.css('h1'));
nightmare uses a chainable queue model.
// nightmare: Chainable queue
await nightmare
.goto('https://example.com')
.evaluate(() => document.title);
Modern automation often requires more than just clicking buttons.
playwright includes network interception natively.
// playwright: Network mocking
await page.route('**/api/data', route => route.fulfill({ json: { mock: true } }));
await page.pdf({ path: 'page.pdf' });
puppeteer excels at PDF generation.
// puppeteer: PDF focus
await page.setRequestInterception(true);
await page.pdf({ path: 'page.pdf', format: 'A4' });
selenium-webdriver lacks native network mocking.
// selenium-webdriver: Limited network control
await driver.takeScreenshot(); // Returns base64 string
// No native PDF support
nightmare has basic screenshot support.
// nightmare: Basic screenshot
await nightmare.screenshot('screen.png');
Despite their differences, these tools share common goals and patterns.
// All support headless mode
// Playwright
await chromium.launch({ headless: true });
// Puppeteer
await puppeteer.launch({ headless: 'new' });
// Selenium
new Builder().setChromeOptions(new chrome.Options().headless());
// Nightmare
Nightmare({ show: false });
// Common selector usage
// Playwright
await page.click('.btn-primary');
// Puppeteer
await page.click('.btn-primary');
// Selenium
await driver.findElement(By.css('.btn-primary'));
// Nightmare
nightmare.click('.btn-primary');
// Screenshot examples
// Playwright
await page.screenshot({ path: 'test.png' });
// Puppeteer
await page.screenshot({ path: 'test.png' });
// Selenium
await driver.takeScreenshot();
// Nightmare
await nightmare.screenshot('test.png');
| Feature | playwright | puppeteer | selenium-webdriver | nightmare |
|---|---|---|---|---|
| Status | β Active | β Active | β Active | β Abandoned |
| Browsers | Chromium, Firefox, WebKit | Chromium (mostly) | All (via drivers) | Electron |
| Auto-Wait | β Yes | β Manual | β Manual | β οΈ Implicit |
| Network Mock | β Native | β Native | β External Proxy | β No |
| PDF Support | β Yes | β Yes | β No | β No |
| Setup | Easy (bundled browsers) | Easy (bundled browser) | Hard (manage drivers) | Easy (bundled) |
playwright is the modern standard for end-to-end testing.
puppeteer is the specialist for Chrome tasks.
selenium-webdriver is the enterprise legacy choice.
nightmare is a legacy tool.
playwright for a similar high-level API with active support.Final Thought: For most new Node.js projects, playwright offers the best balance of power, reliability, and developer experience. Use puppeteer only if you have specific Chrome-only requirements. Avoid nightmare entirely.
Choose playwright if you need reliable cross-browser testing (Chromium, Firefox, WebKit) with a single API. It is ideal for complex end-to-end testing scenarios requiring network interception, mobile emulation, and auto-waiting capabilities. It is maintained by Microsoft and designed for modern web applications.
Do NOT choose nightmare for new projects. It is effectively deprecated and unmaintained, relying on older versions of Electron that lack modern web standards support. Existing projects using it should plan a migration to playwright or puppeteer to ensure security and compatibility with current websites.
Choose puppeteer if your focus is primarily on Chromium or Chrome-specific features like PDF generation or Chrome extension testing. It is a solid choice for scraping tasks or CI pipelines where Chrome is guaranteed. It offers a lower-level API than Playwright but is highly stable for single-browser use cases.
Choose selenium-webdriver if you need to support legacy browsers like Internet Explorer or require a language-agnostic grid setup (e.g., Java backend with Node tests). It is suitable for large enterprises with existing Selenium infrastructure, though it often requires more boilerplate code than modern alternatives.
Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable, and fast.
| Linux | macOS | Windows | |
|---|---|---|---|
| Chromium 145.0.7632.6 | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| WebKit 26.0 | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Firefox 146.0.1 | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Headless execution is supported for all browsers on all platforms. Check out system requirements for details.
Looking for Playwright for Python, .NET, or Java?
Playwright has its own test runner for end-to-end tests, we call it Playwright Test.
The easiest way to get started with Playwright Test is to run the init command.
# Run from your project's root directory
npm init playwright@latest
# Or create a new project
npm init playwright@latest new-project
This will create a configuration file, optionally add examples, a GitHub Action workflow and a first test example.spec.ts. You can now jump directly to writing assertions section.
Add dependency and install browsers.
npm i -D @playwright/test
# install supported browsers
npx playwright install
You can optionally install only selected browsers, see install browsers for more details. Or you can install no browsers at all and use existing browser channels.
Auto-wait. Playwright waits for elements to be actionable prior to performing actions. It also has a rich set of introspection events. The combination of the two eliminates the need for artificial timeouts - a primary cause of flaky tests.
Web-first assertions. Playwright assertions are created specifically for the dynamic web. Checks are automatically retried until the necessary conditions are met.
Tracing. Configure test retry strategy, capture execution trace, videos and screenshots to eliminate flakes.
Browsers run web content belonging to different origins in different processes. Playwright is aligned with the architecture of the modern browsers and runs tests out-of-process. This makes Playwright free of the typical in-process test runner limitations.
Multiple everything. Test scenarios that span multiple tabs, multiple origins and multiple users. Create scenarios with different contexts for different users and run them against your server, all in one test.
Trusted events. Hover elements, interact with dynamic controls and produce trusted events. Playwright uses real browser input pipeline indistinguishable from the real user.
Test frames, pierce Shadow DOM. Playwright selectors pierce shadow DOM and allow entering frames seamlessly.
Browser contexts. Playwright creates a browser context for each test. Browser context is equivalent to a brand new browser profile. This delivers full test isolation with zero overhead. Creating a new browser context only takes a handful of milliseconds.
Log in once. Save the authentication state of the context and reuse it in all the tests. This bypasses repetitive log-in operations in each test, yet delivers full isolation of independent tests.
Codegen. Generate tests by recording your actions. Save them into any language.
Playwright inspector. Inspect page, generate selectors, step through the test execution, see click points and explore execution logs.
Trace Viewer. Capture all the information to investigate the test failure. Playwright trace contains test execution screencast, live DOM snapshots, action explorer, test source and many more.
Looking for Playwright for TypeScript, JavaScript, Python, .NET, or Java?
To learn how to run these Playwright Test examples, check out our getting started docs.
This code snippet navigates to Playwright homepage and saves a screenshot.
import { test } from '@playwright/test';
test('Page Screenshot', async ({ page }) => {
await page.goto('https://playwright.dev/');
await page.screenshot({ path: `example.png` });
});
This snippet emulates Mobile Safari on a device at given geolocation, navigates to maps.google.com, performs the action and takes a screenshot.
import { test, devices } from '@playwright/test';
test.use({
...devices['iPhone 13 Pro'],
locale: 'en-US',
geolocation: { longitude: 12.492507, latitude: 41.889938 },
permissions: ['geolocation'],
})
test('Mobile and geolocation', async ({ page }) => {
await page.goto('https://maps.google.com');
await page.getByText('Your location').click();
await page.waitForRequest(/.*preview\/pwa/);
await page.screenshot({ path: 'colosseum-iphone.png' });
});
This code snippet navigates to example.com, and executes a script in the page context.
import { test } from '@playwright/test';
test('Evaluate in browser context', async ({ page }) => {
await page.goto('https://www.example.com/');
const dimensions = await page.evaluate(() => {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio
}
});
console.log(dimensions);
});
This code snippet sets up request routing for a page to log all network requests.
import { test } from '@playwright/test';
test('Intercept network requests', async ({ page }) => {
// Log and continue all network requests
await page.route('**', route => {
console.log(route.request().url());
route.continue();
});
await page.goto('http://todomvc.com');
});