Getting Started With Playwright Testing
Playwright is a Node.js library that uses a single API to automate Chromium, Firefox, and WebKit. It is designed to enable powerful, reliable, and efficient automated browser testing. Playwright can also automate Microsoft Edge since it is built on the open-source Chromium web framework.
TestMu AI allows you to run Playwright tests across real browsers and operating system combinations. This guide will cover the basics of getting started with Playwright testing on the TestMu AI platform.
You can run tests using Playwright versions v1.15.0 to the latest.
Prerequisites
Note: All the code samples in this documentation can be found in the TestMu AI's Repository on GitHub. You can either download or clone the repository to quickly run your tests.
View on GitHub
-
Clone the TestMu AI-Playwright repository on your system.
-
Install the npm dependencies.
npm install
- Add browserWSEndpoint (browser end point URL) in your test script.
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
- In order to run your Playwright tests, you will need to 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
set LT_USERNAME="YOUR_LAMBDATEST_USERNAME"
set LT_ACCESS_KEY="YOUR_LAMBDATEST_ACCESS_KEY"
macOS/Linux
export LT_USERNAME="YOUR_LAMBDATEST_USERNAME"
export LT_ACCESS_KEY="YOUR_LAMBDATEST_ACCESS_KEY"
Run Your First Test
- Add the below code snippet in your test scripts.
(async () => {
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,
'network': true,
'video': true,
'console': true
}
}
const browser = await chromium.connect({
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
})
Once you are done with the above-mentioned steps, you can initiate your first Playwright test on TestMu AI.
The below test script searches the term 'TestMu AI' on DuckDuckGo.
const { chromium } = require('playwright')
const { expect } = require('@playwright/test');
(async () => {
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,
'network': true,
'video': true,
'console': true
}
}
const browser = await chromium.connect({
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
})
const page = await browser.newPage()
await page.goto('https://duckduckgo.com')
const element = await page.$('[name="q"]')
await element.click()
await element.type('TestMu AI')
await element.press('Enter')
const title = await page.title()
try {
expect(title).toEqual('TestMu AI at DuckDuckGo')
// Mark the test as completed or failed
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: 'setTestStatus', arguments: { status: 'passed', remark: 'Title matched' } })}`)
} catch {
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: 'setTestStatus', arguments: { status: 'failed', remark: 'Title not matched' } })}`)
}
await browser.close()
})()
- Pass the below command to run the test.
node playwright-single.js
Run Tests in Parallel
Once your first test runs, you can execute the same test across multiple browser and OS configurations at once. Define a capabilities array (one entry per configuration) and run each through a shared function.
The example below runs the DuckDuckGo search test on three configurations: Chrome on Windows 10, Microsoft Edge on Windows 11, and Chrome on macOS Sonoma.
const { chromium } = require('playwright')
const { expect } = require('@playwright/test')
const parallelTests = async (capability) => {
console.log('Initialising test:: ', capability['LT:Options']['name'])
const browser = await chromium.connect({
wsEndpoint: `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(capability))}`
})
const page = await browser.newPage()
await page.goto('https://duckduckgo.com')
const element = await page.$('[name="q"]')
await element.click()
await element.type('TestMu AI')
await element.press('Enter')
const title = await page.title()
try {
expect(title).toEqual('TestMu AI at DuckDuckGo')
// Mark the test as completed or failed
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: 'setTestStatus', arguments: { status: 'passed', remark: 'Title matched' } })}`)
} catch {
await page.evaluate(_ => {}, `lambdatest_action: ${JSON.stringify({ action: 'setTestStatus', arguments: { status: 'failed', remark: 'Title not matched' } })}`)
}
await browser.close()
}
// Capabilities array with the respective configuration for the parallel tests
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 on Windows 10 - Chrome',
'user': process.env.LT_USERNAME,
'accessKey': process.env.LT_ACCESS_KEY,
'network': true,
'video': true,
'console': true
}
},
{
'browserName': 'MicrosoftEdge',
'browserVersion': 'latest',
'LT:Options': {
'platform': 'Windows 11',
'build': 'Playwright Sample Build',
'name': 'Playwright Sample Test on Windows 11 - MicrosoftEdge',
'user': process.env.LT_USERNAME,
'accessKey': process.env.LT_ACCESS_KEY,
'network': true,
'video': true,
'console': true
}
},
{
'browserName': 'Chrome',
'browserVersion': 'latest',
'LT:Options': {
'platform': 'MacOS Sonoma',
'build': 'Playwright Sample Build',
'name': 'Playwright Sample Test on MacOS Sonoma - Chrome',
'user': process.env.LT_USERNAME,
'accessKey': process.env.LT_ACCESS_KEY,
'network': true,
'video': true,
'console': true
}
}]
capabilities.forEach(async (capability) => {
await parallelTests(capability)
})
Run the parallel test:
node playwright-parallel.js
View your Playwright test results
The TestMu AI Automation Dashboard is where you can see the results of your Playwright tests after running them on the TestMu AI platform.
You can view the details of Playwright test session that you just executed.
For example, the below screenshot shows a test execution details of Playwright test like Test Name, Test ID, selected configurations, test logs, basic info, input config, and test session video.
Run Playwright BDD Tests
playwright-bdd lets you run Gherkin .feature files on Playwright's test runner. On TestMu AI, the @lambdatest/playwright-node-sdk runs the generated specs across the browser and OS matrix defined in your lambdatest.yml.
How Playwright BDD Works
Playwright BDD converts your Gherkin into runnable Playwright specs, then the SDK runs them on the cloud:
- Write
.featurefiles and map each step to a Playwright action in thesteps/folder. npx bddgengenerates Playwright spec files into the.features-genfolder.- The Playwright Node SDK runs those specs on TestMu AI using the configuration in
lambdatest.yml.
Running Your BDD Tests
Clone the sample repository, then install the dependencies, which include playwright-bdd and @lambdatest/playwright-node-sdk:
npm install
Verified with
playwright-bdd@8.3.1,@playwright/test@1.53.0, and@lambdatest/playwright-node-sdk@1.0.2(October 2026).
Set your TestMu AI Username and Access Key as environment variables (see Prerequisites), then generate the specs and run them on the cloud grid in a single command:
npx bddgen && npx playwright-node-sdk playwright test
Define your target browsers and operating systems in lambdatest.yml. For the full configuration, refer to the Playwright BDD sample repository.
Testing Locally Hosted Pages With Playwright BDD
To run your Playwright BDD tests against locally hosted or firewalled pages, enable the tunnel under a tunnelSettings block in your lambdatest.yml:
tunnelSettings:
tunnel: true
# autostart: true
tunnelName: "tunnel-name"
# localdirectory: "./log"
verbose: true
loglevel: "debug"
Set tunnel: true to route traffic through the tunnel, and tunnelName to reuse an already-running tunnel by name. The verbose and loglevel keys control the tunnel's logging output. See how to test locally hosted pages.
Viewing the BDD Results
Each scenario appears on the TestMu AI Automation Dashboard with its name, status, logs, and session video.
Related Playwright guides
- Playwright WebView Testing - automate WebView components using Playwright on TestMu AI.
- Migrate Existing Playwright Tests - move your existing Playwright suite to the TestMu AI cloud.
