Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onboard Azure.Developer.MicrosoftPlaywrightTesting sdk #45044

Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a8a27c9
feat(): onboard Azure.Developer.MicrosoftPlaywrightTesting sdk
Sid200026 Jul 16, 2024
cb8de63
chore(): add support for github summary
Sid200026 Jul 16, 2024
8b57e8e
docs(): sample, CHANGELOG and README
Sid200026 Jul 16, 2024
ad7d11a
docs(): content of samples
Sid200026 Jul 16, 2024
1404423
chore():: modify samples as per azure sdk guidelines
Sid200026 Jul 31, 2024
dde5490
refactor(): unit tests as per azure sdk guidelines
Sid200026 Jul 31, 2024
5937f70
Merge pull request #1 from Sid200026/resolve-comments
Sid200026 Jul 31, 2024
21eca6d
chore(): use autorest to generate api clients
Aug 12, 2024
868c50c
fix(): json parsing of error messages
Aug 12, 2024
8cc4441
chore(): add live tests
Aug 14, 2024
817e120
fix(): run id handling across scalable and reporting
Aug 23, 2024
dc9a98f
Adressing comments
vvs11 Aug 26, 2024
733a700
comment
vvs11 Aug 26, 2024
628a990
Merge pull request #2 from Sid200026/vvs11/SDK-comments
Sid200026 Aug 28, 2024
cc953aa
chore(): resolve documentation comments
Sid200026 Aug 28, 2024
4123d01
docs(): import c# code snippets from .cs files
Sid200026 Aug 28, 2024
d7fe041
refactor(): update CODEOWNERS with latest labels
Sid200026 Sep 1, 2024
f2ce9a6
chore(): add git commit based display name
Sep 1, 2024
d908310
feat(): scalable run error handling
Sep 1, 2024
079daa0
refactor(): convert API client class to internal
Sep 5, 2024
3888ff4
chore(): apiview review comments addressed for base sdk
Sep 16, 2024
1ebca35
refactor(): rename tokenCredential to credential
Sep 16, 2024
1aad692
refactor(): rename PlaywrightServiceSettings to PlaywrightServiceOptions
Sep 16, 2024
74ddbee
refactor(): use serviceAuth only
Sep 16, 2024
71ee32f
refactor(): remove defaultAuth references
Sep 16, 2024
a5adb8e
refactor(): convert serviceOs class to internal
Sep 16, 2024
f28d86d
refactor(): convert public fields into properties
Sep 17, 2024
466f9ee
chore(): add cancellation token in async methods
Sep 17, 2024
2ec69f3
refactor(): use default for null cancellation tokens
Sep 17, 2024
b26ef96
Merge branch 'main' of https://github.com/Sid200026/azure-sdk-for-net…
Sep 20, 2024
2649d4c
refactor(): added users in CODEOWNERS
Sep 20, 2024
ac004ff
fix(): live test resource json
Sep 20, 2024
7683887
docs(): add missing sections in README files
Sep 23, 2024
2d0b53c
refactor(): rename base package to Azure.Developer.MicrosoftPlaywrigh…
Sep 23, 2024
a831d18
docs(): move authenticate client section after prerequisites
Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,10 @@
# ServiceLabel: %Image Analysis
# ServiceOwners: @rhurey @dargilco

# PRLabel: %Playwright
/sdk/playwrighttesting/ @shreyaanand @mjmadhu
# PRLabel: %Microsoft Playwright Testing
/sdk/playwrighttesting/ @Sid200026 @puagarwa @ShreyaAnand

# ServiceLabel: %Playwright
# ServiceLabel: %Microsoft Playwright Testing
# ServiceOwners: @shreyaanand @mjmadhu

# ServiceLabel: %Policy
Expand Down
7 changes: 7 additions & 0 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,13 @@
<PackageReference Update="Microsoft.Extensions.Logging.Configuration" Version="2.1.1" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.StartsWith('Azure.Developer.MicrosoftPlaywrightTesting'))">
<PackageReference Update="Microsoft.TestPlatform.ObjectModel" Version="17.10.0" />
<PackageReference Update="NUnit" Version="3.13.2" />
</ItemGroup>



