Dela via


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]!

Getting started

Install the package

Install the client library for .NET with NuGet:

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

Prerequisites

Authenticate the client

To learn more about options for Microsoft Entra Id authentication, refer to Azure.Identity credentials. You can also refer to [our samples] on how to configurate different Azure Identity credentials.

Create a Workspace

  1. Sign in to the Playwright portal with your Azure account.

  2. Create the Workspace

    Create new workspace

    Field Description
    Workspace Name A unique name to identify your workspace.
    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

using Azure.Developer.MicrosoftPlaywrightTesting.NUnit;

namespace PlaywrightTests.Sample2; // 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, copy the command under Add region endpoint in your set up.

    Set workspace endpoint

    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.

dotnet test --logger "microsoft-playwright-testing"

Key concepts

Key concepts of the Microsoft Playwright Testing NUnit SDK for .NET can be found here

Examples

Code samples for using this SDK can be found in the following locations

Troubleshooting

Next steps

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