Skip to main content

Executing Playwright in Selenium Agent

Digital.ai Testing supports running Playwright tests on a remote Selenium agent using a Selenium Grid–compatible interface.This allows execution on cloud-hosted browsers instead of running locally.

info

Playwright can connect to selenium-agent to launch Chrome or Microsoft Edge browser only.

warning
  • This is an experimental feature and it may have limitations.
  • There is a risk of Playwright integration with Selenium Grid Hub breaking in the future. Make sure you weigh risks against benefits before using it.
  • Internally, Playwright connects to the browser using Chrome DevTools Protocol websocket. Selenium 4 currently exposes this capability. However, this might not be the case in the future. If Selenium drops this capability, Playwright will stop working with it.

In this setup we will learn how to run Playwright tests on a remote Selenium agent. The Selenium agent will manage browser instances in the Digital.ai Testing cloud, allowing you to execute tests on real browsers without local setup. This section also explains how:

  • Playwright connects to a remote Selenium agent
  • Browsers run in the Digital.ai Testing cloud
  • Communication is handled via CDP (Chrome DevTools Protocol)

Prerequisites

  • Node.js installed
  • Playwright project initialized
  • Digital.ai Testing access key (mandatory)
  • Cloud URL for your environment

Important:

Run commands from the directory where your Playwright project is located.


Run Tests Using Environment Variables

macOS / Linux

export SELENIUM_REMOTE_URL="https://<cloud_url>/wd/hub"
export SELENIUM_REMOTE_CAPABILITIES='{
"browserName":"chrome",
"digitalai:options":{
"accessKey":"<accessKey>",
"testName":"Playwright Remote Execution Test"
}
}'
npx playwright test

Alternative Inline format

export SELENIUM_REMOTE_URL="https://<cloud_url>/wd/hub" \
export SELENIUM_REMOTE_CAPABILITIES='{
"browserName":"chrome",
"digitalai:options":{
"accessKey":"<accessKey>",
"testName":"Playwright Remote Execution Test"
}
}' \

npx playwright test

Windows (PowerShell)

$env:SELENIUM_REMOTE_URL="https://<cloud_url>/wd/hub"
$env:SELENIUM_REMOTE_CAPABILITIES='{
"browserName":"chrome",
"digitalai:options":{
"accessKey":"<accessKey>",
"testName":"Playwright Remote Execution Test"
}
}'
npx playwright test

Configure Using Playwright Config File

You can define the connection in playwright.config.ts:

use: {
connectOptions: {
wsEndpoint: 'https://<cloud_url>/wd/hub',
headers: {
'x-capabilities': JSON.stringify({
browserName: 'chrome',
'digitalai:options': {
accessKey: process.env.DIGITALAI_KEY
}
})
}
}
}
note

Use environment variables to store sensitive values like access keys.

Capabilities

Required capabilities:

  • digitalai:options.accessKey → Authentication key (required)
  • digitalai:options.testName → Optional test identifier

Important Notes

  • The accessKey is mandatory
  • Ensure correct working directory before execution
  • Uses CDP (Chrome DevTools Protocol) for communication

Compatibility

Playwright and browser versions must be compatible due to CDP limitations. Note that, mismatched versions might result in test failures.

Reporting Behavior

  • Reports and artifacts are stored locally
  • Cloud reports include CDP command traces

Limitations

  • No video recording in reports
  • Experimental feature (may be unstable)
  • Limited browser support