Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Box test steps are causing an error in my Playwright test

I have the following code

import { test, expect,Page } from '@playwright/test';

async function addAndViewCart(page: Page){
await page.getByRole('menuitem', { name: 'Women' }).hover();
await page.getByRole('menuitem', { name: 'Tops' }).hover();
await page.getByRole('menuitem', { name: 'Jackets' }).click();
await page.getByLabel('Items').getByText('Jackets').isVisible();
await page.locator('li').filter({ hasText: 'Olivia 1/4 Zip Light Jacket' }).getByLabel('M', { exact: true }).click();
await page.locator('li').filter({ hasText: 'Olivia 1/4 Zip Light Jacket' }).getByLabel('Purple').click();
await page.locator('li').filter({ hasText: 'Olivia 1/4 Zip Light Jacket' }).locator('button').click();}

test('testing', async ({ page }) => {

await page.goto("https://www.website.com/");

await expect(page).toHaveURL("https://www.website.com/");
await addAndViewCart(page);


});

What i did is define a function addAndViewCart for certain steps that later i can use in my test cases without having to write them every time.

The issue i am having is when i run the test i get an error "No test found". How can i avoid this ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The "No tests found" error in Playwright can occur due to several reasons. Here are some solutions you could try:

  1. Directory Structure: Playwright expects the test files to be in a specific location, i.e., directories with the name tests or __tests__. If your test files are located elsewhere and you haven’t configured Playwright to look into that directory, it will not find them.

  2. File Naming Convention: Test files are recognized by their name endings, such as .spec.js, .test.js, etc. If your test files do not follow this naming convention, they will not be recognized.

  3. Empty Test Files: If your test files are empty with no test cases, or you have commented or skipped the test cases in those files, then Playwright will throw the "No tests found" error.

  4. Misconfigurations: If you have set up the Playwright configuration file (like playwright.config.js) in a way that does not include your test files, then an error may occur. This can be due to misconfigured file paths, patterns, or other settings.

  5. Test Filters: If you are using command line arguments or configuration settings to set a filter on tests to run and all of your tests are excluded due to this filter, then you will get this error.

  6. Incorrect Test Syntax: If the syntax in your test files is incorrect, or if you are using a test structure that Playwright does not recognize, you will receive the "No tests found" error.

  7. Version Issues/Corrupted Installation: If there is a mismatch between Playwright versions or if the current installation gets corrupted somehow, then it can lead to unexpected behavior of Playwright.

In your case, please ensure that your test file follows the correct naming convention (e.g., foobar.spec.js or foobar.spec.ts). Also, try updating your Playwright version to the latest. If none of these solutions work, try completely closing VSCode and reopening it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading