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] Getting "Please install @playwright/test package to use Playwright Test." #6981

Closed
thecodrr opened this issue Jun 9, 2021 · 29 comments
Labels
feature-test-runner Playwright test specific issues

Comments

@thecodrr
Copy link

thecodrr commented Jun 9, 2021

Context:

System:

  • OS: Linux 5.4 Ubuntu 21.04 (Hirsute Hippo)
  • Memory: 502.32 MB / 15.52 GB
  • Container: Yes

Binaries:

  • Node: 15.14.0 - ~/.volta/tools/image/node/15.14.0/bin/node
  • Yarn: 1.22.10 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
  • npm: 7.15.0 - ~/.volta/tools/image/npm/7.15.0/bin/npm

Languages:

  • Bash: 5.1.4 - /usr/bin/bash

npmPackages:

  • playwright: ^1.12.0 => 1.12.0

Describe the bug

I just installed playwright version 1.12 to try out the new test runner but I am consistently getting Please install @playwright/test package to use Playwright Test. no matter how many times I do yarn add --dev @playwright/test.

@pavelfeldman
Copy link
Member

You don't need playwright when using @playwright/test:

yarn init -y
yarn add --dev @playwright/test
npx playwright test

@cyrilletuzi
Copy link

Had the same issue, because previous beta versions of @playwright/test did require playwright.

Solution:

  • npm rm playwright
  • npm install @playwright/test -D

Then it works.

@cyrilletuzi
Copy link

Note/question: for projects using Playwright for both unit tests and e2e tests, could this be a problem? or is @playwright/test-only the way to go in this scenario?

@mxschmitt mxschmitt added the feature-test-runner Playwright test specific issues label Jun 9, 2021
@mpuertao
Copy link

mpuertao commented Jun 9, 2021

In my case,

  • Delete playwright,
  • Install @playwright/test
  • Reinstall playwright.

Success!!!

@thecodrr
Copy link
Author

thecodrr commented Jun 9, 2021

You don't need playwright when using @playwright/test:

yarn init -y
yarn add --dev @playwright/test
npx playwright test

Yep. This worked.

@thecodrr thecodrr closed this as completed Jun 9, 2021
@mariusc23
Copy link

I ran into this issue because I had test in my .yarnclean file. Yarn removed the lib/test folder and the entire node_modules/@playright/test folder because of this 🤦

I fixed by adding this to .yarnclean:

