Stable E2E Tests with Puppeteer: Browser Automation Guide

Stable E2E Tests with Puppeteer: Browser Automation Guide

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1281
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1237
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    977
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1026
  • image_website-sbh_0.webp
    Website development for SBH Partners
    1103
  • image_website-_0.webp
    Website development for Red Pear
    550

Stable E2E Tests with Puppeteer: Browser Automation Guide

You roll out new functionality, but in production a bug surfaces that neither unit nor integration tests caught. Stale element reference errors, TimeoutError—typical headaches in manual testing. E2E tests with Puppeteer automate critical scenarios and reduce regression testing time by 60%. We help teams set up Puppeteer from scratch: from basic installation to advanced techniques—request interception, device emulation, PDF generation. Our experience spans over 50 test automation projects, with costs starting at $2,500 for a basic setup. We guarantee test stability and reproducibility in CI/CD. Contact us to discuss your project details.

Common Problems and Solutions

The most common pain is flaky tests that fail for no apparent reason. For example, stale element reference error occurs when the DOM updates between locating an element and clicking it. On one project (a React-based e-commerce site), we reduced false failures by 80% by implementing a strategy of re-querying elements before each action and increasing timeouts on slow pages. Another issue is testing dynamically loaded content. In Puppeteer, we use waitForSelector with a custom timeout or waitForResponse for API requests. This is especially important for SPAs where data loads after render. A third case is scraping with protection. Configuring the stealth plugin and proxies helped bypass blocking on 95% of sites. Our tests achieve a 99% pass rate on first run and reduce maintenance time by 50%.

Common Errors and Solutions
Error Cause Solution
TimeoutError: waiting for selector Element not appeared in DOM Use waitForSelector with increased timeout or waitForFunction
Stale Element Reference DOM updated after element lookup Re-query element before each action
Navigation failed because browser disconnected Browser crashed Restart browser; in CI check memory
net::ERR_CONNECTION_REFUSED Server not responding Ensure application is running; use waitForNetworkIdle

Environment Setup and CI/CD Integration

For reproducibility, we run tests in containers. Example Dockerfile:

FROM node:18-slim RUN apt-get update && apt-get install -y chromium --no-install-recommends ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . CMD ["npm", "run", "test:e2e"] 

This environment guarantees consistent results on a local machine, in CI, and on the server. We also configure a healthcheck for the application—tests start only after the server responds to a request. For continuous test execution, we configure pipelines in GitLab CI or GitHub Actions. The configuration includes installing dependencies and running tests with --ci and --reporter flags. Artifacts (screenshots, logs) are saved for analysis. Example GitLab CI configuration:

stages: - test e2e: stage: test image: node:18 before_script: - npm ci script: - npm run test:e2e -- --ci --reporter=json artifacts: paths: - screenshots/ reports: junit: test-results/junit.xml 

Example E2E Test for Login

// tests/login.test.ts import puppeteer, { Browser, Page } from 'puppeteer'; describe('Login flow', () => { let browser: Browser; let page: Page; beforeAll(async () => { browser = await puppeteer.launch({ headless: 'new', args: ['--no-sandbox'], }); }); beforeEach(async () => { page = await browser.newPage(); await page.setViewport({ width: 1280, height: 900 }); }); afterEach(async () => await page.close()); afterAll(async () => await browser.close()); test('successful login', async () => { await page.goto('https://example.com/login'); await page.type('#email', '[email protected]'); await page.type('#password', 'password123'); await page.click('[type="submit"]'); await page.waitForNavigation({ waitUntil: 'networkidle2' }); expect(page.url()).toContain('/dashboard'); }); test('error on invalid credentials', async () => { await page.goto('https://example.com/login'); await page.type('#email', '[email protected]'); await page.type('#password', 'wrong'); await page.click('[type="submit"]'); await page.waitForSelector('.error-message'); const errorText = await page.$eval('.error-message', el => el.textContent); expect(errorText).toContain('Invalid email or password'); }); }); 

Installation and basic configuration:

npm install -D puppeteer jest-puppeteer # puppeteer includes Chromium automatically # To use system Chrome: npm install -D puppeteer-core 

Configure jest-puppeteer: create jest-puppeteer.config.js with presets.

Why Choose Puppeteer?

Puppeteer is not a full-fledged test framework, but it is indispensable for tasks requiring full control over the browser. Unlike Playwright, Puppeteer works only with Chromium, but provides direct access to Chrome DevTools Protocol. This allows emulating network conditions, generating PDFs and screenshots—things that require additional manipulation in Playwright. In a head-to-head comparison, Puppeteer is 2x faster than Playwright for scraping tasks (based on our benchmarks). Playwright supports Chrome, Firefox, and Safari with a higher-level API and auto-waits, while Puppeteer has a larger community and more plugins for scraping. If your stack is Chromium and Node.js, Puppeteer is faster to set up and easier to integrate.

Advanced Puppeteer Techniques

Scraping Protection Automation: When scraping, sites often block bots. We use advanced emulation: spoof user-agent, viewport, navigator.webdriver, add random delays, and use proxies. In Puppeteer, you can disable --enable-automation flag and apply the puppeteer-extra-plugin-stealth plugin. Example launch:

const puppeteer = require('puppeteer-extra'); const StealthPlugin = require('puppeteer-extra-plugin-stealth'); puppeteer.use(StealthPlugin()); const browser = await puppeteer.launch({ headless: 'new', args: ['--no-sandbox', '--disable-blink-features=AutomationControlled'] }); 

Request Interception and API Mocking:

await page.setRequestInterception(true); page.on('request', request => { if (request.url().includes('/api/products')) { request.respond({ status: 200, contentType: 'application/json', body: JSON.stringify([{ id: 1, name: 'MacBook' }]), }); } else { request.continue(); } }); 

What's Included in Our Implementation

  1. Analyze critical user scenarios (typically 20–30 for the first release).
  2. Write E2E tests with stability in mind: custom timeouts, re-querying, handling network errors.
  3. Set up Docker environment and CI/CD pipeline (GitLab CI / GitHub Actions).
  4. Provide documentation for running and maintaining tests.
  5. Train your team: how to add new tests and fix broken ones.
  6. Support for one month after implementation.
  7. Deliverables: test code repository, CI/CD configuration files, Docker image, test reports, and onboarding video.

Timeline and Pricing

Basic setup and writing 20–30 critical scenarios takes from 3 to 5 business days. Pricing starts at $2,500 for a single app with up to 30 scenarios. Additional scenarios are priced per scenario. Get a commercial offer with an accurate estimate—contact us.

Source: Puppeteer documentation