Skip to content

Commit

Permalink
Onboard Azure.Developer.MicrosoftPlaywrightTesting sdk (Azure#45044)
Browse files Browse the repository at this point in the history
* feat(): onboard Azure.Developer.MicrosoftPlaywrightTesting sdk

* chore(): add support for github summary

* docs(): sample, CHANGELOG and README

* docs(): content of samples

* chore():: modify samples as per azure sdk guidelines

* refactor(): unit tests as per azure sdk guidelines

* chore(): use autorest to generate api clients

* fix(): json parsing of error messages

* chore(): add live tests

* fix(): run id handling across scalable and reporting

* Adressing comments

* comment

* chore(): resolve documentation comments

* docs(): import c# code snippets from .cs files

* refactor(): update CODEOWNERS with latest labels

* chore(): add git commit based display name

* feat(): scalable run error handling

* refactor(): convert API client class to internal

* chore(): apiview review comments addressed for base sdk

* refactor(): rename tokenCredential to credential

* refactor(): rename PlaywrightServiceSettings to PlaywrightServiceOptions

* refactor(): use serviceAuth only

* refactor(): remove defaultAuth references

* refactor(): convert serviceOs class to internal

* refactor(): convert public fields into properties

* chore(): add cancellation token in async methods

* refactor(): use default for null cancellation tokens

* refactor(): added users in CODEOWNERS

* fix(): live test resource json

* docs(): add missing sections in README files

* refactor(): rename base package to Azure.Developer.MicrosoftPlaywrightTesting.TestLogger

* docs(): move authenticate client section after prerequisites

---------

Co-authored-by: Siddharth Singha Roy <[email protected]>
Co-authored-by: Vansh Vardhan Singh <[email protected]>
  • Loading branch information
3 people authored Oct 8, 2024
1 parent e6fd97a commit 0598a8e
Show file tree
Hide file tree
Showing 50 changed files with 4,921 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,10 @@
# ServiceOwners: @rhurey @dargilco

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

# ServiceLabel: %Microsoft Playwright Testing
# ServiceOwners: @shreyaanand @mjmadhu
# ServiceOwners: @Sid200026 @puagarwa @ShreyaAnand

# ServiceLabel: %Policy
# ServiceOwners: @aperezcloud @kenieva
Expand Down
5 changes: 5 additions & 0 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
<PackageReference Update="OpenAI" Version="2.1.0-beta.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>

<!--
Dependency versions for Track 2, Microsoft.* libraries.
These are dependencies for Track 2 integration packages
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,119 @@
# Microsoft Azure Playwright Testing NUnit 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).

### 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.

#### 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.

### 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"
```

## Key concepts

Key concepts of the Microsoft Playwright Testing NUnit SDK for .NET can be found [here](https://aka.ms/mpt/what-is-mpt)

## Examples

Code samples for using this SDK can be found in the following locations
- [.NET Microsoft Playwright Testing NUnit Library Code Samples](https://aka.ms/mpt/sample)

## Troubleshooting

- File an issue via [GitHub Issues](https://github.com/Azure/azure-sdk-for-net/issues).
- Check [previous questions](https://stackoverflow.com/questions/tagged/azure+.net) or ask new ones on Stack Overflow using Azure and .NET tags.

## 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
[[email protected]][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.TestLogger.PlaywrightService
{
public PlaywrightServiceNUnit(Azure.Core.TokenCredential? credential = null) : base (default(Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.PlaywrightServiceOptions), default(Azure.Core.TokenCredential)) { }
public static Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.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

0 comments on commit 0598a8e

Please sign in to comment.