Run Playwright tests at scale using Azure Playwright Workspaces (formerly Microsoft Playwright Testing). Use when scaling browser tests across cloud-hosted browsers, integrating with CI/CD pipelines, or publishing test results to the Azure portal.
Add this skill
npx mdskills install sickn33/azure-microsoft-playwright-testing-tsComprehensive SDK documentation with detailed setup, auth patterns, and CI/CD examples
1---2name: azure-microsoft-playwright-testing-ts3description: Run Playwright tests at scale using Azure Playwright Workspaces (formerly Microsoft Playwright Testing). Use when scaling browser tests across cloud-hosted browsers, integrating with CI/CD pipelines, or publishing test results to the Azure portal.4package: "@azure/playwright"5---67# Azure Playwright Workspaces SDK for TypeScript89Run Playwright tests at scale with cloud-hosted browsers and integrated Azure portal reporting.1011> **Migration Notice:** `@azure/microsoft-playwright-testing` is retired on **March 8, 2026**. Use `@azure/playwright` instead. See [migration guide](https://aka.ms/mpt/migration-guidance).1213## Installation1415```bash16# Recommended: Auto-generates config17npm init @azure/playwright@latest1819# Manual installation20npm install @azure/playwright --save-dev21npm install @playwright/test@^1.47 --save-dev22npm install @azure/identity --save-dev23```2425**Requirements:**26- Playwright version 1.47+ (basic usage)27- Playwright version 1.57+ (Azure reporter features)2829## Environment Variables3031```bash32PLAYWRIGHT_SERVICE_URL=wss://eastus.api.playwright.microsoft.com/playwrightworkspaces/{workspace-id}/browsers33```3435## Authentication3637### Microsoft Entra ID (Recommended)3839```bash40# Sign in with Azure CLI41az login42```4344```typescript45// playwright.service.config.ts46import { defineConfig } from "@playwright/test";47import { createAzurePlaywrightConfig, ServiceOS } from "@azure/playwright";48import { DefaultAzureCredential } from "@azure/identity";49import config from "./playwright.config";5051export default defineConfig(52 config,53 createAzurePlaywrightConfig(config, {54 os: ServiceOS.LINUX,55 credential: new DefaultAzureCredential(),56 })57);58```5960### Custom Credential6162```typescript63import { ManagedIdentityCredential } from "@azure/identity";64import { createAzurePlaywrightConfig } from "@azure/playwright";6566export default defineConfig(67 config,68 createAzurePlaywrightConfig(config, {69 credential: new ManagedIdentityCredential(),70 })71);72```7374## Core Workflow7576### Service Configuration7778```typescript79// playwright.service.config.ts80import { defineConfig } from "@playwright/test";81import { createAzurePlaywrightConfig, ServiceOS } from "@azure/playwright";82import { DefaultAzureCredential } from "@azure/identity";83import config from "./playwright.config";8485export default defineConfig(86 config,87 createAzurePlaywrightConfig(config, {88 os: ServiceOS.LINUX,89 connectTimeout: 30000,90 exposeNetwork: "<loopback>",91 credential: new DefaultAzureCredential(),92 })93);94```9596### Run Tests9798```bash99npx playwright test --config=playwright.service.config.ts --workers=20100```101102### With Azure Reporter103104```typescript105import { defineConfig } from "@playwright/test";106import { createAzurePlaywrightConfig, ServiceOS } from "@azure/playwright";107import { DefaultAzureCredential } from "@azure/identity";108import config from "./playwright.config";109110export default defineConfig(111 config,112 createAzurePlaywrightConfig(config, {113 os: ServiceOS.LINUX,114 credential: new DefaultAzureCredential(),115 }),116 {117 reporter: [118 ["html", { open: "never" }],119 ["@azure/playwright/reporter"],120 ],121 }122);123```124125### Manual Browser Connection126127```typescript128import playwright, { test, expect, BrowserType } from "@playwright/test";129import { getConnectOptions } from "@azure/playwright";130131test("manual connection", async ({ browserName }) => {132 const { wsEndpoint, options } = await getConnectOptions();133 const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);134 const context = await browser.newContext();135 const page = await context.newPage();136137 await page.goto("https://example.com");138 await expect(page).toHaveTitle(/Example/);139140 await browser.close();141});142```143144## Configuration Options145146```typescript147type PlaywrightServiceAdditionalOptions = {148 serviceAuthType?: "ENTRA_ID" | "ACCESS_TOKEN"; // Default: ENTRA_ID149 os?: "linux" | "windows"; // Default: linux150 runName?: string; // Custom run name for portal151 connectTimeout?: number; // Default: 30000ms152 exposeNetwork?: string; // Default: <loopback>153 credential?: TokenCredential; // REQUIRED for Entra ID154};155```156157### ServiceOS Enum158159```typescript160import { ServiceOS } from "@azure/playwright";161162// Available values163ServiceOS.LINUX // "linux" - default164ServiceOS.WINDOWS // "windows"165```166167### ServiceAuth Enum168169```typescript170import { ServiceAuth } from "@azure/playwright";171172// Available values173ServiceAuth.ENTRA_ID // Recommended - uses credential174ServiceAuth.ACCESS_TOKEN // Use PLAYWRIGHT_SERVICE_ACCESS_TOKEN env var175```176177## CI/CD Integration178179### GitHub Actions180181```yaml182name: playwright-ts183on: [push, pull_request]184185permissions:186 id-token: write187 contents: read188189jobs:190 test:191 runs-on: ubuntu-latest192 steps:193 - uses: actions/checkout@v4194195 - name: Azure Login196 uses: azure/login@v2197 with:198 client-id: ${{ secrets.AZURE_CLIENT_ID }}199 tenant-id: ${{ secrets.AZURE_TENANT_ID }}200 subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}201202 - run: npm ci203204 - name: Run Tests205 env:206 PLAYWRIGHT_SERVICE_URL: ${{ secrets.PLAYWRIGHT_SERVICE_URL }}207 run: npx playwright test -c playwright.service.config.ts --workers=20208```209210### Azure Pipelines211212```yaml213- task: AzureCLI@2214 displayName: Run Playwright Tests215 env:216 PLAYWRIGHT_SERVICE_URL: $(PLAYWRIGHT_SERVICE_URL)217 inputs:218 azureSubscription: My_Service_Connection219 scriptType: pscore220 inlineScript: |221 npx playwright test -c playwright.service.config.ts --workers=20222 addSpnToEnvironment: true223```224225## Key Types226227```typescript228import {229 createAzurePlaywrightConfig,230 getConnectOptions,231 ServiceOS,232 ServiceAuth,233 ServiceEnvironmentVariable,234} from "@azure/playwright";235236import type {237 OsType,238 AuthenticationType,239 BrowserConnectOptions,240 PlaywrightServiceAdditionalOptions,241} from "@azure/playwright";242```243244## Migration from Old Package245246| Old (`@azure/microsoft-playwright-testing`) | New (`@azure/playwright`) |247|---------------------------------------------|---------------------------|248| `getServiceConfig()` | `createAzurePlaywrightConfig()` |249| `timeout` option | `connectTimeout` option |250| `runId` option | `runName` option |251| `useCloudHostedBrowsers` option | Removed (always enabled) |252| `@azure/microsoft-playwright-testing/reporter` | `@azure/playwright/reporter` |253| Implicit credential | Explicit `credential` parameter |254255### Before (Old)256257```typescript258import { getServiceConfig, ServiceOS } from "@azure/microsoft-playwright-testing";259260export default defineConfig(261 config,262 getServiceConfig(config, {263 os: ServiceOS.LINUX,264 timeout: 30000,265 useCloudHostedBrowsers: true,266 }),267 {268 reporter: [["@azure/microsoft-playwright-testing/reporter"]],269 }270);271```272273### After (New)274275```typescript276import { createAzurePlaywrightConfig, ServiceOS } from "@azure/playwright";277import { DefaultAzureCredential } from "@azure/identity";278279export default defineConfig(280 config,281 createAzurePlaywrightConfig(config, {282 os: ServiceOS.LINUX,283 connectTimeout: 30000,284 credential: new DefaultAzureCredential(),285 }),286 {287 reporter: [288 ["html", { open: "never" }],289 ["@azure/playwright/reporter"],290 ],291 }292);293```294295## Best Practices2962971. **Use Entra ID auth** — More secure than access tokens2982. **Provide explicit credential** — Always pass `credential: new DefaultAzureCredential()`2993. **Enable artifacts** — Set `trace: "on-first-retry"`, `video: "retain-on-failure"` in config3004. **Scale workers** — Use `--workers=20` or higher for parallel execution3015. **Region selection** — Choose region closest to your test targets3026. **HTML reporter first** — When using Azure reporter, list HTML reporter before Azure reporter303
Full transparency — inspect the skill content before installing.