microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.

Home Page:https://playwright.dev/dotnet/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Fresh Playwright for .NET Install Throws 'Invalid browser name'

djlawhead opened this issue · comments

System info

  • Playwright Version: 1.41.1
  • Operating System: Ubuntu 22 (devcontainer dotnet:8.0-jammy)
  • Browser: All
  • Other info: .NET 8.0.101

Source code

using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;

namespace PlaywrightTests;

[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class Tests : PageTest
{
    [Test]
    public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
    {
        await Page.GotoAsync("https://playwright.dev");

        // Expect a title "to contain" a substring.
        await Expect(Page).ToHaveTitleAsync(new Regex("Playwright"));

        // create a locator
        var getStarted = Page.GetByRole(AriaRole.Link, new() { Name = "Get started" });

        // Expect an attribute "to be strictly equal" to the value.
        await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro");

        // Click the get started link.
        await getStarted.ClickAsync();

        // Expects the URL to contain intro.
        await Expect(Page).ToHaveURLAsync(new Regex(".*intro"));
    }
}

Steps

Expected

Playwright test execute successfully in one or more browsers, whether they pass or not.

Actual

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
  Failed HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage [228 ms]
  Error Message:
   System.ArgumentException : Invalid browser name: /vscode/vscode-server/bin/linux-x64/8b3775030ed1a69b13e4f4c628c612102e30a681/bin/helpers/browser.sh
  Stack Trace:
     at Microsoft.Playwright.TestAdapter.PlaywrightSettingsProvider.ValidateBrowserName(String browserName) in /_/src/Playwright.TestAdapter/PlaywrightSettingsProvider.cs:line 102
   at Microsoft.Playwright.TestAdapter.PlaywrightSettingsProvider.get_BrowserName() in /_/src/Playwright.TestAdapter/PlaywrightSettingsProvider.cs:line 45
   at Microsoft.Playwright.NUnit.PlaywrightTest.PlaywrightSetup() in /_/src/Playwright.NUnit/PlaywrightTest.cs:line 44
   at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
   at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
   at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
   at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, IMethodInfo method)
   at NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUp(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.SetUpTearDownCommand.<>c__DisplayClass0_0.<.ctor>b__0(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0()
   at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

Failed!  - Failed:     1, Passed:     0, Skipped:     0, Total:     1, Duration: 228 ms - YogaEndToEndTests.dll (net8.0)

The Problem is that GitHub Codespaces by default sets the BROWSER env var, which is not compatible with what we expect. We should either:

a) Silently fall back to Chromium in this case
b) Stop looking at the environment variable

In the meantime as a workaround, you can do: BROWSER= dotnet test -- NUnit.NumberOfTestWorkers=5

Setting BROWSER inline with the command works! I'm going to see if I can somehow set an environment variable in the container to keep it at a sane value, like chromium.