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.

Asynchronous Playwright

Asynchronous Playwright

In the previous lesson, we learned about the difference between synchronous and asynchronous programming. In this lesson, we'll go ahead and implement the same using the Playwrights Async API. So first of all, we need to import the AsyncIO module, which enables us to run asynchronous code. we'll go ahead and import the async MPI from playwright. So async playwright. Now, because we want to execute or write some asynchronous code, we'll have to do that inside of a asynchronous function. And to do that, we'll start with a normal function definition like this. And then to mark it as asynchronous we just go ahead and prefix it with the async keyword like this now we can go ahead and write our async code and that will start with defining a with context manager for our async playwright so with async playwright as playwright we'll go ahead and create a block of code. Now because we'll perform some asynchronous code in this indented block, we need to mark our with context manager async as…

Contents