Skip to content

Commit

Permalink
chore: replace headful with headed (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Apr 1, 2021
1 parent c856c0e commit 8d36d47
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
16 changes: 9 additions & 7 deletions pytest_playwright/pytest_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions tests/test_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def test_slowmo(testdir: Any) -> None:
def test_slowmo(page):
start_time = monotonic()
email = "[email protected]"
page.goto("https://google.com")
page.type("input[name=q]", email)
page.set_content("<input type='text'/>")
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)


Expand Down Expand Up @@ -238,15 +238,15 @@ 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):
user_agent = page.evaluate("window.navigator.userAgent")
assert "HeadlessChrome" not in user_agent
"""
)
result = testdir.runpytest("--browser", "chromium", "--headful")
result = testdir.runpytest("--browser", "chromium", "--headed")
result.assert_outcomes(passed=1)


Expand Down

0 comments on commit 8d36d47

Please sign in to comment.