Skip to content

Commit 990fe36

Browse files
authored
Merge pull request #287194 from vvs11/vvs11-reporting-quickstart
Update quickstart to show reporting screenshots
2 parents 9bad038 + d903b3a commit 990fe36

10 files changed

+278
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ In this article, you learn how to use the features provided by Microsoft Playwri
2222
## Background
2323

2424
Microsoft Playwright Testing preview allows you to:
25-
- Run your Playwright tests on cloud-hosted browsers.
26-
- Publish test reports and artifacts to the service and view them in the service portal.
25+
- Accelerate build pipelines by running tests in parallel using cloud-hosted browsers.
26+
- Simplify troubleshooting by publishing test results and artifacts to the service, making them easily accessible through the service portal.
2727

2828
These features have their own pricing plans and are billed separately. You can choose to use either feature or both. These features can be enabled or disabled for the workspace or for any specific run. To know more about pricing, see [Microsoft Playwright Testing preview pricing](https://aka.ms/mpt/pricing)
2929

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: "Include file"
3+
description: "Include file"
4+
ms.custom: "include file"
5+
ms.topic: "include"
6+
ms.date: 09/23/2024
7+
---
8+
9+
10+
1. 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:
11+
- CI build details
12+
- Overall test run status
13+
- The commit ID linked to the test run
14+
15+
:::image type="content" source="../media/include-playwright-portal-view-test-results/playwright-testing-open-test-run.png" alt-text="Screenshot that shows list of tests in the test run." lightbox="../media/include-playwright-portal-view-test-results/playwright-testing-open-test-run.png":::
16+
17+
3. The Playwright portal provides all the necessary information for troubleshooting. You can:
18+
- Switch between retries.
19+
- View detailed error logs, test steps, and attached artifacts such as screenshots or videos.
20+
- Navigate directly to the **Trace Viewer** for deeper analysis.
21+
22+
:::image type="content" source="../media/include-playwright-portal-view-test-results/playwright-testing-open-test.png" alt-text="Screenshot that shows the preview of a test." lightbox="../media/include-playwright-portal-view-test-results/playwright-testing-open-test.png":::
23+
24+
4. The Trace Viewer allows you to step through your test execution visually. You can:
25+
- Use the timeline to hover over individual steps, revealing the page state before and after each action.
26+
- Inspect detailed logs, DOM snapshots, network activity, errors, and console output for each step.
27+
28+
:::image type="content" source="../media/include-playwright-portal-view-test-results/playwright-testing-trace-viewer.png" alt-text="Screenshot that shows the trace viewer." lightbox="../media/include-playwright-portal-view-test-results/playwright-testing-trace-viewer.png":::
29+

articles/playwright-testing/index.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ landingContent:
3636
url: quickstart-run-end-to-end-tests.md
3737
- text: Set up continuous end-to-end testing
3838
url: quickstart-automate-end-to-end-testing.md
39+
- text: Troubleshoot using rich reports and artifacts
40+
url: quickstart-generate-rich-reports-for-tests.md
3941
- linkListType: concept
4042
links:
4143
- text: Determine optimal test suite configuration
Loading
137 KB
Loading
Loading

articles/playwright-testing/quickstart-automate-end-to-end-testing.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,39 @@ If you haven't configured your Playwright tests yet for running them on cloud-ho
6565

6666
Optionally, use the `playwright.service.config.ts` file in the [sample repository](https://github.com/microsoft/playwright-testing-service/blob/main/samples/get-started/playwright.service.config.ts).
6767

68-
1. Add the following content to it:
68+
2. Add the following content to it:
6969

7070
:::code language="typescript" source="~/playwright-testing-service/samples/get-started/playwright.service.config.ts":::
7171

72-
1. Save and commit the file to your source code repository.
72+
By default, the service configuration enables you to:
73+
- Accelerate build pipelines by running tests in parallel using cloud-hosted browsers.
74+
- Simplify troubleshooting with easy access to test results and artifacts published to the service.
75+
76+
However, you can choose to use either of these features or both. See [How to use service features](./how-to-use-service-features.md#manage-features-while-running-tests) and update the service configuration file as per your requirement.
77+
78+
3. Save and commit the file to your source code repository.
7379

7480
## Update package.json file
7581

7682
Update the `package.json` file in your repository to add details about Microsoft Playwright Testing service package in `devDependencies` section.
7783

78-
```json
84+
```typescript
7985
"devDependencies": {
8086
"@azure/microsoft-playwright-testing": "^1.0.0-beta.3"
8187
}
8288
```
89+
90+
## Enable artifacts in Playwright configuration
91+
92+
In the `playwright.config.ts` file of your project, make sure you are collecting all the required artifacts.
93+
```typescript
94+
use: {
95+
trace: 'on-first-retry',
96+
video:'retain-on-failure',
97+
screenshot:'on'
98+
},
99+
```
100+
83101
## Update the workflow definition
84102

85103
Update the CI workflow definition to run your Playwright tests with the Playwright CLI. Pass the [service configuration file](#add-service-configuration-file) as an input parameter for the Playwright CLI. You configure your environment by specifying environment variables.
@@ -95,7 +113,7 @@ Update the CI workflow definition to run your Playwright tests with the Playwrig
95113
```yml
96114

97115
# This step is to sign-in to Azure to run tests from GitHub Action workflow.
98-
# You can choose how set up Authentication to Azure from GitHub Actions, this is one example.
116+
# Choose how to set up authentication to Azure from GitHub Actions. This is one example.
99117
- name: Login to Azure with AzPowershell (enableAzPSSession true)
100118
uses: azure/login@v2
101119
with:
@@ -176,9 +194,19 @@ Update the CI workflow definition to run your Playwright tests with the Playwrig
176194
>
177195
> ```npx playwright test {name-of-file.spec.ts} --config=playwright.service.config.ts```
178196

197+
## View test runs and results in the Playwright portal
198+
199+
You can now troubleshoot the CI pipeline in the Playwright portal,
200+
201+
[!INCLUDE [View test runs and results in the Playwright portal](./includes/include-playwright-portal-view-test-results.md)]
202+
179203

180204
> [!TIP]
181-
> 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.
205+
> 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, see [How to use service features](./how-to-use-service-features.md).
206+
207+
> [!NOTE]
208+
> The test results and artifacts that you publish are retained on the service for 90 days. After that, they are automatically deleted.
209+
182210

183211
## Related content
184212

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
---
2+
title: 'Quickstart: Generate rich reports for Playwright tests'
3+
description: 'This quickstart shows how to troubleshoot your test runs using Microsoft Playwright Testing Preview.'
4+
ms.topic: quickstart
5+
ms.date: 09/23/2024
6+
ms.custom: playwright-testing-preview
7+
---
8+
9+
# Quickstart: Troubleshoot tests with Microsoft Playwright Testing Preview
10+
11+
In this quickstart, you learn how to troubleshoot your Playwright tests easily using reports and artifacts published on Microsoft Playwright Testing Preview. Additionally, this guide demonstrates how to utilize the reporting feature, regardless of whether you're running tests on the cloud-hosted browsers provided by the service.
12+
13+
After you complete this quickstart, you'll have a Microsoft Playwright Testing workspace to view test results and artifacts in the service portal.
14+
15+
> [!IMPORTANT]
16+
> 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+
18+
## Background
19+
20+
Microsoft Playwright Testing service enables you to:
21+
22+
- Accelerate build pipelines by running tests in parallel using cloud-hosted browsers.
23+
- Simplify troubleshooting by publishing test results and artifacts to the service, making them accessible through the service portal.
24+
25+
These two features of the service can be used independently of each other and each has its own [pricing plan](https://aka.ms/mpt/pricing). This means you can:
26+
27+
- Expedite test runs and streamline troubleshooting by running tests in cloud-hosted browsers and publishing results to the service.
28+
- Run tests only in cloud-hosted browsers to finish test runs faster.
29+
- Publish test results to the service while continuing to run tests locally for efficient troubleshooting.
30+
31+
## Prerequisites
32+
33+
* An Azure account with an active subscription. If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
34+
* Your Azure account needs the [Owner](/azure/role-based-access-control/built-in-roles#owner), [Contributor](/azure/role-based-access-control/built-in-roles#contributor), or one of the [classic administrator roles](/azure/role-based-access-control/rbac-and-directory-admin-roles#classic-subscription-administrator-roles).
35+
* A Playwright project. If you don't have project, create one by using the [Playwright getting started documentation](https://playwright.dev/docs/intro) or use our [Microsoft Playwright Testing sample project](https://github.com/microsoft/playwright-testing-service/tree/main/samples/get-started).
36+
* Azure CLI. If you don't have Azure CLI, see [Install Azure CLI](/cli/azure/install-azure-cli).
37+
38+
## Create a workspace
39+
40+
To get started with publishing test results on Playwright Testing service, first create a Microsoft Playwright Testing workspace in the Playwright portal.
41+
42+
[!INCLUDE [Create workspace in Playwright portal](./includes/include-playwright-portal-create-workspace.md)]
43+
44+
When the workspace creation finishes, you're redirected to the setup guide.
45+
46+
## Install Microsoft Playwright Testing package
47+
48+
To use the service, install the Microsoft Playwright Testing package.
49+
50+
```npm
51+
npm init @azure/microsoft-playwright-testing
52+
```
53+
54+
This command generates `playwright.service.config.ts` file which serves to:
55+
56+
- Direct and authenticate your Playwright client to the Microsoft Playwright Testing service.
57+
- Adds a reporter to publish test results and artifacts.
58+
59+
If you already have this file, the prompt asks you to override it.
60+
61+
To use only reporting feature for the test run, disable cloud-hosted browsers by setting `useCloudHostedBrowsers` as false.
62+
63+
```typescript
64+
export default defineConfig(
65+
config,
66+
getServiceConfig(config, {
67+
timeout: 30000,
68+
os: ServiceOS.LINUX,
69+
useCloudHostedBrowsers: false // Do not use cloud hosted browsers
70+
}),
71+
{
72+
reporter: [['list'], ['@azure/microsoft-playwright-testing/reporter']], // Reporter for Microsoft Playwright Testing service
73+
}
74+
);
75+
```
76+
Setting the value as `false` ensures that cloud-hosted browsers aren't used to run the tests. The tests run on your local machine but the results and artifacts are published on the service.
77+
78+
> [!TIP]
79+
> If you wish to accelerate your test run using cloud-hosted browser, you can set `useCloudHostedBrowsers` as true. This will run your tests on the service managed browsers.
80+
81+
## Configure the service region endpoint
82+
83+
In your setup, you have to provide the region-specific service endpoint. The endpoint depends on the Azure region you selected when creating the workspace.
84+
85+
To get the service endpoint URL:
86+
87+
1. In **Add region endpoint in your setup**, copy the region endpoint for your workspace.
88+
89+
The endpoint URL matches the Azure region that you selected when creating the workspace.
90+
91+
:::image type="content" source="./media/quickstart-run-end-to-end-tests/playwright-testing-region-endpoint.png" alt-text="Screenshot that shows how to copy the workspace region endpoint in the Playwright Testing portal." lightbox="./media/quickstart-run-end-to-end-tests/playwright-testing-region-endpoint.png":::
92+
93+
## Set up your environment
94+
95+
To set up your environment, you have to configure the `PLAYWRIGHT_SERVICE_URL` environment variable with the value you obtained in the previous steps.
96+
97+
We recommend that you use the `dotenv` module to manage your environment. With `dotenv`, you define your environment variables in the `.env` file.
98+
99+
1. Add the `dotenv` module to your project:
100+
101+
```shell
102+
npm i --save-dev dotenv
103+
```
104+
105+
1. Create a `.env` file alongside the `playwright.config.ts` file in your Playwright project:
106+
107+
```
108+
PLAYWRIGHT_SERVICE_URL={MY-REGION-ENDPOINT}
109+
```
110+
111+
Make sure to replace the `{MY-REGION-ENDPOINT}` text placeholder with the value you copied earlier.
112+
113+
114+
## Set up authentication
115+
116+
To publish test results and artifacts to your Microsoft Playwright Testing workspace, you need to authenticate the Playwright client where you're running the tests with the service. The client could be your local dev machine or CI machine.
117+
118+
The service offers two authentication methods: Microsoft Entra ID and Access Tokens.
119+
120+
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.
121+
122+
##### Set up authentication using Microsoft Entra ID
123+
124+
Microsoft Entra ID is the default and recommended authentication for the service. From your local dev machine, you can use [Azure CLI](/cli/azure/install-azure-cli) to sign-in
125+
126+
```CLI
127+
az login
128+
```
129+
> [!NOTE]
130+
> If you're a part of multiple Microsoft Entra tenants, make sure you sign in to the tenant where your workspace belongs. You can get the tenant ID from Azure portal. See [Find your Microsoft Entra Tenant](/azure/azure-portal/get-subscription-tenant-id#find-your-microsoft-entra-tenant). Once you get the ID, sign-in using the command `az login --tenant <TenantID>`
131+
132+
##### Set up authentication using access tokens
133+
134+
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.
135+
136+
1. Authentication using access tokens is disabled by default. To use, [Enable access-token based authentication](./how-to-manage-authentication.md#enable-authentication-using-access-tokens)
137+
138+
2. [Set up authentication using access tokens](./how-to-manage-authentication.md#set-up-authentication-using-access-tokens)
139+
140+
> [!CAUTION]
141+
> We strongly recommend using Microsoft Entra ID for authentication to the service. If you are using access tokens, see [How to Manage Access Tokens](./how-to-manage-access-tokens.md)
142+
143+
## Enable artifacts in Playwright configuration
144+
In the `playwright.config.ts` file of your project, make sure you're collecting all the required artifacts.
145+
```typescript
146+
use: {
147+
trace: 'on-first-retry',
148+
video:'retain-on-failure',
149+
screenshot:'on'
150+
},
151+
```
152+
153+
## Run your tests and publish results on Microsoft Playwright Testing
154+
155+
You've now prepared the configuration for publishing test results and artifacts with Microsoft Playwright Testing. Run tests using the newly created `playwright.service.config.ts` file and publish test results and artifacts to the service.
156+
157+
```bash
158+
npx playwright test --config=playwright.service.config.ts
159+
```
160+
> [!NOTE]
161+
> For the Reporting feature of Microsoft Playwright Testing, you get charged based on the number test results published. If you're a first-time user or [getting started with a free trial](./how-to-try-playwright-testing-free.md), you might start with publishing single test result instead of your full test suite to avoid exhausting your free trial limits.
162+
163+
After the test completes, you can view the test status in the terminal.
164+
165+
```output
166+
Running 6 test using 2 worker
167+
5 passed, 1 failed (20.2s)
168+
169+
Test report: https://playwright.microsoft.com/workspaces/<workspace-id>/runs/<run-id>
170+
```
171+
172+
> [!CAUTION]
173+
> Depending on the size of your test suite, you might incur additional charges for the test results beyond your allotted free test results.
174+
175+
## View test runs and results in the Playwright portal
176+
177+
You can now troubleshoot the failed test cases in the Playwright portal.
178+
179+
[!INCLUDE [View test runs and results in the Playwright portal](./includes/include-playwright-portal-view-test-results.md)]
180+
181+
182+
> [!TIP]
183+
> You can also use Microsoft Playwright Testing service to run tests in parallel using cloud-hosted browsers. Both Reporting and cloud-hosted browsers are independent features and are billed separately. You can use either of these or both. For details, see [How to use service features](./how-to-use-service-features.md)
184+
185+
> [!NOTE]
186+
> The test results and artifacts that you publish are retained on the service for 90 days. After that, they are automatically deleted.
187+
188+
189+
## Next step
190+
191+
You've successfully created a Microsoft Playwright Testing workspace in the Playwright portal and run your Playwright tests on cloud browsers.
192+
193+
Advance to the next quickstart to set up continuous end-to-end testing by running your Playwright tests in your CI/CD workflow.
194+
195+
> [!div class="nextstepaction"]
196+
> [Set up continuous end-to-end testing in CI/CD](./quickstart-automate-end-to-end-testing.md)

0 commit comments

Comments
 (0)