How to Run Puppeteer Tests With Jest on TestMu AI
If you write Puppeteer tests with Jest, you can run the same specs across real browsers and operating systems on TestMu AI instead of a single local machine. This gives you Jest's structured output and assertions on a browser farm, whether you target a single test or an entire suite. You connect Puppeteer to the TestMu AI cloud grid through a browserWSEndpoint in your Jest configuration, then run the suite with the standard npm run test command.
Prerequisites
Before you run your first suite, clone the sample repository and set the credentials TestMu AI uses to authenticate your session.
-
Clone the TestMu AI Puppeteer repository on your system.
-
Install the npm dependencies.
npm install
- 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 find them.
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 Puppeteer Jest Tests on TestMu AI
The sample test script searches for TestMu AI on DuckDuckGo and verifies the page title. Configure the capabilities, then run the suite with a single command.
- To run the Puppeteer tests using Jest on TestMu AI, make the required changes to the
jest-puppeteer.config.jsfile.
const caps_chrome = {
browserName : 'Chrome',
browserVersion : 'latest',
'LT:Options' : {
platform : 'Windows 10',
build : 'Sample Puppeteer-Jest',
name : 'Puppeteer-jest test on Chrome',
resolution : '1366x768',
user : process.env.LT_USERNAME,
accessKey : process.env.LT_USER_KEY,
network : true
}
};
const caps_edge = {
browserName : 'MicrosoftEdge',
browserVersion : 'latest',
'LT:Options' : {
platform : 'Windows 10',
build : 'Sample Puppeteer-Jest',
name : 'Puppeteer-jest test on Edge',
resolution : '1366x768',
user : process.env.LT_USERNAME,
accessKey : process.env.LT_USER_KEY,
network : true
}
};
module.exports = {
connect : {
browserWSEndpoint : `wss://cdp.lambdatest.com/puppeteer?capabilities=${encodeURIComponent(
JSON.stringify(caps_chrome)
)}`
}
};
- Run the following command to execute your test.
npm run test
- Visit the TestMu AI Automation Dashboard to see the results of your Puppeteer Jest tests.
Related Puppeteer Guides
Continue with the guides below to configure and scale your Puppeteer runs on TestMu AI.
