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.

Device emulation

Device emulation

In this lesson, we'll learn how to emulate devices and different properties in PlayWrite. By default, the browser acts as a desktop browser, but I would like to emulate a Pixel 5 that is a mobile, we can do that using the browser context and its different options. To get the options for the pixel 5 device, we can use the playwrights devices property. It gives us a dictionary of all the devices and their options. We can access the pixel 5 options like this. It will give us a dictionary of the pixel 5 device. Now we can provide this after unpacking the same to our new context method. Now our browser context will emulate the pixel 5 device. So if I go ahead and run the script, you can see it emulates the pixel 5 device. Now the options which this device controls or specifies is something like whether or not this is a mobile it sets to true has touch through that and you can also set the viewport using the viewport argument so let's go ahead and use the same let's say what we want to do…

Contents