[Question] Does it possible to limit storageState/use to the test describe block?
See original GitHub issueEdit from maintainers
If you experience issues, make sure to follow https://github.com/microsoft/playwright/issues/17337#issuecomment-1248608637. This should fix issues. If not, please file a new issue.
Hi folks!
I am working on storageState/use for a one-time authentication strategy, the problem is that storageState is not reflected on the page on each test suite while limiting a storageState to a test describe block.
import { faker } from "@faker-js/faker";
import { test, expect } from "@playwright/test";
import TestHelper from "../helpers";
test.describe("Admin Test - Group Manage:", () => {
  test.use({ storageState: TestHelper.storageStateByRole("admin") });
  test.beforeEach(async ({ page }) => {
    await page.goto("/groups/create", { waitUntil: "networkidle" });
    await expect(page).toHaveURL(/.*groups\/create/);
  });
  test("Admin user should access to the group create screen", async ({
    page,
  }) => {
    const titleSelector = '[aria-label="breadcrumb"] >> text=Create Group';
    await test.expect((await page.locator(titleSelector)).count()).toEqual(1);
  });
  test("Admin user can create & delete a group", async ({ page }) => {
    const groupName = faker.commerce.productName();
    const groupDescription = faker.commerce.productDescription();
    // Fill group title
    await page.locator('input[type="text"]').fill(groupName);
    // Fill group description textarea
    await page.locator("textarea").first().fill(groupDescription);
    // Save group information
    await page.locator('button:has-text("Save Changes")').click();
    await expect(page).toHaveURL(/.*groups/);
    const rowSelector = `div[role="row"]:has-text("${groupName}")`;
    await page.waitForSelector(rowSelector);
    await expect(await page.locator(rowSelector).count()).toEqual(1);
    const newGroupRow = await page.locator(rowSelector);
    await expect(newGroupRow).toContainText(groupName);
    await expect(newGroupRow).toContainText(groupDescription);
    // Remove created Group
    await page
      .locator(`div[role="row"]:has-text("${groupName}") >> button`)
      .nth(1)
      .click();
    await page.locator("text=Confirm").click();
    await expect(await page.locator(rowSelector).count()).toEqual(0);
  });
});
I confirmed that testing the first suite works correctly, but the playwright open a new worker for the second test suite, I realized that auth cookie wasn’t set to the browser. Is that possible, or not?
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:10 (4 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
Is it possible to limit storageState/use to the test describe block ...
I am working on storageState/use for a one-time authentication strategy, the problem is that storageState is not reflected on the page on ...
Read more >How many 'it' can we define inside a describe block?
I am using Protractor for e2e testing. I want to know, How many 'it' we can define inside a 'describe block' in a...
Read more >Test-Taking Strategies – Common Questions
Examine opposites carefully: one is definitely incorrect, and one is likely to be correct. • Explain answers in the margins, especially when you...
Read more >Improving Your Test Questions
Essay exams limit the extent of content covered. T, F ? 8. Essay and objective exams can be used to measure the same...
Read more >Constructing tests - Center for Teaching and Learning
Designing tests is an important part of assessing students understanding of course content and their level of competency in applying what they are...
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

I was able to reproduce it in 1.25.2 but its fixed in 1.26 which we release soon. To benefit today from the fix to the following:
Close all browsersin the testing tabnpm i -D @playwright/test@nextAfter that it was working for me. Sorry for the inconvenience.
Could you try how it behaves with
npm install -D @playwright/test@next?