Skip to content

Commit b94b18f

Browse files
authored
Merge pull request #290539 from MicrosoftDocs/release-ignite-playwright-testing
[Ignite 2024 ship room] Playwright testing content updates for NUnit runner
2 parents ad65ae9 + 88c1b70 commit b94b18f

9 files changed

+680
-30
lines changed

articles/playwright-testing/how-to-manage-authentication.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: Learn how to manage authentication and authorization for Microsoft
44
ms.topic: how-to
55
ms.date: 09/07/2024
66
ms.custom: playwright-testing-preview
7+
zone_pivot_group_filename: playwright-testing/zone-pivots-groups.json
8+
zone_pivot_groups: microsoft-playwright-testing
79
---
810

911
# Manage authentication and authorization for Microsoft Playwright Testing preview
@@ -49,6 +51,8 @@ To enable authentication using access tokens:
4951
5052
## Set up authentication using access-tokens
5153

54+
::: zone pivot="playwright-test-runner"
55+
5256
1. While running the tests, enable access token auth in the `playwright.service.config.ts` file in your setup.
5357

5458
```typescript
@@ -57,14 +61,29 @@ To enable authentication using access tokens:
5761
serviceAuthType:'ACCESS_TOKEN'
5862
}));
5963
```
64+
::: zone-end
65+
66+
::: zone pivot="nunit-test-runner"
67+
68+
1. While running the tests, enable access token auth in the `.runsettings` file in your setup.
69+
70+
```xml
71+
<TestRunParameters>
72+
<!-- Use this option when you want to authenticate using access tokens. This mode of auth should be enabled for the workspace. -->
73+
<Parameter name="ServiceAuthType" value="AccessToken" />
74+
</TestRunParameters>
75+
```
76+
::: zone-end
77+
78+
2. Create access token
6079

61-
1. Create access token
80+
Follow the steps to [create an access token](./how-to-manage-access-tokens.md#generate-a-workspace-access-token). Copy the value of the access token generated.
6281

63-
Follow the steps to [create an access token](./how-to-manage-access-tokens.md#generate-a-workspace-access-token)
82+
::: zone pivot="playwright-test-runner"
6483

65-
1. Set up your environment
84+
3. Set up your environment
6685

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.
86+
To set up your environment, configure the `PLAYWRIGHT_SERVICE_ACCESS_TOKEN` environment variable with the value you obtained in the previous steps. Ensure this environment variable is available in your setup where you are running tests.
6887

6988
We recommend that you use the `dotenv` module to manage your environment. With `dotenv`, you define your environment variables in the `.env` file.
7089

@@ -74,23 +93,39 @@ To enable authentication using access tokens:
7493
npm i --save-dev dotenv
7594
```
7695

77-
1. Create a `.env` file alongside the `playwright.config.ts` file in your Playwright project:
96+
2. Create a `.env` file alongside the `playwright.config.ts` file in your Playwright project:
7897

7998
```
8099
PLAYWRIGHT_SERVICE_ACCESS_TOKEN={MY-ACCESS-TOKEN}
81100
```
82101

83102
Make sure to replace the `{MY-ACCESS-TOKEN}` text placeholder with the value you copied earlier.
84103

104+
::: zone-end
105+
106+
::: zone pivot="nunit-test-runner"
107+
108+
3. Set up your environment
109+
110+
To set up your environment, configure the `PLAYWRIGHT_SERVICE_ACCESS_TOKEN` environment variable with the value you obtained in the previous steps. Ensure this environment variable is available in your setup where you are running tests.
111+
112+
::: zone-end
85113

86114
## Run tests on the service and publish results
87115

88116
Run Playwright tests against cloud-hosted browsers and publish the results to the service using the configuration you created above.
89117

118+
::: zone pivot="playwright-test-runner"
90119
```typescript
91120
npx playwright test --config=playwright.service.config.ts --workers=20
92121
```
122+
::: zone-end
93123

124+
::: zone pivot="nunit-test-runner"
125+
```bash
126+
dotnet test --settings:.runsettings --logger "microsoft-playwright-testing" -- NUnit.NumberOfTestWorkers=20
127+
```
128+
::: zone-end
94129
## Related content
95130

96131
- Learn more about [managing access tokens](./how-to-manage-access-tokens.md).

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
---
2-
title: Use remote browsers for local applications
2+
title: Use remote browsers for local or private applications
33
description: Learn how to run end-to-end for locally deployed applications with Microsoft Playwright Testing Preview. Use cloud-hosted browsers to test apps on localhost or private networks.
44
ms.topic: how-to
55
ms.date: 10/04/2023
66
ms.custom: playwright-testing-preview
7+
zone_pivot_group_filename: playwright-testing/zone-pivots-groups.json
8+
zone_pivot_groups: microsoft-playwright-testing
79
---
810

9-
# Use cloud-hosted browsers for locally deployed apps with Microsoft Playwright Testing Preview
11+
# Use cloud-hosted browsers for locally deployed or privately hosted apps with Microsoft Playwright Testing Preview
1012

1113
Learn how to use Microsoft Playwright Testing Preview to run end-to-end tests for locally deployed applications. Microsoft Playwright Testing uses cloud-hosted, remote browsers for running Playwright tests at scale. You can use the service to run tests for apps on localhost, or that you host on your infrastructure.
1214

@@ -21,7 +23,9 @@ To expose local networks and resources to remote browsers, you can use the `expo
2123

2224
You can specify one or multiple networks by using a list of rules. For example, to expose test/staging deployments and [localhost](https://en.wikipedia.org/wiki/Localhost): `*.test.internal-domain,*.staging.internal-domain,<loopback>`.
2325

24-
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:
26+
::: zone pivot="playwright-test-runner"
27+
28+
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. You can also replace `localhost` with a domain that you want to enable for the service.
2529

2630
```typescript
2731
import { getServiceConfig, ServiceOS } from "@azure/microsoft-playwright-testing";
@@ -43,6 +47,27 @@ You can now reference `localhost` in the Playwright test code, and run the tests
4347
```bash
4448
npx playwright test --config=playwright.service.config.ts --workers=20
4549
```
50+
::: zone-end
51+
52+
53+
::: zone pivot="nunit-test-runner"
54+
55+
You can configure the `ExposeNetwork` option in `.runsettings`. The following example shows how to expose the `localhost` network by using the [`<loopback>`](https://en.wikipedia.org/wiki/Loopback) rule. You can also replace `localhost` with a domain that you want to enable for the service.
56+
57+
```xml
58+
<TestRunParameters>
59+
<!--Use this option to connect to local resources from your Playwright test code without having to configure additional firewall-->
60+
<Parameter name="ExposeNetwork" value="loopback" />
61+
</TestRunParameters>
62+
```
63+
64+
You can now reference `localhost` in the Playwright test code, and run the tests on cloud-hosted browsers with Microsoft Playwright Testing:
65+
66+
```bash
67+
dotnet test --settings:.runsettings --logger "microsoft-playwright-testing" -- NUnit.NumberOfTestWorkers=20
68+
```
69+
70+
::: zone-end
4671

4772
## Related content
4873

articles/playwright-testing/how-to-use-service-config-file.md

Lines changed: 146 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@ description: Learn how to use options available in configuration file with Micro
44
ms.topic: how-to
55
ms.date: 09/07/2024
66
ms.custom: playwright-testing-preview
7+
zone_pivot_group_filename: playwright-testing/zone-pivots-groups.json
8+
zone_pivot_groups: microsoft-playwright-testing
79
---
8-
# Use options available in configuration file with Microsoft Playwright Testing preview
10+
11+
# Use options available in service package with Microsoft Playwright Testing preview
12+
13+
::: zone pivot="playwright-test-runner"
914

1015
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)
16+
If you don't have this file in your code, follow [Quickstart: Run end-to-end tests at scale with Microsoft Playwright Testing Preview](./quickstart-run-end-to-end-tests.md)
17+
18+
::: zone-end
19+
20+
::: zone pivot="nunit-test-runner"
21+
22+
This article shows you how to use the options available in the `.runsettings` file.
23+
If you don't have this file in your code, follow [Quickstart: Run end-to-end tests at scale with Microsoft Playwright Testing Preview](./quickstart-run-end-to-end-tests.md)
24+
25+
::: zone-end
1226

1327
> [!IMPORTANT]
1428
> 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/).
@@ -17,6 +31,8 @@ If you don't have this file in your code, follow the QuickStart guide, see [Quic
1731

1832
* 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)
1933

34+
::: zone pivot="playwright-test-runner"
35+
2036
Here's version of the `playwright.service.config.ts` file with all the available options:
2137

2238
```typescript
@@ -77,7 +93,7 @@ export default defineConfig(
7793
```
7894

7995
* **`runId`**:
80-
- **Description**: This setting allows you to set a unique ID for every test run to distinguish them in the service portal.
96+
- **Description**: This setting allows you to set a unique ID for every test run to distinguish them in the service portal. Using the same runId for multiple test runs results in error. For sharding, keep this same across all shards.
8197
- **Example**:
8298
```typescript
8399
runId: new Date().toISOString()
@@ -136,4 +152,131 @@ export default defineConfig(
136152
],
137153
]
138154
```
155+
::: zone-end
156+
157+
::: zone pivot="nunit-test-runner"
158+
159+
160+
Here's version of the `.runsettings` file with all the available options:
161+
162+
```xml
163+
<?xml version="1.0" encoding="utf-8"?>
164+
<RunSettings>
165+
<TestRunParameters>
166+
<!-- Use this option when you want to authenticate using access tokens. This mode of auth should be enabled for the workspace. -->
167+
<Parameter name="ServiceAuthType" value="EntraId" />
168+
<!-- Select the operating system where you want to run tests. -->
169+
<Parameter name="Os" value="linux" />
170+
<!-- Set a unique ID for every test run to distinguish them in the service portal.-->
171+
<Parameter name="RunId" value="sample-run-id1" />
172+
<!--Select if you want to use cloud-hosted browsers to run your Playwright tests.-->
173+
<Parameter name="UseCloudHostedBrowsers" value="true" />
174+
<!--Use this option to connect to local resources from your Playwright test code without having to configure additional firewall-->
175+
<Parameter name="ExposeNetwork" value="loopback" />
176+
<!--Select the authentication method you want to use with Entra-->
177+
<Parameter name="AzureTokenCredentialType" value="DefaultAzureCredential" />
178+
<!--Enable/disable GitHub summary in GitHub Actions workflow.-->
179+
<Parameter name="EnableGitHubSummary" value="false" />
180+
</TestRunParameters>
181+
<!-- NUnit adapter -->
182+
<NUnit>
183+
<!-- Adjust parallel workers, parallel worker would also be bound by number of unit test files -->
184+
<NumberOfTestWorkers>10</NumberOfTestWorkers>
185+
</NUnit>
186+
<!-- General run configuration -->
187+
<RunConfiguration>
188+
<EnvironmentVariables>
189+
<!-- For debugging selectors, it's recommend to set the following environment variable -->
190+
<DEBUG>pw:api</DEBUG>
191+
</EnvironmentVariables>
192+
</RunConfiguration>
193+
<!-- Playwright -->
194+
<Playwright>
195+
<BrowserName>chromium</BrowserName>
196+
<!--Set the timeout for your tests.-->
197+
<ExpectTimeout>5000</ExpectTimeout>
198+
<LaunchOptions>
199+
<Headless>false</Headless>
200+
<!--Channel>msedge</Channel-->
201+
</LaunchOptions>
202+
</Playwright>
203+
<LoggerRunSettings>
204+
<Loggers>
205+
<!--microsoft playwright testing service logger for reporting -->
206+
<Logger friendlyName="microsoft-playwright-testing" enabled="true" />
207+
<!--could enable any logger additionally -->
208+
<Logger friendlyName="trx" enabled="false" />
209+
</Loggers>
210+
</LoggerRunSettings>
211+
</RunSettings>
212+
213+
```
139214

215+
## Options in `.runsettings` file
216+
217+
* **`serviceAuthType`**:
218+
- **Description**: This setting allows you to choose the authentication method you want to use for your test run.
219+
- **Available Options**:
220+
- `AccessToken` 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).
221+
- `EntraId` to use Microsoft Entra ID for authentication. It's the default mode.
222+
- **Default Value**: `EntraId`
223+
- **Example**:
224+
```xml
225+
<Parameter name="ServiceAuthType" value="EntraId" />
226+
```
227+
228+
* **`os`**:
229+
- **Description**: This setting allows you to choose the operating system where the browsers running Playwright tests are hosted.
230+
- **Available Options**:
231+
- "windows" for Windows OS.
232+
- "linux" for Linux OS.
233+
- **Default Value**: "linux"
234+
- **Example**:
235+
```xml
236+
<Parameter name="Os" value="linux" />
237+
```
238+
239+
* **`RunId`**:
240+
- **Description**: This setting allows you to set a unique ID for every test run to distinguish them in the service portal. Using the same runId for multiple test runs results in error. If you don't set it, the service package will generate a unique ID every time you trigger a test run. For sharding, keep this same across all shards.
241+
- **Example**:
242+
```xml
243+
<Parameter name="RunId" value="sample-run-id1" />
244+
```
245+
246+
* **`AzureTokenCredentialType`**:
247+
- **Description**: This setting allows you to select the authentication method you want to use with Microsoft Entra ID.
248+
- **Example**:
249+
```xml
250+
<Parameter name="AzureTokenCredentialType" value="DefaultAzureCredential" />
251+
```
252+
253+
* **`UseCloudHostedBrowsers`**
254+
- **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.
255+
- **Default Value**: true
256+
- **Example**:
257+
```xml
258+
<Parameter name="UseCloudHostedBrowsers" value="true" />
259+
```
260+
* **`ExposeNetwork`**
261+
- **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)
262+
- **Example**:
263+
```xml
264+
<Parameter name="ExposeNetwork" value="loopback" />
265+
```
266+
267+
* **`reporter`**
268+
- **Description**: You can publish your test results and artifacts to the service using `microsoft-playwright-testing` logger. You can disable reporting by removing this from your `.runsettings` or by setting it to false.
269+
- **Default Value**: true
270+
- **Example**:
271+
```xml
272+
<Logger friendlyName="microsoft-playwright-testing" enabled="true" />
273+
```
274+
275+
* **`EnableGitHubSummary`**:
276+
- **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.
277+
- **Default Value**: true
278+
- **Example**:
279+
```xml
280+
<Parameter name="EnableGitHubSummary" value="false" />
281+
```
282+
::: zone-end

articles/playwright-testing/how-to-use-service-features.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: Learn how to use different features offered by Microsoft Playwright
44
ms.topic: how-to
55
ms.date: 09/07/2024
66
ms.custom: playwright-testing-preview
7+
zone_pivot_group_filename: playwright-testing/zone-pivots-groups.json
8+
zone_pivot_groups: microsoft-playwright-testing
79
---
810

911
# Use features of Microsoft Playwright Testing preview
@@ -48,7 +50,7 @@ You can also choose to use either feature or both for a test run.
4850

4951
> [!IMPORTANT]
5052
> You can only use a feature in a test run if it is enabled for the workspace.
51-
53+
::: zone pivot="playwright-test-runner"
5254
1. In your Playwright setup, go to `playwright.service.config.ts` file and use these settings for feature management.
5355

5456
```typescript
@@ -87,7 +89,51 @@ export default defineConfig(
8789
["@azure/microsoft-playwright-testing/reporter"]],
8890
```
8991

92+
::: zone-end
93+
94+
::: zone pivot="nunit-test-runner"
95+
96+
1. In your Playwright setup, go to `.runsettings` file and use these settings for feature management.
97+
98+
```xml
99+
<?xml version="1.0" encoding="utf-8"?>
100+
<RunSettings>
101+
<TestRunParameters>
102+
<!--Select if you want to use cloud-hosted browsers to run your Playwright tests.-->
103+
<Parameter name="UseCloudHostedBrowsers" value="true" />
104+
</TestRunParameters>
105+
<!-- NUnit adapter -->
106+
.
107+
.
108+
.
109+
<LoggerRunSettings>
110+
<Loggers>
111+
<!--microsoft playwright testing service logger for reporting -->
112+
<Logger friendlyName="microsoft-playwright-testing" enabled="true" />
113+
<!--could enable any logger additionally -->
114+
<Logger friendlyName="trx" enabled="false" />
115+
</Loggers>
116+
</LoggerRunSettings>
117+
</RunSettings>
118+
119+
```
90120

121+
* **`UseCloudHostedBrowsers`**
122+
- **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.
123+
- **Default Value**: true
124+
- **Example**:
125+
```xml
126+
<Parameter name="UseCloudHostedBrowsers" value="true" />
127+
```
128+
129+
* **`reporter`**
130+
- **Description**: You can publish your test results and artifacts to the service using `microsoft-playwright-testing` logger. You can disable reporting by removing this from your `.runsettings` or by setting it to false.
131+
- **Default Value**: true
132+
- **Example**:
133+
```xml
134+
<Logger friendlyName="microsoft-playwright-testing" enabled="true" />
135+
```
136+
::: zone-end
91137
## Related content
92138

93139
- Learn more about [Microsoft Playwright Testing preview pricing](https://aka.ms/mpt/pricing).

0 commit comments

Comments
 (0)