Skip to main content

Playwright - Test Execution Setup


Whenever you run a Playwright test, you must specify the operating system and the browser you wish to use. The LambdaTest Desired Capabilities Generator allows you to automatically create the capabilities class needed to run your Playwright automation scripts on LambdaTest.

In this document, learn how to configure the desired capability for selecting browsers and OS, organzing tests, changing desktop resolution, and more for your Playwright tests.

Choosing Browser And OS


To perform Playwright testing on LambdaTest, you need to define the browserName, browserVersion, and platform capabilities in your automation scripts.

KeyExpected ValuesDescriptionCapability
browserNameChrome, Microsoft Edge

Playwright Bundled Browsers: pw-chromium, pw-webkit, and pw-firefox
Specify the browser to test onconst capability = {"browserName": "pw-webkit"}
browserVersionChrome 83 & above, Edge 83 & aboveSpecify the browser version to test onconst capability = {"browserVersion": "latest"}
platformWindows: 11, 10, 8, 8.1, 7

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

Playwright Supported Browsers


Following is a list of compatible Playwright bundled browsers that you can use to run tests on the LambdaTest platform.

Playwright VersionsCompatible Browsers
v1.44Chromium 125.0
Firefox 125.0.1
WebKit 17.4
v1.43Chromium 124.0
Firefox 124.0
WebKit 17.4
v1.42Chromium 123.0
Firefox 123.0
WebKit 17.4
v1.41Chromium 121.0
Firefox 121.0
WebKit 17.4
v1.40Chromium 120.0
Firefox 119.0
WebKit 17.4
v1.39Chromium 119.0
Firefox 118.0
WebKit 17.4
v1.38Chromium 117.0
Firefox 117.0
WebKit 17.0
v1.37Chromium 116.0
Firefox 115.0
WebKit 17.0
v1.36Chromium 115.0
Firefox 115.0
WebKit 17.0
v1.35Chromium 115.0
Firefox 113.0
WebKit 16.4
v1.34Chromium 115.0
Firefox 113.0
WebKit 16.4
v1.33Chromium 113.0
Firefox 112.0
WebKit 16.4
v1.32Chromium 112.0
Firefox 111.0
WebKit 16.4
v1.31Chromium 111.0
Firefox 109.0
WebKit 16.4
v1.30Chromium 110.0
Firefox 108.0
WebKit 16.4
v1.29Chromium 109.0
Firefox 107.0
WebKit 16.0
v1.28Chromium 108.0
Firefox 106.0
WebKit 16.4
v1.27Chromium 107.0
Firefox 105.0
WebKit 16.0
v1.26Chromium 106.0
Firefox 104.0
WebKit 16.0
v1.25Chromium 105.0
Firefox 103.0
WebKit 16.0
v1.24Chromium 103.0
Firefox 102.0
WebKit 16.0
v1.23Chromium 103.0
Firefox 100.0
WebKit 15.4
v1.22Chromium 102.0
Firefox 99.0
WebKit 15.4
v1.21Chromium 101.0
Firefox 98.0
WebKit 15.4
v1.20Chromium 101.0
Firefox 97.0
WebKit 15.4
v1.19Chromium 100.0
Firefox 96.0
WebKit 15.4
v1.18Chromium 99.0
Firefox 95.0
WebKit 15.4
v1.17Chromium 98.0
Firefox 94.0
WebKit 15.4
v1.16Chromium 97.0
Firefox 93.0
WebKit 15.4
v1.15Chromium 96.0
Firefox 92.0
WebKit 15.0

Organizing Tests


You can name your test cases and categorize your Playwright builds by build number, build name, test and build tags for easier analysis. Use the following capabilities to organize your Playwright tests.

KeyValuesDescriptionCapability
buildPlaywright Sample BuildRepresent the build number for your testconst capability = {"LT:Options": {"build": "<build_name>",}}
namePlaywright Sample TestRepresents the name of a testconst capability = {"LT:Options": {"name": "<test_name>",}}
projectNamePlaywright Sample ProjectRepresents the name of a projectconst capability = {"LT:Options": {"projectName": "<project_name>",}}
tags["tag1", "tag2", "tag3"]Group your Playwright testsconst capability = {"LT:Options": { "tags": ["tag1", "tag2", "tag3"], }}
buildTags["build1", "build2", "build3"]Group your Playwright buildsconst capability = {"LT:Options": { "buildTags": ["build1", "build2", "build3"] }}

