Search code examples
azure-devopsplaywright

Running Playwright tests in Azure Devops Pipeline to QA environment with IP restrictions?


I have created some Playwright tests in our NextJS project to run E2E tests. I want these tests to run automatically as part of the Azure DevOps Pipeline.

We have a pipeline that triggers as soon as someone merge to main. The artifact is built using microsoft-hosted agents. The artifact is then released to dev.customer.com. This domain has IP restrictions.

Now, the agent does not have static IP. Azure just assigns it a random IP from a huge range. So it's impossible for us to whitelist it to access dev.customer.com.

How should Playwright be able to access the site with its headless browser? Am I missing something obvious? I guess the main problem is that we have access restrictions to our QA site, but this have to be a pretty common setup I guess?


Solution

  • You can use the self-hosted agent with a static IP instead the Microsoft-hosted agents.

    If you can modify the whitelist of your dev.customer.com in your pipeline with some bash/powershell command, then you can use Microsoft-hosted agents with the following steps:

    • obtain the IP of the current Microsoft-hosted agent.
    • add the IP to the target's whitelist
    • run your test.
    • delete this IP from the whitelist.

    You can refer this question and the example.