我试图确保在每个运行的测试中,我不必登录到我正在测试的平台。为了实现这一目标,我正在实施“重用状态”和“重用身份验证”。但是,Firebase 使用 indexedDB 而不是 Cookie 或 SessionStorage。StorageState 此处不持久保存 indexedDB。也许你知道这个问题的解决方案?
全局设置.ts:
import { Browser, chromium, expect, Page } from "@playwright/test";
async function globalSetup(){
const browser = await chromium.launch({headless: false});
const context = await browser.newContext();
const page: Page = await context.newPage();
await page.goto("<'url'>")
await page.getByLabel('Email').fill('<'email'>');
await page.getByLabel('Password').fill('<'password'>');
await page.getByRole('button', { name: 'Sign in' }).click();
await expect (page.getByRole('link', { name: 'logo' })).toBeVisible({ timeout: 30000 });
//save state
await page.context().storageState({ path: "./LoginAuth.json" });
await browser.close();
}
export default globalSetup;
Run Code Online (Sandbox Code Playgroud)
有用的链接:
https://playwright.dev/docs/auth#reuse-authentication-in-playwright-test https://github.com/microsoft/playwright/issues/11164