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.

Save authentication state

Save authentication state

In the previous lesson, we learned how can we fill input fields and login to our Google account. But, we encountered a problem that is if our account requires manual interaction for things like two-step authentication, then it will be a problem to do that for every time we have to run our script and login to our website. That's why in this lesson, we'll learn how to save our authentication slash login state and reuse it whenever we run our playwright scripts. So let's go ahead and do the things which we just did in the previous lesson. I'll start by launching the Firefox browser. So playwright Firefox driver, launch it in the headless mode. And that will be false, slow-mo let's say by 500 times. And then instead of creating a page directly, I will go ahead and create a browser context using the browser's new context method. This browser context will allow us to store the authentication state and save it when we have performed our login. So let's go ahead and store it in a context…

Contents