This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Important
Microsoft Playwright Testing will be retired on March 8, 2026. To continue running your Playwright tests,create a newPlaywright Workspace inAzure App Testing, now generally available.Learn how to migrate.
In this quickstart, you set up continuous end-to-end testing with Microsoft Playwright Testing Preview to validate that your web app runs correctly across different browsers and operating systems with every code commit and troubleshoot tests easily using the service dashboard. Learn how to add your Playwright tests to a continuous integration (CI) workflow, such as GitHub Actions, Azure Pipelines, or other CI platforms.
After you complete this quickstart, you have a CI workflow that runs your Playwright test suite at scale and helps you troubleshoot tests easily with Microsoft Playwright Testing.
Important
Microsoft Playwright Testing is currently in preview. For legal terms that apply to Azure features that are in beta, in preview, or otherwise not yet released into general availability, see theSupplemental Terms of Use for Microsoft Azure Previews.
An Azure account with an active subscription. If you don't have an Azure subscription, create afree account before you begin.
A Microsoft Playwright Testing workspace. Complete thequickstart: run Playwright tests at scale and create a workspace.
In the service configuration, you have to provide the region-specific service endpoint. The endpoint depends on the Azure region you selected when creating the workspace.
To get the service endpoint URL and store it as a CI workflow secret, perform the following steps:
Sign in to thePlaywright portal with your Azure account.
On the workspace home page, selectView setup guide.
Tip
If you have multiple workspaces, you can switch to another workspace by selecting the workspace name at the top of the page, and then selectManage all workspaces.
InAdd region endpoint in your setup, copy the service endpoint URL.
The endpoint URL matches the Azure region that you selected when creating the workspace.
Store the service endpoint URL in a CI workflow secret:
| Secret name | Value |
|---|---|
| PLAYWRIGHT_SERVICE_URL | Paste the endpoint URL you copied previously. |
If you don't have Playwright tests configured to run with the service, add a service configuration file to your repository. In the next step, you then specify this service configuration file on the Playwright CLI.
Create a new fileplaywright.service.config.ts alongside theplaywright.config.ts file.
Optionally, use theplaywright.service.config.ts file in thesample repository.
Add the following content to it:
import { defineConfig } from '@playwright/test';import { getServiceConfig, ServiceOS } from '@azure/microsoft-playwright-testing';import config from './playwright.config';/* Learn more about service configuration at https://aka.ms/mpt/config */export default defineConfig( config, getServiceConfig(config, { exposeNetwork: '<loopback>', timeout: 30000, os: ServiceOS.LINUX, useCloudHostedBrowsers: true }), { /* Playwright Testing service reporter is added by default. This will override any reporter options specified in the base playwright config. If you are using more reporters, please update your configuration accordingly. */ reporter: [['list'], ['@azure/microsoft-playwright-testing/reporter']], });By default, the service configuration enables you to:
However, you can choose to use either of these features or both. SeeHow to use service features and update the service configuration file as per your requirements.
Save and commit the file to your source code repository.
Update thepackage.json file in your repository to add details about Microsoft Playwright Testing service package indevDependencies section.
"devDependencies": { "@azure/microsoft-playwright-testing": "^1.0.0-beta.6"}In theplaywright.config.ts file of your project, make sure you're collecting all the required artifacts.
use: { trace: 'on-first-retry', video:'retain-on-failure', screenshot:'on' },Create a new filePlaywrightServiceSetup.cs in the root directory of your project. This file facilitates authentication of your client with the service.
Add the following content to it:
using Azure.Developer.MicrosoftPlaywrightTesting.NUnit;using NUnit.Framework;namespace PlaywrightTests; // Remember to change this as per your project namespace[SetUpFixture]public class PlaywrightServiceSetup : PlaywrightServiceNUnit { };Save and commit the file to your source code repository.
In your project, install Microsoft Playwright Testing package.
dotnet add package Azure.Developer.MicrosoftPlaywrightTesting.NUnit --prereleaseThis command updates your project'scsproj file by adding the service package details to theItemGroup section. Remember to commit these changes.
<ItemGroup> <PackageReference Include="Azure.Developer.MicrosoftPlaywrightTesting.NUnit" Version="1.0.0-beta.2" /> </ItemGroup>.runsettings file for your project.If you haven't configured your Playwright tests yet for running them with service, add.runsettings file to your repository. In the next step, you then specify this service configuration file on the Playwright CLI.
Create a new.runsettings file.
Optionally, use the.runsettings file in thesample repository.
Add the following content to it:
<?xml version="1.0" encoding="utf-8"?><RunSettings> <TestRunParameters> <!-- The below parameters are optional --> <Parameter name="Os" value="linux" /> <!--<Parameter name="RunId" value="sample-run-id1" />--> <Parameter name="ServiceAuthType" value="EntraId" /> <Parameter name="UseCloudHostedBrowsers" value="true" /> <Parameter name="AzureTokenCredentialType" value="DefaultAzureCredential" /> <!--<Parameter name="ManagedIdentityClientId" value="{clientId-value}" />--> <Parameter name="EnableGitHubSummary" value="false" /> <!--<Parameter name="ExposeNetwork" value="*" />--> </TestRunParameters> <!-- NUnit adapter --> <NUnit> <!-- Adjust parallel workers, parallel worker would also be bound by number of unit test files --> <NumberOfTestWorkers>10</NumberOfTestWorkers> </NUnit> <!-- General run configuration --> <RunConfiguration> <EnvironmentVariables> <!-- For debugging selectors, it's recommend to set the following environment variable --> <!--<DEBUG>pw:api*</DEBUG>--> </EnvironmentVariables> </RunConfiguration> <!-- Playwright --> <Playwright> <BrowserName>chromium</BrowserName> <ExpectTimeout>5000</ExpectTimeout> <LaunchOptions> <Headless>false</Headless> <!--Channel>msedge</Channel--> </LaunchOptions> </Playwright> <LoggerRunSettings> <Loggers> <!--microsoft playwright testing service logger for reporting --> <Logger friendlyName="microsoft-playwright-testing" enabled="True" /> <!--could enable any logger additionally --> <Logger friendlyName="trx" enabled="false" /> </Loggers> </LoggerRunSettings></RunSettings>The settings in this file enable you to:
However, you can choose to use either of these features or both. SeeHow to use service features and update the service configuration file as per your requirements.
Save and commit the file to your source code repository.
Set up Playwright to capture artifacts such as screenshot, videos and traces.
Once you collect these artifacts, attach them to theTestContext to ensure they're available in your test reports. For more information, see oursample project for NUnit.
The CI machine running Playwright tests must authenticate with Playwright Testing service to get the browsers to run the tests and to publish the test results and artifacts.
The service offers two authentication methods: Microsoft Entra ID and Access Tokens. We strongly recommend using Microsoft Entra ID to authenticate your pipelines.
If you're using GitHub Actions, you can connect to the service using GitHub OpenID Connect. Follow the steps to set up the integration:
Option 1: Microsoft Entra application
Create a Microsoft Entra application with a service principal byAzure portal,Azure CLI, orAzure PowerShell.
Copy the values forClient ID,Subscription ID, andDirectory (tenant) ID to use later in your GitHub Actions workflow.
Assign theOwner orContributor role to the service principal created in the previous step. These roles must be assigned on the Playwright Testing workspace. For more details, seehow to manage access.
Configure a federated identity credential on a Microsoft Entra application to trust tokens issued by GitHub Actions to your GitHub repository.
Option 2: User-assigned managed identity
Copy the values forClient ID,Subscription ID, andDirectory (tenant) ID to use later in your GitHub Actions workflow.
Assign theOwner orContributor role to the user-assigned managed identity created in the previous step. These roles must be assigned on the Playwright Testing workspace. For more details, seehow to manage access.
Configure a federated identity credential on a user-assigned managed identity to trust tokens issued by GitHub Actions to your GitHub repository.
| GitHub Secret | Source (Microsoft Entra Application or Managed Identity) |
|---|---|
AZURE_CLIENT_ID | Client ID |
AZURE_SUBSCRIPTION_ID | Subscription ID |
AZURE_TENANT_ID | Directory (Tenant) ID |
Note
For enhanced security, it is strongly recommended to use GitHub Secrets to store sensitive values rather than including them directly in your workflow file.
Caution
We strongly recommend using Microsoft Entra ID for authentication to the service. If you're using access tokens, seeHow to manage access tokens
You can generate an access token from your Playwright Testing workspace and use it in your setup. However, we strongly recommend Microsoft Entra ID for authentication due to its enhanced security. Access tokens, while convenient, function like long-lived passwords and are more susceptible to being compromised.
Authentication using access tokens is disabled by default. To use,Enable access-token based authentication.
Store the access token in a CI workflow secret and use it in the GitHub Actions workflow or Azure Pipeline yaml file.
| Secret name | Value |
|---|---|
| PLAYWRIGHT_SERVICE_ACCESS_TOKEN | Paste the value of Access Token you created previously. |
Update the CI workflow definition to run your Playwright tests with the Playwright CLI. Pass theservice configuration file as an input parameter for the Playwright CLI. You configure your environment by specifying environment variables.
Open the CI workflow definition
Add the following steps to run your Playwright tests in Microsoft Playwright Testing.
The following steps describe the workflow changes for GitHub Actions or Azure Pipelines. Similarly, you can run your Playwright tests by using the Playwright CLI in other CI platforms.
# This step is to sign-in to Azure to run tests from GitHub Action workflow. # Choose how to set up authentication to Azure from GitHub Actions. This is one example. name: Playwright Tests (Microsoft Playwright Testing) on: push: branches: [main, master] pull_request: branches: [main, master] permissions: # Required when using Microsoft Entra ID to authenticate id-token: write contents: read jobs: test: timeout-minutes: 60 runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Login to Azure with AzPowershell (enableAzPSSession true) uses: azure/login@v2 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} # GitHub Open ID connect values copied in previous steps tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} enable-AzPSSession: true - name: Install dependencies working-directory: path/to/playwright/folder # update accordingly run: npm ci - name: Run Playwright tests working-directory: path/to/playwright/folder # update accordingly env: # Regional endpoint for Microsoft Playwright Testing PLAYWRIGHT_SERVICE_URL: ${{ secrets.PLAYWRIGHT_SERVICE_URL }} # PLAYWRIGHT_SERVICE_ACCESS_TOKEN: ${{ secrets.PLAYWRIGHT_SERVICE_ACCESS_TOKEN }} # Not recommended, use Microsoft Entra ID authentication. run: npx playwright test -c playwright.service.config.ts --workers=20 - name: Upload Playwright report uses: actions/upload-artifact@v3 if: always() with: name: playwright-report path: path/to/playwright/folder/playwright-report/ # update accordingly retention-days: 10Update the CI workflow definition to run your Playwright tests with the Playwright NUnit CLI. Pass the.runsettings file as an input parameter for the Playwright CLI. You configure your environment by specifying environment variables.
Open the CI workflow definition.
Add the following steps to run your Playwright tests in Microsoft Playwright Testing.
The following steps describe the workflow changes for GitHub Actions or Azure Pipelines. Similarly, you can run your Playwright tests by using the Playwright CLI in other CI platforms.
on: push: branches: [ main, master ] pull_request: branches: [ main, master ]permissions: # Required when using AuthType as EntraId id-token: write contents: readjobs: test: timeout-minutes: 60 runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 # This step is to sign-in to Azure to run tests from GitHub Action workflow. # Choose how to set up authentication to Azure from GitHub Actions. This is one example. - name: Login to Azure with AzPowershell (enableAzPSSession true) uses: azure/login@v2 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} # GitHub Open ID connect values copied in previous steps tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} enable-AzPSSession: true - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore working-directory: path/to/playwright/folder # update accordingly - name: Build run: dotnet build --no-restore working-directory: path/to/playwright/folder # update accordingly - name: Run Playwright tests working-directory: path/to/playwright/folder # update accordingly env: # Regional endpoint for Microsoft Playwright Testing PLAYWRIGHT_SERVICE_URL: ${{ secrets.PLAYWRIGHT_SERVICE_URL }} # PLAYWRIGHT_SERVICE_ACCESS_TOKEN: ${{ secrets.PLAYWRIGHT_SERVICE_ACCESS_TOKEN }} # Not recommended, use Microsoft Entra ID authentication. run: dotnet test --settings:.runsettings --logger "microsoft-playwright-testing" -- NUnit.NumberOfTestWorkers=20 - name: Upload Playwright report uses: actions/upload-artifact@v3 if: always() with: name: playwright-report path: path/to/playwright/folder/playwright-report/ # update accordingly retention-days: 10Save and commit your changes.
When the CI workflow is triggered, your Playwright tests run in your Microsoft Playwright Testing workspace on cloud-hosted browsers, across 20 parallel workers. The results and artifacts collected are published to the service and can be viewed on service portal.
The settings for your test run can be defined in.runsettings file. For more information, seehow to use service package options
Note
Reporting feature is enabled by default for existing workspaces. This is being rolled out in stages and will take a few days. To avoid failures, confirm thatRich diagnostics using reporting setting is ON for your workspace before proceeding. For more information, see,Enable reporting for workspace.
Caution
With Microsoft Playwright Testing, you get charged based on the number of total test minutes consumed and test results published. If you're a first-time user orgetting started with a free trial, you might start with running a single test at scale instead of your full test suite to avoid exhausting your free test minutes and test results.
After you validate that the test runs successfully, you can gradually increase the test load by running more tests with the service.
You can run a single test with the service by using the following command-line:
npx playwright test {name-of-file.spec.ts} --config=playwright.service.config.tsYou can now troubleshoot the CI pipeline in the Playwright portal,
After your test run completes, a link to the Playwright Portal is generated. Open this link to view detailed test results and associated artifacts. The portal displays essential information, including:
The Playwright portal provides all the necessary information for troubleshooting. You can:
The Trace Viewer allows you to step through your test execution visually. You can:
After your test run completes, you get a link to the Playwright portal in your terminal. Open this link to view detailed test results and associated artifacts. The portal displays essential information, including:
The Playwright portal provides all the necessary information for troubleshooting. You can:
Note
Some metadata, such as the owner, description, and category, is currently not displayed on the service dashboard. If there’s additional information you’d like to see included, please submit aGitHub issue in our repository.
Tip
You can use Microsoft Playwright Testing service features independently. You can publish test results to the portal without using the cloud-hosted browsers feature and you can also use only cloud-hosted browsers to expedite your test suite without publishing test results. For details, seeHow to use service features.
Note
The test results and artifacts that you publish are retained on the service for 90 days. After that, they are automatically deleted.
You've successfully set up a continuous end-to-end testing workflow to run your Playwright tests at scale on cloud-hosted browsers.
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?