How to run Tests in Puppeteer with Firefox

On This Page What is Puppeteer?Why Use Puppeteer with Firefox?March 14, 2026 · 10 min read · Testing Guide

How to run Tests in Puppeteer with Firefox

Puppeteer, a Node.js library for browser mechanization, supports Firefox alongside Chrome, enable cross-browser testing. It provides developers with tool to automatize tasks like UI try, performance monitoring, and web scraping. Integrating Firefox with Puppeteer allows you to expand your test coverage and ensure compatibility for a wider range of user.

This guidebook explicate how to set up Puppeteer with Firefox and run automated tests to ensure unlined functionality across browser.

What is Puppeteer?

is a NodeJS-based framework, it is Open beginning and maintained by Google. Puppeteer allows us to indite the tests utilize Javascript or Typescript.

The Chrome DevToolsprotocol is an API spec that allows you to interact with the Chromium and Blink-based browser. The puppeteer uses the DevTools Protocol to provide the automation capability by expend a slender wrapper around it.

Puppeteer is successful in the world because of its core advantages:

  • Speed:Puppeteer provides full speed for mechanisation tests.
  • Security:Puppeteer provides protection over malicious pages.
  • Stability:Puppeteer tests are more stable compared to any other framework, more stable besides means that your tests are less flaky
  • Simplicity:Puppeteer provide a thin wrapper around chrome DevTools Protocol, which makes it easy to realise, debug and use.

When compared with Selenium, Puppeteer was initially designed to execute for Chromium-based browser with high reliability. However, is more focused on cross-browser capability.

Read More:

Due to high demand from users, Puppeteer widen its support to Firefox. However, Puppeteer Firefox support is withal in the experimental stage, Puppeteer tests can be run on Firefox Nightly build.

Why Use Puppeteer with Firefox?

Firefox, be one of the most widely used browsers, ensures that web applications function seamlessly for a broader user base.

Using Puppeteer with Firefox has many benefits, some of them are:

  • Enhanced : Using Puppeteer with Firefox enable effortless cross-browser testing, ascertain web coating work seamlessly for a wider audience.
  • Early Detection of Issues: Integration helps name browser-specific issues early, ameliorate application reliability.
  • Ordered API: Puppeteer ’ s Firefox support offers a consistent API similar to Chrome, allowing developer to reuse scripts with minimal changes.
  • Time and Effort Savings: Reusing existing Puppeteer scripts reduces development sweat and speeds up the testing process.
  • Streamlined Testing: Combining Puppeteer and Firefox ascertain effective and exact testing across multiple browsers.

Also Read:

How to run Puppeteer tests in Firefox

Running Puppeteer tests in Firefox let developers to expand their examination capabilities to one of the about wide used browsers. With Puppeteer ’ s built-in support for Firefox, you can publish and execute automated scripts seamlessly.

Prerequisites for Puppeteer tests in Firefox

To get started, see you get a basic Puppeteer framework set up in your task. This involves installing Puppeteer via Node.js and verifying that your Puppeteer adaptation back Firefox.

Read More:

Steps to run Puppeteer tests in Firefox

Step 1:To run Puppeteer tests with Firefox, set the environment variable for Puppeteer firefox using:

Windows Command Line

set PUPPETEER_PRODUCT=firefox

Windows Powershell / Visual Studio Code Terminal

$ env: PUPPETEER_PRODUCT=firefox

Mac/ Linux terminal

exportPUPPETEER_PRODUCT=firefox

Step 2: After specify the environment variable, install Puppeteer again employ the following bid

npm i puppeteer

After executing the above dictation, Puppeteer should download Firefox nightly progress binaries on your local machine.

Note: If npm install puppeteerdoesn & # 8217; t install the firefox binaries, so delete yournode_modulesfolder and run thenpm install puppeteerdictation again.

Step 3:Navigate to your task,jest-puppeteer.config.jsfile, and change the & # 8220; ware & # 8221; option to firefox utilise the undermentioned command

// jest-puppeteer.config.js module.exports = {launch: {headless: mistaken, merchandise: 'firefox ', defaultViewport: {width: 1700, height: 800}}, browserContext: 'default ',}

Once you make the above form in yourjest-puppeteer.config.js file, Puppeteer Firefox is ready to execute the tests.

Step 4:Execute your Puppeteer-Jest tests with firefox using the below bid.

npx jest -c ./jest.config.js

Tests depart execute and you will see the resultant on the bid line.

Common Issues and Troubleshooting

You may find a few issues while setting up and utilize Puppeteer with Firefox. Below are some of the most common problems users front and their solutions to help you trouble-shoot effectively.

1. Firefox Not Launching

When attempt to launch Puppeteer with Firefox, the browser may miscarry to start, or you might incur an error related to finding the Firefox executable.

Solution:

Ensure you haveFirefox Nightlyinstalled, as this is the version supported by Puppeteer for Firefox. Puppeteer requires Firefox Nightly to work aright with its APIs. You can download it from the official site and ensure it ’ s properly installed.

