Skip to content

Commit 3595331

Browse files
authored
Merge pull request #286300 from vvs11/main
Playwright Testing documentation updates for reporting and Entra ID support
2 parents 04bf272 + 0345371 commit 3595331

25 files changed

+502
-409
lines changed

articles/playwright-testing/how-to-configure-visual-comparisons.md

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,40 +44,29 @@ Example service config that runs visual comparisons and configures the path for
4444

4545
```typeScript
4646
import { defineConfig } from '@playwright/test';
47+
import { getServiceConfig, ServiceOS } from '@azure/microsoft-playwright-testing';
4748
import config from './playwright.config';
48-
import dotenv from 'dotenv';
49-
50-
dotenv.config();
51-
52-
// Name the test run if it's not named yet.
53-
process.env.PLAYWRIGHT_SERVICE_RUN_ID = process.env.PLAYWRIGHT_SERVICE_RUN_ID || new Date().toISOString();
54-
55-
// Can be 'linux' or 'windows'.
56-
const os = process.env.PLAYWRIGHT_SERVICE_OS || 'linux';
57-
58-
export default defineConfig(config, {
59-
workers: 20,
60-
61-
// Enable screenshot testing and configure directory with expectations.
62-
ignoreSnapshots: false,
63-
snapshotPathTemplate: `{testDir}/__screenshots__/{testFilePath}/${os}/{arg}{ext}`,
64-
65-
use: {
66-
// Specify the service endpoint.
67-
connectOptions: {
68-
wsEndpoint: `${process.env.PLAYWRIGHT_SERVICE_URL}?cap=${JSON.stringify({
69-
os,
70-
runId: process.env.PLAYWRIGHT_SERVICE_RUN_ID
71-
})}`,
72-
timeout: 30000,
73-
headers: {
74-
'x-mpt-access-key': process.env.PLAYWRIGHT_SERVICE_ACCESS_TOKEN!
75-
},
76-
// Allow service to access the localhost.
77-
exposeNetwork: '<loopback>'
78-
}
49+
50+
/* Learn more about service configuration at https://aka.ms/mpt/config */
51+
export default defineConfig(
52+
config,
53+
getServiceConfig(config, {
54+
exposeNetwork: '<loopback>',
55+
timeout: 30000,
56+
os: ServiceOS.LINUX
57+
}),
58+
{
59+
/*
60+
Playwright Testing service reporter is added by default.
61+
This will override any reporter options specified in the base playwright config.
62+
If you are using more reporters, please update your configuration accordingly.
63+
*/
64+
reporter: [["list"], ['@azure/microsoft-playwright-testing/reporter']],
65+
ignoreSnapshots: false,
66+
// Enable screenshot testing and configure directory with expectations. 
67+
snapshotPathTemplate: `{testDir}/__screenshots__/{testFilePath}/${ServiceOS.LINUX}/{arg}{ext}`,
7968
}
80-
});
69+
);
8170
```
8271

8372
## Related content

articles/playwright-testing/how-to-manage-access-tokens.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,4 @@ You can only delete access tokens that you created in a workspace. To create an
105105
## Related content
106106