<PropertyGroup>
<TestProxyVersion>1.0.0-dev.20240619.2</TestProxyVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Developer.MicrosoftPlaywrightTesting.NUnit", "src\Azure.Developer.MicrosoftPlaywrightTesting.NUnit.csproj", "{CF3C8F52-D3FD-4338-9432-58FF4BF4475E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Developer.MicrosoftPlaywrightTesting.NUnit.Tests", "tests\Azure.Developer.MicrosoftPlaywrightTesting.NUnit.Tests.csproj", "{081210F2-A9F8-4137-97F4-5D5EF238B553}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CF3C8F52-D3FD-4338-9432-58FF4BF4475E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF3C8F52-D3FD-4338-9432-58FF4BF4475E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF3C8F52-D3FD-4338-9432-58FF4BF4475E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF3C8F52-D3FD-4338-9432-58FF4BF4475E}.Release|Any CPU.Build.0 = Release|Any CPU
{081210F2-A9F8-4137-97F4-5D5EF238B553}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{081210F2-A9F8-4137-97F4-5D5EF238B553}.Debug|Any CPU.Build.0 = Debug|Any CPU
{081210F2-A9F8-4137-97F4-5D5EF238B553}.Release|Any CPU.ActiveCfg = Release|Any CPU
{081210F2-A9F8-4137-97F4-5D5EF238B553}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Release History

## 1.0.0-beta.1 (2024-09-11)

### Features Added

- Added authentication using Microsoft Entra ID for the service.
- Added reporting capabilities for the service. You can now publish the reports and artifacts generated by Playwright OSS to the service.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Add any shared properties you want for the projects under this package directory that need to be set before the auto imported Directory.Build.props
-->
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Microsoft Playwright Testing client library for .NET

Microsoft Playwright Testing is a fully managed service that uses the cloud to enable you to run Playwright tests with much higher parallelization across different operating system-browser combinations simultaneously. This means faster test runs with broader scenario coverage, which helps speed up delivery of features without sacrificing quality. The service also enables you to publish test results and related artifacts to the service and view them in the service portal enabling faster and easier troubleshooting. With Microsoft Playwright Testing service, you can release features faster and more confidently.

