microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.
https://playwright.dev/dotnet/
MIT License
2.47k stars 235 forks source link

[Feature]: Configure (Chromium) channel when using PageTest in NUnit #1730

Closed jevgenijusmarinuskinas closed 2 years ago

jevgenijusmarinuskinas commented 3 years ago

Your question

Hello,

I can specify BROWSER and HEADED through the means of environment variables, to be used with a PageTest base class in my code. I've looked through the playwright sources, and was unable to find an environment variable for a Chromium channel. Is it possible to somehow control it in this scenario (for example, by setting some property, etc.)?

avodovnik commented 3 years ago

No, unfortunately this isn't possible at the moment. I'll convert this into a feature request though, and we can explore adding it.

PavanMudigondaTR commented 3 years ago

I have the same question and request. Playwright supports browser_channel environment variable for Python, Java, JS/TS. I am not seeing it working in dotnet. I am struggling to figure out how to run Github Actions for Chrome and MSEdge.

avodovnik commented 3 years ago

As a workaround, you can manually instantiate the browser instance, obviously, for example, by doing:

 public class ChannelTest : PlaywrightTest
{
    private IBrowser browser;

    [SetUp]
    public async Task SetUp()
    {
        browser = await Playwright.Chromium.LaunchAsync(new()
        {
            Headless = false,
            Channel = "chrome-dev"
        });
    }

    [Test]
    public async Task ShouldUseChannel() {
        var page = await browser.NewPageAsync();
        var res = await page.GotoAsync("https://www.microsoft.com");
        Assert.IsTrue(res.Status == 200);
    }
}

You just have to understand the drawbacks in this approach, which is that a new Browser will be spun up depending on your parallelization settings. By default, we have the following in our tests:

[assembly: NUnit.Framework.Parallelizable(NUnit.Framework.ParallelScope.Fixtures)]

You need to adapt the above to the scope you've chosen & use the appropriate setup methods.