Skip to content

Commit

Permalink
chore: upgrade to new Playwright with snake case (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Jan 21, 2021
1 parent fd3960e commit b1bb438
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Use the `page` fixture to write a basic test. See [more examples](#examples).
```py
def test_example_is_working(page):
page.goto("https://example.com")
assert page.innerText('h1') == 'Example Domain'
assert page.inner_text('h1') == 'Example Domain'
page.click("text=More information")
```

Expand All @@ -44,7 +44,6 @@ If you want to add the CLI arguments automatically without specifying them, you
[pytest]
# Run firefox with UI
addopts = --headful --browser firefox

```

## Fixtures
Expand All @@ -59,8 +58,8 @@ def test_my_app_is_working(fixture_name):

**Function scope**: These fixtures are created when requested in a test function and destroyed when the test ends.

- `context`: New [browser context](https://playwright.dev/#path=docs%2Fcore-concepts.md&q=browser-contexts) for a test.
- `page`: New [browser page](https://playwright.dev/#path=docs%2Fcore-concepts.md&q=pages-and-frames) for a test.
- `context`: New [browser context](https://playwright.dev/python/docs/core-concepts#browser-contexts) for a test.
- `page`: New [browser page](https://playwright.dev/python/docs/core-concepts#pages-and-frames) for a test.

**Session scope**: These fixtures are created when requested in a test function and destroyed when all tests end.

Expand All @@ -70,8 +69,8 @@ def test_my_app_is_working(fixture_name):

**Customizing fixture options**: For `browser` and `context` fixtures, use the the following fixtures to define custom launch options.

- `browser_type_launch_args`: Override launch arguments for [`browserType.launch()`](https://playwright.dev/#path=docs%2Fapi.md&q=browsertypelaunchoptions). It should return a Dict.
- `browser_context_args`: Override the options for [`browser.newContext()`](https://playwright.dev/#path=docs%2Fapi.md&q=browsernewcontextoptions). It should return a Dict.
- `browser_type_launch_args`: Override launch arguments for [`browserType.launch()`](https://playwright.dev/python/docs/api/class-browsertype#browser_typelaunchoptions). It should return a Dict.
- `browser_context_args`: Override the options for [`browser.new_context()`](https://playwright.dev/python/docs/api/class-browser#browsernew_contextoptions). It should return a Dict.

## Examples

Expand Down Expand Up @@ -132,7 +131,7 @@ import pytest
def browser_context_args(browser_context_args):
return {
**browser_context_args,
"ignoreHTTPSErrors": True
"ignore_https_errors": True
}
```

Expand Down Expand Up @@ -205,7 +204,7 @@ def pytest_runtest_makereport(item, call) -> None:

## Deploy to CI

Use the [Playwright GitHub Action](https://github.com/microsoft/playwright-github-action) or [guides for other CI providers](https://playwright.dev/#path=docs%2Fci.md&q=) to deploy your tests to CI/CD
Use the [Playwright GitHub Action](https://github.com/microsoft/playwright-github-action) or [guides for other CI providers](https://playwright.dev/python/docs/ci) to deploy your tests to CI/CD

## Special thanks

Expand Down
7 changes: 3 additions & 4 deletions pytest_playwright/pytest_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import pytest

from playwright import sync_playwright
from playwright.sync_api import Browser, BrowserContext, Page
from playwright.sync_api import sync_playwright, Browser, BrowserContext, Page


def pytest_generate_tests(metafunc: Any) -> None:
Expand Down Expand Up @@ -126,7 +125,7 @@ def browser(launch_browser: Callable[[], Browser]) -> Generator[Browser, None, N
def context(
browser: Browser, browser_context_args: Dict
) -> Generator[BrowserContext, None, None]:
context = browser.newContext(**browser_context_args)
context = browser.new_context(**browser_context_args)
yield context
context.close()

Expand All @@ -142,7 +141,7 @@ def _handle_page_goto(

@pytest.fixture
def page(context: BrowserContext, base_url: str) -> Generator[Page, None, None]:
page = context.newPage()
page = context.new_page()
page._goto = page.goto # type: ignore
page.goto = lambda *args, **kwargs: _handle_page_goto( # type: ignore
page, list(args), kwargs, base_url
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
url="https://github.com/microsoft/playwright-pytest",
packages=["pytest_playwright"],
include_package_data=True,
install_requires=["playwright>=0.170.0", "pytest", "pytest-base-url"],
install_requires=["playwright==1.8.0a1", "pytest", "pytest-base-url"],
entry_points={"pytest11": ["playwright = pytest_playwright.pytest_playwright"]},
classifiers=[
"Programming Language :: Python :: 3",
Expand Down
10 changes: 5 additions & 5 deletions tests/test_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_default(page, browser_name):
assert browser_name == "chromium"
user_agent = page.evaluate("window.navigator.userAgent")
assert "HeadlessChrome" in user_agent
page.setContent('<span id="foo">bar</span>')
assert page.querySelector("#foo")
page.set_content('<span id="foo">bar</span>')
assert page.query_selector("#foo")
"""
)
result = testdir.runpytest()
Expand All @@ -36,8 +36,8 @@ def test_multiple_browsers(testdir: Any) -> None:
testdir.makepyfile(
"""
def test_multiple_browsers(page):
page.setContent('<span id="foo">bar</span>')
assert page.querySelector("#foo")
page.set_content('<span id="foo">bar</span>')
assert page.query_selector("#foo")
"""
)
result = testdir.runpytest(
Expand All @@ -53,7 +53,7 @@ def test_browser_context_args(testdir: Any) -> None:
@pytest.fixture(scope="session")
def browser_context_args():
return {"userAgent": "foobar"}
return {"user_agent": "foobar"}
"""
)
testdir.makepyfile(
Expand Down

0 comments on commit b1bb438

Please sign in to comment.