Ready to get started? Jump into our [quickstart guide]<!--(https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/README.md#getting-started)-->!

## Useful links
- [Quickstart: Run end-to-end tests at scale](https://aka.ms/mpt/quickstart)
- [View Microsoft Playwright Testing service demo](https://youtu.be/GenC1jAeTZE)
- [Documentation](https://aka.ms/mpt/docs)
- [Pricing](https://aka.ms/mpt/pricing)
- [Share feedback](https://aka.ms/mpt/feedback)

## Getting started

### Install the package

Install the client library for .NET with [NuGet](https://www.nuget.org/):

```dotnetcli
dotnet add package Azure.Developer.MicrosoftPlaywrightTesting.NUnit --prerelease
```

### Prerequisites

- An [Azure subscription](https://azure.microsoft.com/free/dotnet/)
- Your Azure account must be assigned the [Owner](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#owner), [Contributor](https://learn.microsoft.com/azure/role-based-access-control/built-in-roles#contributor), or one of the [classic administrator roles](https://learn.microsoft.com/azure/role-based-access-control/rbac-and-directory-admin-roles#classic-subscription-administrator-roles).

#### Create a Workspace

1. Sign in to the [Playwright portal](https://aka.ms/mpt/portal) with your Azure account.

2. Create the Workspace

![Create new workspace](https://github.com/microsoft/playwright-testing-service/assets/12104064/d571e86b-9d43-48ac-a2b7-63afb9bb86a8)

|Field |Description |
|---------|---------|
|**Workspace Name** | A unique name to identify your workspace.<BR>The name can't contain special characters or whitespace. |
|**Azure Subscription** | Select an Azure subscription where you want to create the workspace. |
|**Region** | This is where test run data will be stored for your workspace. |

> [!NOTE]
> If you don't see this screen, select an existing workspace and go to the next section.
```

### Set up Microsoft Playwright Testing

Create a file `PlaywrightServiceSetup.cs` in the root directory with the below content

```C# Snippet:Sample2_SetDefaultAuthenticationMechanism
using Azure.Developer.MicrosoftPlaywrightTesting.NUnit;

namespace PlaywrightATests; // Remember to change this as per your project namespace

[SetUpFixture]
public class PlaywrightServiceSetup : PlaywrightServiceNUnit {};
```

> [!NOTE]
> Make sure your project uses `Microsoft.Playwright.NUnit` version 1.37 or above.

### Obtain region endpoint

1. In the [Playwright portal](https://aka.ms/mpt/portal), copy the command under **Add region endpoint in your set up**.

![Set workspace endpoint](https://github.com/microsoft/playwright-testing-service/assets/12104064/d81ca629-2b23-4d34-8b70-67b6f7061a83)

The endpoint URL corresponds to the workspace region. You might see a different endpoint URL in the Playwright portal, depending on the region you selected when creating the workspace.

### Set up environment

Ensure that the `PLAYWRIGHT_SERVICE_URL` that you obtained in previous step is available in your environment.

### Authenticate the client

To learn more about options for Microsoft Entra Id authentication, refer to [Azure.Identity credentials](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/identity/Azure.Identity#credentials). You can also refer to [our samples]<!--(https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/samples/Sample1_CustomisingServiceParameters.md)--> on how to configurate different Azure Identity credentials.

### Run the tests

Run Playwright tests against browsers managed by the service using the configuration you created above.

```dotnetcli
dotnet test --logger "ms-playwright-service"
```

## Next steps

- Run tests in a [CI/CD pipeline.](https://aka.ms/mpt/configure-pipeline)

- Learn how to [manage access](https://aka.ms/mpt/manage-access) to the created workspace.

- Experiment with different number of workers to [determine the optimal configuration of your test suite](https://aka.ms/mpt/parallelism).

## Contributing
This project welcomes contributions and suggestions. Most contributions require
you to agree to a Contributor License Agreement (CLA) declaring that you have
the right to, and actually do, grant us the rights to use your contribution. For
details, visit [cla.microsoft.com][cla].

This project has adopted the [Microsoft Open Source Code of Conduct][coc].
For more information see the [Code of Conduct FAQ][coc_faq] or contact
[opencode@microsoft.com][coc_contact] with any additional questions or comments.

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/README.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Azure.Developer.MicrosoftPlaywrightTesting.NUnit
{
[NUnit.Framework.SetUpFixtureAttribute]
public partial class PlaywrightServiceNUnit : Azure.Developer.MicrosoftPlaywrightTesting.PlaywrightService
{
public PlaywrightServiceNUnit(Azure.Core.TokenCredential? credential = null) : base (default(Azure.Developer.MicrosoftPlaywrightTesting.PlaywrightServiceOptions), default(Azure.Core.TokenCredential)) { }
public static Azure.Developer.MicrosoftPlaywrightTesting.PlaywrightServiceOptions playwrightServiceOptions { get { throw null; } }
[NUnit.Framework.OneTimeSetUpAttribute]
public System.Threading.Tasks.Task SetupAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
[NUnit.Framework.OneTimeTearDownAttribute]
public void Teardown() { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
page_type: sample
languages:
- csharp
products:
- azure
- playwright-testing
name: Azure.Developer.MicrosoftPlaywrightTesting.NUnit samples for .NET
description: Samples for the Azure.Developer.MicrosoftPlaywrightTesting.NUnit client library
---

# Azure.Developer.MicrosoftPlaywrightTesting.NUnit samples for .NET

- [Customising service parameters]<!--(https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/samples/Sample1_CustomisingServiceParameters.md)-->
- [Set default authentication mechanism]<!--(https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/samples/Sample2_SetDefaultAuthenticationMechanism.md)-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
## Learn about different available service parameters and how to use them

Follow the steps listed in this [README]<!--(https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/README.md)--> to integrate your existing Playwright test suite with the Microsoft Playwright Testing service.

This guide explains the different options available to you in the Azure.Developer.MicrosoftPlaywrightTesting.NUnit package and how to use them.

### Using .runsettings file

1. Create a `.runsettings` file in the root directory:

```xml
<?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-id" />
<Parameter name="ExposeNetwork" value="<loopback>" />
<Parameter name="ServiceAuth" value="EntraId" />
<Parameter name="UseCloudHostedBrowsers" value="true" />
<Parameter name="AzureTokenCredentialType" value="DefaultAzureCredential" />
<Parameter name="ManagedIdentityClientId" value="77bfc267-86cb-4eeb-9e4a-747a217a318c" />
<Parameter name="EnableGitHubSummary" value="false" />
</TestRunParameters>
<!-- Enable Reporting feature -->
<LoggerRunSettings>
<Loggers>
<Logger friendlyName="ms-playwright-service" enabled="true" />
</Loggers>
</LoggerRunSettings>
</RunSettings>
```

> [!NOTE]
> You can also modify the runid by setting the environment variable `PLAYWRIGHT_SERVICE_RUN_ID`.

2. Run tests using the above `.runsettings` file:

```dotnetcli
dotnet test --settings .runsettings
```

#### Known issue: Minimal support for Azure Identity library credentials

This issue only impacts the reporting feature. Currently, the service provides minimal support for the following [Azure Credential types.](https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes)

Along with this, we also support passing a Managed Identity ClientId to be used along with `DefaultAzureCredential` and `ManagedIdentityCredential`.

If you only want to use cloud-hosted browsers along with your tests, you can disable the reporting feature by removing the logger from the runsettings file and then modify the `PlaywrightServiceSetup.cs` file as per the following.

```C# Snippet:Sample1_CustomisingServiceParameters
using Azure.Core;
using Azure.Developer.MicrosoftPlaywrightTesting.NUnit;
using Azure.Identity;

namespace PlaywrightTests;

[SetUpFixture]
public class PlaywrightServiceSetup : PlaywrightServiceNUnit
{
public static readonly TokenCredential managedIdentityCredential = new ManagedIdentityCredential();

public PlaywrightServiceSetup() : base(managedIdentityCredential) {}
}
```

## Options

1. **`Os`**:
- **Description**: This setting allows you to choose the operating system where the browsers running Playwright tests will be hosted.
- **Available Options**:
- `System.Runtime.InteropServices.OSPlatform.Windows` for Windows OS.
- `System.Runtime.InteropServices.OSPlatform.LINUX` for Linux OS.
- **Default Value**: `System.Runtime.InteropServices.OSPlatform.LINUX`

2. **`RunId`**:
- **Description**: This setting allows you to set a unique ID for every test run to distinguish them in the service portal.

3. **`ExposeNetwork`**:
- **Description**: This settings exposes network available on the connecting client to the browser being connected to.

4. **`ServiceAuth`**
- **Description**: This setting allows you to specify the default authentication mechanism to be used for sending requests to the service.
- **Available Options**:
- `ServiceAuthType.EntraId` for Microsoft Entra ID authentication.
- `ServiceAuthType.AccessToken` for MPT Access Token authentication.
- **Default Value**: `ServiceAuthType.EntraId`

5. **`UseCloudHostedBrowsers`**
- **Description**: This setting allows you to select whether to use cloud-hosted browsers to run your Playwright tests. Reporting features remain available even if you disable this setting.
- **Default Value**: `true`

6. **`AzureTokenCredentialType`**:
- **Description**: This setting allows you to select the authentication method you want to use with Entra.
- **Available Options**:
- `AzureTokenCredentialType.EnvironmentCredential`
- `AzureTokenCredentialType.WorkloadIdentityCredential`
- `AzureTokenCredentialType.ManagedIdentityCredential`
- `AzureTokenCredentialType.SharedTokenCacheCredential`
- `AzureTokenCredentialType.VisualStudioCredential`
- `AzureTokenCredentialType.VisualStudioCodeCredential`
- `AzureTokenCredentialType.AzureCliCredential`
- `AzureTokenCredentialType.AzurePowerShellCredential`
- `AzureTokenCredentialType.AzureDeveloperCliCredential`
- `AzureTokenCredentialType.InteractiveBrowserCredential`
- `AzureTokenCredentialType.DefaultAzureCredential`
- **Default Value**: `AzureTokenCredentialType.DefaultAzureCredential`

7. **`ManagedIdentityClientId`**
- **Description**: This setting allows you to specify the managed identity client id to be used for Microsoft Entra Id authentication.

8. **`EnableGitHubSummary`**:
- **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.
- **Default Value**: `true`

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# How to authenticate to Microsoft Playwright Testing service using service access token.

Follow the steps listed in this [README]<!--(https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/README.md)--> to integrate your existing Playwright test suite with the Microsoft Playwright Testing service.

This guide will walk you through the steps to integrate your Playwright project where you are launching browsers from within the tests with the service.

### Setup Microsoft Playwright Testing

1. Create a file `PlaywrightServiceSetup.cs` in the root directory with the following

```C# Snippet:Sample2_SetDefaultAuthenticationMechanism
using Azure.Developer.MicrosoftPlaywrightTesting.NUnit;

namespace PlaywrightATests; // Remember to change this as per your project namespace

[SetUpFixture]
public class PlaywrightServiceSetup : PlaywrightServiceNUnit {};
```

2. Create a .runsettings file to modify default authentication mechanism.

```xml
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<TestRunParameters>
<!-- Set the service auth type as AccessToken -->
<Parameter name="ServiceAuth" value="AccessToken" />
</TestRunParameters>
</RunSettings>
```

> [!NOTE]
> Make sure your project uses Microsoft.Playwright.NUnit version 1.37 or above.

### Obtain region endpoint

1. In the [Playwright portal](https://aka.ms/mpt/portal), copy the command under **Add region endpoint in your set up**.

![Set workspace endpoint](https://github.com/microsoft/playwright-testing-service/assets/12104064/d81ca629-2b23-4d34-8b70-67b6f7061a83)

The endpoint URL corresponds to the workspace region. You might see a different endpoint URL in the Playwright portal, depending on the region you selected when creating the workspace.

### Set up environment

Ensure that the `PLAYWRIGHT_SERVICE_URL` that you obtained in previous step is available in your environment.

### Authenticate the client

To learn more about options for Microsoft Entra Id authentication, refer to [Azure.Identity credentials](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/identity/Azure.Identity#credentials). You can also refer to [our samples]<!--(https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/playwrighttesting/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/samples/Sample1_CustomisingServiceParameters.md)--> on how to configurate different Azure Identity credentials.

### Run the tests

Run Playwright tests against browsers managed by the service using the configuration you created above.

```dotnetcli
dotnet test --settings .runsettings
```
Loading