For AI agents and LLMs: a machine-readable index is available at llms.txt. A plain-Markdown version of any documentation page is available by appending .md to its URL.
Skip to main content

How to Set Up the Puppeteer Test Environment on TestMu AI


When you run Puppeteer End-to-End (E2E) testing on TestMu AI, you must tell the cloud machine which operating system and browser to use. Setting the right capabilities gives your scripts access to the browser, OS, resolution, and debugging logs each run needs. You do it by defining a capabilities object in your Puppeteer script and passing it to the CDP endpoint, so every test targets the exact environment you want.

The TestMu AI Capability Generator can auto-create the capabilities class for your Puppeteer scripts. The sections below cover selecting browsers and OS, organizing tests, changing desktop resolution, and enabling debugging logs.

Choosing the Browser and OS​


To run a Puppeteer test on TestMu AI, define the browser, browser version, and platform in your automation script. The three capabilities below set the exact environment the test targets.

KeyExpected ValuesDescriptionExample
browserNameChrome, EdgeSpecify the browser to test onconst capability = {"browserName": "Chrome"}
browserVersionChrome 83 & above, Edge 83 & aboveSpecify the browser version to test onconst capability = {"browserVersion": "113.0"}
platformWindows: 11, 10, 8, 8.1, 7

macOS: Monterey, Big Sur, Catiline, Mojave
Specify the platform nameconst capability = { "LT:Options": {"platform": "Windows 10",}}

Organizing Tests With Build and Name Capabilities​


Name your test cases and group your builds so runs stay easy to find in the dashboard. Use the capabilities below to organize your Puppeteer tests.

KeyValuesDescriptionCapability
buildPuppeteer Sample BuildRepresent the build number for your testconst capability = { "LT:Options": {"build": "<build_name>",}}
namePuppeteer Sample TestRepresents the name of a testconst capability = { "LT:Options": {"name": "<test_name>",}}
projectNameExample: My TestRepresent the name of your projectconst capability = { "LT:Options": {"projectName": "<project_name>",}}
tags["tag1", "tag2", "tag3"]Group your Puppeteer testsconst capability = {"LT:Options": { "tags": ["tag1", "tag2", "tag3"], }}
buildTags["build1", "build2", "build3"]Group your Puppeteer buildsconst capability = {"LT:Options": { "buildTags": ["build1", "build2", "build3"] }}

The script below configures the build and name capabilities inside the LT:Options object.

Verified
// add test code after initializing your browser
'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 || "LT_USERNAME",
'accessKey': process.env.LT_ACCESS_KEY || "LT_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);
}
})();

Getting Session Details​


Each Puppeteer test generates its own logs on TestMu AI. To read the information for the current session, add the snippet below to your Puppeteer test script.

Verified
let response = await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: 'getTestDetails' })}`)
console.log("Test details: ", JSON.parse(response).data);

Upon executing the script, you will get the details for the particular test session as a JSON response as shown below.

Verified
{
data: {
test_id: 'RWA9R-AC4V8-GJRET-YHBO2',
build_id: 9415381,
name: 'Puppeteer Sample Test',
user_id: 1001150,
username: 'newuser',
test_type: 'puppeteer',
platform: 'win10',
browser: 'Chrome',
browser_version: '107.0',
status_ind: 'running',
session_id: 'RWA9R-AC4V8-GJRET-YHBO2',
build_name: 'Puppeteer Sample Build',
create_timestamp: '2022-12-07 10:53:16',
start_timestamp: '2022-12-07 10:53:16',
remark: 'running',
console_logs_url: 'https://api.lambdatest.com/automation/api/v1/sessions/RWA9R-AC4V8-GJRET-YHBO2/log/console',
network_logs_url: 'https://api.lambdatest.com/automation/api/v1/sessions/RWA9R-AC4V8-GJRET-YHBO2/log/network',
command_logs_url: 'https://api.lambdatest.com/automation/api/v1/sessions/RWA9R-AC4V8-GJRET-YHBO2/log/command',
video_url: 'https://automation.lambdatest.com/public/video?testID=RWA9R-AC4V8-GJRET-YHBO2&auth=50471585dd55293d204fe87f63400f5f',
screenshot_url: 'https://video-bundler.lambdatest.com/RWA9R-AC4V8-GJRET-YHBO2/screenshots.zip?orgId=588659&createTimestamp=1670410396&testCreateTimestamp=2022-12-07%2010:53:16'
},
message: 'Retrieve session was successful',
status: 'success'
}

Changing Desktop Resolutions​


Puppeteer tests run at 1920x1080 by default on desktop browsers. Set the resolution capability to run at a different screen resolution.

CapabilityDescriptionExpected ValuesExample
resolutionSpecifying your desktop resolution before initiating the testString, Default value: 1920x1080

Windows 11 & 10: 1024x768, 1280x800, 1280x1024, 1366x768, 1440x900, 1680x1050, 1600x1200, 1920x1200, 1920x1080 and 2048x1536

macOS: 1024x768, 1280x960, 1280x1024, 1600x1200 and 1920x1080
const caps =
{
'resolution': '1024x768',
};

Changing Browser Window Size​


To change the browser window size during a Puppeteer test, call page.setViewport() as shown below.

Verified
await page.setViewport({
width: 1024,
height: 768,
deviceScaleFactor: 1,
});

Naming Your Project​


Group related builds under a project by setting the projectName key to a name of your choice. Use the capability below.

KeyValuesDescriptionCapability
projectNameExample: My TestRepresent the name of your projectconst capabilities = { 'LT:Options': {'projectName': 'My Test',}}

Debugging Tests With Logs and Video​


Enable network logs, console logs, and video recording to debug failed Puppeteer sessions. Set the capabilities below to capture each type of log.

KeyValuesDescriptionCapability
networktrue/falseEnable network logsconst capabilities = { 'LT:Options': {'network': true,}}
consoletrue/falseEnable browser console logsconst capabilities = { 'LT:Options': {'console': true,}}
videotrue/falseEnable Video recording of the entire screenconst capabilities = { 'LT:Options': {'video': true,}}

Mark Tests as Passed or Failed​


A test that fails on your local machine can still pass on TestMu AI, so set the status explicitly to match your own assertions. By default, a test that finishes without error is marked Completed, and one that hits an error is marked Failed. Use the setTestStatus action to override this.

  1. To mark test status as passed:
Verified
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: 'setTestStatus', arguments: { status:'passed', remark: 'Title matched' } })}`)
  1. To mark test status as failed:
