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 opened a new worker for the second test suite, I realized that auth cookie wasn't set to the browser. Is that possible, or not?