Playwright + Python · Lesson 36 of 37

0/37 done

Module 36: Playwright Configuration

36. Centralized Configuration, pytest.ini & Device Emulation

16 minlesson

Your task

Implement make_viewport_config(width=1920, height=1080):

  1. Return {"viewport": {"width": width, "height": height}}

Write it in the editor, then press Check answer (Ctrl + Enter).

Configuration in pytest.ini

ini
[pytest]
addopts = --base-url https://staging.targetqa.com --headed=false --tracing retain-on-failure
testpaths = tests

Mobile Device Emulation

python
def test_mobile_layout(playwright):
    iphone = playwright.devices["iPhone 14"]
    browser = playwright.chromium.launch()
    context = browser.new_context(**iphone)
    page = context.new_page()
    page.goto("https://targetqa.com")

Key Takeaways & Walkthrough Summary

Configuring test parameters in a centralized file keeps your test suites clean and portable. In this lesson, you will configure Base URLs, viewports, mobile device emulation, and default timeouts in Python. Let's configure our framework!

Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Can I emulate touch events in Playwright Python?

Yes! When using device emulation or setting has_touch=True in new_context, Playwright accurately simulates touch and mobile tap events.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip