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 7 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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@
# ServiceOwners: @rhurey @dargilco

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

# ServiceLabel: %Playwright
# ServiceOwners: @shreyaanand @mjmadhu
Expand Down
9 changes: 9 additions & 0 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,15 @@
<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.0.0, 17.10.0)" />
<PackageReference Update="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Update="Newtonsoft.Json" Version="[13.0.1, 13.0.3)" />
<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,22 @@

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
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
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 1.0.0-beta.1 (2024-07-31)

## Added

- **Initial release of the package**: This is the first version of the Microsoft Playwright Testing service package for NUnit. It enables you to integrate your NUnit Playwright test suite with the Microsoft Playwright Testing service.
- The service package enables you to:
- Expedite your Playwright test suite by running more tests in parallel on cloud-hosted browsers.
- Improve test coverage by enabling you to test on multiple OS-browser combinations.
- Troubleshoot easily and faster by publishing test results and artifacts generated by Playwright to the service and viewing them in the service portal.

## Useful Links
- [Quickstart: Run end-to-end tests at scale](https://aka.ms/mpt/quickstart)
- [Quickstart: Set up continuous end-to-end testing across different browsers and operating systems](https://aka.ms/mpt/ci)
- [Explore features and benefits](https://aka.ms/mpt/about)
- [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)
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,125 @@
# Microsoft Playwright Testing preview

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](#get-started)!


## Useful Links
- [Quickstart: Run end-to-end tests at scale](https://aka.ms/mpt/quickstart)
- [Quickstart: Set up continuous end-to-end testing across different browsers and operating systems](https://aka.ms/mpt/ci)
- [Explore features and benefits](https://aka.ms/mpt/about)
- [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)

## Get Started
Follow these steps to run your existing Playwright test suite with the service.

### Prerequisites

- An Azure account with an active subscription. If you don't have an Azure subscription, [create a free account](https://aka.ms/mpt/create-azure-subscription) before you begin.
- Your Azure account must be assigned the [Owner](https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#owner), [Contributor](https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#contributor), or one of the [classic administrator roles](https://learn.microsoft.com/en-us/azure/role-based-access-control/rbac-and-directory-admin-roles#classic-subscription-administrator-roles).
- [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) must be installed in the machine from where you are running Playwright tests.

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

### Install Microsoft Playwright Testing package

1. Run this command to install the service package

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

### Setup Microsoft Playwright Testing

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

```c#
using Azure.Developer.MicrosoftPlaywrightTesting.NUnit;

namespace PlaywrightTests; // 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.

### Sign in to Azure

You need to sign in to Azure using Azure CLI to enable authentication via Entra ID. Run the command to sign-in

```azurecli
az login
```

**NOTE**: If you are a part of multiple tenants, you will have to login to a particular tenant. Run `az login --tenant=<TENANT_ID>' to sign in to the tenant where the workspace is created. You can find the tenant id through these [steps.](https://learn.microsoft.com/en-us/entra/fundamentals/how-to-find-tenant)

### 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 https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

## Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos is subject to those third-party's policies.
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 static Azure.Developer.MicrosoftPlaywrightTesting.PlaywrightServiceSettings playwrightServiceSettings;
public PlaywrightServiceNUnit(Azure.Core.TokenCredential? tokenCredential = null) : base (default(Azure.Developer.MicrosoftPlaywrightTesting.PlaywrightServiceSettings), default(Azure.Core.TokenCredential)) { }
[NUnit.Framework.OneTimeSetUpAttribute]
public System.Threading.Tasks.Task SetupAsync() { throw null; }
[NUnit.Framework.OneTimeTearDownAttribute]
public void Teardown() { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
page_type: sample
languages:
- csharp
products:
- azure
- microsoft-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](./Sample1_CustomisingServiceParameters.md)
- [Set default authentication mechanism](./Sample2_SetDefaultAuthenticationMechanism.md)
- [Manually connecting to browsers](./Sample3_ManuallyConnectingToBrowsers.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
## Learn about different available service parameters and how to use them

Follow the steps listed in this [README](../../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="DefaultAuth" value="ENTRA" />
<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 Credentials

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

- EnvironmentCredential
- WorkloadIdentityCredential
- ManagedIdentityCredential
- SharedTokenCacheCredential
- VisualStudioCredential
- VisualStudioCodeCredential
- AzureCliCredential
- AzurePowerShellCredential
- AzureDeveloperCliCredential
- InteractiveBrowserCredential
- DefaultAzureCredential (Default)

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#
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)
{ }
};
```

## Settings

1. **`Os`**:
- **Description**: This setting allows you to choose the operating system where the browsers running Playwright tests will be hosted.
- **Available Options**:
- `ServiceOS.WINDOWS` for Windows OS.
- `ServiceOS.LINUX` for Linux OS.
- **Default Value**: `ServiceOS.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. **`DefaultAuth`**
- **Description**: This setting allows you to specify the default authentication mechanism to be used for sending requests to the service.
- **Available Options**:
- `ServiceAuth.ENTRA` for Entra ID authentication.
- `ServiceAuth.TOKEN` for MPT Access Token authentication.
- **Default Value**: `ServiceAuth.ENTRA`

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

Loading
Loading