107107
- Learn more about [managing access to a workspace](./how-to-manage-workspace-access.md).
108+
- Learn more about [managing authentication to the workspace](./how-to-manage-authentication.md)
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: Microsoft Playwright Testing authentication
3+
description: Learn how to manage authentication and authorization for Microsoft Playwright Testing preview
4+
ms.topic: how-to
5+
ms.date: 09/07/2024
6+
ms.custom: playwright-testing-preview
7+
---
8+
9+
# Manage authentication and authorization for Microsoft Playwright Testing preview
10+
11+
In this article, you learn how to manage authentication and authorization for Microsoft Playwright Testing preview. Authentication is required to run Playwright tests on cloud-hosted browsers and to publish test results and artifacts to the service.
12+
13+
By default, [Microsoft Entra ID](/entra/identity/) is used for authentication. This method is more secure and is the recommended authentication method. You can't disable authentication using Microsoft Entra ID. However, you can also use access tokens to authenticate and authorize.
14+
15+
16+
> [!IMPORTANT]
17+
> 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 the [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
18+
19+
## Background
20+
21+
Microsoft Playwright Testing Preview is built on the Playwright open-source framework. It runs Playwright tests on cloud-hosted browsers and publishes reports and artifacts back to the service.
22+
23+
To use the service, the client must authenticate with the service to access the browsers. Similarly, publishing results and artifacts requires authenticated API interactions. The service offers two authentication methods: Microsoft Entra ID and access tokens.
24+
25+
Microsoft Entra ID uses your Azure credentials, requiring a sign-in to your Azure account for secure access. Alternatively, you can generate an access token from your Playwright 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.
26+
27+
## Enable authentication using access-tokens
28+
29+
Microsoft Playwright Testing service also supports authentication using access tokens. This authentication method is less secure. We recommend using Microsoft Entra ID to authenticate to the service.
30+
31+
> [!CAUTION]
32+
> Your workspace access tokens are similar to a password for your Microsoft Playwright Testing workspace. Always be careful to protect your access tokens. Avoid distributing access tokens to other users, hard-coding them, or saving them anywhere in plain text that is accessible to others.
33+
34+
Revoke and recreate your tokens if you believe they are compromised.
35+
36+
To enable authentication using access tokens:
37+
38+
1. Sign in to the [Playwright portal](https://aka.ms/mpt/portal) with your Azure account and select your workspace.
39+
40+
1. Select the settings icon on the home page to go to the workspace settings.
41+
42+
1. Select the **Authentication** page and turn on **Enable authentication using Access tokens**
43+
44+
45+
:::image type="content" source="./media/how-to-manage-authentication/playwright-testing-enable-access-token.png" alt-text="Screenshot that shows the access tokens settings page in the Playwright portal." lightbox="./media/how-to-manage-authentication/playwright-testing-enable-access-token.png":::
46+
47+
> [!CAUTION]
48+
> Authentication using access tokens is less secure. [Learn how to manage access tokens](./how-to-manage-access-tokens.md)
49+
50+
## Set up authentication using access-tokens
51+
52+
1. While running the tests, enable access token auth in the `playwright.service.config.ts` file in your setup.
53+
54+
```typescript
55+
/* Learn more about service configuration at https://aka.ms/mpt/config */
56+
export default defineConfig(config, getServiceConfig( config {
57+
serviceAuthType:'ACCESS_TOKEN'
58+
}));
59+
```
60+
61+
1. Create access token
62+
63+
Follow the steps to [create an access token](./how-to-manage-access-tokens.md#generate-a-workspace-access-token)
64+
65+
1. Set up your environment
66+
67+
To set up your environment, you have to configure the `PLAYWRIGHT_SERVICE_ACCESS_TOKEN` environment variable with the value you obtained in the previous steps.
68+
69+
We recommend that you use the `dotenv` module to manage your environment. With `dotenv`, you define your environment variables in the `.env` file.
70+
71+
1. Add the `dotenv` module to your project:
72+
73+
```shell
74+
npm i --save-dev dotenv
75+
```
76+
77+
1. Create a `.env` file alongside the `playwright.config.ts` file in your Playwright project:
78+
79+
```
80+
PLAYWRIGHT_SERVICE_ACCESS_TOKEN={MY-ACCESS-TOKEN}
81+
```
82+
83+
Make sure to replace the `{MY-ACCESS-TOKEN}` text placeholder with the value you copied earlier.
84+
85+
86+
## Run tests on the service and publish results
87+
88+
Run Playwright tests against cloud-hosted browsers and publish the results to the service using the configuration you created above.
89+
90+
```typescript
91+
npx playwright test --config=playwright.service.config.ts --workers=20
92+
```
93+
94+
## Related content
95+
96+
- Learn more about [managing access tokens](./how-to-manage-access-tokens.md).

articles/playwright-testing/how-to-test-local-applications.md

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,18 @@ You can specify one or multiple networks by using a list of rules. For example,
2424
You can configure the `exposeNetwork` option in `playwright.service.config.ts`. The following example shows how to expose the `localhost` network by using the [`<loopback>`](https://en.wikipedia.org/wiki/Loopback) rule:
2525

2626
```typescript
27-
export default defineConfig(config, {
28-
workers: 20,
29-
use: {
30-
// Specify the service endpoint.
31-
connectOptions: {
32-
wsEndpoint: `${process.env.PLAYWRIGHT_SERVICE_URL}?cap=${JSON.stringify({
33-
// Can be 'linux' or 'windows'.
34-
os: process.env.PLAYWRIGHT_SERVICE_OS || 'linux',
35-
runId: process.env.PLAYWRIGHT_SERVICE_RUN_ID
36-
})}`,
37-
timeout: 30000,
38-
headers: {
39-
'x-mpt-access-key': process.env.PLAYWRIGHT_SERVICE_ACCESS_TOKEN!
40-
},
41-
// Allow service to access the localhost.
42-
exposeNetwork: '<loopback>'
43-
}
44-
}
45-
});
27+
import { getServiceConfig, ServiceOS } from "@azure/microsoft-playwright-testing";
28+
import { defineConfig } from "@playwright/test";
29+
import { AzureCliCredential } from "@azure/identity";
30+
import config from "./playwright.config";
31+
32+
export default defineConfig(
33+
config,
34+
getServiceConfig(config, {
35+
exposeNetwork: '<loopback>', // Allow service to access the localhost.
36+
}),
37+
);
38+
4639
```
4740

4841
You can now reference `localhost` in the Playwright test code, and run the tests on cloud-hosted browsers with Microsoft Playwright Testing:

articles/playwright-testing/how-to-try-playwright-testing-free.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.custom: playwright-testing-preview
88

99
# Try Microsoft Playwright Testing Preview for free
1010

11-
Microsoft Playwright Testing Preview is a fully managed service for end-to-end testing built on top of Playwright. With the free trial, you can try Microsoft Playwright Testing for free for 30 days and 100 test minutes. In this article, you learn about the limits of the free trial, how to get started, and how to track your free trial usage.
11+
Microsoft Playwright Testing Preview is a fully managed service for end-to-end testing built on top of Playwright. With the free trial, you can try Microsoft Playwright Testing for free for 30 days, 100 test minutes, and 1,000 test results. In this article, you learn about the limits of the free trial, how to get started, and how to track your free trial usage.
1212

1313
> [!IMPORTANT]
1414
> 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 the [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
@@ -26,9 +26,10 @@ The following table lists the limits for the Microsoft Playwright Testing free t
2626
|-|-|
2727
| Duration of trial | 30 days |
2828
| Total test minutes¹ | 100 minutes |
29+
| Total test results¹ | 1,000 results |
2930
| Number of workspaces²³ | 1 |
3031

31-
¹ If you run a test that exceeds the free trial test minute limit, only the overage test minutes account towards the pay-as-you-go billing model.
32+
¹ If your usage exceeds either the free test minute limit or the free test result limit, only the overage counts toward the pay-as-you-go billing model. The two features are billed separately. See [Microsoft Playwright Testing preview pricing](https://aka.ms/mpt/pricing)
3233

3334
² These limits only apply to the *first* workspace you create in your Azure subscription. Any subsequent workspaces you create in the subscription automatically uses the pay-as-you-go billing model.
3435

@@ -82,7 +83,7 @@ In the list of all workspaces, you can view a banner message that indicates if a
8283

8384
When you exceed any of the limits of the free trial, your workspace is automatically converted to the pay-as-you-go billing model.
8485

85-
All test runs, access tokens, and other artifacts linked to your workspace remain available.
86+
All test runs, test results, and other artifacts linked to your workspace remain available.
8687

8788
## Next step
8889

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
---
2+
title: Microsoft Playwright Testing service configuration file options
3+
description: Learn how to use options available in configuration file with Microsoft Playwright Testing preview
4+
ms.topic: how-to
5+
ms.date: 09/07/2024
6+
ms.custom: playwright-testing-preview
7+
---
8+
# Use options available in configuration file with Microsoft Playwright Testing preview
9+
10+
This article shows you how to use the options available in the `playwright.service.config.ts` file that was generated for you.
11+
If you don't have this file in your code, follow the QuickStart guide, see [Quickstart: Run end-to-end tests at scale with Microsoft Playwright Testing Preview](./quickstart-run-end-to-end-tests.md)
12+
13+
> [!IMPORTANT]
14+
> 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 the [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
15+
16+
## Prerequisites
17+
18+
* Follow the Quickstart guide and set up a project to run with Microsoft Playwright Testing service. See, [Quickstart: Run end-to-end tests at scale with Microsoft Playwright Testing Preview](./quickstart-run-end-to-end-tests.md)
19+
20+
Here's version of the `playwright.service.config.ts` file with all the available options:
21+
22+
```typescript
23+
import { getServiceConfig, ServiceOS } from "@azure/microsoft-playwright-testing";
24+
import { defineConfig } from "@playwright/test";
25+
import { AzureCliCredential } from "@azure/identity";
26+
import config from "./playwright.config";
27+
28+
export default defineConfig(
29+
config,
30+
getServiceConfig(config, {
31+
serviceAuthType:'ACCESS_TOKEN' // Use this option when you want to authenticate using access tokens. This mode of auth should be enabled for the workspace.
32+
os: ServiceOS.WINDOWS, // Select the operating system where you want to run tests.
33+
runId: new Date().toISOString(), // Set a unique ID for every test run to distinguish them in the service portal.
34+
credential: new AzureCliCredential(), // Select the authentication method you want to use with Entra.
35+
useCloudHostedBrowsers: true, // Select if you want to use cloud-hosted browsers to run your Playwright tests.
36+
exposeNetwork: '<loopback>', // Use this option to connect to local resources from your Playwright test code without having to configure additional firewall settings.
37+
timeout: 30000 // Set the timeout for your tests.
38+
}),
39+
{
40+
reporter: [
41+
["list"],
42+
[
43+
"@azure/microsoft-playwright-testing/reporter",
44+
{
45+
enableGitHubSummary: true, // Enable/disable GitHub summary in GitHub Actions workflow.
46+
},
47+
],
48+
],
49+
},
50+
);
51+
52+
```
53+
54+
## Settings in `playwright.service.config.ts` file
55+
56+
* **`serviceAuthType`**:
57+
- **Description**: This setting allows you to choose the authentication method you want to use for your test run.
58+
- **Available Options**:
59+
- `ACCESS_TOKEN` to use access tokens. You need to enable authentication using access tokens if you want to use this option, see [manage authentication](./how-to-manage-authentication.md).
60+
- `ENTRA_ID` to use Microsoft Entra ID for authentication. It's the default mode.
61+
- **Default Value**: `ENTRA_ID`
62+
- **Example**:
63+
```typescript
64+
serviceAuthType:'ENTRA_ID'
65+
```
66+
67+
68+
* **`os`**:
69+
- **Description**: This setting allows you to choose the operating system where the browsers running Playwright tests are hosted.
70+
- **Available Options**:
71+
- `ServiceOS.WINDOWS` for Windows OS.
72+
- `ServiceOS.LINUX` for Linux OS.
73+
- **Default Value**: `ServiceOS.LINUX`
74+
- **Example**:
75+
```typescript
76+
os: ServiceOS.WINDOWS
77+
```
78+
79+
* **`runId`**:
80+
- **Description**: This setting allows you to set a unique ID for every test run to distinguish them in the service portal.
81+
- **Example**:
82+
```typescript
83+
runId: new Date().toISOString()
84+
```
85+
86+
* **`credential`**:
87+
- **Description**: This setting allows you to select the authentication method you want to use with Microsoft Entra ID.
88+
- **Example**:
89+
```typescript
90+
credential: new AzureCliCredential()
91+
```
92+
93+
* **`useCloudHostedBrowsers`**
94+
- **Description**: This setting allows you to choose whether to use cloud-hosted browsers or the browsers on your client machine to run your Playwright tests. If you disable this option, your tests run on the browsers of your client machine instead of cloud-hosted browsers, and you don't incur any charges.
95+
- **Default Value**: true
96+
- **Example**:
97+
```typescript
98+
useCloudHostedBrowsers: true
99+
```
100+
101+
* **`exposeNetwork`**
102+
- **Description**: This setting allows you to connect to local resources from your Playwright test code without having to configure another firewall settings. To learn more, see [how to test local applications](./how-to-test-local-applications.md)
103+
- **Example**:
104+
```typescript
105+
exposeNetwork: '<loopback>'
106+
```
107+
108+
* **`timeout`**
109+
- **Description**: This setting allows you to set timeout for your tests connecting to the cloud-hosted browsers.
110+
- **Example**:
111+
```typescript
112+
timeout: 30000,
113+
```
114+
115+
* **`reporter`**
116+
- **Description**: The `playwright.service.config.ts` file extends the playwright config file of your setup. This option overrides the existing reporters and sets Microsoft Playwright Testing reporter. You can add or modify this list to include the reporters that you want to use. You're billed for Microsoft Playwright Testing reporting if you add `@azure/microsoft-playwright-testing/reporter`.
117+
- **Default Value**: ["@azure/microsoft-playwright-testing/reporter"]
118+
- **Example**:
119+
```typescript
120+
reporter: [
121+
["list"],
122+
["@azure/microsoft-playwright-testing/reporter"],
123+
```
124+
* **`enableGitHubSummary`**:
125+
- **Description**: This setting allows you to configure the Microsoft Playwright Testing service reporter. You can choose whether to include the test run summary in the GitHub summary when running in GitHub Actions.
126+
- **Default Value**: true
127+
- **Example**:
128+
```typescript
129+
reporter: [
130+
["list"],
131+
[
132+
"@azure/microsoft-playwright-testing/reporter",
133+
{
134+
enableGitHubSummary: true,
135+
},
136+
],
137+
]
138+
```
139+

0 commit comments

Comments
 (0)