126 文字
1 分

Playwrightでセッションを再利用する

2022-10-04

次のようなコマンドを入力して実行し終了すると、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://...");
//...
});
Playwrightでセッションを再利用する
https://blog.ohirunewani.com/posts/playwright-reuse-session/
作者
hrdtbs
公開日
2022-10-04
ライセンス
CC BY-NC-SA 4.0