Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Playwright start maximized window

I have a problem starting Playwright in Python maximized. I found some articles for other languages but doesn't work in Python, also nothing is written about maximizing window in Python in the official documentation.

I tried browser = p.chromium.launch(headless=False, args=["--start-maximized"])

And it starts maximized but then automatically restores back to the default small window size.

Any ideas? Thanks

like image 365
bbfl Avatar asked Aug 31 '26 00:08

bbfl


1 Answers

I'm using playwright and pytest-playwright.

def test_foo(playwright):
    browser = playwright.chromium.launch(headless=False, args=["--start-maximized"])
    # create a new incognito browser context.
    context = browser.new_context(no_viewport=True)
    # create a new page in a pristine context.
    page = context.new_page()
    page.goto("https://example.com")

Run tests with pytest ., no need to specify the browser and headless params. With new_context it won't share cookies/cache with other browser contexts so we get separation of test runs

like image 157
Bartek Skwira Avatar answered Sep 02 '26 13:09

Bartek Skwira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!