This document provides a step-by-step guide to set up Microsoft Playwright testing in Azure for running tests at scale for NUnit Playwright project.
- Azure Subscription: Ensure you have an active Azure account.
- NUnit Playwright Project: A project configured with Playwright for NUnit.
- Sign in to the Playwright Portal using your Azure account
- Create the Workspace and note down the Playwright Service URL for integration.
-
Create a new file PlaywrightServiceSetup.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 { };In your project, install Microsoft Playwright Testing package.
dotnet add package Azure.Developer.MicrosoftPlaywrightTesting.NUnit --prerelease- Create or update a .runsettings file.
- Add the following content:
<?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>Ensure your GitHub Actions workflow runs tests in Azure Playwright Testing Service. Refer the file in this repo
-
Create App Registration in Entra ID
- Go to Azure Portal > Microsoft Entra ID > App Registrations.
- Create a new app registration.
-
Grant Permissions
- Ensure the app has necessary permissions (e.g., Azure Service Management or Playwright service-specific permissions).
-
Configure GitHub Actions for OIDC OIDC allows GitHub Actions to authenticate directly with Azure without storing credentials. Make sure you’ve followed the required setup:
- Go to Azure Active Directory > App Registrations > Federated Credentials.
- Create a new credential with:
- Subject Identifier: repo:/:branch:<branch_name>
- Audience: api://AzureADTokenExchange.
-
Set Secrets in GitHub Actions
- Add the following secrets:
- AZURE_CLIENT_ID
- AZURE_TENANT_ID
- AZURE_SUBSCRIPTION_ID
- Add the following secrets:
-
Assign Contributor Role to App
- Go to your Playwright Workspace in Azure Portal.
- Navigate to Access Control (IAM) and assign the Contributor role to the app.
For configuring the Azure Playwright Testing service for Azure pipelines refer here
For more details, refer to the Microsoft Playwright Documentation.