playwright 'no tests found.' on simple copy of example.spec.ts
Asked Answered
S

16

14

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 [email protected]
2 info using [email protected]
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 [email protected]
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?

Scheider answered 9/2, 2022 at 16:47 Comment(2)
Note, I can get this to work by renaming the test4.ts to test4.spec.ts - but what if I don't want this?Scheider
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.Connally
M
8

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.

Minnesota answered 10/2, 2022 at 14:1 Comment(3)
hmm... adding testMatch: /.*.ts/, doesn't seem to make a difference.Scheider
Could you explain the test, spec convention?Hungry
@Hungry #16802530Minnesota
A
8

I used forward slashes after launching terminal from vscode on windows laptop and it worked.

npx playwright test ./tests/example.spec.js
Allout answered 20/2, 2023 at 17:11 Comment(0)
M
2

On Windows, use

npx playwright test ./tests/whateverthetestdatasnameis.spec.js

instead of

npx playwright test .\tests\whateverthetestdatasnameis.spec.js
Mccaleb answered 5/10, 2023 at 14:6 Comment(0)
G
1

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)

Glanti answered 22/6, 2023 at 17:23 Comment(0)
H
0

Just replace \ with / and we are good to go.

Earlier:

npx playwright test .\tests\sample.spec.js

Now:

npx playwright test ./tests/sample.spec.js
Havildar answered 7/11, 2023 at 14:46 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Cattima
H
0

if your test has an error in it, say the wrong import path of a particular module, then it won't appear in the test list.

Hyacinthhyacintha answered 8/4, 2024 at 7:44 Comment(0)
V
0

My issue turned out to be that the web server that was being configured via the webServer property in playwright.config.ts was not starting up correctly. Before starting tests, Playwright pings the URL that is specified in webServer.url, and if the ping fails then the tests are not run.

Variety answered 8/7, 2024 at 12:45 Comment(0)
A
-1

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

Affixation answered 1/12, 2022 at 18:38 Comment(0)
W
-1

try using this on your playwright config file

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

Whiffen answered 23/1, 2023 at 9:38 Comment(0)
C
-1

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.

Contrariwise answered 24/1, 2023 at 9:17 Comment(0)
M
-1

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.

Macnamara answered 16/2, 2023 at 1:34 Comment(0)
F
-1

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: "../.",

Fosterfosterage answered 16/3, 2023 at 9:37 Comment(0)
A
-1

worked fine when I updated testDir: './tests' in the playwright.config.js. Ideally this should be exact folder name of your your tests are created.

Adali answered 11/9, 2023 at 16:17 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Cattima
S
-1

Make sure the that your file ends with .spec.js , my_test.spec.js Pass the full path: npx playwright test /full_path/my_test.spec.js

Skirting answered 13/1, 2024 at 3:18 Comment(0)
R
-1

I had the following situation. All my tests were working. But when I changed from deconstruction the arguments to just object direct access the tests disappeared.

Oh and loginPage and tenantManagementPage are playwright fixtures.

It took me some time to figure out this is the reason. I hope it helps other people as well.

Works

test('setup initial data', async ({
        loginPage,
        tenantManagementPage,
    }) => {
    loginPage.someMethod(),
    tenantManagementPage.someMethod(),
// rest of the test

Doesn't work

test('setup initial data', async (props) => {
    props.loginPage.someMethod(),
    props.tenantManagementPage.someMethod(),
// rest of the test
Ramayana answered 13/3, 2024 at 8:1 Comment(0)
H
-1

you might wanna check your project block in config file, here is mine and its working good

{
  name: 'test',
  testDir: '../tests/',
  testMatch: "test.spec.ts",
},
Hyden answered 25/6, 2024 at 7:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.