9

I have just installed playwright (v1.18.1) to try it out (Windows 11) and I feel like something is wrong. I can run the example.spec.ts script fine, but if I copy that file and then try to run the copy then I get a no tests found. error.

The steps seem very basic...

First test run the C:\playwright\test\tests\example.spec.ts script....

C:\playwright\test\tests>npx playwright test example.spec.ts

Running 25 tests using 1 worker

  -  example.spec.ts:14:3 › New Todo › should allow me to add todo items
Terminate batch job (Y/N)?

  25 skipped

[that worked so] then create a copy to start playing...

C:\playwright\test\tests>copy example.spec.ts test4.ts
        1 file(s) copied.

but before editing test4.ts I check it will run...

C:\playwright\test\tests>npx playwright test test4.ts

=================
 no tests found.
=================
npm ERR! code 1
npm ERR! path C:\playwright\test\tests
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c playwright test test4.ts

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\xxxxx\AppData\Local\npm-cache\_logs\2022-02-09T16_29_19_723Z-debug.log

If it helps the log reads:

C:\playwright\test\tests>type C:\Users\xxxxx\AppData\Local\npm-cache\_logs\2022-02-09T16_37_46_149Z-debug.log
0 verbose cli [
0 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
0 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
0 verbose cli   'exec',
0 verbose cli   '--',
0 verbose cli   'playwright',
0 verbose cli   '-version'
0 verbose cli ]
1 info using npm@7.0.15
2 info using node@v15.4.0
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:C:\Program Files\nodejs\node_modules\npm\npmrc Completed in 1ms
5 timing config:load:builtin Completed in 2ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:C:\playwright\test\.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:C:\Users\xxxxx\.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:C:\Users\xxxxx\AppData\Roaming\npm\etc\npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 7ms
19 verbose npm-session c0bee43e8701d230
20 timing npm:load Completed in 16ms
21 timing command:exec Completed in 633ms
22 verbose stack Error: command failed
22 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\promise-spawn\index.js:64:27)
22 verbose stack     at ChildProcess.emit (node:events:376:20)
22 verbose stack     at maybeClose (node:internal/child_process:1063:16)
22 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:295:5)
23 verbose pkgid test@1.0.0
24 verbose cwd C:\playwright\test\tests
25 verbose Windows_NT 10.0.22000
26 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "exec" "--" "playwright" "-version"
27 verbose node v15.4.0
28 verbose npm  v7.0.15
29 error code 1
30 error path C:\playwright\test\tests
31 error command failed
32 error command C:\WINDOWS\system32\cmd.exe /d /s /c playwright -version
33 verbose exit 1

Why is it giving me an error when it is just a copy of an original that does work?

hardkoded
  • 18,915
  • 3
  • 52
  • 64
user1432181
  • 918
  • 1
  • 9
  • 24
  • 1
    Note, I can get this to work by renaming the `test4.ts` to `test4.spec.ts` - but what if I don't want this? – user1432181 Feb 09 '22 at 17:28
  • Make sure `testDir` is set to the folder where you're storing your tests (as it may vary according to your needs and the default configuration playwright provides). It doesn't matter if you fully reference the test you want to execute, it'll anyway fail because of that. – Sebastián Palma Jun 11 '23 at 12:56

8 Answers8

5

You can set up your own test match regex in the playwright test config.
By default, Playwright Test looks for files matching .*(test|spec)\.(js|ts|mjs), but you can run any js file by doing this:

import { PlaywrightTestConfig, devices } from '@playwright/test';

const config: PlaywrightTestConfig = {
  testMatch: /.*\.js/,
};
export default config;

Keep in mind that it would try to load tests from any helper file you have in your folder. I think that following the test or spec convention is a good thing.

hardkoded
  • 18,915
  • 3
  • 52
  • 64
2

Even I was facing this problem. I used forward slashes after launching terminal from vscode on windows laptop and it worked. npx playwright test ./tests/example.spec.js

0

make sure you did not add "test.only"

like that "test.only('test assertion', async({page}) => { "

because your runner not sees any test except this test

if you try to run a test that take ".only" will run

0

try using this on your playwright config file

testMatch: ["**/*.js"],

raja
  • 13
  • 1
0

The test.describe and test() description must be different.

Your original file has spec.ts Copied file is .ts Rename copied file to test4.spec.ts or add an appropriate testmatch to your config file.

Michael Pratt
  • 3,438
  • 1
  • 17
  • 31
BMar cg
  • 13
  • 4
0

Example: File name: ...spec.js or ts Config file: testMatch: '*.spec.js', (or ts)

Not for sure why the file has to be postfixed with spec yet. Probably a config requirement.

0

My problem was that the file was inside a folder inside the playwright folder, this fixed it (in typescript):

 const config: PlaywrightTestConfig = {
   testDir: "../../playwright",
   // more configs
   };
 export default config;

I guess you I could also write testDir: "../.",

Chen Peleg
  • 953
  • 10
  • 16
0

I was using npm init playwright@latest and the default configuration.

For me, the solution was just SEE the specific path of my tests.

If you are using the default configuration, you must modify your playwright.config.js.

From: testDir: './e2e', (Default config)

To: testDir: './tests', (Your test folder)