question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Does it possible to limit storageState/use to the test describe block?

See original GitHub issue

Edit 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:closed
  • Created a year ago
  • Reactions:2
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mxschmittcommented, Sep 15, 2022

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:

  • Stop VSCode or Click Close all browsers in the testing tab
  • Install the next dev version via npm i -D @playwright/test@next
  • Run tests again

After that it was working for me. Sorry for the inconvenience.

1reaction
mxschmittcommented, Sep 15, 2022

Could you try how it behaves with npm install -D @playwright/test@next?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found