Rayrun
← Back to Discord Forum

more than 1 describe in a test file

I created a single test file for the functionality of one page, Im using Page Object Model and used 3 different describe blocks for different sections of the page in the one file.

When running the tests the first describe block runs as expected but then each describe block after that fails to login.

When i run each describe block individually they all pass.

I'm not sure if this is an issue with playwright or an issue with how i have written the tests. Any help would be appreciated

This thread is trying to answer question "Why do subsequent 'describe' blocks fail to login in a single test file using the Page Object Model?"

17 replies

Hi, I have the same issue, I get these kind of errors: ration file., - You are calling ${title} 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.`].join('\n')); ^

Error: Playwright Test did not expect test() to be called here. Most common reasons include:

  • You are calling test() in a configuration file.
  • You are calling test() 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.

So i get an error on the assertion cause it didn't use the storage state and log in, but when i run each describe block independantly it works as expected

for me it is I am just trying to call the test with .only but inside teh test file I have to .describe blocks

and even with .only I get the same error

I did not try to remove the 2nd desc. block to another file, I guess then it would work, as till now I tried to comment out one describe block, then the test went through

was the new release today?

or was it this week?

I will just give it a try to delete node modules and reinstall them again,

can you post on what error do you get, or do you get any error message?

hmm for me, the issue I found is, I had some attributes outside the test block and I was trying to sue them inside it, and that's why I got the error that I sent

I removed them back to the test case block and now it looks fine

I have the goto(/) within the beforeEach hook

Here is an example of one of them test.beforeEach(async ({ page }) => { await page.goto("/"); await expect(page.getByRole("button", { name: "autotest" })).toBeVisible(); const dashboard = new dashboardPage(page); await dashboard.organizationDropDown.click(); await dashboard.selectOrganization.click(); await page.locator(".MuiPopover-root > div").first().click(); const closeNotificationBox = await page.$('div:has-text("View") >> svg'); if (closeNotificationBox != null) { await closeNotificationBox.click(); } });

test.afterEach(async ({ page }) => { await page.close() })

Im using the same beforeEach/afterEach for each describe block

After more digging its like the following describe blocks are not using the storage state, The first describe block uses it no problem but after the first describe block its not using the storage state

What happens if your remove the page.close() in the after each block? Still have an issue?

Still same issue

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].