Playwrightでセッションを再利用する
次のようなコマンドを入力して実行し終了すると、Cookie や Local storage を state.json に保存してくれる
playwright --save-storage=auth.json例えば、次のようなコマンドで目的のサイトを開いてログインしてからブラウザを閉じる
npx playwright open "https://..." --save-storage=auth.jsonコマンドから再利用する場合は次のようにする。
npx playwright --load-storage=auth.jsonコードから再利用する場合は次のようにする。
import { test } from "@playwright/test";
test.use({ storageState: "auth.json",});
test("auth", async ({ page }) => { await page.goto("https://..."); //...});