robotframework-browserpom 0.5.2__tar.gz → 0.6.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.5.2 → robotframework_browserpom-0.6.1}/BrowserPOM/__init__.py +21 -2
- robotframework_browserpom-0.6.1/BrowserPOM/addons/filter_locator.js +25 -0
- {robotframework_browserpom-0.5.2 → robotframework_browserpom-0.6.1}/BrowserPOM/uiobject.py +1 -4
- {robotframework_browserpom-0.5.2 → robotframework_browserpom-0.6.1}/PKG-INFO +1 -1
- {robotframework_browserpom-0.5.2 → robotframework_browserpom-0.6.1}/pyproject.toml +3 -2
- robotframework_browserpom-0.5.2/BrowserPOM/addons/playwright_page_method.js +0 -52
- {robotframework_browserpom-0.5.2 → robotframework_browserpom-0.6.1}/.gitignore +0 -0
- {robotframework_browserpom-0.5.2 → robotframework_browserpom-0.6.1}/BrowserPOM/decorator.py +0 -0
- {robotframework_browserpom-0.5.2 → robotframework_browserpom-0.6.1}/BrowserPOM/pageobject.py +0 -0
- {robotframework_browserpom-0.5.2 → robotframework_browserpom-0.6.1}/BrowserPOM/pom_stubs.py +0 -0
- {robotframework_browserpom-0.5.2 → robotframework_browserpom-0.6.1}/LICENSE +0 -0
- {robotframework_browserpom-0.5.2 → robotframework_browserpom-0.6.1}/readme.md +0 -0
|
@@ -7,6 +7,7 @@ from typing import TYPE_CHECKING, cast
|
|
|
7
7
|
|
|
8
8
|
from Browser import Browser
|
|
9
9
|
from Browser.utils import ScreenshotFileTypes, ScreenshotReturnType
|
|
10
|
+
from robot.api import logger
|
|
10
11
|
from robot.api.deco import keyword
|
|
11
12
|
from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
|
|
12
13
|
|
|
@@ -121,7 +122,7 @@ class BrowserPOM(Browser):
|
|
|
121
122
|
Optional arguments are passed to the
|
|
122
123
|
[https://robotframework-browser.org/|BrowserLibrary] constructor.
|
|
123
124
|
"""
|
|
124
|
-
addon_path = Path(__file__).parent / "addons" / "
|
|
125
|
+
addon_path = Path(__file__).parent / "addons" / "filter_locator.js"
|
|
125
126
|
with contextlib.suppress(RobotNotRunningError):
|
|
126
127
|
BuiltIn().set_library_search_order("BrowserPOM", "Browser")
|
|
127
128
|
|
|
@@ -135,7 +136,25 @@ class BrowserPOM(Browser):
|
|
|
135
136
|
kwargs["jsextension"] = jsextensions
|
|
136
137
|
|
|
137
138
|
browser_init = cast("Callable[..., None]", super().__init__)
|
|
138
|
-
|
|
139
|
+
try:
|
|
140
|
+
browser_init(*args, **kwargs)
|
|
141
|
+
except Exception as error: # noqa: BLE001
|
|
142
|
+
# Passing a ``jsextension`` makes BrowserLibrary eagerly start the
|
|
143
|
+
# Playwright Node.js process during ``__init__`` (to register the JS
|
|
144
|
+
# keywords). When BrowserPOM is only imported so another library or
|
|
145
|
+
# tool can gather its keywords, that spawn can fail in fork-unsafe
|
|
146
|
+
# contexts (e.g. grpc already initialised, pabot,
|
|
147
|
+
# pytest_robotframework), raising errors such as
|
|
148
|
+
# "TypeError: 'NoneType' object is not callable" from subprocess.
|
|
149
|
+
# Fall back to a plain init so keyword gathering does not crash the
|
|
150
|
+
# importing library.
|
|
151
|
+
logger.warn(
|
|
152
|
+
"BrowserPOM: failed to load the 'filter_locator' jsextension "
|
|
153
|
+
f"during import ({error}). The library was initialised without "
|
|
154
|
+
"it so keyword gathering can continue.",
|
|
155
|
+
)
|
|
156
|
+
kwargs["jsextension"] = [extension for extension in jsextensions if extension != str(addon_path)] or None
|
|
157
|
+
browser_init(*args, **kwargs)
|
|
139
158
|
|
|
140
159
|
@keyword
|
|
141
160
|
def take_screenshot(self, *args, **kwargs): # noqa:ANN002,ANN003,ANN201
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
async function filterLocator(base_locator, filter_statement, page, logger) {
|
|
2
|
+
const playwright_function = "(page.locator('" + base_locator + "').filter({" + filter_statement + "}))"
|
|
3
|
+
logger("Filtering Playwright locator: " + playwright_function)
|
|
4
|
+
const result = await eval(playwright_function);
|
|
5
|
+
// If the result is an object we assume it's a locator so we return the _selector property of the locator object
|
|
6
|
+
if (typeof result == "object") {
|
|
7
|
+
return result._selector;
|
|
8
|
+
} else {
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
filterLocator.rfdoc = `
|
|
14
|
+
This keyword returns a Playwright locator with the given filter applied.
|
|
15
|
+
|
|
16
|
+
Parameters:
|
|
17
|
+
base_locator : (string) The locator on which the filter should be applied.
|
|
18
|
+
filter_statement : (string) The filter to apply, e.g. 'hasText: "foo"'
|
|
19
|
+
|
|
20
|
+
Example
|
|
21
|
+
| Filter Locator //li hasText: "foo"
|
|
22
|
+
`
|
|
23
|
+
|
|
24
|
+
exports.__esModule = true;
|
|
25
|
+
exports.filterLocator = filterLocator;
|
|
@@ -71,10 +71,7 @@ class UIObject:
|
|
|
71
71
|
|
|
72
72
|
"""
|
|
73
73
|
base_locator = str(self).replace("'", '"')
|
|
74
|
-
locator = BuiltIn().run_keyword(
|
|
75
|
-
"Playwright Page Method",
|
|
76
|
-
"locator('" + base_locator + "').filter({" + filter_text + "})",
|
|
77
|
-
)
|
|
74
|
+
locator = BuiltIn().run_keyword("Filter Locator", base_locator, filter_text)
|
|
78
75
|
return self.__class__(locator)
|
|
79
76
|
|
|
80
77
|
def self_locator(self) -> str:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "robotframework-browserpom"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.6.1"
|
|
4
4
|
description = "robotframework-browser library extension to create Page Objects"
|
|
5
5
|
authors = [{ name = "Hasan Alp Zengin", email = "hasanalpzengin@gmail.com" }]
|
|
6
6
|
requires-python = ">=3.9,<4.0"
|
|
@@ -24,9 +24,10 @@ repository = "https://github.com/hasanalpzengin/robotframework-browserpom"
|
|
|
24
24
|
[dependency-groups]
|
|
25
25
|
test = [
|
|
26
26
|
"prek>=0.2.19",
|
|
27
|
-
"pyrefly>=
|
|
27
|
+
"pyrefly>=1.1.1",
|
|
28
28
|
"pytest_robotframework>=4.3.0,<5",
|
|
29
29
|
"ruff>=0.11.0,<0.12",
|
|
30
|
+
"robotframework-browser-batteries>=19.9.0",
|
|
30
31
|
]
|
|
31
32
|
dev = [
|
|
32
33
|
"hatchling",
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const path = require('node:path');
|
|
2
|
-
const { expect } = require(path.resolve('node_modules/playwright/test'));
|
|
3
|
-
|
|
4
|
-
async function playwrightPageMethod(page_method, page, logger) {
|
|
5
|
-
const playwright_function = '(page.' + page_method + ')';
|
|
6
|
-
logger("Executing Playwright Page method: " + page_method)
|
|
7
|
-
const result = await eval(playwright_function);
|
|
8
|
-
// If the result is an object we assume it's a locator so we return the _selector property of the locator object
|
|
9
|
-
if (typeof result == "object") {
|
|
10
|
-
return result._selector;
|
|
11
|
-
} else {
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function playwrightJS(statement, page, logger) {
|
|
17
|
-
const playwright_statement = '(' + statement + ')';
|
|
18
|
-
logger("Executing Playwright method: " + statement)
|
|
19
|
-
const result = await eval(playwright_statement);
|
|
20
|
-
// If the result is an object we assume it's a locator so we return the _selector property of the locator object
|
|
21
|
-
if (typeof result == "object") {
|
|
22
|
-
return result._selector;
|
|
23
|
-
} else {
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
playwrightPageMethod.rfdoc = `
|
|
29
|
-
This keyword executes a Playwright Page method.
|
|
30
|
-
|
|
31
|
-
Parameters: page_method : (string) The page method to be executed in Playwright.
|
|
32
|
-
|
|
33
|
-
Example
|
|
34
|
-
| Playwright Page Method getByRole('link', { name: 'Get started' }).click()
|
|
35
|
-
`
|
|
36
|
-
|
|
37
|
-
playwrightJS.rfdoc = `
|
|
38
|
-
This keyword executes a JavaScript Playwright statement, which can be page methods including assertions.
|
|
39
|
-
Except for the following assertions which are not supported:
|
|
40
|
-
| expect(page).toHaveScreenshot()
|
|
41
|
-
| expect(page).toMatchSnapshot()
|
|
42
|
-
|
|
43
|
-
Parameters: statement : (string) The Playwright statement to be executed.
|
|
44
|
-
|
|
45
|
-
Example
|
|
46
|
-
| Playwright JS page.getByRole('link', { name: 'Get started' }).click()
|
|
47
|
-
| Playwright JS expect(page.getByRole('link', { name: 'Get started' })).toBeVisible()
|
|
48
|
-
`
|
|
49
|
-
|
|
50
|
-
exports.__esModule = true;
|
|
51
|
-
exports.playwrightPageMethod = playwrightPageMethod;
|
|
52
|
-
exports.playwrightJS = playwrightJS;
|
|
File without changes
|
|
File without changes
|
{robotframework_browserpom-0.5.2 → robotframework_browserpom-0.6.1}/BrowserPOM/pageobject.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|