Use cloud-hosted browsers for locally deployed or privately hosted apps with Microsoft Playwright Testing Preview
Article
Learn how to use Microsoft Playwright Testing Preview to run end-to-end tests for locally deployed applications. Microsoft Playwright Testing uses cloud-hosted, remote browsers for running Playwright tests at scale. You can use the service to run tests for apps on localhost, or that you host on your infrastructure.
Playwright enables you to expose networks that are available on the client machine to remote browsers. When you expose a network, you can connect to local resources from your Playwright test code without having to configure additional firewall settings.
Important
Microsoft Playwright Testing is currently in preview. For legal terms that apply to Azure features that are in beta, in preview, or otherwise not yet released into general availability, see the Supplemental Terms of Use for Microsoft Azure Previews.
Configure Playwright to expose local networks
To expose local networks and resources to remote browsers, you can use the exposeNetwork option in Playwright. Learn more about the exposeNetwork option in the Playwright documentation.
You can specify one or multiple networks by using a list of rules. For example, to expose test/staging deployments and localhost: *.test.internal-domain,*.staging.internal-domain,<loopback>.
You can configure the exposeNetwork option in playwright.service.config.ts. The following example shows how to expose the localhost network by using the <loopback> rule. You can also replace localhost with a domain that you want to enable for the service.
You can now reference localhost in the Playwright test code, and run the tests on cloud-hosted browsers with Microsoft Playwright Testing:
Bash
npx playwright test --config=playwright.service.config.ts --workers=20
You can configure the ExposeNetwork option in .runsettings. The following example shows how to expose the localhost network by using the <loopback> rule. You can also replace localhost with a domain that you want to enable for the service.
XML
<TestRunParameters><!--Use this option to connect to local resources from your Playwright test code without having to configure additional firewall--><Parametername="ExposeNetwork"value="loopback" /></TestRunParameters>
You can now reference localhost in the Playwright test code, and run the tests on cloud-hosted browsers with Microsoft Playwright Testing:
Bash
dotnet test --settings:.runsettings --logger "microsoft-playwright-testing" -- NUnit.NumberOfTestWorkers=20
In this module, you'll learn how to use Playwright to test a sample web application. You'll learn how to run tests, view test reports, and understand the structure of a Playwright project. You'll also learn how to use Visual Studio Code to run tests, debug tests, and record new tests.