Microsoft VS --> Playwright --> execution inside the example.spec.ts file works, but if I want to do it from the terminal via "npx playwright test" I always get Error: No tests found
.
Even if I try it with the exact path tests/example.spec.js .
Error: Playwright Test did not expect test.describe() to be called here.
Most mon 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 dependencies in your package.json depends on @playwright/test.
at example.spec.js:7
5 | // 2. Group tests together using a describe block
6 | test.describe('IMDB:', () => {
> 7 | // 3. Use test block to define executable code necessary to implement the test
| ^
8 | // 4. Here is a '{ page }' that the test above has access to
9 | test('verify search functionality', async ({ page }) => {
10 | // 5. Define test data
at TestTypeImpl._currentSuite (/Users/myname/Desktop/TS:Playwright:Cucumber/node_modules/@playwright/test/lib/mon/testType.js:69:13)
at TestTypeImpl._describe (/Users/myname/Desktop/TS:Playwright:Cucumber/node_modules/@playwright/test/lib/mon/testType.js:87:24)
at Function.describe (/Users/myname/Desktop/TS:Playwright:Cucumber/node_modules/@playwright/test/lib/transform/transform.js:235:12)
at Object.<anonymous> (/Users/myname/Desktop/TS:Playwright:Cucumber/tests/example.spec.js:7:12)
Error: No tests found
This is my config file:
import type { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
projects: [
{
name: 'Chrome Stable',
use: {
browserName: 'chromium',
channel: 'chrome',
},
},
],
};
export default config;
How to resolve this?
- Microsoft VS is up to date
- Closed and reopened VS after playwright installation
- Deleted the whole project folder and created again with fresh playwright installation several times
- Tried to insert testDir: '/Users/myname/Desktop/TS:Playwright:Cucumber' into the config file, also didn't help
Example of a feature/scenario:
import { test, expect } from '@playwright/test';
const { chromium } = require('playwright');
test.describe('Login:', () => {
test('verify successful login functionality', async ({}) => {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('xxx');
await page.getByRole('banner').getByRole('button', { name: 'Login' }).click();
await page.getByLabel('Username').click();
await page.getByLabel('Username').fill('xxx');
await page.getByLabel('Password').click();
await page.getByLabel('Password').fill('xxxx');
await page.getByRole('button', { name: 'Log In' }).click({ force: true });
// 8. Assert search result
expect(await page.getByRole('heading', { name: 'Multi-factor authentication' })).toBeVisible;
browser.close();
});
});
File hierarchy
Microsoft VS --> Playwright --> execution inside the example.spec.ts file works, but if I want to do it from the terminal via "npx playwright test" I always get Error: No tests found
.
Even if I try it with the exact path tests/example.spec.js .
Error: Playwright Test did not expect test.describe() to be called here.
Most mon 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 dependencies in your package.json depends on @playwright/test.
at example.spec.js:7
5 | // 2. Group tests together using a describe block
6 | test.describe('IMDB:', () => {
> 7 | // 3. Use test block to define executable code necessary to implement the test
| ^
8 | // 4. Here is a '{ page }' that the test above has access to
9 | test('verify search functionality', async ({ page }) => {
10 | // 5. Define test data
at TestTypeImpl._currentSuite (/Users/myname/Desktop/TS:Playwright:Cucumber/node_modules/@playwright/test/lib/mon/testType.js:69:13)
at TestTypeImpl._describe (/Users/myname/Desktop/TS:Playwright:Cucumber/node_modules/@playwright/test/lib/mon/testType.js:87:24)
at Function.describe (/Users/myname/Desktop/TS:Playwright:Cucumber/node_modules/@playwright/test/lib/transform/transform.js:235:12)
at Object.<anonymous> (/Users/myname/Desktop/TS:Playwright:Cucumber/tests/example.spec.js:7:12)
Error: No tests found
This is my config file:
import type { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
projects: [
{
name: 'Chrome Stable',
use: {
browserName: 'chromium',
channel: 'chrome',
},
},
],
};
export default config;
How to resolve this?
- Microsoft VS is up to date
- Closed and reopened VS after playwright installation
- Deleted the whole project folder and created again with fresh playwright installation several times
- Tried to insert testDir: '/Users/myname/Desktop/TS:Playwright:Cucumber' into the config file, also didn't help
Example of a feature/scenario:
import { test, expect } from '@playwright/test';
const { chromium } = require('playwright');
test.describe('Login:', () => {
test('verify successful login functionality', async ({}) => {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('xxx');
await page.getByRole('banner').getByRole('button', { name: 'Login' }).click();
await page.getByLabel('Username').click();
await page.getByLabel('Username').fill('xxx');
await page.getByLabel('Password').click();
await page.getByLabel('Password').fill('xxxx');
await page.getByRole('button', { name: 'Log In' }).click({ force: true });
// 8. Assert search result
expect(await page.getByRole('heading', { name: 'Multi-factor authentication' })).toBeVisible;
browser.close();
});
});
File hierarchy
Share Improve this question edited Feb 9 at 21:44 desertnaut 60.5k32 gold badges155 silver badges181 bronze badges asked Sep 4, 2023 at 11:24 N KN K 311 gold badge1 silver badge3 bronze badges 7-
Is
example.spec.js
a test file that you haven't shown? If so, please share it, along with the paths and contents of all of your files in the project and your package.json. The first step is to ensure all 3 of the suggestions in "Most mon reasons include:" are false for your case. Very likely, one of those 3 things applies to your case and it's a matter of figuring out which. But as the question stands, there aren't enough details to make that determination. – ggorlen Commented Sep 4, 2023 at 11:50 -
Hey @ggorlen, thanks for your reply, much appreciated! Unfortunately I can not share my test scenario (example.spec.ts) because there are too many characters for this ment box :/ My package.json though is possible:
{ "description": "", "devDependencies": { "@playwright/test": "^1.37.1", "playwright": "^1.37.1" }, "scripts": {} }
– N K Commented Sep 4, 2023 at 14:48 -
Please create a minimal reproducible example as an edit to your post. Thanks. Based on your package.json alone, do you need to have playwright in there? I would try it with just
@playwright/test
, at least temporarily, to help ensure suggestion #3 doesn't apply. You might try removing node_modules and reinstalling everything fresh, in case it's out of sync with the package.json, again looking to see if #3 applies. – ggorlen Commented Sep 4, 2023 at 14:49 - @ggorlen I edited now my post, thanks for this hint! I think I need playwright yes because of the browser.close() mand afaik. I did install everything fresh from scratch already multiple times, unfortunately it didnt help. – N K Commented Sep 4, 2023 at 15:01
- I mean I deleted the project folder and installed Playwright from scratch multiple times - but I didnt try to do it with MS VS as a whole, maybe I have to try this. – N K Commented Sep 4, 2023 at 15:02
4 Answers
Reset to default 1I've had this happen to be me, and it was because when I CD'd into the code directory in my terminal, I used the wrong case. This shouldn't matter on Windows, but for some reason, it does.
So this would cause a fail:
cd C:\dev\project-name
npx playwright test
and this would work:
cd C:\Dev\project-name
npx playwright test
If I look in Windows Explorer, the folder name is "Dev" not "dev"
Check your playwright version in the package.json file.
Then run these mands: These remove the node_modules folder and reinstall the dependencies to get the correct version of Playwright.
rm -rf node_modules package-lock.json
npm install
After reinstalling, confirm that the correct version is installed:
npm ls @playwright/test
Then run your test again.
In the config file, you need to define the path for your tests. And should be specified under 'testDir:'. This path should be relative to this configuration file.
Refer to the below playwright documentation: https://playwright.dev/docs/test-configuration
I was facing the same issue with playwright version 1.48
My fix was:
npm uninstall playwright
npm install -D @playwright/test