smart-ui-tester 0.1.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smart_ui_tester-0.1.9/PKG-INFO +203 -0
- smart_ui_tester-0.1.9/README.md +178 -0
- smart_ui_tester-0.1.9/pyproject.toml +54 -0
- smart_ui_tester-0.1.9/setup.cfg +4 -0
- smart_ui_tester-0.1.9/src/smart_ui_tester/__init__.py +1 -0
- smart_ui_tester-0.1.9/src/smart_ui_tester/docs/PLUGIN.md +94 -0
- smart_ui_tester-0.1.9/src/smart_ui_tester/docs/UI_ACTIONS.md +261 -0
- smart_ui_tester-0.1.9/src/smart_ui_tester/plugin.py +270 -0
- smart_ui_tester-0.1.9/src/smart_ui_tester/ui_actions.py +1856 -0
- smart_ui_tester-0.1.9/src/smart_ui_tester.egg-info/PKG-INFO +203 -0
- smart_ui_tester-0.1.9/src/smart_ui_tester.egg-info/SOURCES.txt +16 -0
- smart_ui_tester-0.1.9/src/smart_ui_tester.egg-info/dependency_links.txt +1 -0
- smart_ui_tester-0.1.9/src/smart_ui_tester.egg-info/entry_points.txt +2 -0
- smart_ui_tester-0.1.9/src/smart_ui_tester.egg-info/requires.txt +3 -0
- smart_ui_tester-0.1.9/src/smart_ui_tester.egg-info/top_level.txt +1 -0
- smart_ui_tester-0.1.9/tests/test_plugin_cli.py +218 -0
- smart_ui_tester-0.1.9/tests/test_smoke.py +57 -0
- smart_ui_tester-0.1.9/tests/test_ui_actions.py +338 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: smart-ui-tester
|
|
3
|
+
Version: 0.1.9
|
|
4
|
+
Summary: Label, text, attribute, and fallback-driven UI automation wrapper for Playwright and Pytest.
|
|
5
|
+
Author-email: Jeorge Concepcion <jeorge.concepcion@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/je0rge
|
|
8
|
+
Project-URL: Documentation, https://github.com/je0rge/smart-ui-tester-docs/blob/main/README.md
|
|
9
|
+
Project-URL: Repository, https://github.com/je0rge/smart-ui-tester-docs
|
|
10
|
+
Project-URL: Issues, https://github.com/je0rge/smart_ui_tester-docs/issues
|
|
11
|
+
Keywords: playwright,pytest,ui-automation,testing,qa,locators
|
|
12
|
+
Classifier: Framework :: Pytest
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Software Development :: Testing
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
Requires-Dist: pytest>=8.0.0
|
|
23
|
+
Requires-Dist: pytest-playwright>=0.5.0
|
|
24
|
+
Requires-Dist: PyYAML>=6.0
|
|
25
|
+
|
|
26
|
+
# Smart UI Tester (`smart-ui-tester`)
|
|
27
|
+
|
|
28
|
+
A smart hybrid **Playwright + Pytest** UI automation framework that locates web elements primarily by their **visible label, placeholder, accessible role, or text**, while seamlessly falling back to **unique HTML/`data-*` attributes**, **tag-agnostic `near` spatial scoping**, and **auto-discovered `*locator*.yml`/`.json` registries** for unlabeled elements.
|
|
29
|
+
|
|
30
|
+
Designed so **manual QAs** can write clean, readable, English-like tests while **developers/SDETs** retain full Playwright and Python power.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Key Features
|
|
35
|
+
|
|
36
|
+
- **User-Facing & Semantic Locators:** Automatically resolves elements by `<label>`, `placeholder`, `title`, `aria-label`, button/link `role`, or visible text.
|
|
37
|
+
- **Unique Attribute Fallback:** Matches `id`, `name`, `data-element-ref`, `data-testid`, `data-test`, `data-cy`, `data-qa`, plus custom `data-*` attributes (all case-insensitive).
|
|
38
|
+
- **Multi-File YAML / JSON Locator Registry (`locators/`):** Auto-discovers `*locator*.yml`, `*locator*.yaml`, and `*locator*.json` files inside your project's `locators/` directory with 3-level namespacing (`Locator`, `Group.Locator`, `filename.Group.Locator`) and distinct `[UI REGISTRY CONFLICT]` vs. `[UI REGISTRY DUPLICATE]` warnings.
|
|
39
|
+
- **Smart Spatial Scoping (`near=`):** Disambiguates duplicate labels or buttons by walking up to the Lowest Common Ancestor shared with any `near` anchor.
|
|
40
|
+
- **Ordinal Selection (`index=`):** Target specific occurrences when identical elements appear in a list.
|
|
41
|
+
- **Iframe & Multi-Tab Context Managers:** Clean `with ui.frame(...)` and `with ui.new_tab(...)` blocks powered by the same unified resolver.
|
|
42
|
+
- **Visual Element Highlighting:** Floating overlay highlights every accessed element by default (with `--no-ui-highlight` option for CI).
|
|
43
|
+
- **Auto-Dismissing Popups:** Background handlers clear cookie banners and unexpected modals automatically.
|
|
44
|
+
- **Zero-Boilerplate Pytest Plugin:** Auto-registers the `ui` fixture, live `[UI]` console logs, and automatic failure screenshots & Playwright `.zip` traces.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Documentation
|
|
49
|
+
|
|
50
|
+
* **[Plugin & Configuration Guide (`PLUGIN.md`)](https://github.com/je0rge/smart-ui-tester-docs/blob/main/PLUGIN.md)** — CLI flags, `pyproject.toml` defaults, timeouts, viewports, and failure artifacts.
|
|
51
|
+
* **[UI Actions Reference (`UI_ACTIONS.md`)](https://github.com/je0rge/smart-ui-tester-docs/blob/main/UI_ACTIONS.md)** — Complete method list, `_resolve()` fallback order, `*locator*.yml` schema, iframes, and multi-tab helpers.
|
|
52
|
+
|
|
53
|
+
> **Offline Docs:** After installing via `pip install smart-ui-tester`, you can also read both guides directly in your terminal using `pytest --ui-docs`.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install smart-ui-tester
|
|
61
|
+
playwright install chromium
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Quick Start (Zero Boilerplate)
|
|
67
|
+
|
|
68
|
+
Once installed, Pytest automatically registers the `ui` fixture—no `conftest.py` or imports required:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
# tests/test_login.py
|
|
72
|
+
def test_user_can_login(ui):
|
|
73
|
+
ui.open("https://your-app.com/login")
|
|
74
|
+
|
|
75
|
+
# Locate by visible label, placeholder, or text
|
|
76
|
+
ui.fill("Email Address", "qa_tester@example.com")
|
|
77
|
+
ui.fill("Password", "SuperSecret123")
|
|
78
|
+
ui.click("Sign In")
|
|
79
|
+
|
|
80
|
+
ui.verify_visible("Welcome to your Dashboard")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Run with a visible browser window and slow-motion debugging:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pytest --headed --slowmo 300
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## How Element Resolution Works (`_resolve`)
|
|
92
|
+
|
|
93
|
+
Every action and assertion routes through a single unified resolver in this exact order:
|
|
94
|
+
|
|
95
|
+
1. **Project Locator Registry (`*locator*.yml` / `.json`):** Case-insensitive lookup for friendly names (supports `Locator`, `Group.Locator`, and `filename.Group.Locator` namespaces).
|
|
96
|
+
2. **Explicit CSS / XPath Selectors:** Any identifier prefixed with `#`, `.`, `/`, `[` or `(`.
|
|
97
|
+
3. **User-Facing & Accessibility Locators:** `get_by_label()`, `get_by_placeholder()`, `get_by_title()`, `get_by_test_id()`, `get_by_role("button")`, `get_by_role("link")`, and `get_by_text()`.
|
|
98
|
+
4. **Case-Insensitive HTML & `data-*` Attributes:** Matches `[id="..." i]`, `[name="..." i]`, `[data-element-ref="..." i]`, `[data-testid="..." i]`, `[data-test="..." i]`, `[data-cy="..." i]`, `[data-qa="..." i]`, plus any custom attributes configured via YAML, CLI, or `pyproject.toml`.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Self-Healing Locators
|
|
103
|
+
|
|
104
|
+
When a CSS/XPath selector stored in `locators/*locator*.yml` breaks after a UI refactor, `smart-ui-tester` automatically falls back to resolving the element by its friendly locator name (label, text, or `data-*` attribute), computes a fresh resilient selector from the live DOM, and logs a `[UI HEALED]` warning:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Default (enabled in memory for CI/CD safety): keeps tests green and logs [UI HEALED] warnings
|
|
108
|
+
pytest
|
|
109
|
+
|
|
110
|
+
# Local development: automatically overwrite broken selectors in locators/*.yml with healed ones
|
|
111
|
+
pytest --ui-heal-save
|
|
112
|
+
|
|
113
|
+
# Disable self-healing completely
|
|
114
|
+
pytest --no-ui-heal
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Handling Unlabeled Elements, Duplicates & Scopes
|
|
120
|
+
|
|
121
|
+
### 1. Multi-File `*locator*.yml` / `.json` Registry
|
|
122
|
+
Any `.yml`, `.yaml`, or `.json` file in your project `locators/` folder containing `locator` in its filename (e.g., `locators/app_locators.yml`, `locators/checkout_locator.json`) is **auto-discovered and loaded** before every test:
|
|
123
|
+
|
|
124
|
+
```yaml
|
|
125
|
+
# app_locators.yml
|
|
126
|
+
attributes:
|
|
127
|
+
- data-automation-id
|
|
128
|
+
- data-e2e
|
|
129
|
+
|
|
130
|
+
popups:
|
|
131
|
+
"We value your privacy": "Accept All"
|
|
132
|
+
|
|
133
|
+
locators:
|
|
134
|
+
Header:
|
|
135
|
+
Profile Avatar: "header img.user-avatar"
|
|
136
|
+
Checkout:
|
|
137
|
+
Payment Frame: "iframe[name^='__privateStripeFrame']"
|
|
138
|
+
Submit Button: "button#pay-now"
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Use them in your tests via short name, group namespace, or file namespace:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
def test_checkout(ui):
|
|
145
|
+
ui.open("https://your-app.com/checkout")
|
|
146
|
+
ui.click("Profile Avatar")
|
|
147
|
+
ui.click("Checkout.Submit Button")
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### Duplicate & Conflict Diagnostics
|
|
151
|
+
* **`[UI REGISTRY CONFLICT]`:** Logged when two files define the same locator name with **different** selectors.
|
|
152
|
+
* **`[UI REGISTRY DUPLICATE]`:** Logged when two files define the same locator name with the **exact same** selector.
|
|
153
|
+
* Enable **Strict Mode** (`--ui-strict-registry`, `UI_STRICT_REGISTRY=true`, or `ui_strict_registry = true` in `pyproject.toml`) to fail fast with a `ValueError` on any conflict or redundant duplicate.
|
|
154
|
+
|
|
155
|
+
### 2. Disambiguating Duplicate Elements (`near=` and `index=`)
|
|
156
|
+
```python
|
|
157
|
+
# Tag-agnostic Lowest Common Ancestor scoping (works with any identifier type)
|
|
158
|
+
ui.click("Edit", near="Billing Address")
|
|
159
|
+
ui.fill("Quantity", "2", near="product-card-101")
|
|
160
|
+
|
|
161
|
+
# Ordinal indexing (0-based)
|
|
162
|
+
ui.click("Add to Cart", index=2)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### 3. Iframes & Multi-Tab Context Managers
|
|
166
|
+
```python
|
|
167
|
+
with ui.frame("Payment Frame"):
|
|
168
|
+
ui.fill("Card Number", "4242424242424242")
|
|
169
|
+
|
|
170
|
+
with ui.new_tab("Terms & Conditions"):
|
|
171
|
+
ui.verify_visible("User Agreement")
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## CLI Flags, INI Options & Environment Variables
|
|
177
|
+
|
|
178
|
+
| CLI Flag | `pyproject.toml` INI | Env Variable | Default | Description |
|
|
179
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
180
|
+
| `--ui-timeout` | — | `UI_TIMEOUT` | `10000` | Default action & assertion timeout (ms). |
|
|
181
|
+
| `--viewport` | — | `UI_VIEWPORT` | `1280x720` | Browser viewport size (`WIDTHxHEIGHT`). |
|
|
182
|
+
| `--ui-registry` | — | `UI_REGISTRY` | Auto-discover | Path, folder, or glob for `*locator*` files. |
|
|
183
|
+
| `--ui-attributes` | `ui_attributes` | `UI_ATTRIBUTES` | Built-in list | Extra HTML/`data-*` attributes to match. |
|
|
184
|
+
| `--ui-strict-registry` | `ui_strict_registry` | `UI_STRICT_REGISTRY` | `false` | Raise `ValueError` on duplicate/conflicting locators. |
|
|
185
|
+
| `--no-ui-highlight` | `ui_highlight` | `UI_HIGHLIGHT` | Highlight ON | Disable floating red/gold highlight overlays. |
|
|
186
|
+
| `--ui-docs` | — | — | `None` | Print bundled docs (`all`, `plugin`, `actions`). |
|
|
187
|
+
| `--headed` | `addopts` | — | Headless | Run browser in visible headed mode. |
|
|
188
|
+
| `--browser` | `addopts` | — | `chromium` | Target browser (`chromium`, `firefox`, `webkit`). |
|
|
189
|
+
| `--slowmo` | `addopts` | — | `0` | Delay in ms between Playwright actions. |
|
|
190
|
+
| `--no-ui-heal` | `ui_auto_heal` (`true`) | `UI_AUTO_HEAL` | Disable automatic self-healing fallback when a registry selector breaks |
|
|
191
|
+
| `--ui-heal-save` | `ui_auto_heal_save` (`false`) | `UI_AUTO_HEAL_SAVE` | Persist healed selectors back into their source `*locator*.yml`/`.json` file |
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Offline Documentation
|
|
196
|
+
|
|
197
|
+
After installing `smart-ui-tester`, view the complete guides anytime in your terminal:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
pytest --ui-docs
|
|
201
|
+
pytest --ui-docs=plugin
|
|
202
|
+
pytest --ui-docs=actions
|
|
203
|
+
```
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Smart UI Tester (`smart-ui-tester`)
|
|
2
|
+
|
|
3
|
+
A smart hybrid **Playwright + Pytest** UI automation framework that locates web elements primarily by their **visible label, placeholder, accessible role, or text**, while seamlessly falling back to **unique HTML/`data-*` attributes**, **tag-agnostic `near` spatial scoping**, and **auto-discovered `*locator*.yml`/`.json` registries** for unlabeled elements.
|
|
4
|
+
|
|
5
|
+
Designed so **manual QAs** can write clean, readable, English-like tests while **developers/SDETs** retain full Playwright and Python power.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **User-Facing & Semantic Locators:** Automatically resolves elements by `<label>`, `placeholder`, `title`, `aria-label`, button/link `role`, or visible text.
|
|
12
|
+
- **Unique Attribute Fallback:** Matches `id`, `name`, `data-element-ref`, `data-testid`, `data-test`, `data-cy`, `data-qa`, plus custom `data-*` attributes (all case-insensitive).
|
|
13
|
+
- **Multi-File YAML / JSON Locator Registry (`locators/`):** Auto-discovers `*locator*.yml`, `*locator*.yaml`, and `*locator*.json` files inside your project's `locators/` directory with 3-level namespacing (`Locator`, `Group.Locator`, `filename.Group.Locator`) and distinct `[UI REGISTRY CONFLICT]` vs. `[UI REGISTRY DUPLICATE]` warnings.
|
|
14
|
+
- **Smart Spatial Scoping (`near=`):** Disambiguates duplicate labels or buttons by walking up to the Lowest Common Ancestor shared with any `near` anchor.
|
|
15
|
+
- **Ordinal Selection (`index=`):** Target specific occurrences when identical elements appear in a list.
|
|
16
|
+
- **Iframe & Multi-Tab Context Managers:** Clean `with ui.frame(...)` and `with ui.new_tab(...)` blocks powered by the same unified resolver.
|
|
17
|
+
- **Visual Element Highlighting:** Floating overlay highlights every accessed element by default (with `--no-ui-highlight` option for CI).
|
|
18
|
+
- **Auto-Dismissing Popups:** Background handlers clear cookie banners and unexpected modals automatically.
|
|
19
|
+
- **Zero-Boilerplate Pytest Plugin:** Auto-registers the `ui` fixture, live `[UI]` console logs, and automatic failure screenshots & Playwright `.zip` traces.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
* **[Plugin & Configuration Guide (`PLUGIN.md`)](https://github.com/je0rge/smart-ui-tester-docs/blob/main/PLUGIN.md)** — CLI flags, `pyproject.toml` defaults, timeouts, viewports, and failure artifacts.
|
|
26
|
+
* **[UI Actions Reference (`UI_ACTIONS.md`)](https://github.com/je0rge/smart-ui-tester-docs/blob/main/UI_ACTIONS.md)** — Complete method list, `_resolve()` fallback order, `*locator*.yml` schema, iframes, and multi-tab helpers.
|
|
27
|
+
|
|
28
|
+
> **Offline Docs:** After installing via `pip install smart-ui-tester`, you can also read both guides directly in your terminal using `pytest --ui-docs`.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install smart-ui-tester
|
|
36
|
+
playwright install chromium
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Quick Start (Zero Boilerplate)
|
|
42
|
+
|
|
43
|
+
Once installed, Pytest automatically registers the `ui` fixture—no `conftest.py` or imports required:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
# tests/test_login.py
|
|
47
|
+
def test_user_can_login(ui):
|
|
48
|
+
ui.open("https://your-app.com/login")
|
|
49
|
+
|
|
50
|
+
# Locate by visible label, placeholder, or text
|
|
51
|
+
ui.fill("Email Address", "qa_tester@example.com")
|
|
52
|
+
ui.fill("Password", "SuperSecret123")
|
|
53
|
+
ui.click("Sign In")
|
|
54
|
+
|
|
55
|
+
ui.verify_visible("Welcome to your Dashboard")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Run with a visible browser window and slow-motion debugging:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pytest --headed --slowmo 300
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## How Element Resolution Works (`_resolve`)
|
|
67
|
+
|
|
68
|
+
Every action and assertion routes through a single unified resolver in this exact order:
|
|
69
|
+
|
|
70
|
+
1. **Project Locator Registry (`*locator*.yml` / `.json`):** Case-insensitive lookup for friendly names (supports `Locator`, `Group.Locator`, and `filename.Group.Locator` namespaces).
|
|
71
|
+
2. **Explicit CSS / XPath Selectors:** Any identifier prefixed with `#`, `.`, `/`, `[` or `(`.
|
|
72
|
+
3. **User-Facing & Accessibility Locators:** `get_by_label()`, `get_by_placeholder()`, `get_by_title()`, `get_by_test_id()`, `get_by_role("button")`, `get_by_role("link")`, and `get_by_text()`.
|
|
73
|
+
4. **Case-Insensitive HTML & `data-*` Attributes:** Matches `[id="..." i]`, `[name="..." i]`, `[data-element-ref="..." i]`, `[data-testid="..." i]`, `[data-test="..." i]`, `[data-cy="..." i]`, `[data-qa="..." i]`, plus any custom attributes configured via YAML, CLI, or `pyproject.toml`.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Self-Healing Locators
|
|
78
|
+
|
|
79
|
+
When a CSS/XPath selector stored in `locators/*locator*.yml` breaks after a UI refactor, `smart-ui-tester` automatically falls back to resolving the element by its friendly locator name (label, text, or `data-*` attribute), computes a fresh resilient selector from the live DOM, and logs a `[UI HEALED]` warning:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Default (enabled in memory for CI/CD safety): keeps tests green and logs [UI HEALED] warnings
|
|
83
|
+
pytest
|
|
84
|
+
|
|
85
|
+
# Local development: automatically overwrite broken selectors in locators/*.yml with healed ones
|
|
86
|
+
pytest --ui-heal-save
|
|
87
|
+
|
|
88
|
+
# Disable self-healing completely
|
|
89
|
+
pytest --no-ui-heal
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Handling Unlabeled Elements, Duplicates & Scopes
|
|
95
|
+
|
|
96
|
+
### 1. Multi-File `*locator*.yml` / `.json` Registry
|
|
97
|
+
Any `.yml`, `.yaml`, or `.json` file in your project `locators/` folder containing `locator` in its filename (e.g., `locators/app_locators.yml`, `locators/checkout_locator.json`) is **auto-discovered and loaded** before every test:
|
|
98
|
+
|
|
99
|
+
```yaml
|
|
100
|
+
# app_locators.yml
|
|
101
|
+
attributes:
|
|
102
|
+
- data-automation-id
|
|
103
|
+
- data-e2e
|
|
104
|
+
|
|
105
|
+
popups:
|
|
106
|
+
"We value your privacy": "Accept All"
|
|
107
|
+
|
|
108
|
+
locators:
|
|
109
|
+
Header:
|
|
110
|
+
Profile Avatar: "header img.user-avatar"
|
|
111
|
+
Checkout:
|
|
112
|
+
Payment Frame: "iframe[name^='__privateStripeFrame']"
|
|
113
|
+
Submit Button: "button#pay-now"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Use them in your tests via short name, group namespace, or file namespace:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
def test_checkout(ui):
|
|
120
|
+
ui.open("https://your-app.com/checkout")
|
|
121
|
+
ui.click("Profile Avatar")
|
|
122
|
+
ui.click("Checkout.Submit Button")
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### Duplicate & Conflict Diagnostics
|
|
126
|
+
* **`[UI REGISTRY CONFLICT]`:** Logged when two files define the same locator name with **different** selectors.
|
|
127
|
+
* **`[UI REGISTRY DUPLICATE]`:** Logged when two files define the same locator name with the **exact same** selector.
|
|
128
|
+
* Enable **Strict Mode** (`--ui-strict-registry`, `UI_STRICT_REGISTRY=true`, or `ui_strict_registry = true` in `pyproject.toml`) to fail fast with a `ValueError` on any conflict or redundant duplicate.
|
|
129
|
+
|
|
130
|
+
### 2. Disambiguating Duplicate Elements (`near=` and `index=`)
|
|
131
|
+
```python
|
|
132
|
+
# Tag-agnostic Lowest Common Ancestor scoping (works with any identifier type)
|
|
133
|
+
ui.click("Edit", near="Billing Address")
|
|
134
|
+
ui.fill("Quantity", "2", near="product-card-101")
|
|
135
|
+
|
|
136
|
+
# Ordinal indexing (0-based)
|
|
137
|
+
ui.click("Add to Cart", index=2)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 3. Iframes & Multi-Tab Context Managers
|
|
141
|
+
```python
|
|
142
|
+
with ui.frame("Payment Frame"):
|
|
143
|
+
ui.fill("Card Number", "4242424242424242")
|
|
144
|
+
|
|
145
|
+
with ui.new_tab("Terms & Conditions"):
|
|
146
|
+
ui.verify_visible("User Agreement")
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## CLI Flags, INI Options & Environment Variables
|
|
152
|
+
|
|
153
|
+
| CLI Flag | `pyproject.toml` INI | Env Variable | Default | Description |
|
|
154
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
155
|
+
| `--ui-timeout` | — | `UI_TIMEOUT` | `10000` | Default action & assertion timeout (ms). |
|
|
156
|
+
| `--viewport` | — | `UI_VIEWPORT` | `1280x720` | Browser viewport size (`WIDTHxHEIGHT`). |
|
|
157
|
+
| `--ui-registry` | — | `UI_REGISTRY` | Auto-discover | Path, folder, or glob for `*locator*` files. |
|
|
158
|
+
| `--ui-attributes` | `ui_attributes` | `UI_ATTRIBUTES` | Built-in list | Extra HTML/`data-*` attributes to match. |
|
|
159
|
+
| `--ui-strict-registry` | `ui_strict_registry` | `UI_STRICT_REGISTRY` | `false` | Raise `ValueError` on duplicate/conflicting locators. |
|
|
160
|
+
| `--no-ui-highlight` | `ui_highlight` | `UI_HIGHLIGHT` | Highlight ON | Disable floating red/gold highlight overlays. |
|
|
161
|
+
| `--ui-docs` | — | — | `None` | Print bundled docs (`all`, `plugin`, `actions`). |
|
|
162
|
+
| `--headed` | `addopts` | — | Headless | Run browser in visible headed mode. |
|
|
163
|
+
| `--browser` | `addopts` | — | `chromium` | Target browser (`chromium`, `firefox`, `webkit`). |
|
|
164
|
+
| `--slowmo` | `addopts` | — | `0` | Delay in ms between Playwright actions. |
|
|
165
|
+
| `--no-ui-heal` | `ui_auto_heal` (`true`) | `UI_AUTO_HEAL` | Disable automatic self-healing fallback when a registry selector breaks |
|
|
166
|
+
| `--ui-heal-save` | `ui_auto_heal_save` (`false`) | `UI_AUTO_HEAL_SAVE` | Persist healed selectors back into their source `*locator*.yml`/`.json` file |
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Offline Documentation
|
|
171
|
+
|
|
172
|
+
After installing `smart-ui-tester`, view the complete guides anytime in your terminal:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
pytest --ui-docs
|
|
176
|
+
pytest --ui-docs=plugin
|
|
177
|
+
pytest --ui-docs=actions
|
|
178
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "smart-ui-tester"
|
|
7
|
+
version = "0.1.9"
|
|
8
|
+
description = "Label, text, attribute, and fallback-driven UI automation wrapper for Playwright and Pytest."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Jeorge Concepcion", email = "jeorge.concepcion@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["playwright", "pytest", "ui-automation", "testing", "qa", "locators"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Framework :: Pytest",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Topic :: Software Development :: Testing",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"pytest>=8.0.0",
|
|
28
|
+
"pytest-playwright>=0.5.0",
|
|
29
|
+
"PyYAML>=6.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/je0rge"
|
|
34
|
+
Documentation = "https://github.com/je0rge/smart-ui-tester-docs/blob/main/README.md"
|
|
35
|
+
Repository = "https://github.com/je0rge/smart-ui-tester-docs"
|
|
36
|
+
Issues = "https://github.com/je0rge/smart_ui_tester-docs/issues"
|
|
37
|
+
|
|
38
|
+
# Automatically registers the `ui` fixture and CLI flags whenever pytest runs
|
|
39
|
+
[project.entry-points.pytest11]
|
|
40
|
+
smart_ui_tester = "smart_ui_tester.plugin"
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.packages.find]
|
|
43
|
+
where = ["src"]
|
|
44
|
+
|
|
45
|
+
# Bundle Markdown documentation inside the wheel distribution
|
|
46
|
+
[tool.setuptools.package-data]
|
|
47
|
+
smart_ui_tester = ["docs/*.md"]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
testpaths = ["tests"]
|
|
51
|
+
norecursedirs = [".venv", "venv", "dist", "build", "*.egg-info"]
|
|
52
|
+
filterwarnings = [
|
|
53
|
+
"ignore:Session-scoped fixtures defined as instance methods are deprecated:pytest.PytestRemovedIn10Warning",
|
|
54
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .ui_actions import UIActions
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Smart UI Tester — Pytest Plugin Guide (`PLUGIN.md`)
|
|
2
|
+
|
|
3
|
+
`smart_ui_tester.plugin` is registered via the `pytest11` entry point in `pyproject.toml`. Once installed, Pytest loads it automatically across any test repository without requiring a `conftest.py`.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Auto-Registered Fixtures
|
|
8
|
+
|
|
9
|
+
### `ui` (Function Scope)
|
|
10
|
+
Injects an initialized `UIActions` instance into any test function (`def test_example(ui):`).
|
|
11
|
+
|
|
12
|
+
**Setup Lifecycle:**
|
|
13
|
+
1. Applies `--ui-timeout` (`UI_TIMEOUT`) to Playwright actions and page navigations.
|
|
14
|
+
2. Starts Playwright tracing (`screenshots=True`, `snapshots=True`, `sources=True`).
|
|
15
|
+
3. Merges built-in HTML/`data-*` attributes with `--ui-attributes` / `ui_attributes`.
|
|
16
|
+
4. Loads custom locators, attributes, and auto-popup rules:
|
|
17
|
+
* If `--ui-registry` / `UI_REGISTRY` is provided, loads that explicit path, folder, or glob pattern.
|
|
18
|
+
* Otherwise, automatically scans `<project_root>/locators/` (including nested subdirectories) for any `.yml`, `.yaml`, or `.json` file containing `locator` in its filename.
|
|
19
|
+
5. Applies `ui_strict_registry` / `--ui-strict-registry` (`UI_STRICT_REGISTRY`) rules during registry loading.
|
|
20
|
+
|
|
21
|
+
**Teardown Lifecycle:**
|
|
22
|
+
* **On Pass:** Discards trace recording to save disk space.
|
|
23
|
+
* **On Failure (Setup or Call):** Creates `test-results/` and saves:
|
|
24
|
+
* `<test_name>.png` — Full-page screenshot of the active tab.
|
|
25
|
+
* `<test_name>_trace.zip` — Full Playwright trace archive (also attached to `pytest-html` reports if installed).
|
|
26
|
+
|
|
27
|
+
### `browser_context_args` (Session Scope)
|
|
28
|
+
Configures every browser context with the `--viewport` (`UI_VIEWPORT`) dimensions (`WIDTHxHEIGHT`).
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 2. Configuration Reference
|
|
33
|
+
|
|
34
|
+
All options can be passed via CLI flags, configured permanently in `pyproject.toml`, or injected via environment variables in CI/CD:
|
|
35
|
+
|
|
36
|
+
| CLI Flag | `pyproject.toml` INI | Environment Variable | Default | Description |
|
|
37
|
+
| :--- | :--- | :--- | :--- | :--- |
|
|
38
|
+
| `--ui-timeout` | *(via `addopts`)* | `UI_TIMEOUT` | `10000` | Global timeout in milliseconds |
|
|
39
|
+
| `--viewport` | *(via `addopts`)* | `UI_VIEWPORT` | `1280x720` | Viewport dimensions as `WIDTHxHEIGHT` |
|
|
40
|
+
| `--ui-registry` | *(via `addopts`)* | `UI_REGISTRY` | *(auto `locators/`)* | Explicit path, folder, or glob for `*locator*` files |
|
|
41
|
+
| `--ui-attributes` | `ui_attributes` (list) | `UI_ATTRIBUTES` | `[]` | Comma-separated or list of extra `data-*` attributes |
|
|
42
|
+
| `--ui-strict-registry` | `ui_strict_registry` (bool) | `UI_STRICT_REGISTRY` | `false` | Fail immediately on duplicate/conflicting locators |
|
|
43
|
+
| `--no-ui-highlight` | `ui_highlight` (bool) | `UI_HIGHLIGHT` | `true` | Disable floating red/gold highlight overlay |
|
|
44
|
+
| `--ui-docs` | — | — | — | Print bundled docs (`all`, `plugin`, or `actions`) and exit |
|
|
45
|
+
| `--headed` | *(via `addopts`)* | — | `false` | Run browser with visible UI window |
|
|
46
|
+
| `--browser` | *(via `addopts`)* | — | `chromium` | Target browser (`chromium`, `firefox`, `webkit`) |
|
|
47
|
+
| `--slowmo` | *(via `addopts`)* | — | `0` | Slow down Playwright operations by N milliseconds |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 3. Sample Project `pyproject.toml` Setup
|
|
52
|
+
|
|
53
|
+
```toml
|
|
54
|
+
[tool.pytest.ini_options]
|
|
55
|
+
testpaths = ["tests"]
|
|
56
|
+
addopts = "--browser chromium --headed --slowmo 300 --viewport=1920x1080 --ui-timeout=15000"
|
|
57
|
+
ui_highlight = true
|
|
58
|
+
ui_strict_registry = true
|
|
59
|
+
ui_attributes = [
|
|
60
|
+
"data-automation-id",
|
|
61
|
+
"data-e2e",
|
|
62
|
+
]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Overriding for CI/CD Pipelines
|
|
66
|
+
```bash
|
|
67
|
+
UI_STRICT_REGISTRY=true pytest -o addopts="--browser chromium --viewport=1920x1080 --ui-timeout=10000" --no-ui-highlight
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 4. Registry Auto-Discovery & Duplicate Diagnostics
|
|
73
|
+
|
|
74
|
+
### Auto-Discovery Rules (`locators/` Directory)
|
|
75
|
+
When `--ui-registry` is not explicitly set, the plugin scans `<project_root>/locators/` (including subfolders) for files matching:
|
|
76
|
+
* Extension: `.yml`, `.yaml`, or `.json`
|
|
77
|
+
* Filename: Contains `locator` (case-insensitive, e.g., `locators/login_locators.yml`, `locators/admin/modalLocator.json`)
|
|
78
|
+
|
|
79
|
+
Files outside `locators/` or files without `locator` in their name (such as `test_data.json` or `docker-compose.yml`) are safely ignored unless explicitly loaded via `--ui-registry` or `ui.load_registry()`.
|
|
80
|
+
|
|
81
|
+
### Conflict vs. Duplicate Warnings
|
|
82
|
+
* **`[UI REGISTRY CONFLICT]`:** Logged when two files define the same locator name with **different** selectors (e.g., `button#login` vs. `button#pay`).
|
|
83
|
+
* **`[UI REGISTRY DUPLICATE]`:** Logged when two files define the same locator name with the **exact same** selector.
|
|
84
|
+
* **Strict Mode (`ui_strict_registry = true` / `--ui-strict-registry` / `UI_STRICT_REGISTRY=true`):** Converts both `[UI REGISTRY CONFLICT]` and `[UI REGISTRY DUPLICATE]` into an immediate `ValueError` during fixture setup.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## 5. Inspecting Failure Artifacts
|
|
89
|
+
|
|
90
|
+
When any test fails, open the saved Playwright trace in `test-results/` to inspect DOM snapshots, network calls, console logs, and highlighted elements step-by-step:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
playwright show-trace test-results/<test_name>_trace.zip
|
|
94
|
+
```
|