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

[Question] Has anyone gotten Playwright installed and running on Windows Server? #1788

Closed cleverchrismartinez closed 2 years ago

cleverchrismartinez commented 3 years ago

I built a tool using Playwright dotnet, and it runs great locally. I'm trying to deploy it on my Windows server so other people can use it, and the problem is getting the headless browsers properly installed on the server.

If I do all of the quickstart tasks on https://playwright.dev/dotnet/docs/intro within Windows PowerShell out on the server, it goes fine until the playwright install step. At that point I get the following Error:

Unhandled Exception: System.IO.FileNotFoundException: Could not load the file or assembly 'System.Runtime, Version=5.0.0.0...

Even if I try inputting the command dotnet add package System.Runtime it adds the package, but then when I try playwright install again, it throws the same error.

I even went so far as to try deploying the app anyway, and when I get to the part that requires Playwright, it says:

Looks like Playwright Test or Playwright was just installed or updated. Please run the following command to download new browsers:

npx playwright install

So I said screw it and installed Node on the server, then ran the npx command, and it says it installed the browsers, but I still get the same error telling me to run the npx command.

Has anyone had any luck getting Playwright installed and implemented on a Windows server?

fr4gles commented 3 years ago

Yes, we are using published project (internal tool) on windows server which is using https://github.com/microsoft/playwright-dotnet.

Our steps that are integrated into our publish pipeline to accomplish that:

  1. dotnet build "XYZ.sln" --configuration="Release" --framework="net5.0" --runtime="win-x64" --force
  2. dotnet tool update --global Microsoft.Playwright.CLI
  3. $env:PLAYWRIGHT_BROWSERS_PATH=0;Invoke-Expression "$env:USERPROFILE\.dotnet\tools\playwright.exe install"
  4. dotnet publish "ABC.csproj" --output="<publish destination for project ABC>" --configuration="Release" --framework="net5.0" --runtime="win-x64" --self-contained="false"
  5. Copy-Item -Path "<ABC project path>\bin\Release\net5.0\.playwright\package\.local-browsers" -Destination "<publish destination for project ABC>\.playwright\package" -Recurse

Sources:

aljones commented 3 years ago

I invoke the dotnet tool's cli directly when my program starts.
Microsoft.Playwright.Program.Main(new[] { "install" })

cleverchrismartinez commented 3 years ago

I invoke the dotnet tool's cli directly when my program starts. Microsoft.Playwright.Program.Main(new[] { "install" })

That definitely seemed to work as far as getting it installed. My program still seems to think it should live in a different folder and refuses to acknowledge the installation, but that's a separate issue.

Thanks for your help!

mxschmitt commented 2 years ago

npx playwright install

This was a bug on our side, it should be just "playwright install". So when you have the Playwright CLI via the .NET tool installed, it will install the browser see here.