Header Ads

  • Breaking News

    Authentication in Playwright - full tutorial

    When running automation tests, repeatedly handling authentication can be both tedious and time-consuming. Playwright offers an efficient solution to streamline authentication. With Playwright, you can authenticate just once, save the authentication state, and reuse it across other tests. This means all tests can run in an authenticated state by default, saving time and simplifying your testing workflow. In the Playwright interview, this is also a frequently asked question. 

    I have created 3 detailed tutorials on authentication covering almost all the Playwright authentication topics. Please subscribe "Software Testing Tips and Tricks" Channel.  

    1. Basic: shared account in all tests
    2. Moderate: one account per parallel worker
    3. Advanced scenarios 
    First of all, the user needs to create a playwright/.auth directory inside the playwright directory. All the login-related states will be saved there. 

    1. Basic: shared account in all tests

    In this tutorial video I have covered -
    • Creating an Auth Directory: Discover how to set up a directory for storing authentication details. 
    • Creating a Setup File for Authentication: Learn how to configure a setup file to handle authentication for your tests. 
    • Modifying Your Project: See how to update your Playwright configuration file to include the authentication setup. 
    • Running Playwright with Authentication: Get hands-on examples of how to execute your tests with the shared authentication. 
    • UI Mode Authentication: Find out how to manage authentication in UI mode for interactive testing. 
    • Limitations of Basic Shared Authentication: Understand the limitations and considerations when using a shared account approach. 
    • Running Tests Without Authentication: Learn how to run specific tests without requiring authentication.


    2. Moderate: one account per parallel worker

    In this video, I have covered  - 

    • How to configure "Moderate" authentication? Live code.
    • When to use and when not to use moderate authentication? 
    • The difference between basic and moderate authentication.



    3. Advanced Scenarios 
    In this video, I have covered- 
    • Authenticate with API request - Instead of doing login from the UI and user can use APIs for login which is fast and reliable. 
    • It works the same was as login using UI in both Basic- shared accounts for all workers and Moderate: one account per parallel worker. 
    • Multiple signed-in roles - When more roles are possible like user and admin. In this case, we can create two authentications that can be used while running. Testing multiple roles together 
    • When a user has various roles that need to be used in a single test, then how to create context and use it. 
    • Testing multiple roles with POM fixtures.
    • How to define multiple roles in Pages and use it in tests? 
    • Avoid authentication in some tests - If some tests do not require login at all?



    • Playwright official document link on authentication. 
    • If you have any doubts or suggestions feel free to reach out on social media. Follow Us on RedditFacebook, and Twitter. Don't forget to subscribe to the channel -> Youtube channel. Thank You

    No comments

    Post Top Ad

    Post Bottom Ad