Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

Commit

Permalink
Merge 161f9ea into 63a2b79
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Jul 13, 2020
2 parents 63a2b79 + 161f9ea commit 7b103ed
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 5 deletions.
83 changes: 80 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

### `browser_name` - session scope

A string which contains the current browser name.
A string that contains the current browser name.

### `browser` - session scope

Expand All @@ -34,11 +34,11 @@ A separate Playwright page instance for each new test.

### `launch_arguments` - session scope

A fixture which you can define to overwrite the launch arguments. It should return a Dict.
A fixture that you can define to overwrite the launch arguments. It should return a Dict.

### `context_arguments` - session scope

A fixture which you can define to overwrite the context arguments. It should return a Dict.
A fixture that you can define to overwrite the context arguments. It should return a Dict.

### `is_chromium`, `is_firefox`, `is_webkit` - session scope

Expand All @@ -55,3 +55,80 @@ Possible values: `chromium`, `firefox`, `webkit`
### `--headful`

By default, the tests run in headless mode. You can pass the `--headful` CLI flag to run the browser in headful mode.

## Examples

### Performing basic tests

All your tests need to be async. This can be done by using the [pytest-asyncio](https://github.com/pytest-dev/pytest-asyncio) plugin.

```py
import pytest

@pytest.mark.asyncio
async def test_is_chromium(page):
await page.goto("https://www.google.com")
await page.type("input[name=q]", "Playwright GitHub")
await page.click("input[type=submit]")
await page.waitForSelector("text=microsoft/Playwright")
```

### Skipping by browser type

```py
import pytest

@pytest.mark.asyncio
@pytest.mark.skip_browser("firefox")
async def test_is_chromium(page):
await page.goto("https://www.google.com")
# ...
```

### Running only on a specific browser

```py
import pytest

@pytest.mark.asyncio
@pytest.mark.only_browser("chromium")
async def test_is_chromium(page):
await page.goto("https://www.google.com")
# ...
```

### Handle base-url

Start Pytest with the `base-url` argument. Example: `pytest --base-url http://localhost:8080`

```py
import pytest

@pytest.mark.asyncio
async def test_is_chromium(page):
await page.goto("/admin")
# -> Will result in http://localhost:8080/admin
```

## Best practices

### Run all tests in the folder with asyncio

Put this into the `conftest.py` of your browser test folder.

```py
import pytest

# Will mark all the tests as async
def pytest_collection_modifyitems(items):
for item in items:
item.add_marker(pytest.mark.asyncio)
```

Alternatively, you can enable it also per file by putting this into the top of your test file.

```py
import pytest

pytestmark = pytest.mark.asyncio
```
1 change: 0 additions & 1 deletion local-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
black==19.10b0
pytest==5.4.3
pytest-asyncio==0.14.0
pytest-cov==2.10.0
mypy==0.782
setuptools==49.1.0
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/mxschmitt/pytest-playwright",
packages=["pytest_playwright"],
include_package_data=True,
install_requires=["playwright", "pytest", "pytest-base-url"],
install_requires=["playwright", "pytest", "pytest-base-url", "pytest-asyncio"],
entry_points={"pytest11": ["playwright = pytest_playwright.pytest_playwright"]},
classifiers=[
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit 7b103ed

Please sign in to comment.