If you ’ ve already installed Firefox Nightly, check your configuration and make certain the route to the Firefox executable is correct. You can explicitly delimitate the way using theexecutablePathoption when launching Puppeteer, as shown below:

const browser = await puppeteer.launch ({ware: 'firefox ', executablePath: '/path/to/your/firefox/nightly'});

2. Puppeteer Not Found in Your Project

You might encounter an error where Puppeteer itself isn & # 8217; t found, even though it & # 8217; s been installed.

Solution:

First, make sure you hold installed Puppeteer and Puppeteer Firefox Nightly correctly. If you have any matter, reinstall Puppeteer by escape:

npm install puppeteer npm install puppeteer-firefox

After installing, try rerun your hand. If the matter persists, double-check that the node modules folder (node_modules/puppeteerandnode_modules/puppeteer-firefox) is present.

3. Errors Due to Missing Dependencies

If you receive errors related to miss libraries or dependency when running Puppeteer with Firefox, this is typically an issue with Firefox Nightly ’ s dependencies.

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

Solution:

Ensure your operating system has all the necessary dependencies installed to run Firefox Nightly. For Linux users, habituation can vary depend on the distribution, but common colony include:

  • libx11-xcb1,libdbus-glib-1-2, and others for Ubuntu/Debian-based systems.

Use the following command to instal missing dependency:

sudo apt-get install -y libx11-xcb1 libdbus-glib-1-2

For macOS, make certain you have the latest version of Xcode Command Line Tools install:

xcode-select -- install

4. Page Load Failures or Timeouts

Sometimes, Puppeteer may fail to load a page or clip out, particularly with page with heavy resources or long load times.

Solution:

Increase the default timeout for page navigation and resources. For example, you can add a longer timeout topage.goto ():

await page.goto ('https: //example.com ', {waitUntil: 'load ', timeout: 60000}); // 60 seconds

Additionally, consider usingpage.setDefaultNavigationTimeout ()to increase timeouts globally for all navigation commands.

5. Firefox-Specific Test Failures

Puppeteer with Firefox Nightly might behave slightly differently from Chrome due to Firefox & # 8217; s own rendering engine. Some tests that work in Chrome may miscarry in Firefox.

Solution:

If a test works in Chrome but fails in Firefox, ensure the topic is specific to Firefox and not a problem in your test frame-up. You can run the like test in headless Chrome to compare result and narrow-minded down the cause.

To further isolate Firefox-specific issues, run your tryout in non-headless mode to observe the deportment more easily:

const browser = await puppeteer.launch ({ware: 'firefox ', headless: false});

Read More:

Execute a Puppeteer Firefox Tests on BrowserStack

To run the Puppeteer Firefox Test on existent device and browsers,SignUp on BrowserStackand follow the below stairs.

Step 1: Configurejest-puppeteer.config.js

Once tests execution on your machine are successful, you can fulfill the same tests on

BrowserStack with a few increase name below

jest-puppeteer.config.js.

In the jest-puppeteer.config.jsfile add, and connect. The completejest-puppeteer.config.jsfile looks like the one below.

// jest-puppeteer.config.js const caps_firefox = {'browser ': 'firefox ', 'browser_version ': 'latest ', 'os ': 'windows ', 'os_version ': '10 ', 'name ': 'Puppeteer-jest test on Firefox ', 'build ': 'puppeteer-jest-build-3 ', 'browserstack.username ': process.env.BROWSERSTACK_USERNAME || ' 'your_user_name ', 'browserstack.accessKey ': process.env.BROWSERSTACK_ACCESS_KEY || ' your_access_key'}; module.exports = {launch: {headless: false, production: 'firefox ', defaultViewport: {breadth: 1700, height: 800}, devtools: true}, browserContext: 'default ', connect: {browserWSEndpoint: ` wss: //cdp.browserstack.com/puppeteer? caps= $ {encodeURIComponent (JSON.stringify (caps_firefox))} `,}}

Note:Copy ‘ browserstack.username ’ and ‘ browserstack.accessKey ’ from BrowserStack Account page. Documents all different sets of capability options.

Step 2:Add the test case as seen below

//demo.test.js describe ('Browserstack Demo ', () = & gt; {jest.setTimeout (50000); beforeAll (async () = & gt; {await page.goto ('https: //www.browserstack.com/ ')}) it ('Verify Product Submenus ', async () = & gt; {await page.click (' # product-menu-toggle '); const el = await page. $ ('ul [class= '' horizontal-list product-menu ''] & gt; li & gt; div & gt; div & gt; ul '); const text = await page.evaluate (el = & gt; el.innerText, el); expect look (text) .toContain ('Interactive cross browser quiz ') expect expect (text) .toContain ('Percy ') await anticipate (text) .toContain ('Automate ') await expect (text) .toContain ('Percy New ') await expect (schoolbook) .toContain ('Visual examination & amp; review ')})})

