From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Reuse auth state

Reuse auth state

Now that we have saved our authentication state into a json file like this, we can reuse it when we create a new context and have our authentication state. So we'll go ahead and remove the saving state line. We'll remove the login code as well. And then we'll just keep the account visiting or the navigation code. And to actually load in or reuse our storage state, when we create this new context right here, we'll provide it the storage state using the storage state keyword argument, and then a string with the path to the same that is playwright slash dot auth slash storage state json like this. Now whenever it will go ahead and try to create a new browser context, it will find the already saved context or the state and load in into this context right here. And when we try to create a new page using this context, it will have our Google account data. So when we try to visit our accounts, Google, we will be logged in already. So let's go ahead and just visit to this page and pause the…

Contents