Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
djlawhead opened this issue Jan 26, 2024 · 3 comments · Fixed by #2849 · May be fixed by #3068
Closed

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

djlawhead opened this issue Jan 26, 2024 · 3 comments · Fixed by #2849 · May be fixed by #3068
Assignees
Labels

Comments

@djlawhead
Copy link

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)
@mxschmitt
Copy link
Member

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

@djlawhead
Copy link
Author

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.

@mxschmitt mxschmitt self-assigned this Jan 27, 2024
@mxschmitt mxschmitt transferred this issue from microsoft/playwright Jan 27, 2024
@Depechie
Copy link

@djlawhead where you able to tweak the devcontainer, if so, how? Because creating a new one, I still encounter this issue. // @mxschmitt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants