Cannot install playwright: Couldn't find project using Playwright. Ensure a project or a solution exists in
Asked Answered
A

2

6

I'm trying to install playwright on my deployment target machine in order to run UI tests.

# Install the CLI once.
dotnet tool install --global Microsoft.Playwright.CLI

playwright install

however when using the playwright CLI including playwright install I get:

Couldn't find project using Playwright. Ensure a project or a solution exists in C:\users\myuser, or provide another path using -p.

How do I install playwright on a vm?

EDIT:

Unfortunately, the .NET nuget packages for playwright are not very well designed. While the API is wonderful, the deployment is nightmare.

Not only you are not able to install browsers using CLI on deployment server, but the package adds 3x NodeJS runtime (200MB) to your project, and all projects that reference it.

It is untrivial to prevent those files from being published and your build artifacts can easily grow to 1GB for each build!

You are not able to configure path to NodeJS, or to the playwright itself.

You can vote for fixing this here: https://github.com/microsoft/playwright-dotnet/issues/1850

Abbreviate answered 13/11, 2021 at 17:53 Comment(0)
S
9

You need to execute playwright install in the folder that contains the csproj or use -p to specify the project file

# Create project
dotnet new console -n PlaywrightDemo
cd PlaywrightDemo

# Install dependencies, build project and download necessary browsers.
dotnet add package Microsoft.Playwright
dotnet build
playwright install

See the documentation for more details: https://playwright.dev/dotnet/docs/intro#first-project

You can also install the browser from the code using:

using Microsoft.Playwright;

var exitCode = Microsoft.Playwright.Program.Main(new[] { "install" });

More details: https://www.meziantou.net/distributing-applications-that-depend-on-microsoft-playwright.htm

Shaer answered 13/11, 2021 at 18:3 Comment(2)
but it doesn't make any sense on deployment VM. There are only compiled binaries, no project. I'm not creating playwright project, I want to execute it. See playwright.dev/dotnet/docs/cli#install-browsersAbbreviate
Playwright CLI is just a helper to call Microsoft.Playwright.Program.Run from the Microsoft.Playwright.dll. This dll is in the NuGet package Microsoft.Playwright. This method calls the exe located in the .playwright folder. This folder is copied to the build folder when building the project. That's why you need a project file and build the project before calling playwright install. Alternatively, you can install the browsers from the code. I've updated the answer with an example.Shaer
S
0

Work around for me was.. Can restore playwright package again using restore command of .net core in pipeline before build solution in pipeline and installing playwright driver using powershell after build pipeline like below

choose Type FilePath

Script Path: YourProjectName\bin\Debug\netcoreapp3.1\playwright.ps1

Scleritis answered 18/7, 2022 at 6:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.