playwright: Cannot run any Playwright test

Context:

  • Playwright Version: 1.20.1
  • Operating System: Windows 10
  • Node.js version: 16.13.0]
  • Browser: All
  • Extra:

Describe the bug

A fresh installation of Playwright and attempting to run example spec produces this error:

$ npx playwright test

Running 0 test using 0 worker


Error: tests\example.spec.ts:5:12: Playwright Test did not expect test.beforeEach() to be called here.
Most common reasons include:
- You are calling test.beforeEach() in a configuration file.
- You are calling test.beforeEach() in a file that is imported by the configuration file.
- You have two different versions of @playwright/test. This usually happens
  when one of the dependenices in your package.json depends on @playwright/test.

   at ..\node_modules\@playwright\test\lib\util.js:198

  196 |
  197 | function errorWithLocation(location, message) {
> 198 |   return new Error(`${formatLocation(location)}: ${message}`);
      |          ^
  199 | }
  200 |
  201 | function expectType(receiver, type, matcherName) {

    at errorWithLocation (C:\projects\virtonomy\web_platform_main\e2e\node_modules\@playwright\test\lib\util.js:198:10)
    at TestTypeImpl._ensureCurrentSuite (C:\projects\virtonomy\web_platform_main\e2e\node_modules\@playwright\test\lib\testType.js:78:41)
    at TestTypeImpl._hook (C:\projects\virtonomy\web_platform_main\e2e\node_modules\@playwright\test\lib\testType.js:129:24)
    at Function.beforeEach (C:\projects\virtonomy\web_platform_main\e2e\node_modules\@playwright\test\lib\transform.js:253:12)
    at Object.<anonymous> (C:\projects\virtonomy\web_platform_main\e2e\tests\example.spec.ts:5:12)
    at Module._compile (C:\Projects\virtonomy\web_platform_main\e2e\node_modules\pirates\lib\index.js:136:24)
    at Object.newLoader (C:\Projects\virtonomy\web_platform_main\e2e\node_modules\pirates\lib\index.js:141:7)

=================
 no tests found.

To open last HTML report run:

  npx playwright show-report

package.json

{
  "name": "e2e",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {},
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@playwright/test": "^1.20.1"
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 13
  • Comments: 29

Most upvoted comments

I also had this issue. In my case the problem was I was executing npx playwright test from root directory and not inside tests repository.

I had the same problem with pnpm. It was resolved by using pnpm exec playwright test instead of pnnpm dlx playwright test.

I’m also using git bash, and in my case I had CDed into a directory with incorrect casing, e.g. myplaywrightdir instead of myPlaywrightDir. Going up a directory and then cding back down into the dir with the correct casing fixed the problem for me.

I encountered this problem when I used lowercase paths to cd with powershell to the project directory. When I navigated from c:\ into the full directory path with the correct casing, the problem disappeared.

yarn remove playwright
yarn create playwright
yarn install playwright

I had the same problem with pnpm. It was resolved by using pnpm exec playwright test instead of pnnpm dlx playwright test.

In case anyone else is searching: Same goes for yarn. It wasn’t working for me with yarn dlx playwright test but did with yarn exec playwright test.

@qwertie In my case I had multiple packages of a monorepo with different versions of @playwright/test. As soon as I updated @playwright/test in devDepencencies(!) of each package to the same version, it started working. I was using pnpm exactly to not have these version collisions, but here I am 👎 .

I am having this problem also. Our configuration is in playwright.config.ts but Playwright is ignoring it.

C:\...\UI>npx playwright test --project=chromium

Running 0 test using 0 worker


Error: ui-tests\scenario.spec.ts:32:12: Playwright Test did not expect test.beforeAll() to be called here.

The same code is working on the machine of the developer who originally wrote our playwright scripts. We are using yarn install (with yarn.lock in source control), so presumably it’s not that we have different node_modules…

The advice above didn’t work but I found a workaround: the Playwright Test for VSCode (ms-playwright.playwright) extension is able to run and debug our tests.

Turned out the problem is related to Git Bash. Tests run fine when executed in Windows CMD. I think it has to do with double global.ts

This happened to me as well. I changed the casing of my folder names in Windows Explorer, but MS Code was still “using” the original casing in the terminal window, and it failed to run the tests. Navigating out and back into the folder in Code using the correct casing resolved the issue.

Turned out the problem is related to Git Bash. Tests run fine when executed in Windows CMD. I think it has to do with double global.ts

I’m also using git bash, and in my case I had CDed into a directory with incorrect casing, e.g. myplaywrightdir instead of myPlaywrightDir. Going up a directory and then cding back down into the dir with the correct casing fixed the problem for me.

same problem on windows. ok. sorry. problem solved: I’ve forget the intialisation: npm init playwright@latest now test sample is ok!