Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.83 KB

README.md

File metadata and controls

44 lines (33 loc) · 1.83 KB

playwright-state-example

This example shows how to use Playwright's new browserContext.storageState() and corresponding browser.newContext({storageState}) functionality.

Basic state storage

This repo is appropriate for custom/advanced state storage (e.g. state merging). If you only need basic state storage, check out the docs for Reuse Authentication State.

Installation

This example uses features that are currently only available on the master branch of Playwright. For this code to work, you must manually install and build playwright in the playwright directory. E.g:

  1. git clone https://github.com/microsoft/playwright
  2. cd playwright
  3. npm install
  4. npm run build

Usage

Every time you run the script, you should notice the visit counter increasing. This is stored in LocalStorage by the page the Playwright accesses.

Rinogo:playwright-state-example rinogo$ node example.js 
You have been here...

LocalStorage: 10 time(s).
Rinogo:playwright-state-example rinogo$ node example.js 
You have been here...

LocalStorage: 11 time(s).
Rinogo:playwright-state-example rinogo$ node example.js 
You have been here...

LocalStorage: 12 time(s).

You can clear the saved state in the savedState file to see the counter reset:

Rinogo:playwright-state-example rinogo$ rm savedState 
Rinogo:playwright-state-example rinogo$ node example.js 
You have been here...

LocalStorage: 1 time(s).

Awesome

That's it. Thanks to the Playwright team for such a sweet tool. Now, go build something!