|
| 1 | +# Azure Playwright MSTest client library for .NET |
| 2 | + |
| 3 | +Azure Playwright 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 Azure Playwright, you can release features faster and more confidently. |
| 4 | + |
| 5 | +Ready to get started? Jump into our [quickstart guide]<!--(https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/loadtestservice/Azure.Developer.Playwright.MSTest/README.md#getting-started)-->! |
| 6 | + |
| 7 | +## Useful links |
| 8 | + |
| 9 | +- [Quickstart: Run end-to-end tests at scale](https://aka.ms/mpt/quickstart) |
| 10 | +- [View Azure Playwright service demo](https://youtu.be/GenC1jAeTZE) |
| 11 | +- [Documentation](https://aka.ms/mpt/docs) |
| 12 | +- [Pricing](https://aka.ms/mpt/pricing) |
| 13 | +- [Share feedback](https://aka.ms/mpt/feedback) |
| 14 | + |
| 15 | +## Getting started |
| 16 | + |
| 17 | +### Install the package |
| 18 | + |
| 19 | +Install the client library for .NET with [NuGet](https://www.nuget.org/): |
| 20 | + |
| 21 | +```dotnetcli |
| 22 | +dotnet add package Azure.Developer.Playwright.MSTest --prerelease |
| 23 | +``` |
| 24 | + |
| 25 | +### Prerequisites |
| 26 | + |
| 27 | +- An [Azure subscription](https://azure.microsoft.com/free/dotnet/) |
| 28 | +- 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). |
| 29 | + |
| 30 | +### Authenticate the client |
| 31 | + |
| 32 | +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). |
| 33 | + |
| 34 | +#### Create a Workspace |
| 35 | + |
| 36 | +1. Sign in to the [Playwright portal](https://aka.ms/mpt/portal) with your Azure account. |
| 37 | + |
| 38 | +2. Create the Workspace |
| 39 | + |
| 40 | +  |
| 41 | + |
| 42 | + | Field | Description | |
| 43 | + | ---------------------- | ----------------------------------------------------------------------------------------------------- | |
| 44 | + | **Workspace Name** | A unique name to identify your workspace.<BR>The name can't contain special characters or whitespace. | |
| 45 | + | **Azure Subscription** | Select an Azure subscription where you want to create the workspace. | |
| 46 | + | **Region** | This is where test run data will be stored for your workspace. | |
| 47 | + |
| 48 | +> [!NOTE] |
| 49 | +> If you don't see this screen, select an existing workspace and go to the next section. |
| 50 | +
|
| 51 | + ``` |
| 52 | + |
| 53 | +### Set up Azure Playwright |
| 54 | + |
| 55 | +Create a file `PlaywrightServiceSetup.cs` in the root directory with the below content |
| 56 | + |
| 57 | +```C# Snippet:MSTest_Sample1_SimpleSetup |
| 58 | +using System.Threading.Tasks; |
| 59 | +using Azure.Developer.Playwright.MSTest; |
| 60 | +using Azure.Identity; |
| 61 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 62 | + |
| 63 | +namespace PlaywrightService.SampleTests; // Remember to change this as per your project namespace |
| 64 | +
|
| 65 | +public class PlaywrightServiceMSTestSetup |
| 66 | +{ |
| 67 | + private static PlaywrightServiceBrowserMSTest playwrightClient = null!; |
| 68 | + |
| 69 | + [AssemblyInitialize] |
| 70 | + public static async Task AssemblyInitialize(TestContext testContext) |
| 71 | + { |
| 72 | + playwrightClient = new PlaywrightServiceBrowserMSTest(context: testContext, credential: new DefaultAzureCredential()); |
| 73 | + await playwrightClient.InitializeAsync(); |
| 74 | + } |
| 75 | + |
| 76 | + [AssemblyCleanup] |
| 77 | + public static async Task AssemblyCleanup() |
| 78 | + { |
| 79 | + await playwrightClient.DisposeAsync(); |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +> [!NOTE] |
| 85 | +> Make sure your project uses `Microsoft.Playwright.MSTest` version 1.37 or above. |
| 86 | +
|
| 87 | +### Obtain region endpoint |
| 88 | + |
| 89 | +1. In the [Playwright portal](https://aka.ms/mpt/portal), copy the command under **Add region endpoint in your set up**. |
| 90 | + |
| 91 | +  |
| 92 | + |
| 93 | + 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. |
| 94 | + |
| 95 | +### Set up environment |
| 96 | + |
| 97 | +Ensure that the `PLAYWRIGHT_SERVICE_URL` that you obtained in previous step is available in your environment. |
| 98 | + |
| 99 | +### Run the tests |
| 100 | + |
| 101 | +Run Playwright tests against browsers managed by the service using the configuration you created above. |
| 102 | + |
| 103 | +```dotnetcli |
| 104 | +dotnet test |
| 105 | +``` |
| 106 | + |
| 107 | +## Key concepts |
| 108 | + |
| 109 | +Key concepts of the Azure Playwright MSTest SDK for .NET can be found [here](https://aka.ms/mpt/what-is-mpt) |
| 110 | + |
| 111 | +## Examples |
| 112 | + |
| 113 | +Code samples for using this SDK can be found in the following locations |
| 114 | + |
| 115 | +- [.NET Azure Playwright MSTest Library Code Samples](https://aka.ms/mpt/sample) |
| 116 | + |
| 117 | +## Troubleshooting |
| 118 | + |
| 119 | +- File an issue via [GitHub Issues](https://github.com/Azure/azure-sdk-for-net/issues). |
| 120 | +- Check [previous questions](https://stackoverflow.com/questions/tagged/azure+.net) or ask new ones on Stack Overflow using Azure and .NET tags. |
| 121 | + |
| 122 | +## Next steps |
| 123 | + |
| 124 | +- Run tests in a [CI/CD pipeline.](https://aka.ms/mpt/configure-pipeline) |
| 125 | + |
| 126 | +- Learn how to [manage access](https://aka.ms/mpt/manage-access) to the created workspace. |
| 127 | + |
| 128 | +- Experiment with different number of workers to [determine the optimal configuration of your test suite](https://aka.ms/mpt/parallelism). |
| 129 | + |
| 130 | +## Contributing |
| 131 | + |
| 132 | +This project welcomes contributions and suggestions. Most contributions require |
| 133 | +you to agree to a Contributor License Agreement (CLA) declaring that you have |
| 134 | +the right to, and actually do, grant us the rights to use your contribution. For |
| 135 | +details, visit [cla.microsoft.com][cla]. |
| 136 | + |
| 137 | +This project has adopted the [Microsoft Open Source Code of Conduct][coc]. |
| 138 | +For more information see the [Code of Conduct FAQ][coc_faq] or contact |
| 139 | +[[email protected]][coc_contact] with any additional questions or comments. |
| 140 | + |
| 141 | + |
0 commit comments