From 8d36d47b5e1b662436c0ad97fa232160f3a53ea7 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 1 Apr 2021 20:11:29 +0200 Subject: [PATCH] chore: replace headful with headed (#48) --- README.md | 8 ++++---- pytest_playwright/pytest_playwright.py | 16 +++++++++------- tests/test_playwright.py | 10 +++++----- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4ef2c2a..72990e6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Write end-to-end tests for your web apps with [Playwright](https://github.com/microsoft/playwright-python) and [pytest](https://docs.pytest.org/en/stable/). - Support for **all modern browsers** including Chromium, WebKit and Firefox. -- Support for **headless and headful** execution. +- Support for **headless and headed** execution. - **Built-in fixtures** that provide browser primitives to test functions. ## Usage @@ -27,8 +27,8 @@ To run your tests, use pytest CLI. # Run tests (Chromium and headless by default) pytest -# Run tests in headful mode -pytest --headful +# Run tests in headed mode +pytest --headed # Run tests in a different browser (chromium, firefox, webkit) pytest --browser firefox @@ -43,7 +43,7 @@ If you want to add the CLI arguments automatically without specifying them, you # content of pytest.ini [pytest] # Run firefox with UI -addopts = --headful --browser firefox +addopts = --headed --browser firefox ``` ## Fixtures diff --git a/pytest_playwright/pytest_playwright.py b/pytest_playwright/pytest_playwright.py index c52aa8e..8630628 100644 --- a/pytest_playwright/pytest_playwright.py +++ b/pytest_playwright/pytest_playwright.py @@ -109,16 +109,18 @@ def launch_browser( browser_name: str, ) -> Callable[..., Browser]: def launch(**kwargs: Dict) -> Browser: - headful_option = pytestconfig.getoption("--headful") - slowmo_option = pytestconfig.getoption("--slowmo") - browser_channel_option = pytestconfig.getoption("--browser-channel") launch_options = {**browser_type_launch_args, **kwargs} + + headed_option = pytestconfig.getoption("--headed") + if headed_option: + launch_options["headless"] = False + browser_channel_option = pytestconfig.getoption("--browser-channel") if browser_channel_option: launch_options["channel"] = browser_channel_option - if headful_option: - launch_options["headless"] = False + slowmo_option = pytestconfig.getoption("--slowmo") if slowmo_option: launch_options["slow_mo"] = slowmo_option + browser = getattr(playwright, browser_name).launch(**launch_options) return browser @@ -195,10 +197,10 @@ def pytest_addoption(parser: Any) -> None: help="Browser engine which should be used", ) group.addoption( - "--headful", + "--headed", action="store_true", default=False, - help="Run tests in headful mode.", + help="Run tests in headed mode.", ) group.addoption( "--browser-channel", diff --git a/tests/test_playwright.py b/tests/test_playwright.py index 78cffe2..995af67 100644 --- a/tests/test_playwright.py +++ b/tests/test_playwright.py @@ -42,13 +42,13 @@ def test_slowmo(testdir: Any) -> None: def test_slowmo(page): start_time = monotonic() email = "test@test.com" - page.goto("https://google.com") - page.type("input[name=q]", email) + page.set_content("") + page.type("input", email) end_time = monotonic() assert end_time - start_time >= len(email) """ ) - result = testdir.runpytest("--browser", "chromium", "--slowmo", "1000", "--headful") + result = testdir.runpytest("--browser", "chromium", "--slowmo", "1000", "--headed") result.assert_outcomes(passed=1) @@ -238,7 +238,7 @@ def test_without_browser(): assert "test_without_browser PASSED" in "\n".join(result.outlines) -def test_headful(testdir: Any) -> None: +def test_headed(testdir: Any) -> None: testdir.makepyfile( """ def test_base_url(page, browser_name): @@ -246,7 +246,7 @@ def test_base_url(page, browser_name): assert "HeadlessChrome" not in user_agent """ ) - result = testdir.runpytest("--browser", "chromium", "--headful") + result = testdir.runpytest("--browser", "chromium", "--headed") result.assert_outcomes(passed=1)