I'm new to playwright and trying to reuse the signed-in but i always end with storageState.json file empty
I added this code to playwright.config.ts
globalSetup: require.resolve('./utils/global-config.ts'),
And my global file is
import { chromium, expect } from "@playwright/test"
async function globalConfig() {
const browser = await chromium.launch()
const page = await browser.newPage()
await page.goto('https://qacart-todo.herokuapp.com/login');
await page.locator("#login").fill("hatem@example.com")
await page.locator('//input[@data-testid="password"]').fill("123456")
await page.locator('button:has-text("login")').click();
await expect(page.locator('[data-testid="welcome"]')).toBeVisible
await page.context().storageState({ path: 'storageState.json'});
}
export default globalConfig
And the test case
import { test, expect } from '@playwright/test';
test.describe("todo page test cases", async()=> {
// test.use({
// storageState: 'storageState.json' })
test.beforeEach(async({page})=> {
await page.goto('https://qacart-todo.herokuapp.com/login');
await page.locator("#login").fill("hatem@example.com")
await page.locator('//input[@data-testid="password"]').fill("123456")
await page.locator('button:has-text("login")').click();
})
test("mark a todo as completed", async({page}) => {
await page.locator('[data-testid="add"]').click()
await page.locator('[data-testid="new-todo"]').fill('My First Automation To DO')
await page.locator('[data-testid="submit-newTask"]').click()
await page.locator('[data-testid="complete-task"]').nth(0).click()
await expect(page.locator('[data-testid="todo-item"]').nth(0)).toHaveCSS('background-color', 'rgb(33, 76, 97)')
})
test("welcome message displayed", async({page}) => {
await expect(page.locator('[data-testid="welcome"]')).toBeVisible()
})
})