microsoft / playwright-dotnet

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

[BUG] Not able to use Playwright on macOS Catalyst #2843

Open lk-code opened 9 months ago

lk-code commented 9 months ago

System info

Source code

i use the sample code from playwright on macOS and got an exception at the following line (the logic is in a .NET 8 Class Library):

using var playwright = await Playwright.CreateAsync();
...

EXCEPTION:

Microsoft.Playwright.PlaywrightException: Unknown platform
   at Microsoft.Playwright.Helpers.Driver.GetPath(String driversPath) in /_/src/Playwright/Helpers/Driver.cs:line 119
   at Microsoft.Playwright.Helpers.Driver.GetExecutablePath() in /_/src/Playwright/Helpers/Driver.cs:line 82
   at Microsoft.Playwright.Transport.StdIOTransport.GetProcess(String driverArgs) in /_/src/Playwright/Transport/StdIOTransport.cs:line 116
   at Microsoft.Playwright.Transport.StdIOTransport..ctor() in /_/src/Playwright/Transport/StdIOTransport.cs:line 46
   at Microsoft.Playwright.Playwright.CreateAsync() in /_/src/Playwright/Playwright.cs:line 44
   at ArmyPlanner.Admin.Core.WebsiteParsers.CitadelColorSearch.GetImageUrl(String colorName, CancellationToken cancellationToken) in /Users/larskramer/Projects/lk-code/armyplanner-admin-app/source/ArmyPlanner.Admin.Core/WebsiteParsers/CitadelColorSearch.cs:line 90
   at ArmyPlanner.Admin.Maui.ViewModels.ColorManagement.DetailViewModel.OnColorCodeSearchAsync(CancellationToken cancellationToken) in /Users/larskramer/Projects/lk-code/armyplanner-admin-app/source/ArmyPlanner.Admin.Maui/ViewModels/ColorManagement/DetailViewModel.cs:line 41

I followed the code through the StackTrace and came to a place where basically the string "OSX" is compared with the string "MACCATALYST" and "IOS" and therefore fails. The value "OSX" is set in Driver.cs line 107 and compared with the current platform in the if. In the OperatingSystem.cs file, however, only MACCATALAYST and IOS are checked as described.

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool IsOSPlatform(string platform)
    {
      ArgumentNullException.ThrowIfNull((object) platform, nameof (platform));
      return platform.Equals("MACCATALYST", StringComparison.OrdinalIgnoreCase) || platform.Equals("IOS", StringComparison.OrdinalIgnoreCase);
    }

As soon as the platform names for macOS are used correctly everywhere, the bug is fixed and the "Unknown-Platform" exception no longer occurs :)

lk-code commented 9 months ago

In short, Playwright is currently not usable for macOS users :(

mxschmitt commented 9 months ago

The error gets thrown here:

https://github.com/microsoft/playwright-dotnet/blob/ec7d7fafa34de96c81df188cdc07d5aba411808b/src/Playwright/Helpers/Driver.cs#L119

We do RuntimeInformation.IsOSPlatform(OSPlatform.OSX) inside, which is for some reason not working on your environment. Which TFM are you using? Are you using net6.0-maccatalyst?

lk-code commented 9 months ago

the class library has net8.0 and the app net8.0-maccatalyst.

I know that the exception is thrown there :)

The if statement in line 107 specifies OSX, but behind it are the values MACCATALYST and IOS. This means that the if fails every time. The string comparison is always wrong on macOS.

cyrilgupta commented 6 months ago

I am experiencing the same issue. I am trying to use this on MacOS in a Blazor MAUI app.

erodriguezh commented 6 months ago

Here same as @cyrilgupta