How to Run Your First Puppeteer Test on TestMu AI
If you automate Chrome with Puppeteer over the DevTools Protocol, you can run that same End-to-End (E2E) testing against real browsers and operating systems by connecting to TestMu AI. This gives your Puppeteer scripts access to a browser farm of real browser and OS combinations instead of a single local machine. You point Puppeteer's connect call at the TestMu AI CDP WebSocket endpoint, pass your capabilities, then view every run in the Automation Dashboard.
Prerequisites
Before you run a test, set up the sample project and your credentials.
-
Clone the TestMu AI Puppeteer repository on your system.
-
Install the npm dependencies.
npm install
- Add
browserWSEndpoint(the browser endpoint URL) in your test script.
`wss://cdp.lambdatest.com/puppeteer?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
- Set your TestMu AI username and access key in the environment variables. Click the Access Key button at the top-right of the Automation Dashboard to access it.
Windows
Verifiedset LT_USERNAME="YOUR_LAMBDATEST_USERNAME"
set LT_ACCESS_KEY="YOUR_LAMBDATEST_ACCESS_KEY"
macOS/Linux
Verifiedexport LT_USERNAME="YOUR_LAMBDATEST_USERNAME"
export LT_ACCESS_KEY="YOUR_LAMBDATEST_ACCESS_KEY"
Run Your First Puppeteer Test
With the project cloned and your credentials set, follow these steps to run a Puppeteer test on the TestMu AI platform.
- Clone the TestMu AI Puppeteer sample repository and switch to the cloned directory.
git clone https://github.com/LambdaTest/puppeteer-sample.git
cd puppeteer-sample
-
Ensure you have npm dependencies installed.
-
Configure your TestMu AI authentication credentials.
Once these steps are complete, you can run your first Puppeteer test on TestMu AI.
VerifiedTest Scenario: The below test script runs on the Chrome browser on Windows 10. It visits the TestMu AI platform, opens the Pricing page, then navigates to the Automation Testing page.
'use strict';
const { strict } = require('once');
const puppeteer = require('puppeteer');
const expect = require('chai').expect;
(async () => {
const capabilities = {
'browserName': 'Chrome',
'browserVersion': 'latest',
'LT:Options': {
'platform': 'Windows 10',
'build': 'puppeteer-build-1',
'name': 'My first Puppeteer test',
'resolution':'1366x768',
'user': process.env.LT_USERNAME || "Your Username",
'accessKey': process.env.LT_ACCESS_KEY || "Your Access Key",
'network': true
}
};
try {
const browser = await puppeteer.connect({
browserWSEndpoint:
`wss://cdp.lambdatest.com/puppeteer?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`,
});
const page = await browser.newPage();
await page.setViewport({
width: 1024,
height: 768,
deviceScaleFactor: 1,
});
console.log("Navigating to LambdaTest");
await page.goto('https://www.lambdatest.com/');
console.log("Navigating to Pricing");
await page.goto('https://www.lambdatest.com/pricing');
console.log("Navigating to Automation");
await page.goto('https://www.lambdatest.com/automation-testing');
console.log("Closing browser");
await browser.close();
} catch (e) {
console.log("Error - ", e);
}
})();
- Run the test with the command below.
node navigation.js
View Your Puppeteer Test Results
After a run finishes, the TestMu AI Automation Dashboard is where you see the results of your Puppeteer tests. Click the session name of a test to view the details of the Puppeteer session you just executed. The session view shows Test Name, Test ID, selected configurations, test logs, basic info, input config, and the test session video.
Related Puppeteer Guides
Continue with these related guides to configure and extend your Puppeteer runs on TestMu AI.
- Configure your environment to execute Puppeteer tests walks through the setup needed before a cloud run.
- Set browser, OS, and build capabilities for Puppeteer covers the full capabilities reference.
- Run Puppeteer tests with the Mocha framework shows how to structure tests with Mocha.