Changing Desktop Resolutions


Playwright tests run with a 1920x1080 resolution by default for desktop browsers. With our resolution capability, you can set a different screen resolution for your tests.

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 capabilities = { 'LT:Options': {'resolution': '2048x1536',}}

Changing Browser Window Size


The default viewport size for Playwright tests is 1280x720. If you wish to maximize the browser window during your Playwright test, you can do it as shown in the code below.

// Create context with given viewport
const context = await browser.newContext({
viewport: { width: 1280, height: 1024 }
});

The above Playwright test runs on a default viewport of 1280x1024. However, you can also select any other viewport when creating a new context.

If you resize viewport for individual page then run the below command.

await page.setViewportSize({ width: 1600, height: 1200 });

Setting Browser Options


Playwright lets you set browser arguments for Chromium based browsers. When selecting Chrome and Edge, you can set browser options using 'goog:chromeOptions' and 'ms:edgeOptions' capability as shown below.

For Chrome

const { chromium } = require('playwright');

const capabilities = {
'browserName': 'Chrome', // Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit`
'browserVersion': 'latest',
'LT:Options': {
'platform': 'Windows 10',
'build': 'Playwright Sample Build',
'name': 'Playwright Sample Test',
'user': process.env.LT_USERNAME,
'accessKey': process.env.LT_ACCESS_KEY,
'goog:chromeOptions':[
'--user-agent=<Any custom user agent>',
],

}
}

const browser = await chromium.connect({
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
})

For Edge

const { chromium } = require('playwright');

const capabilities = {
'browserName': 'Chrome', // Browsers allowed: `Chrome`, `MicrosoftEdge`, `pw-chromium`, `pw-firefox` and `pw-webkit`
'browserVersion': 'latest',
'LT:Options': {
'platform': 'Windows 10',
'build': 'Playwright Sample Build',
'name': 'Playwright Sample Test',
'user': process.env.LT_USERNAME,
'accessKey': process.env.LT_ACCESS_KEY,
'ms:edgeOptions':[
'--user-agent=<Any custom user agent>',
],

}
}

const browser = await chromium.connect({
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
})

Note: You can define any Chromium based argument from the list of Chromium command line arguments.

Getting Session Details


When you run a Playwright test on LambdaTest, it generates different logs for each test session. To get relevant information for the specific session, use the snippet provided below in your Playwright test scripts.

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

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

{
data: {
test_id: 'RWA9R-AC4V8-GJRET-YHBO2',
build_id: 9415381,
name: 'Playwright Sample Test',
user_id: 1001150,
username: 'kaustubhd',
test_type: 'playwright',
platform: 'win10',
browser: 'Chrome',
browser_version: '107.0',
status_ind: 'running',
session_id: 'RWA9R-AC4V8-GJRET-YHBO2',
build_name: 'Playwright 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'
}

Configuring Geolocation


You can run your Playwright tests across 53+ geographies using the 'geoLocation' capability as shown below.

KeyValuesDescriptionCapability
geoLocationUSRepresents the geolocation - United Statesconst capabilities = { "LT:Options": { 'geoLocation': 'US', }}

Debugging Tests


By specifying the capabilities for the debugging tools, you can debug and fix your failed Playwright test sessions using network logs, console logs, and video logs.

KeyValuesDescriptionDesired Capability
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


While running Playwright tests on the LambdaTest platform, you may come across a scenario in which a test that failed in your local instance turns up to be successful on LambdaTest. For verifying expected behavior, it is critical to identify automated tests as Passed or Failed based on your testing requirements.

By default, the Status of each test that runs successfully is marked as Completed, and if there are any issues, the Status is marked as Failed.

Shown below is syntax how to mark Playwright tests as Passed or Failed.

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

Test across 3000+ combinations of browsers, real devices & OS.

Book Demo

Help and Support

Related Articles