Skip to content

Commit 08357fe

Browse files
committed
uv
1 parent e36efc3 commit 08357fe

File tree

10 files changed

+581
-109
lines changed

10 files changed

+581
-109
lines changed

.github/workflows/devRun.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Create venv & install dependencies
2424
run: |
2525
uv venv
26-
uv pip sync uv.lock
26+
uv sync --all-extras --dev
2727
- name: Install Playwright Browsers
2828
run: |
2929
PLAYWRIGHT_VERSION=$(grep -E '^playwright = "[^"]*"' pyproject.toml | sed -E 's/playwright = "([^"]*)".*$/\1/')

.github/workflows/nightly.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- name: Create venv & install dependencies
4848
run: |
4949
uv venv
50-
uv pip sync uv.lock
50+
uv sync --all-extras --dev
5151
- name: Install Playwright Browsers
5252
run: |
5353
PLAYWRIGHT_VERSION=$(grep -E '^playwright = "[^"]*"' pyproject.toml | sed -E 's/playwright = "([^"]*)".*$/\1/')

.github/README.md renamed to README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
![YouTube Channel](https://img.shields.io/youtube/channel/subscribers/UCQjS-eoKl0a1nuP_dvpLsjQ?label=YouTube%20Channel)
55
![dev run](https://github.com/nirtal85/Playwright-Python-Example/actions/workflows/devRun.yml/badge.svg)
66
![nightly](https://github.com/nirtal85/Playwright-Python-Example/actions/workflows/nightly.yml/badge.svg)
7-
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
8-
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
7+
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
8+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
99

1010
## 📃 Articles written about this project
1111

@@ -50,15 +50,15 @@ cd playwright-python
5050
pip install uv
5151
uv venv
5252
.\env\Scripts\activate
53-
uv pip sync uv.lock
53+
uv sync --all-extras --dev
5454
```
5555

5656
#### For Mac:
5757
```bash
5858
python3 -m pip install uv
5959
uv venv
60-
source .venv/bin/activate
61-
uv pip sync uv.lock
60+
source .venv/bin/activate
61+
uv sync --all-extras --dev
6262
```
6363

6464
### Install playwright

pyproject.toml

+45-31
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
11
[build-system]
2-
requires = ["hatchling"]
32
build-backend = "hatchling.build"
4-
5-
[project]
6-
name = "playwright-python"
7-
version = "0.1.0"
8-
description = "Playwright Python example project with pytest and Allure report"
9-
authors = [{ name = "nirtal85", email = "[email protected]" }]
10-
requires-python = "~=3.11"
11-
readme = "README.md"
12-
keywords = [
13-
"playwright",
14-
"automation",
15-
"testing",
16-
"web",
17-
]
18-
dependencies = [
19-
"allure-pytest==2.13.5",
20-
"axe-playwright-python==0.1.4",
21-
"playwright==1.51.0",
22-
"pytest==8.3.5",
23-
"pytest-base-url==2.1.0",
24-
"pytest-playwright==0.7.0",
25-
"pytest-split==0.10.0",
26-
"requests==2.32.3",
27-
]
3+
requires = ["hatchling"]
284

295
[dependency-groups]
306
dev = [
31-
"black==25.1.0",
32-
"isort==6.0.1",
33-
"pre-commit==4.2.0",
7+
"ruff==0.11.4",
8+
"pre-commit==4.2.0"
349
]
3510

36-
[tool.isort]
37-
profile = "black"
38-
skip = ["env", "venv"]
11+
[project]
12+
authors = [{name = "nirtal85", email = "[email protected]"}]
13+
dependencies = [
14+
"allure-pytest==2.13.5",
15+
"axe-playwright-python==0.1.4",
16+
"playwright==1.51.0",
17+
"pytest==8.3.5",
18+
"pytest-base-url==2.1.0",
19+
"pytest-playwright==0.7.0",
20+
"pytest-split==0.10.0",
21+
"requests==2.32.3"
22+
]
23+
description = "Playwright Python example project with pytest and Allure report"
24+
keywords = [
25+
"playwright",
26+
"automation",
27+
"testing",
28+
"web"
29+
]
30+
name = "playwright-python"
31+
readme = "README.md"
32+
requires-python = "~=3.11"
33+
version = "0.1.0"
3934

4035
[tool.hatch.build.targets.sdist]
4136
include = ["playwright_python"]
4237

4338
[tool.hatch.build.targets.wheel]
4439
include = ["playwright_python"]
4540

41+
[tool.isort]
42+
profile = "black"
43+
skip = ["env", "venv"]
44+
4645
[tool.pytest.ini_options]
4746
addopts = [
4847
"--clean-alluredir",
@@ -68,3 +67,18 @@ log_cli_level = "INFO"
6867
markers = [
6968
"devRun: marks tests that run before merge to the main branch"
7069
]
70+
71+
[tool.ruff]
72+
exclude = [".venv", "env"]
73+
ignore = [
74+
"D203", # One blank line required before class docstring (conflicts with D211)
75+
"D213", # Multi-line docstring summary should start at the second line
76+
"COM812"
77+
]
78+
line-length = 100
79+
select = ["ALL"]
80+
target-version = "py311"
81+
82+
[tool.ruff.format]
83+
docstring-code-format = true
84+
quote-style = "double"

tests/accesability_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class TestAccessibility:
5-
65
@allure.title("Test Accessibility with Default Counts")
76
def test_accessibility_default_counts(self, axe_playwright, page):
87
axe_playwright.check_accessibility(page)

tests/checkout_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
class TestCheckout:
8-
98
@pytest.mark.parametrize(
109
"browser_context_args", [User.STANDARD_USER], indirect=True
1110
)

tests/conftest.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Dict
2-
31
import allure
42
import pytest
53
import requests
@@ -27,6 +25,7 @@ def goto(page: Page, request: SubRequest):
2725
2826
Example:
2927
@pytest.mark.parametrize('browser_context_args', ["standard_user"], indirect=True)
28+
3029
"""
3130
if request.getfixturevalue("browser_context_args").get("storage_state"):
3231
page.goto("/inventory.html")
@@ -43,27 +42,31 @@ def axe_playwright():
4342
4443
Returns:
4544
AxeHelper: An instance of AxeHelper with Axe initialized.
45+
4646
"""
47-
yield AxeHelper(Axe())
47+
return AxeHelper(Axe())
4848

4949

5050
@pytest.fixture(scope="function")
5151
def browser_context_args(
52-
browser_context_args: Dict, base_url: str, request: SubRequest
52+
browser_context_args: dict, base_url: str, request: SubRequest
5353
):
5454
"""This fixture allows setting browser context arguments for Playwright.
5555
5656
Args:
5757
browser_context_args (dict): Base browser context arguments.
5858
request (SubRequest): Pytest request object to get the 'browser_context_args' fixture value.
5959
base_url (str): The base URL for the application under test.
60+
6061
Returns:
6162
dict: Updated browser context arguments.
63+
6264
See Also:
6365
https://playwright.dev/python/docs/api/class-browser#browser-new-contex
6466
6567
Returns:
6668
dict: Updated browser context arguments.
69+
6770
"""
6871
context_args = {
6972
**browser_context_args,
@@ -85,7 +88,7 @@ def browser_context_args(
8588

8689

8790
@pytest.fixture(scope="session")
88-
def browser_type_launch_args(browser_type_launch_args: Dict, playwright: Playwright):
91+
def browser_type_launch_args(browser_type_launch_args: dict, playwright: Playwright):
8992
"""Fixture to set browser launch arguments.
9093
9194
This fixture updates the browser launch arguments to start the browser maximized
@@ -103,6 +106,7 @@ def browser_type_launch_args(browser_type_launch_args: Dict, playwright: Playwri
103106
104107
See Also:
105108
https://playwright.dev/python/docs/api/class-browsertype#browser-type-launch
109+
106110
"""
107111
playwright.selectors.set_test_id_attribute("data-test")
108112
return {**browser_type_launch_args, "args": ["--start-maximized"]}
@@ -113,6 +117,7 @@ def get_public_ip() -> str:
113117
114118
Returns:
115119
str: Public IP address.
120+
116121
"""
117122
return requests.get(
118123
"http://checkip.amazonaws.com",
@@ -129,6 +134,7 @@ def attach_playwright_results(page: Page, request: FixtureRequest):
129134
Args:
130135
page (Page): Playwright page object.
131136
request: Pytest request object.
137+
132138
"""
133139
yield
134140
if request.node.rep_call.failed:
@@ -158,6 +164,7 @@ def pytest_runtest_makereport(item: Item):
158164
159165
Yields:
160166
Outcome of the test execution.
167+
161168
"""
162169
outcome = yield
163170
rep = outcome.get_result()

tests/inventory_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
class TestInventory:
8-
98
@pytest.mark.parametrize(
109
"browser_context_args", [User.STANDARD_USER], indirect=True
1110
)

utilities/axe_helper.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import json
22
from collections import Counter
3-
from typing import Dict
43

54
import allure
65
from axe_playwright_python.sync_playwright import Axe
76
from playwright.sync_api import Page
87

98

109
class AxeHelper:
11-
1210
def __init__(self, axe: Axe):
1311
self.axe = axe
1412

1513
def check_accessibility(
16-
self, page: Page, maximum_allowed_violations_by_impact: Dict[str, int] = None
14+
self, page: Page, maximum_allowed_violations_by_impact: dict[str, int] = None
1715
) -> None:
1816
"""Checks accessibility of the page using playwright axe.
1917

0 commit comments

Comments
 (0)