Step 3:Execute your scripts

If you have configured a shortcut inpackage.jsonenter the trial command to execute the tests.

npm run test

Alternatively, you can also specify

npx jest -c ./jest.config.js

After windup of execution, we can see the result in the Browserstack Dashboard

Read More:

Step 4:To reckon the Results in the Browserstack dashboard,

and navigate to Dashboard & gt; & gt; Choose the build, and you will see the complete snapshot of your test.

Advanced Use Cases and Customization

Once you ’ ve set up Puppeteer with Firefox and dispatch some basic tests, you might want to customize your testing workflow or explore more advanced use cases. Here are a few advanced technique to extend your Puppeteer-Firefox setup.

1. Customizing Browser Behavior (User Agents and Device Emulation)

Customizing browser behavior helps test how your site behaves on different devices or under assorted weather. Puppeteer allows you to emulate devices, set screen sizes, or imitate specific user agents.

For example, if you need to test how your website looks on roving device, you can set the viewport size and user agent like so:

const browser = await puppeteer.launch ({product: 'firefox '}); const page = await browser.newPage (); // Emulate a mobile gimmick await page.setViewport ({width: 375, tiptop: 667}); // iPhone 6 size await page.setUserAgent ('Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 '); await page.goto ('https: //example.com '); await page.screenshot ({path: 'mobile-view.png '}); await browser.close ();

2. Handling Dynamic Content with Puppeteer and Firefox

When prove web page that load contented dynamically (like single-page applications), you may want to wait for sure elements to seem before performing actions. Puppeteer offers various mode to handle these scenarios.

You can use page.waitForSelector () to wait for an ingredient to appear:

await page.goto ('https: //example.com '); await page.waitForSelector ('.dynamic-content '); // Wait for dynamic message to load await page.click ('.submit-button '); // Interact with content after it has loaded

This check that Puppeteer doesn ’ t try to interact with constituent that haven ’ t fully loaded, preventing errors during test.

3. Running Tests Across Multiple Pages or Tabs

Puppeteer allows you to manage multiple pages or tabs within the same browser instance. This can be utilitarian for testing scenarios where your app opens multiple windows or tabs.

Here ’ s how you can work with multiple Page:

const browser = await puppeteer.launch ({product: 'firefox '}); const [page1, page2] = await Promise.all ([browser.newPage (), browser.newPage ()]); await page1.goto ('https: //example.com '); await page2.goto ('https: //example2.com '); expect page1.click (' # button1 '); expect page2.click (' # button2 '); await browser.close ();

4. Performance Testing and Profiling

Puppeteer can also gather performance metrics for pages you ’ re examination. This can be particularly useful when analyzing consignment times or resource usage.

Here ’ s how you can use Puppeteer to gather performance metrics from Firefox:

const browser = await puppeteer.launch ({product: 'firefox '}); const page = await browser.newPage (); await page.goto ('https: //example.com '); // Collect performance metrics const metrics = expect page.metrics (); console.log (metrics); wait browser.close ();

This will provide datum on respective metrics, such as memory usage, CPU time, and network activity.

5. Automating Authentication Flows

Automating login flows or user authentication is common in. Puppeteer provides various ways to handle hallmark, such as utilise cookies or localStorage to simulate a logged-in user.

Here ’ s an example of using cooky to log in to a website:

const browser = await puppeteer.launch ({product: 'firefox '}); const page = await browser.newPage (); // Set cookies to copy logged-in user await page.setCookie ({gens: 'auth-token ', value: 'your-auth-token ', orbit: 'example.com'}); await page.goto ('https: //example.com/dashboard '); // Now the user is log in await browser.close ();

Best Practices for Testing with Puppeteer and Firefox

Here are some key best practices for testing with Puppeter and Firefox:

  • Keep Puppeteer and Firefox Updated: Use the latest versions to control compatibility and admission new characteristic.
  • Enable Debugging: Use debugging tools to identify and settle test number efficaciously.
  • Handle Firefox-Specific Quirks: Be aware of departure in Firefox ’ s demeanour and adapt your scripts accordingly.
  • Use Modular Test Design: Write reusable and maintainable examination functions to simplify script updates.
  • Monitor Network Requests: Track and validate all API calls and motionless file loads to catch errors early.

Talk to an Expert

Useful Resources for Puppeteer

Understanding Puppeteer:

Tools Comparisons:

Conclusion

Running tests in Puppeteer with Firefox allows developers and testers to ensure that their web coating run correctly across different browser. You can configure Puppeteer Firefox Nightly to automate tests and address Firefox-specific rendering issues to ensure precise test effect.

However, managing multiple browser environments can become challenging as you scale your testing travail. This is where BrowserStack steps in. It allows you to run your Puppeteer examination on Firefox (and other browser) across real devices and different OS environments to assure your application performs as expected in.

Tags
80,000+ Views

# Ask-and-Contributeabout this matter with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free