robotframework-browserpom 0.7.0__tar.gz → 0.8.1__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.
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/.gitignore +4 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/__init__.py +9 -1
- robotframework_browserpom-0.8.1/BrowserPOM/internal/__init__.py +1 -0
- robotframework_browserpom-0.8.1/BrowserPOM/internal/rf_variables.py +44 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/uiobject.py +17 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/PKG-INFO +56 -9
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/pyproject.toml +3 -3
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/readme.md +54 -7
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/addons/filter_locator.js +0 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/__init__.py +0 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/__main__.py +0 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/cli.py +0 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/config.py +0 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/exceptions.py +0 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/formatting.py +0 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/scanner.py +0 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/decorator.py +0 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/pageobject.py +0 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/pom_stubs.py +0 -0
- {robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/LICENSE +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import contextlib
|
|
4
4
|
import importlib
|
|
5
|
+
from datetime import timedelta
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
from typing import TYPE_CHECKING, cast
|
|
7
8
|
|
|
@@ -11,6 +12,7 @@ from robot.api import logger
|
|
|
11
12
|
from robot.api.deco import keyword
|
|
12
13
|
from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
|
|
13
14
|
|
|
15
|
+
from .internal.rf_variables import _resolve_rf_browser_args
|
|
14
16
|
from .pageobject import PageObject
|
|
15
17
|
from .uiobject import UIObject
|
|
16
18
|
|
|
@@ -121,13 +123,19 @@ class BrowserPOM(Browser):
|
|
|
121
123
|
"""Initialize the BrowserPOM library with playwright page functionality.
|
|
122
124
|
Optional arguments are passed to the
|
|
123
125
|
[https://robotframework-browser.org/|BrowserLibrary] constructor.
|
|
126
|
+
|
|
127
|
+
Arguments can also be configured via RF runtime variables,
|
|
128
|
+
[https://github.com/hasanalpzengin/robotframework-browserpom#robotframework-browserpom| read the docs] for more details.
|
|
124
129
|
"""
|
|
125
130
|
addon_path = Path(__file__).parent / "addons" / "filter_locator.js"
|
|
126
131
|
with contextlib.suppress(RobotNotRunningError):
|
|
127
132
|
BuiltIn().set_library_search_order("BrowserPOM", "Browser")
|
|
128
133
|
|
|
134
|
+
args, kwargs = _resolve_rf_browser_args(*args, **kwargs)
|
|
129
135
|
jsextensions = kwargs.pop("jsextension", [])
|
|
130
|
-
if
|
|
136
|
+
if jsextensions is None:
|
|
137
|
+
jsextensions = []
|
|
138
|
+
elif isinstance(jsextensions, str):
|
|
131
139
|
jsextensions = [extension.strip() for extension in jsextensions.split(",")]
|
|
132
140
|
elif not isinstance(jsextensions, list):
|
|
133
141
|
jsextensions = [jsextensions]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Internal BrowserPOM helpers."""
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Discover and convert Browser constructor settings using Robot Framework."""
|
|
2
|
+
|
|
3
|
+
import contextlib
|
|
4
|
+
import inspect
|
|
5
|
+
|
|
6
|
+
from Browser import Browser
|
|
7
|
+
from robot.api import logger
|
|
8
|
+
from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
|
|
9
|
+
from robot.running.arguments import CustomArgumentConverters, PythonArgumentParser
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _warn_conversion_failure(variable: str, error: Exception) -> None:
|
|
13
|
+
logger.warn(
|
|
14
|
+
f"BrowserPOM: ignoring {variable} because its value could not be converted ({type(error).__name__}). The Browser default will be used.",
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _resolve_rf_browser_args(*args: object, **kwargs: object) -> tuple[tuple[object, ...], dict[str, object]]:
|
|
19
|
+
"""Fill omitted arguments from Robot variables and apply Browser's types."""
|
|
20
|
+
signature = inspect.signature(Browser.__init__)
|
|
21
|
+
supplied_arguments = signature.bind_partial(None, *args, **kwargs).arguments
|
|
22
|
+
argument_spec = PythonArgumentParser().parse(Browser.__init__)
|
|
23
|
+
converters = CustomArgumentConverters.from_dict(getattr(Browser, "ROBOT_LIBRARY_CONVERTERS", {}))
|
|
24
|
+
positional, named = argument_spec.convert(args, list(kwargs.items()), converters)
|
|
25
|
+
kwargs = dict(named)
|
|
26
|
+
missing = object()
|
|
27
|
+
with contextlib.suppress(RobotNotRunningError):
|
|
28
|
+
for argument, parameter in list(signature.parameters.items())[1:]:
|
|
29
|
+
if argument in supplied_arguments or parameter.kind not in (
|
|
30
|
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
31
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
32
|
+
):
|
|
33
|
+
continue
|
|
34
|
+
variable = f"${{BROWSERPOM_{argument.upper()}}}"
|
|
35
|
+
value = BuiltIn().get_variable_value(variable, missing)
|
|
36
|
+
if value is missing:
|
|
37
|
+
continue
|
|
38
|
+
try:
|
|
39
|
+
_, converted = argument_spec.convert([], [(argument, value)], converters)
|
|
40
|
+
except (TypeError, ValueError) as error:
|
|
41
|
+
_warn_conversion_failure(variable, error)
|
|
42
|
+
continue
|
|
43
|
+
kwargs.update(converted)
|
|
44
|
+
return tuple(positional), kwargs
|
|
@@ -7,6 +7,8 @@ from typing import TYPE_CHECKING, Self, cast
|
|
|
7
7
|
from robot.libraries.BuiltIn import BuiltIn
|
|
8
8
|
|
|
9
9
|
if TYPE_CHECKING:
|
|
10
|
+
from collections.abc import Iterator
|
|
11
|
+
|
|
10
12
|
from Browser import Browser
|
|
11
13
|
|
|
12
14
|
|
|
@@ -40,6 +42,10 @@ class UIObject:
|
|
|
40
42
|
"""
|
|
41
43
|
return cast("Browser", BuiltIn().get_library_instance("BrowserPOM"))
|
|
42
44
|
|
|
45
|
+
def __contains__(self, item: object) -> bool:
|
|
46
|
+
"""Reject membership tests without falling back to indexed iteration."""
|
|
47
|
+
raise TypeError(f"'{type(self).__name__}' object does not support membership tests")
|
|
48
|
+
|
|
43
49
|
def __getitem__(self, index: int | str) -> Self:
|
|
44
50
|
"""Retrieves an indexed or text-based child UI object.
|
|
45
51
|
|
|
@@ -58,6 +64,17 @@ class UIObject:
|
|
|
58
64
|
return self.filter(f"hasText: '{index}'")
|
|
59
65
|
raise TypeError("Index must be an int or a str.")
|
|
60
66
|
|
|
67
|
+
def __iter__(self) -> Iterator[Self]:
|
|
68
|
+
"""Yield indexed UIObjects for the matches present when iteration begins.
|
|
69
|
+
|
|
70
|
+
Count matches once using the complete locator, including parents. Each
|
|
71
|
+
result behaves like integer indexing: its locator follows the current
|
|
72
|
+
position if the DOM changes. A new iteration queries the count again.
|
|
73
|
+
"""
|
|
74
|
+
count = self.browser.get_element_count(str(self))
|
|
75
|
+
for index in range(count):
|
|
76
|
+
yield self[index]
|
|
77
|
+
|
|
61
78
|
def filter(self, filter_text: str) -> Self:
|
|
62
79
|
"""Filters the UI object by a given filter.
|
|
63
80
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: robotframework-browserpom
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.1
|
|
4
4
|
Summary: robotframework-browser library extension to create Page Objects
|
|
5
5
|
Author-email: Hasan Alp Zengin <hasanalpzengin@gmail.com>
|
|
6
6
|
License-File: LICENSE
|
|
@@ -12,7 +12,7 @@ Classifier: Operating System :: OS Independent
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
13
13
|
Classifier: Topic :: Software Development :: Quality Assurance
|
|
14
14
|
Classifier: Topic :: Software Development :: Testing
|
|
15
|
-
Requires-Python: <4.0,>=3.
|
|
15
|
+
Requires-Python: <4.0,>=3.10
|
|
16
16
|
Requires-Dist: robotframework-browser
|
|
17
17
|
Requires-Dist: robotframework>=5.1.0
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
@@ -89,16 +89,63 @@ Library demo/MainPage.py AS MainPage
|
|
|
89
89
|
|
|
90
90
|
Test Setup Browser.Open Browser https://automationbookstore.dev headless=True
|
|
91
91
|
```
|
|
92
|
-
# robotframework-browserpom
|
|
93
92
|
|
|
94
|
-
|
|
93
|
+
## Browser settings from Robot Framework runtime variables
|
|
95
94
|
|
|
96
|
-
|
|
95
|
+
``BrowserPOM`` discovers all named constructor arguments supported by the installed
|
|
96
|
+
``Browser`` library. Each can be configured through a Robot variable named
|
|
97
|
+
`BROWSERPOM_<ARGUMENT>` (the argument name uppercased), without maintaining an
|
|
98
|
+
allowlist.
|
|
99
|
+
These variables let you configure BrowserPOM once in a central location, avoiding the need to repeat library import arguments in every test suite.
|
|
97
100
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
Examples:
|
|
102
|
+
|
|
103
|
+
| Variable | Browser import argument |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| `BROWSERPOM_AUTO_CLOSING_LEVEL` | `auto_closing_level` |
|
|
106
|
+
| `BROWSERPOM_AUTO_DELETE_PASSED_TRACING` | `auto_delete_passed_tracing` |
|
|
107
|
+
| `BROWSERPOM_RETRY_ASSERTIONS_FOR` | `retry_assertions_for` |
|
|
108
|
+
| `BROWSERPOM_PLUGINS` | `plugins` |
|
|
109
|
+
| `BROWSERPOM_TIMEOUT` | `timeout` |
|
|
110
|
+
| `BROWSERPOM_STRICT` | `strict` |
|
|
111
|
+
|
|
112
|
+
Both runtime variable values and explicit import arguments are converted using
|
|
113
|
+
Robot Framework's argument conversion machinery, Browser's constructor type
|
|
114
|
+
annotations, and Browser's registered custom converters. Passing raw values
|
|
115
|
+
directly to Browser's Python constructor does not perform this conversion.
|
|
116
|
+
Invalid runtime variable values produce a warning and leave Browser's default
|
|
117
|
+
unchanged; invalid explicit import arguments fail library initialization.
|
|
118
|
+
|
|
119
|
+
### Usage via ``Suite Variables``
|
|
120
|
+
|
|
121
|
+
```robot
|
|
122
|
+
*** Settings ***
|
|
123
|
+
Library BrowserPOM
|
|
124
|
+
|
|
125
|
+
*** Variables ***
|
|
126
|
+
${BROWSERPOM_AUTO_CLOSING_LEVEL} SUITE
|
|
127
|
+
${BROWSERPOM_AUTO_DELETE_PASSED_TRACING} ${TRUE}
|
|
128
|
+
${BROWSERPOM_RETRY_ASSERTIONS_FOR} 2 seconds
|
|
129
|
+
${BROWSERPOM_PLUGINS} package.FirstPlugin,package.SecondPlugin
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`BROWSERPOM_PLUGINS` accepts a single Python plugin class/module, a
|
|
133
|
+
comma-separated string, or a list of strings, just like Browser's `plugins`
|
|
134
|
+
argument.
|
|
135
|
+
|
|
136
|
+
### Usage via ``robot.toml``
|
|
137
|
+
|
|
138
|
+
```toml
|
|
139
|
+
[variables]
|
|
140
|
+
BROWSERPOM_AUTO_CLOSING_LEVEL = "SUITE"
|
|
141
|
+
BROWSERPOM_RETRY_ASSERTIONS_FOR = "10s"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Variable Precedence
|
|
145
|
+
|
|
146
|
+
Explicit library import arguments take precedence over these variables, even
|
|
147
|
+
when the argument is `False` or `0`. If neither is provided, Browser's default
|
|
148
|
+
is preserved.
|
|
102
149
|
|
|
103
150
|
## Editor / linter integration: the variables problem
|
|
104
151
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "robotframework-browserpom"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.8.1"
|
|
4
4
|
description = "robotframework-browser library extension to create Page Objects"
|
|
5
5
|
authors = [{ name = "Hasan Alp Zengin", email = "hasanalpzengin@gmail.com" }]
|
|
6
|
-
requires-python = ">=3.
|
|
6
|
+
requires-python = ">=3.10,<4.0"
|
|
7
7
|
readme = "readme.md"
|
|
8
8
|
classifiers = [
|
|
9
9
|
"Programming Language :: Python :: 3",
|
|
@@ -31,7 +31,7 @@ test = [
|
|
|
31
31
|
"pytest>=8.4.2",
|
|
32
32
|
"pytest_robotframework>=4.3.0,<5",
|
|
33
33
|
"ruff>=0.11.0,<0.12",
|
|
34
|
-
"robotframework-browser-batteries
|
|
34
|
+
"robotframework-browser-batteries==20.1.0",
|
|
35
35
|
]
|
|
36
36
|
dev = [
|
|
37
37
|
"hatchling",
|
|
@@ -70,16 +70,63 @@ Library demo/MainPage.py AS MainPage
|
|
|
70
70
|
|
|
71
71
|
Test Setup Browser.Open Browser https://automationbookstore.dev headless=True
|
|
72
72
|
```
|
|
73
|
-
# robotframework-browserpom
|
|
74
73
|
|
|
75
|
-
|
|
74
|
+
## Browser settings from Robot Framework runtime variables
|
|
76
75
|
|
|
77
|
-
|
|
76
|
+
``BrowserPOM`` discovers all named constructor arguments supported by the installed
|
|
77
|
+
``Browser`` library. Each can be configured through a Robot variable named
|
|
78
|
+
`BROWSERPOM_<ARGUMENT>` (the argument name uppercased), without maintaining an
|
|
79
|
+
allowlist.
|
|
80
|
+
These variables let you configure BrowserPOM once in a central location, avoiding the need to repeat library import arguments in every test suite.
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
Examples:
|
|
83
|
+
|
|
84
|
+
| Variable | Browser import argument |
|
|
85
|
+
| --- | --- |
|
|
86
|
+
| `BROWSERPOM_AUTO_CLOSING_LEVEL` | `auto_closing_level` |
|
|
87
|
+
| `BROWSERPOM_AUTO_DELETE_PASSED_TRACING` | `auto_delete_passed_tracing` |
|
|
88
|
+
| `BROWSERPOM_RETRY_ASSERTIONS_FOR` | `retry_assertions_for` |
|
|
89
|
+
| `BROWSERPOM_PLUGINS` | `plugins` |
|
|
90
|
+
| `BROWSERPOM_TIMEOUT` | `timeout` |
|
|
91
|
+
| `BROWSERPOM_STRICT` | `strict` |
|
|
92
|
+
|
|
93
|
+
Both runtime variable values and explicit import arguments are converted using
|
|
94
|
+
Robot Framework's argument conversion machinery, Browser's constructor type
|
|
95
|
+
annotations, and Browser's registered custom converters. Passing raw values
|
|
96
|
+
directly to Browser's Python constructor does not perform this conversion.
|
|
97
|
+
Invalid runtime variable values produce a warning and leave Browser's default
|
|
98
|
+
unchanged; invalid explicit import arguments fail library initialization.
|
|
99
|
+
|
|
100
|
+
### Usage via ``Suite Variables``
|
|
101
|
+
|
|
102
|
+
```robot
|
|
103
|
+
*** Settings ***
|
|
104
|
+
Library BrowserPOM
|
|
105
|
+
|
|
106
|
+
*** Variables ***
|
|
107
|
+
${BROWSERPOM_AUTO_CLOSING_LEVEL} SUITE
|
|
108
|
+
${BROWSERPOM_AUTO_DELETE_PASSED_TRACING} ${TRUE}
|
|
109
|
+
${BROWSERPOM_RETRY_ASSERTIONS_FOR} 2 seconds
|
|
110
|
+
${BROWSERPOM_PLUGINS} package.FirstPlugin,package.SecondPlugin
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`BROWSERPOM_PLUGINS` accepts a single Python plugin class/module, a
|
|
114
|
+
comma-separated string, or a list of strings, just like Browser's `plugins`
|
|
115
|
+
argument.
|
|
116
|
+
|
|
117
|
+
### Usage via ``robot.toml``
|
|
118
|
+
|
|
119
|
+
```toml
|
|
120
|
+
[variables]
|
|
121
|
+
BROWSERPOM_AUTO_CLOSING_LEVEL = "SUITE"
|
|
122
|
+
BROWSERPOM_RETRY_ASSERTIONS_FOR = "10s"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Variable Precedence
|
|
126
|
+
|
|
127
|
+
Explicit library import arguments take precedence over these variables, even
|
|
128
|
+
when the argument is `False` or `0`. If neither is provided, Browser's default
|
|
129
|
+
is preserved.
|
|
83
130
|
|
|
84
131
|
## Editor / linter integration: the variables problem
|
|
85
132
|
|
|
File without changes
|
{robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/__init__.py
RENAMED
|
File without changes
|
{robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/__main__.py
RENAMED
|
File without changes
|
|
File without changes
|
{robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/config.py
RENAMED
|
File without changes
|
{robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/exceptions.py
RENAMED
|
File without changes
|
{robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/formatting.py
RENAMED
|
File without changes
|
{robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/cli/scanner.py
RENAMED
|
File without changes
|
|
File without changes
|
{robotframework_browserpom-0.7.0 → robotframework_browserpom-0.8.1}/BrowserPOM/pageobject.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|