diff --git a/docs/out/cli.md b/docs/out/cli.md index 62f0333a38..2aef0fb687 100644 --- a/docs/out/cli.md +++ b/docs/out/cli.md @@ -39,6 +39,24 @@ Run `codegen` and perform actions in the browser. Playwright CLI will generate J +### Preserve authenticated state + +Run `codegen` with `--save-storage` to save [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) and [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) at the end. This is useful to separately record authentication step and reuse it later. + +```sh +$ npx playwright --save-storage=auth.json codegen +# Perform authentication and exit. +# auth.json will contain the storage state. +``` + +Run with `--load-storage` to consume previously loaded storage. This way, all [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) and [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) will be restored, bringing most web apps to the authenticated state. + +```sh +$ npx playwright --load-storage=auth.json open my.web.app +$ npx playwright --load-storage=auth.json codegen my.web.app +# Perform actions in authenticated state. +``` + ## Open pages With `open`, you can use Playwright bundled browsers to browse web pages. Playwright provides cross-platform WebKit builds that can be used to reproduce Safari rendering across Windows, Linux and macOS. diff --git a/docs/src/cli.md b/docs/src/cli.md index 7fca00b0ea..8f9c008fe4 100644 --- a/docs/src/cli.md +++ b/docs/src/cli.md @@ -32,6 +32,24 @@ Run `codegen` and perform actions in the browser. Playwright CLI will generate J +### Preserve authenticated state + +Run `codegen` with `--save-storage` to save [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) and [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) at the end. This is useful to separately record authentication step and reuse it later. + +```sh +$ npx playwright --save-storage=auth.json codegen +# Perform authentication and exit. +# auth.json will contain the storage state. +``` + +Run with `--load-storage` to consume previously loaded storage. This way, all [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) and [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) will be restored, bringing most web apps to the authenticated state. + +```sh +$ npx playwright --load-storage=auth.json open my.web.app +$ npx playwright --load-storage=auth.json codegen my.web.app +# Perform actions in authenticated state. +``` + ## Open pages With `open`, you can use Playwright bundled browsers to browse web pages. Playwright provides cross-platform WebKit builds that can be used to reproduce Safari rendering across Windows, Linux and macOS.