!@playwright/test/**

@mrienstra
Copy link
Contributor

The solutions above did not work for me, I couldn't figure out how to get past

Please install @playwright/test package to use Playwright Test.
  npm install -D @playwright/test

... when running npx playwright test.

Resolved by running yarn playwright test instead of npx playwright test.

See also #8495 for another snag one may encounter when using Yarn 2 PnP and @playwright/test (will likely be fixed in the next release).

(props to @merceyz)

@nathanchase
Copy link

nathanchase commented Sep 21, 2021

I've been trying everything I can think of to get testing to work in an Azure Pipeline.

My YAML:

resources:
  containers:
  - container: playwright
    image: mcr.microsoft.com/playwright:focal

  repositories:
  - repository: self
    type: git
    ref: refs/heads/develop

jobs:
- job: e2e_testing
  container: playwright
  displayName: E2E Testing

  pool:
    vmImage: ubuntu-latest

  steps:
  - checkout: self

  - script: |
      yarn
      npx playwright test
    displayName: 'Run test'

  - task: PublishTestResults@2
    inputs:
      testResultsFormat: 'JUnit'
      testRunTitle: 'Test Report'
    displayName: 'Publish Reports'

but I get...

Please install @playwright/test package to use Playwright Test.
  npm install -D @playwright/test
##[error]Bash exited with code '1'.

If I try to use yarn playwright test, then I get...

yarn run v1.22.11
$ playwright test
/bin/sh: 1: playwright: not found
error Command failed with exit code 127.

What is the magic combination to make this work??

@mrienstra
Copy link
Contributor

@nathanchase, does yarn playwright test work locally? Might be hard to diagnose without knowing more.

@nathanchase
Copy link

@nathanchase, does yarn playwright test work locally? Might be hard to diagnose without knowing more.

Yes, works fine locally.

@mrienstra
Copy link
Contributor

@nathanchase, stab in the dark, but maybe you need to run yarn playwright install in CI?

@nathanchase
Copy link

@nathanchase, stab in the dark, but maybe you need to run yarn playwright install in CI?

Well, that's why I was using their Docker container, since it's supposed to have all that stuff preinstalled and ready to go. I tried manually installing everything and not using the container, and still had the same result.

I just need to find someone that actually has a working Azure DevOps .yaml for Playwright. I've come across some that are for Windows/.NET, but nothing for Linux/Node based projects.

@mrienstra
Copy link
Contributor

mrienstra commented Oct 6, 2021

@nathanchase, just realized it should be yarn playwright install-deps and yarn playwright install in CI.

I assume using Windows or macOS is not an option? https://playwright.dev/docs/ci/#azure-pipelines mentions that possibility.

If you haven't already, try not using their Docker container and instead running yarn playwright install-deps.

(I was previously using microsoft/playwright-github-action@v1 -- not applicable to you of course -- but looks like that's been deprecated)

@devzerker
Copy link

Faced with the same problem on node version 12.19.1
After updating to the latest lts the problem is gone

@nathanchase
Copy link

Faced with the same problem on node version 12.19.1 After updating to the latest lts the problem is gone

Latest node version or latest playwright version?

@devzerker
Copy link

devzerker commented Oct 26, 2021

Latest node version or latest playwright version?

Latest node version

@viveleroi
Copy link

viveleroi commented Nov 12, 2022

I'm running into this as well, yarn 3.2.4 on Windows 11. I installed playwright for the first time using yarn create playwright. npx playwright test was giving me this error. Trying yarn playwright test instead throws a different error, which I opened here:

#18759

@pereorga
Copy link

For anybody experiencing this after upgrading to 1.34.0 (I am), I think this may be related to #23098

@dman777
Copy link

dman777 commented Jun 8, 2023

I am getting this issue only in Azure pipelines. And I don't have playwright installed

   "keywords": [],
    "author": "",
    "license": "ISC",
    "devDependencies": {
      "@playwright/test": "^1.34.3",
      "chai": "^4.3.7"
    },
    "dependencies": {
      "nodemon": "^2.0.22"
    }
  }

@warorc
Copy link

warorc commented Jun 9, 2023

You don't need playwright when using @playwright/test:

yarn init -y
yarn add --dev @playwright/test
npx playwright test

Why I can't use both. In our project we use monorepo. And one of application in this monorepo uses crawlee: https://www.npmjs.com/package/crawlee

where in dependencies it use playwright. So now we have to choose should we test out product, or use one of our critical application. And it means that we need to use cypress instead of playwright for testing or other framework.

@jasonk
Copy link

jasonk commented Jun 9, 2023

If anyone else ends up here looking for a solution. The root cause of this problem is that the playwright package and the @playwright/test package both provide a cli tool named playwright. The one in the playwright package just throws this error if you attempt to run playwright test or something else.

If you have both packages installed then whether playwright test works or not depends entirely on what order they were installed in. If playwright was installed last then it won't work, if @playwright/test was installed last then it will work.

If you need to have both installed, the only way I've found to work around this is to install postinstall-postinstall and add a postinstall script that does this:

cd node_modules/.bin
ln -sf ../@playwright/test/cli.js playwright

This will force the symlink to the package to be replaced with the @playwright/test version every time you run npm install (or yarn install, or whatever).

@utkarshkukreti
Copy link

@jasonk thanks for the pointer! I used a different workaround - pass the full path to cli.js in package.json's scripts.test:

-    "test": "playwright test",
+    "test": "node_modules/@playwright/test/cli.js test",

@kasper573
Copy link

You don't need playwright when using @playwright/test:

yarn init -y
yarn add --dev @playwright/test
npx playwright test

Why I can't use both. In our project we use monorepo. And one of application in this monorepo uses crawlee: https://www.npmjs.com/package/crawlee

where in dependencies it use playwright. So now we have to choose should we test out product, or use one of our critical application. And it means that we need to use cypress instead of playwright for testing or other framework.

I'm also using a monorepo facing this exact issue. With monorepos becoming increasingly popular I think this problem really needs a better solution. Even without a monorepo, it's entirely possible that you have a project that has a different dependency that installs playwright under the hood, meaning you can't remove playwright to fix this unless you remove the dependency that is using it.

@alexn-s
Copy link

alexn-s commented Jun 23, 2023

i just encountered this issue. it really is problematic and counter intuitive that both packages have the same cli name and conflict.
i think the best way forward (altough it breaks a lot of package.json script and ci pipelines) to change the name of the playwright test script and resolve the conflict. it is quite shame but i probably use puppeteer again. there are multiple use case for testing and automation in one "project". would love to use playwright again in the future

@yordan-kanchelov
Copy link

with the attempt to migrate to pnpm i started reproducing this issue as well

@Shruthi-DN
Copy link

Had the same issue, because previous beta versions of @playwright/test did require playwright.

Solution:

  • npm rm playwright
  • npm install @playwright/test -D

Then it works.

Thank you! I just had to explicitly install @playwright/test in the github workflow yml. This error was bothering as it didn't happen in my local runs. I didn't have to remove playwright. Not sure if/where that package is installed.

@sturoid
Copy link

sturoid commented Nov 10, 2023

Reproducing this issue using pnpm.

@averyjl1
Copy link

Solved! In my case I was having same problems as @thecodrr - My solution was to disable Forcepoint/Websense

@andersekdahl
Copy link

I had this issue in a repo using npm workspaces. npx playwright install gave a not found error when run in the root. When I changed to run it inside the workspace package that needed playwright instead it worked fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-test-runner Playwright test specific issues
Projects
None yet
Development

No branches or pull requests