Verified
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: 'setTestStatus', arguments: { status:'failed', remark: 'Title not matched' } })}`)

Capabilities Reference​


The TestMu AI Capability Generator can auto-create the capabilities class for your Puppeteer scripts. The full set of capabilities you can configure is listed below.

KeyExpected ValuesDescriptionCapability
browserNameChrome, EdgeSpecify the browser to test onconst capability = {"browserName": "Chrome"}
browserVersionChrome 83 & above, Edge 83 & aboveSpecify the browser version to test onconst capability = {"browserVersion": "113.0"}
platformWindows: 11, 10, 8, 8.1, 7

macOS: Monterey, Big Sur, Catiline, Mojave
Specify the platform nameconst capability = { "LT:Options": {"platform": "Windows 10",}}
buildPuppeteer Sample BuildRepresent the build number for your testconst capability = { "LT:Options": {"build": "<build_name>",}}
namePuppeteer Sample TestRepresents the name of a testconst capability = { "LT:Options": {"name": "<test_name>",}}
resolutionSpecifying your desktop resolution before initiating the testString, Default value: 1920x1080

Windows 11 & 10: 1024x768, 1280x800, 1280x1024, 1366x768, 1440x900, 1680x1050, 1600x1200, 1920x1200, 1920x1080 and 2048x1536

macOS: 1024x768, 1280x960, 1280x1024, 1600x1200 and 1920x1080
const capability = {"LT:Options": {"resolution": '1024x768'}}
projectNameExample: My TestRepresent the name of your projectconst capability = { "LT:Options": {"projectName": "<project_name>",}}
tags["tag1", "tag2", "tag3"]Group your Puppeteer testsconst capability = {"LT:Options": { "tags": ["tag1", "tag2", "tag3"], }}
buildTags["build1", "build2", "build3"]Group your Puppeteer buildsconst capability = {"LT:Options": { "buildTags": ["build1", "build2", "build3"] }}
networktrue/falseEnable network logsconst capability = { "LT:Options": {"network": true,}}
consoletrue/falseEnable browser console logsconst capabilities = { "LT:Options": {"console": true,}}
videotrue/falseEnable video recording of the entire screenconst capability = { "LT:Options": {"video": true,}}
tunneltrue/falseEnable tunnel for local testingconst capability = { "LT:Options": {"tunnel": true,}}
tunnelNametrue/falseSpecify tunnel nameconst capability = { "LT:Options": {"tunnelName": "<tunnel_name>",}}
geoLocationAR (Argentina)Specify country codeconst capability = { "LT:Options": {"geoLocation": "AR",}}
idleTimeoutnumberSpecifies the timeout of the commands in seconds.

Default value: 300

Max value: 1800

If a value greater than 1800 is added, idleTimeout will be set to 1800.
const capability = { "LT:Options": {"idleTimeout": "<number>",}}

Continue with the guides below to run and scale your Puppeteer tests on TestMu AI.

Terminal First Testing With Kane CLI

Natural language browser & mobile app tests right from terminal.

×
Schedule Your Personal Demo
Kane CLI terminal

Help and Support

Related Articles