Skip to content

rinogo/playwright-state-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published