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

[Bug]: test runner trying to launch Chrome from the wrong folder #3017

Closed Tony20221 closed 2 weeks ago

Tony20221 commented 2 weeks ago

Version

1.47

Steps to reproduce

Example steps (replace with your own):

  1. Clone my repo at https://github.com//example
  2. dotnet run Program.cs
  3. You should see the error come up

Expected behavior

Chrome to launch

Actual behavior

I have an NUnit project that's using Microsoft.Playwright.NUnit 1.47. The last time I ran npx playwright codegen https://.... It asked if I wanted to install 1.48 and entered Y. It installed the new browsers..

Now when I run the test in Visual Studio, I get the error below. My chrome for Playwright is in the chromium-1140 subfolder. Why is it looking in chromium-1134 folder? Where is it getting this path from? I am guessing there's a mismatch now between 1.47 in the app and 1.48 that got installed when it asked me. How do I fix this? I already ran npx playwright install. I tried running pwsh playwright.ps1 install in the folder where playwright.ps1 resides and got 'The argument 'playwright.ps1' is not recognized as the name of a script file.' error.

Error: MyTest Failed: Microsoft.Playwright.PlaywrightException : Executable doesn't exist at C:\Users\Tony\AppData\Local\ms-playwright\chromium-1134\chrome-win\chrome.exe Microsoft.Playwright.PlaywrightException : Executable doesn't exist at C:\Users\Tony\AppData\Local\ms-playwright\chromium-1134\chrome-win\chrome.exe ╔════════════════════════════════════════════════════════════╗ ║ Looks like Playwright was just installed or updated. ║ ║ Please run the following command to download new browsers: ║ ║ ║ ║ pwsh bin/Debug/netX/playwright.ps1 install ║ ║ ║ ║ <3 Playwright Team ║ ╚════════════════════════════════════════════════════════════╝ at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](ChannelOwner object, String method, Dictionary2 dictionary, Boolean keepNulls) in /_/src/Playwright/Transport/Connection.cs:line 206 at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func1 action, Boolean isInternal) in //src/Playwright/Transport/Connection.cs:line 532 at Microsoft.Playwright.Core.BrowserType.LaunchAsync(BrowserTypeLaunchOptions options) in //src/Playwright/Core/BrowserType.cs:line 56 at Microsoft.Playwright.NUnit.BrowserService.CreateBrowser(IBrowserType browserType) in /_/src/Playwright.NUnit/BrowserService.cs:line 54 at Microsoft.Playwright.NUnit.BrowserService.<>cDisplayClass5_0.<b_0>d.MoveNext() in //src/Playwright.NUnit/BrowserService.cs:line 44 --- End of stack trace from previous location --- at Microsoft.Playwright.NUnit.WorkerAwareTest.RegisterService[T](String name, Func1 factory) in /_/src/Playwright.NUnit/WorkerAwareTest.cs:line 55 at Microsoft.Playwright.NUnit.BrowserTest.BrowserSetup() in /_/src/Playwright.NUnit/BrowserTest.cs:line 46 at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter1.BlockUntilCompleted() at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter) at NUnit.Framework.Internal.AsyncToSyncAdapter.Await[TResult](Func1 invoke) at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func1 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.BeforeAndAfterTestCommand.<>cDisplayClass1_0.b__0() at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

Additional context

No response

Environment

- Operating System: Windows 11
- CPU: AMD
- Browser: [All, Chromium, Firefox, WebKit]
- .NET Version (TFM): [net8.0]
- Other info:
mxschmitt commented 2 weeks ago

It looks like you are using .NET and npx (Node.js) in parallel. While this is supported we don't recommend it for your scenario - it would overcomplicate things. All npx playwright commands work with the playwright.ps1 as well. Using npx there adds another risk, because you'd have to keep the versions in sync (thats why it results in "browsers not found" errors for you).

Make sure to use have a recent PowerShell installed, otherwise it won't work: https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.2 - this should fix it for you.

Tony20221 commented 2 weeks ago

It works now. Thanks.