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

Cannot run any Playwright test #13092

Closed
ckmoga opened this issue Mar 26, 2022 · 29 comments
Closed

Cannot run any Playwright test #13092

ckmoga opened this issue Mar 26, 2022 · 29 comments

Comments

@ckmoga
Copy link

ckmoga commented Mar 26, 2022

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"
  }
}
@ckmoga
Copy link
Author

ckmoga commented Mar 26, 2022

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

@ckmoga ckmoga closed this as completed Mar 26, 2022
@fisnikbatusha
Copy link

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.

@emnabn
Copy link

emnabn commented Jul 5, 2022

I have the same error when i want to lunch saucelab test : saucectl run , someone have an idea about it? thanks

@gokul-sol
Copy link

gokul-sol commented Jul 12, 2022

Hi I too have the same error, when using Playwright version 1.22.2 with saucelabs .. any help would be appreciated, thanks in advance

$ saucectl run
Error: tests\*.spec.ts:9:12: Playwright Test did not expect test.describe() to be called here.
Most common reasons include:
- You are calling test.describe() in a configuration file.
- You are calling test.describe() 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:221

  219 |
  220 | function errorWithLocation(location, message) {
> 221 |   return new Error(`${formatLocation(location)}: ${message}`);
      |          ^
  222 | }
  223 |
  224 | function expectTypes(receiver, types, matcherName) {

    at errorWithLocation (D:\sauce-playwright-runner\2.9.0\bundle\__project__\node_modules\@playwright\test\lib\util.js:221:10)
    at TestTypeImpl._ensureCurrentSuite (D:\sauce-playwright-runner\2.9.0\bundle\__project__\node_modules\@playwright\test\lib\testType.js:79:41)
    at TestTypeImpl._describe (D:\sauce-playwright-runner\2.9.0\bundle\__project__\node_modules\@playwright\test\lib\testType.js:106:24)
    at Function.describe (D:\sauce-playwright-runner\2.9.0\bundle\__project__\node_modules\@playwright\test\lib\transform.js:269:12)
    at Object.<anonymous> (D:\sauce-playwright-runner\2.9.0\bundle\__project__\tests\**.spec.ts:9:12)

@qwertie
Copy link

qwertie commented Aug 4, 2022

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.

@rgripper
Copy link

rgripper commented Aug 5, 2022

@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 👎 .

@qwertie
Copy link

qwertie commented Aug 5, 2022

Yeah, I forgot to mention that only one version of @playwright/test is installed in my case.

@glvno
Copy link

glvno commented Aug 5, 2022

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.

@prushforth
Copy link

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.

@andyhinds
Copy link

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.

@jpaxtonrs
Copy link

jpaxtonrs commented Nov 1, 2022

@gokul-sol / @emnabn - Did you ever figure out the issue when wanting to run your Playwright tests in Saucelabs?

@sfc-gh-pleszczewicz
Copy link

@jpaxtonrs for me adding node_modules to .sauceignore did the trick. if you have some packages that you need i believe this part of config should work

@abhay-ranjan-hitachi
Copy link

I avoided using tab to complete file path in terminal. I used npx playwright test ./tests/example.spec.js and it worked

@abhishek747400
Copy link

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.

This was indeed the problem for me. Thanks a lot

@ThinhVD7
Copy link

ThinhVD7 commented Aug 2, 2023

I got this issue when run the feature file XD it just suddenly appear, everything running well yesterday

@sebtinet
Copy link

sebtinet commented Aug 3, 2023

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.

Thanks you for your coments they helped me to solve my issue :)
i got similar things Playwright Test did not expect test() to be called here. when using into our jenkins CI a dir() step on a Windows node such as :

dir('folder')
{
shx 'npx playwright test' 
}

replacing this dir() step by a shx 'cd folder & npx playwright test' fixes the issue !.

@nbaron1
Copy link

nbaron1 commented Aug 6, 2023

I had this issue when using yarn workspaces and having the e2e tests in a non root folder.

Adding: "workspaces": { "nohoist": [ "**" ] } to packages/e2e/package.json was able to resolve the error for me

@ridplace
Copy link

ridplace commented Sep 22, 2023

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

@ChristinaNT
Copy link

I had vitest in my package dev and dependencies and that helped to solve the problem for me

@acapro
Copy link

acapro commented Feb 27, 2024

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

@czibbelvin
Copy link

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.

@pelly-ryu
Copy link

None of above worked but pnpm rm playwright, pnpm i solved my problem.
( https://stackoverflow.com/a/73856094 )

my case: pnpm workspace. only 1 playwright in the workspace.

@asdf23
Copy link

asdf23 commented Apr 25, 2024

I'm not sure if this is related but it seems to be.
If I run playwright in a batch file the line after npx.. will not run:

echo PlayWright %DATE% %TIME% >> log.txt
npx playwright test
:: this will never run
echo Node %DATE% %TIME% >> log.txt
node index.js

Instead this will work

::batch1.bat
CALL batch2.bat
CALL batch3.bat
::batch2.bat
npx playwright test
::batch3.bat
node index.js

It's cumbersome, but I need this to work and move on. I believe this to be a bug with how playwright exits.

@0xIslamTaha
Copy link

yarn remove playwright
yarn create playwright
yarn install playwright

@Jordan466
Copy link

Just adding my 2c since I'm getting this as well.

My tests won't run in powershell or bash suddenly, but will run in command prompt.
Changing package managers and node versions changes nothing.

@skasimova
Copy link

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.

Thanks a lot!! It turned out to be my issue too

@daleyjem
Copy link

daleyjem commented Jul 4, 2024

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.

Playwright already registers it's own package.json bin attribute. Just yarn playwright test seemed to work for me.

@AngelTest2004
Copy link

I had the same issue. My solution is :
The playwright.config.ts defines testDir, update it. This makes sense to me.

@SritamKuRout
Copy link

SritamKuRout commented Oct 9, 2024

Hi when I am creating new spec.js file it is not running in the terminal but default files are executed on terminal using npx playwright test command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests