robotframework-platynui 0.13.0.dev117__py3-none-any.whl → 0.14.0.dev0__py3-none-any.whl
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.
- PlatynUI/BareMetal/__init__.py +1063 -296
- PlatynUI/__version__.py +1 -1
- PlatynUI/_assertable.py +1 -1
- PlatynUI/_our_libcore.py +15 -0
- PlatynUI/core/adapter_devices.py +2 -2
- PlatynUI/core/adapter_factory.py +22 -0
- PlatynUI/core/context.py +37 -8
- PlatynUI/core/locator.py +15 -4
- PlatynUI/core/native_logging.py +122 -0
- PlatynUI/ui/application.py +29 -8
- robotframework_platynui-0.14.0.dev0.dist-info/METADATA +208 -0
- {robotframework_platynui-0.13.0.dev117.dist-info → robotframework_platynui-0.14.0.dev0.dist-info}/RECORD +13 -12
- {robotframework_platynui-0.13.0.dev117.dist-info → robotframework_platynui-0.14.0.dev0.dist-info}/WHEEL +1 -1
- robotframework_platynui-0.13.0.dev117.dist-info/METADATA +0 -173
PlatynUI/BareMetal/__init__.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import base64
|
|
2
|
+
import logging
|
|
2
3
|
import re
|
|
3
4
|
import time
|
|
5
|
+
from collections.abc import Callable
|
|
4
6
|
from dataclasses import dataclass, replace
|
|
5
7
|
from functools import cached_property
|
|
6
8
|
from pathlib import Path
|
|
7
|
-
from typing import Any, Literal, TypedDict, cast
|
|
9
|
+
from typing import TYPE_CHECKING, Any, Literal, TypeAlias, TypedDict, cast
|
|
8
10
|
|
|
9
11
|
from assertionengine import AssertionOperator, verify_assertion
|
|
10
12
|
from platynui_native import (
|
|
@@ -13,11 +15,13 @@ from platynui_native import (
|
|
|
13
15
|
Closeable,
|
|
14
16
|
EvaluatedAttribute,
|
|
15
17
|
EvaluationError,
|
|
18
|
+
KeyboardError,
|
|
16
19
|
KeyboardOverridesLike,
|
|
17
20
|
KeyboardProfileLike,
|
|
18
21
|
Maximizable,
|
|
19
22
|
Minimizable,
|
|
20
23
|
Movable,
|
|
24
|
+
Namespace,
|
|
21
25
|
Point,
|
|
22
26
|
PointerButton,
|
|
23
27
|
PointerButtonLike,
|
|
@@ -30,16 +34,33 @@ from platynui_native import (
|
|
|
30
34
|
Restorable,
|
|
31
35
|
Runtime,
|
|
32
36
|
UiNode,
|
|
33
|
-
UiValue,
|
|
34
37
|
)
|
|
35
38
|
from robot.api import logger
|
|
36
39
|
from robot.api.deco import library
|
|
37
40
|
from robot.libraries.BuiltIn import BuiltIn
|
|
38
41
|
from robot.running.context import EXECUTION_CONTEXTS
|
|
42
|
+
from robot.utils import ErrorDetails
|
|
39
43
|
|
|
40
44
|
from ..__version__ import __version__
|
|
41
45
|
from .._assertable import assertable
|
|
42
46
|
from .._our_libcore import OurDynamicCore, keyword
|
|
47
|
+
from ..core.native_logging import NativeLogScope, flush_native_logs, native_log_levels
|
|
48
|
+
|
|
49
|
+
if TYPE_CHECKING:
|
|
50
|
+
from robot.api.types import Secret
|
|
51
|
+
|
|
52
|
+
KeyboardText: TypeAlias = str | Secret
|
|
53
|
+
else:
|
|
54
|
+
# ``Secret`` exists since Robot Framework 7.4; earlier versions type plain strings only.
|
|
55
|
+
try:
|
|
56
|
+
from robot.api.types import Secret
|
|
57
|
+
except ImportError:
|
|
58
|
+
KeyboardText = str
|
|
59
|
+
else:
|
|
60
|
+
KeyboardText = str | Secret
|
|
61
|
+
|
|
62
|
+
# The library's own records; Robot Framework shows them in the keyword's log at their level.
|
|
63
|
+
_LOG = logging.getLogger('platynui.baremetal')
|
|
43
64
|
|
|
44
65
|
|
|
45
66
|
class BareMetalError(Exception):
|
|
@@ -50,6 +71,26 @@ class ElementNotFoundError(BareMetalError):
|
|
|
50
71
|
"""Raised when a UiNode cannot be found for a given query within the specified timeout."""
|
|
51
72
|
|
|
52
73
|
|
|
74
|
+
class RootNotFoundError(ElementNotFoundError):
|
|
75
|
+
"""Raised when the root set by `Set Root` is not found, so a query relative to it was not evaluated."""
|
|
76
|
+
|
|
77
|
+
def __init__(
|
|
78
|
+
self,
|
|
79
|
+
root_query: str | None,
|
|
80
|
+
timeout: float,
|
|
81
|
+
query: str | None = None,
|
|
82
|
+
*,
|
|
83
|
+
last_error: Exception | None = None,
|
|
84
|
+
) -> None:
|
|
85
|
+
self.root_query = root_query
|
|
86
|
+
self.timeout = timeout
|
|
87
|
+
# The error the root's own lookup raised last, when the root's settings ignore errors.
|
|
88
|
+
self.last_error = last_error
|
|
89
|
+
message = f'The root set by Set Root, {root_query!r}, was not found within timeout of {timeout} seconds'
|
|
90
|
+
message = f'{message}; {query!r} was not evaluated.' if query is not None else f'{message}.'
|
|
91
|
+
super().__init__(_with_last_error(message, last_error))
|
|
92
|
+
|
|
93
|
+
|
|
53
94
|
class ResultTypeError(BareMetalError):
|
|
54
95
|
"""Raised when a query result cannot be interpreted as the expected type (e.g., UiNode)."""
|
|
55
96
|
|
|
@@ -112,9 +153,9 @@ PLATYNUI_QUERY_SETTINGS = (
|
|
|
112
153
|
class QuerySettings:
|
|
113
154
|
"""Fully resolved settings for the query wait/retry loop.
|
|
114
155
|
|
|
115
|
-
These are the values
|
|
116
|
-
how long to
|
|
117
|
-
|
|
156
|
+
These are the values `_poll` consults on every wait: how long to keep retrying (``timeout``),
|
|
157
|
+
how long to pause between attempts (``retry_interval``) and whether to swallow the errors an
|
|
158
|
+
attempt raises instead of failing on them (``ignore_exceptions``).
|
|
118
159
|
"""
|
|
119
160
|
|
|
120
161
|
timeout: float = 30.0
|
|
@@ -134,6 +175,113 @@ class QuerySettingsDict(TypedDict, total=False):
|
|
|
134
175
|
ignore_exceptions: bool
|
|
135
176
|
|
|
136
177
|
|
|
178
|
+
# The errors that waiting cannot fix: a wait ends at once on them, whatever ``ignore_exceptions``
|
|
179
|
+
# says. A `RuntimeError` comes from AssertionEngine, for an operator it does not know, or from
|
|
180
|
+
# Robot Framework, for a ``validate`` expression that cannot be evaluated; like `SystemExit`, it
|
|
181
|
+
# ends the wait.
|
|
182
|
+
_UNWAITABLE_ERRORS: tuple[type[Exception], ...] = (
|
|
183
|
+
ResultTypeError,
|
|
184
|
+
NoQueryError,
|
|
185
|
+
ForeignNodeError,
|
|
186
|
+
PinnedElementGoneError,
|
|
187
|
+
RootNotFoundError,
|
|
188
|
+
RuntimeError,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _with_last_error(message: str, last_error: Exception | None) -> str:
|
|
193
|
+
"""``message``, followed by the error the last attempt raised, the way Robot Framework quotes one.
|
|
194
|
+
|
|
195
|
+
``Wait Until Keyword Succeeds`` ends its failure the same way, and the error reads as it would
|
|
196
|
+
had it failed the keyword itself: its type, then its message, with the type left out where Robot
|
|
197
|
+
Framework leaves it out, as for an ``AssertionError``.
|
|
198
|
+
"""
|
|
199
|
+
if last_error is None:
|
|
200
|
+
return message
|
|
201
|
+
return f'{message} The last error was: {ErrorDetails(last_error).message}'
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class _NotYet:
|
|
205
|
+
"""What an attempt returns when it did not satisfy its wait."""
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
_NOT_YET = _NotYet()
|
|
209
|
+
|
|
210
|
+
# A step that the attempt did not reach.
|
|
211
|
+
_UNSEEN: Any = object()
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
@dataclass(slots=True)
|
|
215
|
+
class _Attempt:
|
|
216
|
+
"""How far one attempt of a wait got, for the failure at the deadline.
|
|
217
|
+
|
|
218
|
+
The attempt fills it in step by step, so an attempt that raises still tells how far it got:
|
|
219
|
+
``result`` is what the selector or expression gave (for `Wait Until Attribute Value` the element,
|
|
220
|
+
or ``None``), ``value`` the attribute's value, and ``mismatch`` why the check did not hold. A
|
|
221
|
+
step the attempt did not reach stays `_UNSEEN`.
|
|
222
|
+
"""
|
|
223
|
+
|
|
224
|
+
result: Any = _UNSEEN
|
|
225
|
+
value: Any = _UNSEEN
|
|
226
|
+
mismatch: AssertionError | TypeError | None = None
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _poll[R](
|
|
230
|
+
library: 'BareMetal',
|
|
231
|
+
settings: QuerySettings,
|
|
232
|
+
context: Callable[[], 'UiNode | None'],
|
|
233
|
+
attempt: Callable[['UiNode | None', _Attempt], R | _NotYet],
|
|
234
|
+
failure: Callable[[_Attempt, Exception | None], Exception],
|
|
235
|
+
*,
|
|
236
|
+
discard_first: bool,
|
|
237
|
+
) -> R:
|
|
238
|
+
"""Wait until an attempt satisfies the wait, or fail once ``settings.timeout`` has elapsed.
|
|
239
|
+
|
|
240
|
+
Every wait of the library runs here: the element lookup of every keyword and of a root, and
|
|
241
|
+
`Wait Until Gone`, `Wait Until Query` and `Wait Until Attribute Value`. So they agree on this:
|
|
242
|
+
|
|
243
|
+
- ``context`` runs first in every attempt and yields the element to evaluate against. It looks
|
|
244
|
+
up the root, and nothing it raises is swallowed: a root that cannot be found ends the wait,
|
|
245
|
+
whatever ``ignore_exceptions`` says.
|
|
246
|
+
- ``attempt`` returns its result, or `_NOT_YET`. An error of `_UNWAITABLE_ERRORS` ends the
|
|
247
|
+
wait. Any other error ends it too, unless ``ignore_exceptions`` is on: then the attempt did
|
|
248
|
+
not satisfy the wait, and its error is the last error, until an attempt completes.
|
|
249
|
+
- The elapsed time is compared with the timeout after each attempt. So there is at least one,
|
|
250
|
+
and nothing is evaluated after the deadline: ``failure`` gets what the last attempt saw and
|
|
251
|
+
the error it raised, and its exception is raised chained to that error.
|
|
252
|
+
- The clock starts after the first ``context``: finding the root takes the root's own timeout,
|
|
253
|
+
not the wait's. A root looked up again during the wait counts, as the attempt it belongs to.
|
|
254
|
+
|
|
255
|
+
``discard_first`` discards the runtime's snapshot before the first attempt as well as before
|
|
256
|
+
every later one. The element lookup keeps it for its first attempt, so that an action right
|
|
257
|
+
after another reuses what that one read. `SystemExit`, `KeyboardInterrupt` and Robot
|
|
258
|
+
Framework's own timeout pass through, since only an `Exception` is caught.
|
|
259
|
+
"""
|
|
260
|
+
start: float | None = None
|
|
261
|
+
while True:
|
|
262
|
+
if discard_first or start is not None:
|
|
263
|
+
library.runtime.clear_cache()
|
|
264
|
+
node = context()
|
|
265
|
+
if start is None:
|
|
266
|
+
start = time.monotonic()
|
|
267
|
+
seen = _Attempt()
|
|
268
|
+
last_error: Exception | None = None
|
|
269
|
+
try:
|
|
270
|
+
result = attempt(node, seen)
|
|
271
|
+
except _UNWAITABLE_ERRORS:
|
|
272
|
+
raise
|
|
273
|
+
except Exception as error:
|
|
274
|
+
if not settings.ignore_exceptions:
|
|
275
|
+
raise
|
|
276
|
+
last_error = error
|
|
277
|
+
else:
|
|
278
|
+
if not isinstance(result, _NotYet):
|
|
279
|
+
return result
|
|
280
|
+
if (time.monotonic() - start) > settings.timeout:
|
|
281
|
+
raise failure(seen, last_error) from last_error
|
|
282
|
+
time.sleep(settings.retry_interval)
|
|
283
|
+
|
|
284
|
+
|
|
137
285
|
class UiNodeDescriptor:
|
|
138
286
|
"""An element reference: either a selector or a captured element.
|
|
139
287
|
|
|
@@ -153,13 +301,13 @@ class UiNodeDescriptor:
|
|
|
153
301
|
|
|
154
302
|
One exception to "holds no resolved element": a selector used **as a root** keeps the element
|
|
155
303
|
it resolved to, reused while that element is still live and still belongs to the resolving
|
|
156
|
-
instance. A root is looked up
|
|
157
|
-
repetition the suite never asked for — and unlike a target selector, whose
|
|
158
|
-
the observation the keyword makes, a root names a container that was pinned
|
|
159
|
-
element is dropped as soon as it stops being valid, so a root still survives its
|
|
160
|
-
and reopening. Note what this rests on:
|
|
161
|
-
|
|
162
|
-
root that is never looked up again.
|
|
304
|
+
instance. A root is looked up on every attempt of a keyword's wait, on top of the keyword's own
|
|
305
|
+
target, so it is repetition the suite never asked for — and unlike a target selector, whose
|
|
306
|
+
re-evaluation *is* the observation the keyword makes, a root names a container that was pinned
|
|
307
|
+
on purpose. The element is dropped as soon as it stops being valid, so a root still survives its
|
|
308
|
+
window closing and reopening, even in the middle of a wait. Note what this rests on:
|
|
309
|
+
`platynui_native.UiNode.is_valid` is a provider-side liveness check whose trait default is
|
|
310
|
+
``True`` — a provider that does not implement it gets a root that is never looked up again.
|
|
163
311
|
"""
|
|
164
312
|
|
|
165
313
|
def __init__(
|
|
@@ -191,7 +339,9 @@ class UiNodeDescriptor:
|
|
|
191
339
|
|
|
192
340
|
An absolute selector (``/`` or ``//``) starts at the document root and ignores the context
|
|
193
341
|
node, so resolving the root for it is not just wasted work — it makes the lookup fail when
|
|
194
|
-
the root itself has vanished, for a query that never needed it.
|
|
342
|
+
the root itself has vanished, for a query that never needed it. The runtime's check looks
|
|
343
|
+
into function arguments and operands too: ``count(.//x)`` needs the root, ``count(//x)``
|
|
344
|
+
does not.
|
|
195
345
|
"""
|
|
196
346
|
if self.query is None:
|
|
197
347
|
return False
|
|
@@ -208,6 +358,14 @@ class UiNodeDescriptor:
|
|
|
208
358
|
"""The runtime that produced this reference's element, or ``None`` for a selector."""
|
|
209
359
|
return self.node.owner_id if isinstance(self.node, UiNode) else None
|
|
210
360
|
|
|
361
|
+
def context_node(self, library: 'BareMetal') -> UiNode | None:
|
|
362
|
+
"""The element a keyword evaluates this selector against: the library's root, or ``None``.
|
|
363
|
+
|
|
364
|
+
``None`` is the desktop. Only a selector that needs the root looks it up (see `needs_root`),
|
|
365
|
+
through `BareMetal.root_for`.
|
|
366
|
+
"""
|
|
367
|
+
return library.root_for(self.query) if self.needs_root(library) else None
|
|
368
|
+
|
|
211
369
|
def resolve(
|
|
212
370
|
self,
|
|
213
371
|
library: 'BareMetal',
|
|
@@ -220,21 +378,18 @@ class UiNodeDescriptor:
|
|
|
220
378
|
if self.node.is_valid():
|
|
221
379
|
return self.node
|
|
222
380
|
if self.query is None:
|
|
223
|
-
raise
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
#
|
|
233
|
-
#
|
|
234
|
-
#
|
|
235
|
-
# with an attribute read per visited node — on a deep tree (Electron, WPF) that is the
|
|
236
|
-
# dominant cost, and `is_valid()` is a single provider call. Target selectors are never
|
|
237
|
-
# cached: re-evaluating them *is* what the keyword is for (see the class docs).
|
|
381
|
+
raise _pinned_element_gone(self.node)
|
|
382
|
+
|
|
383
|
+
query = self.query
|
|
384
|
+
if query is None:
|
|
385
|
+
raise NoQueryError('This element reference has no selector to look the element up with.')
|
|
386
|
+
|
|
387
|
+
# A root is looked up on every attempt of a keyword's wait *in addition* to the keyword's own
|
|
388
|
+
# target, so it is the one repetition the suite did not ask for. Reuse it while it is live: a
|
|
389
|
+
# root names a container that was pinned deliberately, and skipping its lookup skips a
|
|
390
|
+
# descendant search with an attribute read per visited node — on a deep tree (Electron, WPF)
|
|
391
|
+
# that is the dominant cost, and `is_valid()` is a single provider call. Target selectors are
|
|
392
|
+
# never cached: re-evaluating them *is* what the keyword is for (see the class docs).
|
|
238
393
|
if as_root and self._root_node is not None:
|
|
239
394
|
cached = self._root_node
|
|
240
395
|
# A selector root may legitimately be handed to another import, which then shares this
|
|
@@ -244,55 +399,53 @@ class UiNodeDescriptor:
|
|
|
244
399
|
return cached
|
|
245
400
|
self._root_node = None
|
|
246
401
|
|
|
247
|
-
# Resolving a stored root (as_root=True) evaluates the query against the captured parent
|
|
248
|
-
# chain, so a relative root drills into the enclosing root while an absolute query ignores
|
|
249
|
-
# it. As a query target (as_root=False) it evaluates against the library's current root.
|
|
250
|
-
if as_root:
|
|
251
|
-
context = self.parent.resolve(library, as_root=True) if self.parent is not None else None
|
|
252
|
-
else:
|
|
253
|
-
context = library.root if self.needs_root(library) else None
|
|
254
|
-
|
|
255
402
|
# Effective settings for this resolution: the scoped/default base, with this call's partial
|
|
256
403
|
# override applied on top. Computed once — neither layer changes during a synchronous resolve.
|
|
257
404
|
base = library.query_settings
|
|
258
405
|
settings = replace(base, **overrides) if overrides else base
|
|
259
406
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
407
|
+
def context() -> UiNode | None:
|
|
408
|
+
# A stored root (as_root=True) evaluates against the captured parent chain, so a relative
|
|
409
|
+
# root drills into the enclosing root while an absolute query ignores it. A query target
|
|
410
|
+
# evaluates against the library's current root.
|
|
411
|
+
if as_root:
|
|
412
|
+
return self.parent.resolve(library, as_root=True) if self.parent is not None else None
|
|
413
|
+
return self.context_node(library)
|
|
414
|
+
|
|
415
|
+
def attempt(context: UiNode | None, seen: _Attempt) -> UiNode | _NotYet:
|
|
416
|
+
result = library.runtime.evaluate_single(query, context)
|
|
417
|
+
if result is None:
|
|
418
|
+
return _NOT_YET
|
|
419
|
+
if not isinstance(result, UiNode):
|
|
420
|
+
raise ResultTypeError(f'Query {query!r} did not return an element, got: {result!r}')
|
|
421
|
+
return result
|
|
422
|
+
|
|
423
|
+
def failure(seen: _Attempt, last_error: Exception | None) -> Exception:
|
|
424
|
+
if as_root:
|
|
425
|
+
return RootNotFoundError(query, settings.timeout, last_error=last_error)
|
|
426
|
+
return ElementNotFoundError(
|
|
427
|
+
_with_last_error(
|
|
428
|
+
f'No element matched {query!r} within timeout of {settings.timeout} seconds.', last_error
|
|
281
429
|
)
|
|
430
|
+
)
|
|
282
431
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if not isinstance(result, UiNode):
|
|
287
|
-
raise ResultTypeError(f'Query for UiNodeDescriptor {self.query!r} did not return a UiNode, got: {result!r}')
|
|
288
|
-
|
|
432
|
+
# The snapshot is kept for the first attempt: an action right after another reuses what that
|
|
433
|
+
# one read. It is discarded before every retry, to resolve transient UI states.
|
|
434
|
+
node = _poll(library, settings, context, attempt, failure, discard_first=False)
|
|
289
435
|
if as_root:
|
|
290
|
-
self._root_node =
|
|
291
|
-
|
|
292
|
-
return result
|
|
436
|
+
self._root_node = node
|
|
437
|
+
return node
|
|
293
438
|
|
|
294
439
|
@staticmethod
|
|
295
440
|
def convert(value: str | UiNode, library: 'BareMetal') -> 'UiNodeDescriptor':
|
|
441
|
+
"""An element, given as a selector or as an element that `Query` returned.
|
|
442
|
+
|
|
443
|
+
A selector is an XPath 2.0 expression (see `Finding elements`). It is evaluated again on
|
|
444
|
+
every use, so it finds what matches at that moment, inside the current root when it is
|
|
445
|
+
relative (see `Scoping queries to a container`). An element from `Query` stays that one
|
|
446
|
+
element: it has to come from the same library import, and a keyword fails when it no
|
|
447
|
+
longer exists.
|
|
448
|
+
"""
|
|
296
449
|
if isinstance(value, UiNode):
|
|
297
450
|
return UiNodeDescriptor(value, None)
|
|
298
451
|
return library.descriptor_from_query(value)
|
|
@@ -334,6 +487,100 @@ def _assertion_value(result: Any) -> Any:
|
|
|
334
487
|
return result
|
|
335
488
|
|
|
336
489
|
|
|
490
|
+
def _result_text(result: Any) -> str:
|
|
491
|
+
"""How a failure of `Wait Until Query` names what its last attempt got: ``was 0``, ``matched nothing``.
|
|
492
|
+
|
|
493
|
+
An attribute is named by its value, since its own representation shows only which attribute it
|
|
494
|
+
is, and an element in the one form in which PlatynUI describes elements.
|
|
495
|
+
"""
|
|
496
|
+
if result is None:
|
|
497
|
+
return 'matched nothing'
|
|
498
|
+
if isinstance(result, UiNode):
|
|
499
|
+
return f'was {_element_text(result)}'
|
|
500
|
+
return f'was {_assertion_value(result)!r}'
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
def _pinned_element_gone(node: UiNode) -> PinnedElementGoneError:
|
|
504
|
+
"""The error for a captured element that no longer exists and has no selector to be found again."""
|
|
505
|
+
return PinnedElementGoneError(
|
|
506
|
+
f'The pinned element {node.runtime_id!r} is no longer available, and this reference holds no '
|
|
507
|
+
f'selector to look it up again. Query it again to get a current element, or use a selector, '
|
|
508
|
+
f'which is re-evaluated on every use.'
|
|
509
|
+
)
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def _gone_wait_error(target: str, state: str, timeout: float, last_error: Exception | None) -> ElementStillPresentError:
|
|
513
|
+
"""The error `Wait Until Gone` raises at its deadline, for ``target`` as its message names it.
|
|
514
|
+
|
|
515
|
+
``state`` says what the last attempt saw when it completed: the target still present, or still
|
|
516
|
+
valid. When the last attempt raised, the target could not be confirmed gone, and its error follows.
|
|
517
|
+
"""
|
|
518
|
+
within = f'within timeout of {timeout} seconds.'
|
|
519
|
+
if last_error is not None:
|
|
520
|
+
return ElementStillPresentError(_with_last_error(f'{target} could not be confirmed gone {within}', last_error))
|
|
521
|
+
return ElementStillPresentError(f'{target} {state} {within}')
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
# The namespace prefixes an attribute name can carry: the runtime's four namespaces.
|
|
525
|
+
_ATTRIBUTE_PREFIXES = tuple(ns.as_str() for ns in (Namespace.Control, Namespace.Item, Namespace.App, Namespace.Native))
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def _split_attribute_name(attribute_name: str) -> tuple[str | None, str]:
|
|
529
|
+
"""Split ``prefix:Name`` into its namespace and its name, as `Get Attribute Value` reads it.
|
|
530
|
+
|
|
531
|
+
A prefix that names no namespace is rejected here, before any element is read, so that a wait
|
|
532
|
+
fails at once on it, even when the element has not appeared yet or errors are being ignored.
|
|
533
|
+
"""
|
|
534
|
+
if ':' not in attribute_name:
|
|
535
|
+
return None, attribute_name
|
|
536
|
+
namespace, name = attribute_name.split(':', 1)
|
|
537
|
+
if namespace and namespace not in _ATTRIBUTE_PREFIXES:
|
|
538
|
+
raise ValueError(
|
|
539
|
+
f'Unknown namespace prefix {namespace!r} in attribute {attribute_name!r}; '
|
|
540
|
+
f'the prefixes are {", ".join(_ATTRIBUTE_PREFIXES)}.'
|
|
541
|
+
)
|
|
542
|
+
return namespace, name
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
def _attribute_wait_error(
|
|
546
|
+
seen: _Attempt,
|
|
547
|
+
last_error: Exception | None,
|
|
548
|
+
query: str | None,
|
|
549
|
+
attribute_name: str,
|
|
550
|
+
custom_message: bool,
|
|
551
|
+
timeout: float,
|
|
552
|
+
) -> Exception:
|
|
553
|
+
"""The error `Wait Until Attribute Value` raises at its deadline, reporting what its last attempt saw.
|
|
554
|
+
|
|
555
|
+
When that attempt completed, the error says what it saw: no element, no such attribute, or the
|
|
556
|
+
value and why it did not satisfy the condition. When it raised, the error says how far it got —
|
|
557
|
+
no element, the attribute not read, the value not checked — and quotes its error. With a
|
|
558
|
+
``custom_message`` the check's error already starts with it, so the element is not named in
|
|
559
|
+
front of it.
|
|
560
|
+
"""
|
|
561
|
+
within = f'within timeout of {timeout} seconds'
|
|
562
|
+
node = seen.result if isinstance(seen.result, UiNode) else None
|
|
563
|
+
if node is None:
|
|
564
|
+
return ElementNotFoundError(_with_last_error(f'No element matched {query!r} {within}.', last_error))
|
|
565
|
+
element = _element_text(node)
|
|
566
|
+
if seen.value is _UNSEEN:
|
|
567
|
+
if last_error is not None:
|
|
568
|
+
message = f'Attribute {attribute_name!r} of {element} could not be read {within}.'
|
|
569
|
+
return AttributeNotFoundError(_with_last_error(message, last_error))
|
|
570
|
+
return AttributeNotFoundError(f'Attribute {attribute_name!r} did not appear on {element} {within}.')
|
|
571
|
+
if last_error is not None:
|
|
572
|
+
message = f'Attribute {attribute_name!r} of {element} was {seen.value!r} and could not be checked {within}.'
|
|
573
|
+
return AssertionError(_with_last_error(message, last_error))
|
|
574
|
+
if seen.mismatch is None:
|
|
575
|
+
return AssertionError(
|
|
576
|
+
f'Attribute {attribute_name!r} of {element} was {seen.value!r} and did not become truthy {within}.'
|
|
577
|
+
)
|
|
578
|
+
if isinstance(seen.mismatch, TypeError):
|
|
579
|
+
return TypeError(f'Attribute {attribute_name!r} of {element}: {seen.mismatch} ({within})')
|
|
580
|
+
text = str(seen.mismatch) if custom_message else f'Attribute {attribute_name!r} of {element}: {seen.mismatch}'
|
|
581
|
+
return AssertionError(f'{text} ({within})')
|
|
582
|
+
|
|
583
|
+
|
|
337
584
|
ScrollDirection = Literal['UP', 'DOWN', 'LEFT', 'RIGHT']
|
|
338
585
|
"""The visually intended direction for `Pointer Scroll`."""
|
|
339
586
|
|
|
@@ -368,6 +615,103 @@ def _scroll_delta(direction: ScrollDirection, ticks: int) -> tuple[float, float]
|
|
|
368
615
|
return (signs[0] * magnitude, signs[1] * magnitude)
|
|
369
616
|
|
|
370
617
|
|
|
618
|
+
# Where a pointer keyword's point came from, as its action line names it.
|
|
619
|
+
_FROM_ACTIVATION_POINT = 'its activation point'
|
|
620
|
+
_FROM_BOUNDS_CENTER = 'the center of its bounds'
|
|
621
|
+
_FROM_OFFSET = 'an offset from its top-left corner'
|
|
622
|
+
_FROM_ABSOLUTE = 'absolute coordinates'
|
|
623
|
+
_AT_POINTER = 'the current pointer position'
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
def _describe(node: UiNode | None) -> str | None:
|
|
627
|
+
"""The element's one-line description, or ``None`` when the action line is off.
|
|
628
|
+
|
|
629
|
+
Describing asks the provider for the element's name and id, so it happens only when the
|
|
630
|
+
``platynui.baremetal`` logger lets DEBUG through, and before the action, which may remove
|
|
631
|
+
the element. A description never makes the keyword fail.
|
|
632
|
+
"""
|
|
633
|
+
if node is None or not _LOG.isEnabledFor(logging.DEBUG):
|
|
634
|
+
return None
|
|
635
|
+
return _element_text(node)
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
def _element_text(node: UiNode) -> str:
|
|
639
|
+
"""The element's one-line description, falling back to its runtime id when the provider cannot answer.
|
|
640
|
+
|
|
641
|
+
Describing asks the provider, and the element may be gone by then; a message about the element
|
|
642
|
+
must not fail because of that.
|
|
643
|
+
"""
|
|
644
|
+
try:
|
|
645
|
+
return node.describe()
|
|
646
|
+
except Exception: # noqa: BLE001 (a description must not fail the keyword)
|
|
647
|
+
return f'element {node.runtime_id!r}'
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
def _number(value: float) -> str:
|
|
651
|
+
return str(int(value)) if float(value).is_integer() else f'{value:.2f}'.rstrip('0')
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
def _point_text(point: Point) -> str:
|
|
655
|
+
return f'({_number(point.x)}, {_number(point.y)})'
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
def _rect_text(rect: Rect) -> str:
|
|
659
|
+
return f'({_number(rect.x)}, {_number(rect.y)}, {_number(rect.width)}, {_number(rect.height)})'
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
def _button_name(button: PointerButtonLike) -> str:
|
|
663
|
+
try:
|
|
664
|
+
return PointerButton(button).name
|
|
665
|
+
except ValueError:
|
|
666
|
+
return str(button)
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
def _plural(count: int, word: str) -> str:
|
|
670
|
+
return f'{count} {word}' if count == 1 else f'{count} {word}s'
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
def _pointer_target(description: str | None, point: Point | None, source: str) -> str:
|
|
674
|
+
"""What a pointer keyword acted on: ``Button "OK" at (412, 305), its activation point``."""
|
|
675
|
+
where = f'at {_point_text(point)}, {source}' if point is not None else f'at {source}'
|
|
676
|
+
return f'{description} {where}' if description is not None else where
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
def _log_action(verb: str, target: str, details: str | None = None) -> None:
|
|
680
|
+
"""Log a keyword's action line at DEBUG, after the native records of the same action.
|
|
681
|
+
|
|
682
|
+
``target`` is text built from descriptions, never an element: the element may be gone.
|
|
683
|
+
"""
|
|
684
|
+
if not _LOG.isEnabledFor(logging.DEBUG):
|
|
685
|
+
return
|
|
686
|
+
flush_native_logs()
|
|
687
|
+
if details is None:
|
|
688
|
+
_LOG.debug('%s %s', verb, target)
|
|
689
|
+
else:
|
|
690
|
+
_LOG.debug('%s %s; %s', verb, target, details)
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
def _typed_length(text: 'KeyboardText') -> str:
|
|
694
|
+
"""How a keyboard keyword's line gives its input: the length of a string, or only ``secret``."""
|
|
695
|
+
return _plural(len(text), 'character') if isinstance(text, str) else 'secret'
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
def _keyboard_target(description: str | None) -> str:
|
|
699
|
+
return description if description is not None else 'the focused element'
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
def _test_data_hint(message: str) -> str | None:
|
|
703
|
+
"""How the runtime's escape hint is written in Robot Framework test data, if it gives one.
|
|
704
|
+
|
|
705
|
+
Robot Framework removes a backslash before an unknown character before the keyword runs, so
|
|
706
|
+
the sequence ``\\<`` reaches the keyword only when the test data says ``\\\\<``.
|
|
707
|
+
"""
|
|
708
|
+
if '\\<' in message or '\\>' in message:
|
|
709
|
+
return 'In Robot Framework test data, a literal < is written \\\\< (and > as \\\\>).'
|
|
710
|
+
if '\\\\' in message:
|
|
711
|
+
return 'In Robot Framework test data, a backslash is written \\\\\\\\.'
|
|
712
|
+
return None
|
|
713
|
+
|
|
714
|
+
|
|
371
715
|
@library(
|
|
372
716
|
scope='SUITE',
|
|
373
717
|
version=__version__,
|
|
@@ -390,10 +734,17 @@ class BareMetal(OurDynamicCore):
|
|
|
390
734
|
|
|
391
735
|
Everything you automate is an *element* — a window, a button, a list, a single row in that list,
|
|
392
736
|
a text box. PlatynUI presents the whole desktop as one tree of these elements: each running
|
|
393
|
-
application is a branch, and the elements inside it are the branches below. The tree
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
737
|
+
application is a branch, and the elements inside it are the branches below. The tree follows the
|
|
738
|
+
screen: as an application opens a window, loads content or closes a dialog, elements appear in
|
|
739
|
+
and vanish from the tree with it.
|
|
740
|
+
|
|
741
|
+
To stay fast, a keyword may reuse what an earlier keyword read of the tree, as long as the
|
|
742
|
+
elements it read still exist. The library reads the screen again after a lookup that found
|
|
743
|
+
nothing (so an action keyword or `Wait Until Exists` keeps retrying against the current UI
|
|
744
|
+
until the element appears), before every `Query`, and on every attempt of `Wait Until Gone`,
|
|
745
|
+
`Wait Until Query` and `Wait Until Attribute Value`. So when a step changes the UI, wait for
|
|
746
|
+
what it brings to appear, or, with `Wait Until Gone`, `Wait Until Query` or `Wait Until
|
|
747
|
+
Attribute Value`, for what it removes to go or what it changes to take effect.
|
|
397
748
|
|
|
398
749
|
Every element has a *role* and a set of *attributes*.
|
|
399
750
|
|
|
@@ -440,8 +791,9 @@ class BareMetal(OurDynamicCore):
|
|
|
440
791
|
| ``native:`` | raw, technology-specific roles and attributes |
|
|
441
792
|
|
|
442
793
|
Attributes have no default namespace (unlike element names), so a standard attribute is written
|
|
443
|
-
bare — ``@Name``, ``@Id``, ``@Bounds``, an application's ``@ProcessId`` — while
|
|
444
|
-
|
|
794
|
+
bare — ``@Name``, ``@Id``, ``@Bounds``, an application's ``@ProcessId`` — while the others keep
|
|
795
|
+
their prefix: an application's process details under ``@app:...`` (see `Process attributes`),
|
|
796
|
+
and the raw, technology-specific values under ``@native:...``.
|
|
445
797
|
|
|
446
798
|
| @{rows}= `Query` Window[@Name="Mail"]//List[@Name="Inbox"]/item:ListItem
|
|
447
799
|
|
|
@@ -453,7 +805,7 @@ class BareMetal(OurDynamicCore):
|
|
|
453
805
|
|
|
454
806
|
| `Pointer Click` //Button[@Name="OK"] # exact text
|
|
455
807
|
| `Keyboard Type` //Edit[starts-with(@Name, "Address")] 12 Main St # partial text
|
|
456
|
-
| `Get Attribute` //CheckBox[matches(@Name, "Option [0-9]+")] IsEnabled # regular expression
|
|
808
|
+
| `Get Attribute Value` //CheckBox[matches(@Name, "Option [0-9]+")] IsEnabled # regular expression
|
|
457
809
|
| `Pointer Click` (//Button)[last()] # by position
|
|
458
810
|
|
|
459
811
|
``=`` is exact and case-sensitive; use ``contains()``, ``starts-with()`` or ``matches()`` for
|
|
@@ -467,6 +819,25 @@ class BareMetal(OurDynamicCore):
|
|
|
467
819
|
| `Pointer Click` //Button[@Name="Save" and @IsVisible=true()] # named *and* visible
|
|
468
820
|
| `Pointer Click` //Button[@Name="OK" or @Name="Yes"] # either label
|
|
469
821
|
|
|
822
|
+
Matches come in document order: the order in which you meet the elements reading the tree from
|
|
823
|
+
the top, each element before its children. A keyword that needs one element acts on the first.
|
|
824
|
+
|
|
825
|
+
A position counts within its own step, once for every element the step starts from.
|
|
826
|
+
``//Button[2]`` matches every button that is the second button of its parent — possibly several
|
|
827
|
+
— while ``(//Button)[2]`` is the second button of the whole search. Put the search in parentheses
|
|
828
|
+
whenever you mean "the n-th match":
|
|
829
|
+
|
|
830
|
+
| `Pointer Click` (//Button)[2] # the second button of all
|
|
831
|
+
| @{seconds}= `Query` //Button[2] # the second button of every parent
|
|
832
|
+
|
|
833
|
+
The same parentheses help when you pick a child by position below a container that you know is
|
|
834
|
+
unique. ``.//Table[@Name="Orders"]/*[544]`` has to rule out another *Orders* table nested in one
|
|
835
|
+
of the 543 cells before the one you want, whose cells would come first, so it looks inside each
|
|
836
|
+
of them. ``(.//Table[@Name="Orders"])[1]/*[544]`` stops at the first table, and only counts its
|
|
837
|
+
cells:
|
|
838
|
+
|
|
839
|
+
| `Get Attribute Value` (.//Table[@Name="Orders"])[1]/*[544] Name
|
|
840
|
+
|
|
470
841
|
== Narrowing the search ==
|
|
471
842
|
|
|
472
843
|
A bare ``//`` is quick to write, but it searches the *whole desktop*: ``//Edit[@Name="Street"]``
|
|
@@ -540,6 +911,13 @@ class BareMetal(OurDynamicCore):
|
|
|
540
911
|
| `Pointer Click` Window[@Name="Editor"]//Button[@Name="New"]
|
|
541
912
|
| `Keyboard Type` Window[@Name="Editor"]//Edit[@Name="Title"] Q3 Report
|
|
542
913
|
|
|
914
|
+
Each action keyword logs one line at Robot Framework's ``DEBUG`` level once it has acted: the
|
|
915
|
+
element as it was before the action, the point it used and where that point came from, and the
|
|
916
|
+
button, clicks or ticks. At the default ``INFO`` level these lines cost nothing, so leave the level
|
|
917
|
+
there unless you are looking for something:
|
|
918
|
+
|
|
919
|
+
| clicked Button "OK" #ok at (412, 305), its activation point; button LEFT, 1 click
|
|
920
|
+
|
|
543
921
|
Or capture an element once with `Query` and reuse it — every keyword takes it the same way:
|
|
544
922
|
|
|
545
923
|
| ${save}= `Query` Window[@Name="Editor"]//Button[@Name="Save"] only_first=${True}
|
|
@@ -582,7 +960,9 @@ class BareMetal(OurDynamicCore):
|
|
|
582
960
|
succeed while nothing happens.
|
|
583
961
|
|
|
584
962
|
Two of them only change which window is in front: `Activate Window` (like `Bring To Front`) raises
|
|
585
|
-
a window and gives it the keyboard focus.
|
|
963
|
+
a window and gives it the keyboard focus. Raising never changes a window's size: a minimized
|
|
964
|
+
window comes back the way it was before it was minimized — maximized if it was maximized — and a
|
|
965
|
+
maximized window stays maximized. The others change a window's display state — and
|
|
586
966
|
`Restore Window` is the inverse of `Minimize Window` and `Maximize Window`, returning a minimized
|
|
587
967
|
or maximized window to the floating size and position it had before.
|
|
588
968
|
|
|
@@ -613,17 +993,25 @@ class BareMetal(OurDynamicCore):
|
|
|
613
993
|
|
|
614
994
|
= Reading and checking values =
|
|
615
995
|
|
|
616
|
-
`Get Attribute` reads one attribute of one element and, in the same call, can assert on it: add
|
|
996
|
+
`Get Attribute Value` reads one attribute of one element and, in the same call, can assert on it: add
|
|
617
997
|
an operator and the expected value, and the keyword fails if it does not hold.
|
|
618
998
|
|
|
619
|
-
| ${enabled}= `Get Attribute` Window[@Name="Settings"]//Button[@Name="Save"] IsEnabled
|
|
620
|
-
| `Get Attribute` Window[@Name="Settings"]//Button[@Name="Save"] IsEnabled == ${True}
|
|
621
|
-
| `Get Attribute` Window[@Name="Settings"]//CheckBox[@Name="Dark mode"] IsEnabled == ${False}
|
|
999
|
+
| ${enabled}= `Get Attribute Value` Window[@Name="Settings"]//Button[@Name="Save"] IsEnabled
|
|
1000
|
+
| `Get Attribute Value` Window[@Name="Settings"]//Button[@Name="Save"] IsEnabled == ${True}
|
|
1001
|
+
| `Get Attribute Value` Window[@Name="Settings"]//CheckBox[@Name="Dark mode"] IsEnabled == ${False}
|
|
622
1002
|
|
|
623
1003
|
Operators include ``==``, ``!=``, ``contains``, ``starts``, ``ends`` and ``matches`` (see
|
|
624
1004
|
[https://github.com/MarketSquare/AssertionEngine|AssertionEngine]). For several values at once,
|
|
625
1005
|
or a computed one, read them through `Query` instead.
|
|
626
1006
|
|
|
1007
|
+
`Get Attribute Value` reads and checks the value once, at the moment it runs. When an action changes a
|
|
1008
|
+
value a moment later — a window that finishes maximizing, a label that updates after a click —
|
|
1009
|
+
wait for the new value with `Wait Until Attribute Value` instead: it takes the same element,
|
|
1010
|
+
attribute and operators, and reads the attribute again until the check holds.
|
|
1011
|
+
|
|
1012
|
+
| `Maximize Window` Window[@Name="Settings"]
|
|
1013
|
+
| `Wait Until Attribute Value` Window[@Name="Settings"] IsMaximized == ${True}
|
|
1014
|
+
|
|
627
1015
|
= Scoping queries to a container =
|
|
628
1016
|
|
|
629
1017
|
Every query runs against a *context node*, the desktop by default. Scope it to a container you
|
|
@@ -669,8 +1057,11 @@ class BareMetal(OurDynamicCore):
|
|
|
669
1057
|
``TEST`` or ``SUITE`` root does not come back. `Set Root` returns the root that was set at the
|
|
670
1058
|
scope you name, so keep that return value if you want to restore it.
|
|
671
1059
|
|
|
672
|
-
The root stores the *selector*, not a fixed element
|
|
673
|
-
|
|
1060
|
+
The root stores the *selector*, not a fixed element. It keeps using the element the selector
|
|
1061
|
+
found while that element exists, and looks the selector up again once it is gone, so the root
|
|
1062
|
+
keeps working after its window closes and reopens — in the middle of a wait too, since a waiting
|
|
1063
|
+
keyword checks the root on every attempt. A root that cannot be found fails the keyword with its
|
|
1064
|
+
own error, even with ``ignore_exceptions``. (It lives in
|
|
674
1065
|
``${PLATYNUI_ROOT_DESCRIPTOR}``, but set it through `Set Root` — the raw variable holds an
|
|
675
1066
|
internal value.)
|
|
676
1067
|
|
|
@@ -721,6 +1112,32 @@ class BareMetal(OurDynamicCore):
|
|
|
721
1112
|
| ${pid}= Get Process Id ${proc}
|
|
722
1113
|
| `Set Root` /app:Application[@ProcessId=${pid}]
|
|
723
1114
|
|
|
1115
|
+
== Process attributes ==
|
|
1116
|
+
|
|
1117
|
+
An application element also describes its process. Apart from ``@ProcessId`` these attributes
|
|
1118
|
+
carry the ``app:`` prefix:
|
|
1119
|
+
|
|
1120
|
+
| = Attribute = | = What it holds = |
|
|
1121
|
+
| ``@ProcessId`` | the process id, a positive number |
|
|
1122
|
+
| ``@app:ProcessName`` | the program's file name, without folder or, on Windows, ``.exe``: ``python3.12`` |
|
|
1123
|
+
| ``@app:ExecutablePath`` | the full path of that program |
|
|
1124
|
+
| ``@app:CommandLine`` | Windows: the line the process was started with, quotes included; Linux: the arguments |
|
|
1125
|
+
| ``@app:UserName`` | the account the process runs as: ``DOMAIN\\user`` on Windows, the login name on Linux |
|
|
1126
|
+
| ``@app:StartTime`` | when the process started, in UTC to the second: ``2026-09-28T19:45:59Z`` |
|
|
1127
|
+
| ``@app:Architecture`` | Windows only: ``x86``, ``x64``, ``arm`` or ``arm64``, as the process runs |
|
|
1128
|
+
|
|
1129
|
+
On Linux the command line is the arguments joined by spaces. On Windows a local account has the
|
|
1130
|
+
computer name as its domain, and a 32-bit program on 64-bit Windows reports ``x86``.
|
|
1131
|
+
|
|
1132
|
+
Each of them may be absent. An attribute is there only when it could be read for that very
|
|
1133
|
+
process — a process of another user, for example, may not reveal its command line — and it is
|
|
1134
|
+
never filled in with an empty or a made-up value. So test for one before you rely on it:
|
|
1135
|
+
``[@app:CommandLine]`` is true exactly when the command line is there, and `Get Attribute Value` fails
|
|
1136
|
+
for one that is not. Once the process has ended, its application element reports none of them.
|
|
1137
|
+
|
|
1138
|
+
| `Set Root` /app:Application[@app:ProcessName="ledger"][@app:UserName]
|
|
1139
|
+
| ${started}= `Get Attribute Value` /app:Application[@ProcessId=${pid}] app:StartTime
|
|
1140
|
+
|
|
724
1141
|
= Waiting for elements =
|
|
725
1142
|
|
|
726
1143
|
Action and read keywords *wait* for their target, and knowing why explains most of what follows.
|
|
@@ -738,15 +1155,16 @@ class BareMetal(OurDynamicCore):
|
|
|
738
1155
|
`Query` is the deliberate exception. It is a snapshot of the tree at the instant you call it and
|
|
739
1156
|
returns straight away with whatever matches right then — possibly nothing. That makes it the tool
|
|
740
1157
|
for *asking about* the UI rather than *acting on* it: counting how many rows a table has, or
|
|
741
|
-
|
|
742
|
-
|
|
1158
|
+
checking whether a dialog is open *right now* — `Wait Until Exists` would block for the full
|
|
1159
|
+
timeout before it could tell you that it is not. To wait until something has gone, use
|
|
1160
|
+
`Wait Until Gone`.
|
|
743
1161
|
|
|
744
1162
|
Three settings govern the wait, together the *query settings*:
|
|
745
1163
|
|
|
746
1164
|
| = Setting = | = Meaning = |
|
|
747
1165
|
| ``timeout`` | how long to keep retrying before giving up, in seconds (default ``30``) |
|
|
748
1166
|
| ``retry_interval`` | the pause between attempts, in seconds (default ``0.1``) |
|
|
749
|
-
| ``ignore_exceptions`` | keep retrying
|
|
1167
|
+
| ``ignore_exceptions`` | keep retrying when an attempt raises; a timeout quotes its error (default ``False``) |
|
|
750
1168
|
|
|
751
1169
|
``timeout`` is the headroom for the slowest thing you wait on. Thirty seconds suits most UIs; raise
|
|
752
1170
|
it when an application is slow to start or an action takes a while to settle (a save that talks to
|
|
@@ -757,13 +1175,19 @@ class BareMetal(OurDynamicCore):
|
|
|
757
1175
|
responsive without hammering the platform's accessibility layer on every poll; you rarely need to
|
|
758
1176
|
change it — raise it only if polling itself turns out to be expensive on a particular provider.
|
|
759
1177
|
|
|
760
|
-
``ignore_exceptions`` concerns the attempts that do not merely *miss* but *raise*.
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
(the default) the first such error fails the keyword at once; with it on, the loop swallows
|
|
764
|
-
error and keeps retrying until the timeout, so
|
|
765
|
-
|
|
766
|
-
|
|
1178
|
+
``ignore_exceptions`` concerns the attempts that do not merely *miss* but *raise*. An expression
|
|
1179
|
+
can raise for a moment while the application is still getting to the state you wait for:
|
|
1180
|
+
``//Text[xs:integer(@Name) > 3]`` raises as long as a label does not show a number yet. With this
|
|
1181
|
+
off (the default) the first such error fails the keyword at once; with it on, the loop swallows
|
|
1182
|
+
the error and keeps retrying until the timeout, so the keyword succeeds once the value has
|
|
1183
|
+
settled. Turn it on deliberately and narrowly: it also masks a genuinely wrong selector that
|
|
1184
|
+
would otherwise fail fast, turning a clear error into a long wait.
|
|
1185
|
+
If the last attempt before the timeout raised, the failure quotes that error.
|
|
1186
|
+
|
|
1187
|
+
A few errors end the wait even with ``ignore_exceptions``, because waiting cannot fix them: a
|
|
1188
|
+
selector that yields a value where an element is needed, an element from `Query` — or a root
|
|
1189
|
+
pinned to one — that no longer exists, a `Set Root` root that is not found within its own
|
|
1190
|
+
``timeout``, and a ``validate`` expression that raises.
|
|
767
1191
|
|
|
768
1192
|
== Tuning the wait ==
|
|
769
1193
|
|
|
@@ -792,16 +1216,17 @@ class BareMetal(OurDynamicCore):
|
|
|
792
1216
|
including the re-resolution of a `Set Root` root — whereas ``query_overrides`` tunes only that one
|
|
793
1217
|
keyword's own target; if you need to wait longer for the root as well, set it at the scope level.
|
|
794
1218
|
|
|
795
|
-
One subtlety worth keeping in mind: ``timeout`` bounds
|
|
796
|
-
|
|
797
|
-
|
|
1219
|
+
One subtlety worth keeping in mind: ``timeout`` bounds the keyword's own wait, while the root keeps
|
|
1220
|
+
its own. Every attempt looks the root up first, and when the root has to be searched for again,
|
|
1221
|
+
that search may take up to the root's ``timeout`` — so in the worst case a single keyword can
|
|
1222
|
+
wait longer than the number you set.
|
|
798
1223
|
|
|
799
1224
|
== Waiting explicitly ==
|
|
800
1225
|
|
|
801
1226
|
Most of the time you never wait by hand — you state what you expect and the action or read keyword
|
|
802
1227
|
waits for exactly that. Now and then, though, you want a *pure* synchronization point: wait for a
|
|
803
1228
|
splash screen to vanish before carrying on, wait for a window to open without acting on it yet, or
|
|
804
|
-
wait for a row count to settle.
|
|
1229
|
+
wait for a row count to settle. Four keywords cover this, all governed by the same query settings as
|
|
805
1230
|
everything else (see `Tuning the wait`) and tuned per call with ``query_overrides``:
|
|
806
1231
|
|
|
807
1232
|
- `Wait Until Exists` waits for a selector to resolve to an element and *returns* it — the waiting
|
|
@@ -810,13 +1235,17 @@ class BareMetal(OurDynamicCore):
|
|
|
810
1235
|
that becomes invalid. For a value condition — a count dropping to zero, say — use `Wait Until
|
|
811
1236
|
Query` instead.
|
|
812
1237
|
- `Wait Until Query` waits until an XPath result satisfies a condition. It takes the same assertion
|
|
813
|
-
operators as `Get Attribute`; with no operator it waits until the result is truthy. Unlike
|
|
814
|
-
Attribute` it works on the raw query result
|
|
815
|
-
``count(...)``
|
|
1238
|
+
operators as `Get Attribute Value`; with no operator it waits until the result is truthy. Unlike
|
|
1239
|
+
`Get Attribute Value` it works on the raw query result: an attribute step is checked by its
|
|
1240
|
+
value, and ``count(...)`` by its number.
|
|
1241
|
+
- `Wait Until Attribute Value` waits until one attribute of one element has the value you expect,
|
|
1242
|
+
and returns that value. It takes the element, the attribute and the operators as
|
|
1243
|
+
`Get Attribute Value` does; with no operator it waits until the value is truthy.
|
|
816
1244
|
|
|
817
1245
|
| `Wait Until Exists` Window[@Name="Save As"] # wait for the dialog, then return it
|
|
818
1246
|
| `Wait Until Gone` Window[@Name="Please wait"] # wait until the splash is gone
|
|
819
|
-
| `Wait Until Query` count(//item:ListItem) > 0 # wait until the list has filled
|
|
1247
|
+
| `Wait Until Query` count(//item:ListItem) > ${0} # wait until the list has filled
|
|
1248
|
+
| `Wait Until Attribute Value` Window[@Name="Import"]//Button[@Id="next"] IsEnabled # wait until enabled
|
|
820
1249
|
|
|
821
1250
|
= Input timing and motion =
|
|
822
1251
|
|
|
@@ -899,7 +1328,7 @@ class BareMetal(OurDynamicCore):
|
|
|
899
1328
|
|
|
900
1329
|
| `Pointer Click` Window[@Name="Editor"]//Button[@Name="New"] # start a new document
|
|
901
1330
|
| `Keyboard Type` ${None} Q3 Report # type into the focused field
|
|
902
|
-
| `Get Attribute`
|
|
1331
|
+
| `Get Attribute Value` Window[@Name="Editor"]//Button[@Name="Save"] IsEnabled == ${True} # enabled
|
|
903
1332
|
| `Take Screenshot`
|
|
904
1333
|
"""
|
|
905
1334
|
|
|
@@ -913,6 +1342,7 @@ class BareMetal(OurDynamicCore):
|
|
|
913
1342
|
query_settings: QuerySettingsDict | None = None,
|
|
914
1343
|
config: dict[str, Any] | None = None,
|
|
915
1344
|
use_mock: bool = False,
|
|
1345
|
+
native_log_level: str | None = None,
|
|
916
1346
|
) -> None:
|
|
917
1347
|
"""Import the library, optionally tuning window activation and input behaviour.
|
|
918
1348
|
|
|
@@ -931,6 +1361,7 @@ class BareMetal(OurDynamicCore):
|
|
|
931
1361
|
| ``pointer_settings`` | pointer *behaviour*: double-click interval and size, and the default button |
|
|
932
1362
|
| ``pointer_profile`` | pointer *motion*: speed, acceleration, curve, overshoot and jitter |
|
|
933
1363
|
| ``config`` | *session* binding: which display server and accessibility bus this runtime drives |
|
|
1364
|
+
| ``native_log_level`` | *diagnostics*: how much of PlatynUI's own logging reaches the log — default ``warn`` |
|
|
934
1365
|
|
|
935
1366
|
| Library PlatynUI.BareMetal auto_activate=${False} query_settings={'timeout': 60}
|
|
936
1367
|
|
|
@@ -945,18 +1376,60 @@ class BareMetal(OurDynamicCore):
|
|
|
945
1376
|
The ``platform`` bucket also accepts a reserved ``backend`` selector (``'x11'``, ``'wayland'``,
|
|
946
1377
|
``'windows'`` …) that forces a backend instead of auto-detecting it from the environment, and
|
|
947
1378
|
the ``providers`` bucket carries per-provider settings — chiefly ``providers.atspi.bus_address``
|
|
948
|
-
to bind to a chosen session's AT-SPI bus. One dict is portable across operating systems:
|
|
949
|
-
|
|
950
|
-
platform's block in the same dict.
|
|
1379
|
+
to bind to a chosen session's AT-SPI bus. One dict is portable across operating systems: the
|
|
1380
|
+
blocks of platforms and providers that do not run here are ignored, so you may carry every
|
|
1381
|
+
platform's block in the same dict. The backend and the providers that do run check their own
|
|
1382
|
+
block, though: a key they do not know and a value of the wrong type are reported as warnings,
|
|
1383
|
+
and the default applies — a misspelled ``dispaly`` would otherwise fall back to the
|
|
1384
|
+
environment without a word. A top-level key other than ``platform`` and ``providers``, such as
|
|
1385
|
+
a misspelled ``platfrom``, is reported the same way. An absent or empty ``config`` reproduces the default
|
|
951
1386
|
behaviour — the platform is auto-detected and the accessibility bus is discovered from the
|
|
952
1387
|
environment. ``config`` is fixed at construction time (a live connection cannot be re-pointed
|
|
953
1388
|
at another display), so there is no per-call override.
|
|
954
1389
|
|
|
1390
|
+
The profile dictionaries are checked when they are applied: a value of the wrong type fails
|
|
1391
|
+
with an error that names the key and the type it needs, and a key that no setting reads is
|
|
1392
|
+
reported as a warning, so a typo does not go unnoticed.
|
|
1393
|
+
|
|
1394
|
+
PlatynUI writes its own diagnostics into the log of the keyword during which they occur.
|
|
1395
|
+
By default only warnings and errors are written; warnings also appear on the console and among
|
|
1396
|
+
the run's errors, like any other warning. A warning always says what PlatynUI cannot do as
|
|
1397
|
+
asked, and a healthy run has none. ``native_log_level`` makes PlatynUI's diagnostics more
|
|
1398
|
+
detailed. It takes a single level, in any letter case: ``off``, ``error``, ``warn`` (or
|
|
1399
|
+
``warning``), ``info``, ``debug`` or ``trace``; ``critical`` and ``fatal`` mean ``error``. From
|
|
1400
|
+
``warn`` to ``trace``, a level makes only PlatynUI's own diagnostics more detailed, while the
|
|
1401
|
+
third-party components PlatynUI builds on stay at warnings; ``error`` and ``off`` apply to
|
|
1402
|
+
everything, third-party components included. Robot Framework's own log level
|
|
1403
|
+
(``--loglevel`` or ``Set Log Level``) must let the messages through as well, so seeing debug
|
|
1404
|
+
output takes both:
|
|
1405
|
+
|
|
1406
|
+
| Library PlatynUI.BareMetal native_log_level=debug
|
|
1407
|
+
|
|
1408
|
+
Independently of ``native_log_level``, at Robot Framework's ``DEBUG`` level every action
|
|
1409
|
+
keyword logs one line saying what it did: the element it acted on, the point it used and
|
|
1410
|
+
where that point came from, and the button, clicks or scroll ticks — for a keyboard keyword
|
|
1411
|
+
only the length of the input, never the text.
|
|
1412
|
+
|
|
1413
|
+
The setting is shared by every library instance in the run: the most detailed level any
|
|
1414
|
+
instance currently in scope asks for applies. The environment variable ``PLATYNUI_LOG_LEVEL``
|
|
1415
|
+
takes the same single level and applies when no instance asks for one. ``RUST_LOG`` overrides
|
|
1416
|
+
both, as for the PlatynUI command-line tool: it is the one place for filter directives, such
|
|
1417
|
+
as ``platynui_runtime=trace,warn``, and the only way to make third-party components more
|
|
1418
|
+
detailed. A value PlatynUI cannot use is reported once as a warning and ignored.
|
|
1419
|
+
|
|
1420
|
+
*Reporting a problem:* run the failing test with ``native_log_level=debug`` and
|
|
1421
|
+
``--loglevel DEBUG``, and attach its ``output.xml``. It holds PlatynUI's diagnostics inside the
|
|
1422
|
+
keyword they belong to, next to each keyword's own line, and no text that a keyboard keyword
|
|
1423
|
+
typed beyond what Robot Framework itself records about the keyword's arguments. Use ``trace``
|
|
1424
|
+
only when asked for it: it names every key PlatynUI presses, those of a ``Secret`` included, so
|
|
1425
|
+
a trace log of a run that types secrets is not for sharing.
|
|
1426
|
+
|
|
955
1427
|
``use_mock`` exists only for PlatynUI's own development and test suites — it drives a built-in
|
|
956
1428
|
stand-in tree instead of the real desktop, selecting the in-memory mock backend regardless of
|
|
957
1429
|
``config``. Leave it at its default; it is not meant for automating applications.
|
|
958
1430
|
"""
|
|
959
|
-
|
|
1431
|
+
native_log_request = native_log_levels.request(native_log_level) if native_log_level is not None else None
|
|
1432
|
+
super().__init__([NativeLogScope(native_log_request)])
|
|
960
1433
|
self._screenshot_counter = 1
|
|
961
1434
|
self.use_mock = use_mock
|
|
962
1435
|
# Construction-time session binding (immutable); consumed once in _create_runtime().
|
|
@@ -1089,6 +1562,18 @@ class BareMetal(OurDynamicCore):
|
|
|
1089
1562
|
current = current.parent
|
|
1090
1563
|
return None
|
|
1091
1564
|
|
|
1565
|
+
def root_for(self, query: str | None) -> UiNode | None:
|
|
1566
|
+
"""The root to evaluate ``query`` against, or ``None`` when no root is set.
|
|
1567
|
+
|
|
1568
|
+
The lookup waits with the root's own settings, never with a keyword's ``query_overrides``.
|
|
1569
|
+
Its failure is the root's, whatever the keyword's ``ignore_exceptions`` says: a
|
|
1570
|
+
`RootNotFoundError` is raised again naming ``query`` as the one it kept from being evaluated.
|
|
1571
|
+
"""
|
|
1572
|
+
try:
|
|
1573
|
+
return self.root
|
|
1574
|
+
except RootNotFoundError as exc:
|
|
1575
|
+
raise RootNotFoundError(exc.root_query, exc.timeout, query, last_error=exc.last_error) from exc
|
|
1576
|
+
|
|
1092
1577
|
def require_own_node(self, node: UiNode) -> None:
|
|
1093
1578
|
"""Reject an element produced by another import's runtime.
|
|
1094
1579
|
|
|
@@ -1178,9 +1663,7 @@ class BareMetal(OurDynamicCore):
|
|
|
1178
1663
|
return self._default_query_settings
|
|
1179
1664
|
|
|
1180
1665
|
@keyword
|
|
1181
|
-
def set_root(
|
|
1182
|
-
self, descriptor: UiNodeDescriptor | None, scope: Scope = 'LOCAL'
|
|
1183
|
-
) -> UiNodeDescriptor | None:
|
|
1666
|
+
def set_root(self, descriptor: UiNodeDescriptor | None, scope: Scope = 'LOCAL') -> UiNodeDescriptor | None:
|
|
1184
1667
|
"""Set the default root that subsequent *relative* selectors resolve against.
|
|
1185
1668
|
|
|
1186
1669
|
A *relative* selector (``.//``, ``./``, ``..``, ``.``) is resolved against the current root
|
|
@@ -1191,10 +1674,10 @@ class BareMetal(OurDynamicCore):
|
|
|
1191
1674
|
Args:
|
|
1192
1675
|
descriptor: The new root — a selector string, an element (e.g. one returned by a
|
|
1193
1676
|
query), or a root previously returned by this keyword (restored unchanged). Pass
|
|
1194
|
-
``${None}`` to reset to the desktop. A selector
|
|
1195
|
-
so it survives the window closing and reopening; an element pins
|
|
1196
|
-
and must come from this same library import — as must a restored
|
|
1197
|
-
one, which is rejected here rather than on the next lookup.
|
|
1677
|
+
``${None}`` to reset to the desktop. A selector is looked up again once the element
|
|
1678
|
+
it found is gone, so it survives the window closing and reopening; an element pins
|
|
1679
|
+
that one element and must come from this same library import — as must a restored
|
|
1680
|
+
root that pins one, which is rejected here rather than on the next lookup.
|
|
1198
1681
|
scope: Lifetime of the root — the same names Robot Framework's `VAR` syntax uses:
|
|
1199
1682
|
``LOCAL`` (default, current test/keyword only), ``TEST`` (or ``TASK``: the whole
|
|
1200
1683
|
test, including called keywords), ``SUITE`` (every test in the suite, not the
|
|
@@ -1204,8 +1687,8 @@ class BareMetal(OurDynamicCore):
|
|
|
1204
1687
|
runtime and is rejected.
|
|
1205
1688
|
|
|
1206
1689
|
Returns:
|
|
1207
|
-
|
|
1208
|
-
|
|
1690
|
+
The root set at the same ``scope`` before this call (``None`` if none). Pass it back at
|
|
1691
|
+
that scope to restore it.
|
|
1209
1692
|
|
|
1210
1693
|
Examples:
|
|
1211
1694
|
| `Set Root` /app:Application[@Name="Editor"] scope=SUITE # whole suite runs in the Editor
|
|
@@ -1223,9 +1706,7 @@ class BareMetal(OurDynamicCore):
|
|
|
1223
1706
|
old = scope_store.get(name, default=None)
|
|
1224
1707
|
old_root: UiNodeDescriptor | None = old if isinstance(old, UiNodeDescriptor) else None
|
|
1225
1708
|
current_root = self._scoped_value(variables.current, name)
|
|
1226
|
-
effective_root: UiNodeDescriptor | None = (
|
|
1227
|
-
current_root if isinstance(current_root, UiNodeDescriptor) else None
|
|
1228
|
-
)
|
|
1709
|
+
effective_root: UiNodeDescriptor | None = current_root if isinstance(current_root, UiNodeDescriptor) else None
|
|
1229
1710
|
|
|
1230
1711
|
if descriptor is None:
|
|
1231
1712
|
new_root: UiNodeDescriptor | None = None
|
|
@@ -1276,8 +1757,8 @@ class BareMetal(OurDynamicCore):
|
|
|
1276
1757
|
|
|
1277
1758
|
These settings govern how the action and read keywords *wait* for their target (see
|
|
1278
1759
|
`Waiting for elements`): ``timeout`` (how long to keep retrying), ``retry_interval`` (the
|
|
1279
|
-
pause between attempts) and ``ignore_exceptions`` (
|
|
1280
|
-
|
|
1760
|
+
pause between attempts) and ``ignore_exceptions`` (keep retrying when an attempt raises).
|
|
1761
|
+
Name only the fields you want to change — they are applied over the settings already
|
|
1281
1762
|
in effect at that scope, so the rest are inherited. The result lives as long as its variable
|
|
1282
1763
|
``scope``, exactly like `Set Root`: every scope but ``GLOBAL`` clears itself when it ends, so
|
|
1283
1764
|
there is no teardown to remember.
|
|
@@ -1350,8 +1831,9 @@ class BareMetal(OurDynamicCore):
|
|
|
1350
1831
|
`What a query gives you`; how to write the expression is explained in `Finding elements`.
|
|
1351
1832
|
|
|
1352
1833
|
Unlike the action keywords, `Query` does not wait: it reports the tree as it is at that
|
|
1353
|
-
moment and returns immediately, even when nothing matches.
|
|
1354
|
-
|
|
1834
|
+
moment and returns immediately, even when nothing matches. Without ``root``, a relative
|
|
1835
|
+
expression is evaluated inside the `Set Root` root and an absolute one (``count(//Button)``)
|
|
1836
|
+
without it. Pass ``root`` to scope it to a container (see `Scoping queries to a container`).
|
|
1355
1837
|
|
|
1356
1838
|
| @{buttons}= `Query` //Button
|
|
1357
1839
|
| ${ok}= `Query` //Button[@Name="OK"] only_first=${True}
|
|
@@ -1359,7 +1841,9 @@ class BareMetal(OurDynamicCore):
|
|
|
1359
1841
|
"""
|
|
1360
1842
|
|
|
1361
1843
|
if root is None:
|
|
1362
|
-
root
|
|
1844
|
+
# A relative expression evaluates against the Set Root root, and an absolute one does
|
|
1845
|
+
# without it, as in every keyword (see `UiNodeDescriptor.needs_root`).
|
|
1846
|
+
root = self.descriptor_from_query(expression).context_node(self)
|
|
1363
1847
|
else:
|
|
1364
1848
|
self.require_own_node(root)
|
|
1365
1849
|
|
|
@@ -1382,7 +1866,8 @@ class BareMetal(OurDynamicCore):
|
|
|
1382
1866
|
The keyword is element-only: a selector that resolves to a value or an attribute
|
|
1383
1867
|
(``count(...)``, ``.../@Name``) fails rather than waiting. A captured element passed
|
|
1384
1868
|
instead of a selector is simply validated as still present. Per-call waiting is tuned
|
|
1385
|
-
with ``query_overrides`` (see `Tuning the wait`).
|
|
1869
|
+
with ``query_overrides`` (see `Tuning the wait`). When ``timeout`` elapses, it fails with
|
|
1870
|
+
``ElementNotFoundError``.
|
|
1386
1871
|
|
|
1387
1872
|
Args:
|
|
1388
1873
|
descriptor: The element to wait for — a selector or an element from `Query`.
|
|
@@ -1395,13 +1880,7 @@ class BareMetal(OurDynamicCore):
|
|
|
1395
1880
|
| ${dialog}= `Wait Until Exists` Window[@Name="Save As"]
|
|
1396
1881
|
| `Wait Until Exists` //control:ProgressBar[@Name="Importing"] query_overrides={'timeout': 60}
|
|
1397
1882
|
"""
|
|
1398
|
-
|
|
1399
|
-
try:
|
|
1400
|
-
return descriptor.resolve(self, query_overrides)
|
|
1401
|
-
except ElementNotFoundError:
|
|
1402
|
-
raise ElementNotFoundError(
|
|
1403
|
-
f'No element matched {descriptor.query!r} within timeout of {settings.timeout} seconds.'
|
|
1404
|
-
) from None
|
|
1883
|
+
return descriptor.resolve(self, query_overrides)
|
|
1405
1884
|
|
|
1406
1885
|
@keyword
|
|
1407
1886
|
def wait_until_gone(
|
|
@@ -1411,20 +1890,23 @@ class BareMetal(OurDynamicCore):
|
|
|
1411
1890
|
|
|
1412
1891
|
The counterpart to `Wait Until Exists`: it polls until the target disappears and then
|
|
1413
1892
|
returns, or raises ``ElementStillPresentError`` once ``timeout`` elapses with the target
|
|
1414
|
-
still there
|
|
1415
|
-
|
|
1416
|
-
|
|
1893
|
+
still there — or could not be confirmed gone, when its last attempt raised an error that
|
|
1894
|
+
``ignore_exceptions`` swallowed. Pass a *selector* to wait until it matches nothing — the
|
|
1895
|
+
live tree is re-evaluated on every attempt — or a *captured element* from `Query` to wait
|
|
1896
|
+
until it becomes invalid.
|
|
1417
1897
|
|
|
1418
1898
|
The difference matters when something equivalent takes the target's place: a selector then
|
|
1419
1899
|
matches the replacement and keeps waiting, while a captured element reports itself gone
|
|
1420
1900
|
because the element *it* named is no longer there. Pick the one that expresses what you
|
|
1421
1901
|
mean.
|
|
1422
1902
|
|
|
1423
|
-
Whether a captured element ever reports itself gone depends on the
|
|
1424
|
-
|
|
1425
|
-
`Wait Until Query`; a value-producing selector (``count(...)``) is rejected here
|
|
1426
|
-
than silently waiting out the timeout. A `Set Root` root that
|
|
1427
|
-
the root's own
|
|
1903
|
+
Whether a captured element ever reports itself gone depends on the application and the
|
|
1904
|
+
platform noticing that it went away. For a *value* condition — a count dropping to zero,
|
|
1905
|
+
say — use `Wait Until Query`; a value-producing selector (``count(...)``) is rejected here
|
|
1906
|
+
rather than silently waiting out the timeout. A `Set Root` root that cannot be found fails the
|
|
1907
|
+
keyword with the root's own error, so to wait until the root's own container closes, pass
|
|
1908
|
+
that container as an absolute selector or as an element from `Query`. Per-call waiting is
|
|
1909
|
+
tuned with ``query_overrides``.
|
|
1428
1910
|
|
|
1429
1911
|
Args:
|
|
1430
1912
|
descriptor: The target whose disappearance to wait for — a selector or an element
|
|
@@ -1440,59 +1922,52 @@ class BareMetal(OurDynamicCore):
|
|
|
1440
1922
|
"""
|
|
1441
1923
|
settings = replace(self.query_settings, **query_overrides) if query_overrides else self.query_settings
|
|
1442
1924
|
query = descriptor.query
|
|
1443
|
-
if query is None
|
|
1925
|
+
if query is None:
|
|
1926
|
+
captured = descriptor.node
|
|
1927
|
+
if not isinstance(captured, UiNode):
|
|
1928
|
+
raise NoQueryError('This element reference has no selector to look the element up with.')
|
|
1444
1929
|
# A capture belongs to the runtime that produced it; one from another import can
|
|
1445
1930
|
# neither be polled here nor be honestly called gone.
|
|
1446
|
-
self.require_own_node(
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
if
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
# Captured element: poll its liveness directly.
|
|
1465
|
-
node = descriptor.node
|
|
1466
|
-
if node is None:
|
|
1467
|
-
gone = True
|
|
1468
|
-
else:
|
|
1469
|
-
self.runtime.clear_cache()
|
|
1470
|
-
node.invalidate()
|
|
1471
|
-
gone = not node.is_valid()
|
|
1472
|
-
except ResultTypeError:
|
|
1473
|
-
raise # usage error — surface immediately, regardless of ignore_exceptions
|
|
1474
|
-
except (SystemExit, KeyboardInterrupt):
|
|
1475
|
-
raise
|
|
1476
|
-
except Exception:
|
|
1477
|
-
if not settings.ignore_exceptions:
|
|
1478
|
-
raise
|
|
1479
|
-
gone = False # swallowed error => cannot confirm gone => keep waiting
|
|
1480
|
-
|
|
1481
|
-
if gone:
|
|
1482
|
-
return
|
|
1483
|
-
|
|
1484
|
-
if (time.monotonic() - start) > settings.timeout:
|
|
1485
|
-
if query is not None:
|
|
1486
|
-
raise ElementStillPresentError(
|
|
1487
|
-
f'Element matching query {query!r} was still present within timeout of '
|
|
1488
|
-
f'{settings.timeout} seconds.'
|
|
1489
|
-
)
|
|
1490
|
-
raise ElementStillPresentError(
|
|
1491
|
-
f'Captured element {descriptor.node!r} was still valid within timeout of '
|
|
1492
|
-
f'{settings.timeout} seconds.'
|
|
1493
|
-
)
|
|
1931
|
+
self.require_own_node(captured)
|
|
1932
|
+
|
|
1933
|
+
def still_valid(context: UiNode | None, seen: _Attempt) -> _NotYet | None:
|
|
1934
|
+
# A captured element is gone once the element it names is no longer valid.
|
|
1935
|
+
captured.invalidate()
|
|
1936
|
+
return _NOT_YET if captured.is_valid() else None
|
|
1937
|
+
|
|
1938
|
+
_poll(
|
|
1939
|
+
self,
|
|
1940
|
+
settings,
|
|
1941
|
+
lambda: None,
|
|
1942
|
+
still_valid,
|
|
1943
|
+
lambda seen, last_error: _gone_wait_error(
|
|
1944
|
+
f'Captured element {_element_text(captured)}', 'was still valid', settings.timeout, last_error
|
|
1945
|
+
),
|
|
1946
|
+
discard_first=True,
|
|
1947
|
+
)
|
|
1948
|
+
return
|
|
1494
1949
|
|
|
1495
|
-
|
|
1950
|
+
def still_present(context: UiNode | None, seen: _Attempt) -> _NotYet | None:
|
|
1951
|
+
# A selector is re-evaluated every attempt — it never carries a resolved element
|
|
1952
|
+
# between calls, so there is nothing stale to distrust.
|
|
1953
|
+
result = self.runtime.evaluate_single(query, context)
|
|
1954
|
+
if result is not None and not isinstance(result, UiNode):
|
|
1955
|
+
raise ResultTypeError(
|
|
1956
|
+
f'Wait Until Gone expects an element selector or a captured element; query '
|
|
1957
|
+
f'{query!r} returned a value. Use Wait Until Query for value conditions.'
|
|
1958
|
+
)
|
|
1959
|
+
return _NOT_YET if result is not None else None
|
|
1960
|
+
|
|
1961
|
+
_poll(
|
|
1962
|
+
self,
|
|
1963
|
+
settings,
|
|
1964
|
+
lambda: descriptor.context_node(self),
|
|
1965
|
+
still_present,
|
|
1966
|
+
lambda seen, last_error: _gone_wait_error(
|
|
1967
|
+
f'Element matching query {query!r}', 'was still present', settings.timeout, last_error
|
|
1968
|
+
),
|
|
1969
|
+
discard_first=True,
|
|
1970
|
+
)
|
|
1496
1971
|
|
|
1497
1972
|
@keyword
|
|
1498
1973
|
def wait_until_query(
|
|
@@ -1513,17 +1988,27 @@ class BareMetal(OurDynamicCore):
|
|
|
1513
1988
|
for a computed condition: a row count to settle, a value to reach a target, an attribute
|
|
1514
1989
|
to flip.
|
|
1515
1990
|
|
|
1516
|
-
It takes the same assertion arguments as `Get Attribute` — an operator and an expected
|
|
1991
|
+
It takes the same assertion arguments as `Get Attribute Value` — an operator and an expected
|
|
1517
1992
|
value (``==``, ``!=``, ``contains``, ``starts``, ``ends``, ``matches``, ``>``, ``<`` …;
|
|
1518
1993
|
see [https://github.com/MarketSquare/AssertionEngine|AssertionEngine]). With no operator
|
|
1519
1994
|
it waits until the result is *truthy* — a non-zero number, a non-empty string, a true
|
|
1520
|
-
boolean, a present element. Unlike `Get Attribute`, it works on the raw XPath result
|
|
1521
|
-
|
|
1522
|
-
missing attribute is an empty result here,
|
|
1995
|
+
boolean, a present element. Unlike `Get Attribute Value`, it works on the raw XPath result:
|
|
1996
|
+
the condition checks the value of an attribute step (``.../@X``), the number of
|
|
1997
|
+
``count(...)`` and the element of ``//X``, and a missing attribute is an empty result here,
|
|
1998
|
+
not an error.
|
|
1523
1999
|
|
|
1524
2000
|
The ``then`` operator is not supported (it transforms rather than asserts and cannot
|
|
1525
|
-
express a wait) — use ``validate`` for a boolean expression.
|
|
1526
|
-
with ``
|
|
2001
|
+
express a wait) — use ``validate`` for a boolean expression. A ``validate`` expression that
|
|
2002
|
+
raises ends the wait at once, so write it to cope with every result it may get, ``None``
|
|
2003
|
+
included while nothing matches: ``value is not None and 0 < value < 10``. Per-call waiting
|
|
2004
|
+
is tuned with ``query_overrides``.
|
|
2005
|
+
|
|
2006
|
+
A relative expression is evaluated inside the `Set Root` root, also when its path is a
|
|
2007
|
+
function's argument (``count(.//Button)``); an absolute one (``count(//Button)``) does not
|
|
2008
|
+
need the root. When ``timeout`` elapses, it fails with ``ResultTypeError`` without an
|
|
2009
|
+
operator, and with ``AssertionError`` or ``TypeError`` with one. The message says what the
|
|
2010
|
+
last evaluation gave, such as ``was 0 and did not become truthy``, or which error the last
|
|
2011
|
+
attempt raised.
|
|
1527
2012
|
|
|
1528
2013
|
Args:
|
|
1529
2014
|
expression: The XPath 2.0 expression to evaluate.
|
|
@@ -1531,7 +2016,9 @@ class BareMetal(OurDynamicCore):
|
|
|
1531
2016
|
for a truthy result.
|
|
1532
2017
|
assertion_expected: The expected value the operator compares against.
|
|
1533
2018
|
assertion_message: Optional custom failure message.
|
|
1534
|
-
root: Optional
|
|
2019
|
+
root: Optional element to evaluate against, from this same library import; the keyword
|
|
2020
|
+
fails at once when it no longer exists. Without it, a relative expression is
|
|
2021
|
+
evaluated against the current root.
|
|
1535
2022
|
query_overrides: Per-call query settings, e.g. ``{'timeout': 10}``.
|
|
1536
2023
|
|
|
1537
2024
|
Returns:
|
|
@@ -1539,7 +2026,7 @@ class BareMetal(OurDynamicCore):
|
|
|
1539
2026
|
an element), or the value returned by the assertion with one.
|
|
1540
2027
|
|
|
1541
2028
|
Examples:
|
|
1542
|
-
| ${count}= `Wait Until Query` count(//control:ListItem) > 0
|
|
2029
|
+
| ${count}= `Wait Until Query` count(//control:ListItem) > ${0}
|
|
1543
2030
|
| `Wait Until Query` Window[@Name="Editor"]//Button[@Name="Save"]/@IsEnabled == ${True}
|
|
1544
2031
|
| `Wait Until Query` string-join(//control:ListItem/@Name, ", ") contains Welcome
|
|
1545
2032
|
| ${n}= `Wait Until Query` count(//control:Window[@Name="Dialog"]) # wait until truthy
|
|
@@ -1552,68 +2039,208 @@ class BareMetal(OurDynamicCore):
|
|
|
1552
2039
|
)
|
|
1553
2040
|
|
|
1554
2041
|
settings = replace(self.query_settings, **query_overrides) if query_overrides else self.query_settings
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
2042
|
+
if root is not None:
|
|
2043
|
+
# An explicit root is a captured element, so it has to come from this import.
|
|
2044
|
+
self.require_own_node(root)
|
|
2045
|
+
|
|
2046
|
+
descriptor = self.descriptor_from_query(expression)
|
|
2047
|
+
|
|
2048
|
+
def context() -> UiNode | None:
|
|
2049
|
+
# Without an explicit root, a relative expression evaluates against the Set Root root and
|
|
2050
|
+
# an absolute one does without it; `UiNodeDescriptor.needs_root` also finds a relative path
|
|
2051
|
+
# inside a function's arguments, as in ``count(.//x)``. An explicit root is checked on every
|
|
2052
|
+
# attempt instead: once it is gone, nothing can look it up again.
|
|
2053
|
+
if root is None:
|
|
2054
|
+
return descriptor.context_node(self)
|
|
2055
|
+
if not root.is_valid():
|
|
2056
|
+
raise _pinned_element_gone(root)
|
|
2057
|
+
return root
|
|
2058
|
+
|
|
2059
|
+
def attempt(context: UiNode | None, seen: _Attempt) -> Any:
|
|
2060
|
+
seen.result = self.runtime.evaluate_single(expression, context)
|
|
2061
|
+
if assertion_operator is None:
|
|
2062
|
+
# An element is truthy while it is valid, an attribute by its value.
|
|
2063
|
+
return seen.result if seen.result else _NOT_YET
|
|
1560
2064
|
try:
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
except RuntimeError:
|
|
1574
|
-
raise # unknown operator — a programming error, surface immediately
|
|
1575
|
-
except (AssertionError, TypeError):
|
|
1576
|
-
satisfied = False # mismatch, or not-yet-comparable early value — keep polling
|
|
1577
|
-
except Exception:
|
|
1578
|
-
if not settings.ignore_exceptions:
|
|
1579
|
-
raise
|
|
1580
|
-
satisfied = False
|
|
1581
|
-
|
|
1582
|
-
if satisfied:
|
|
1583
|
-
return ret
|
|
1584
|
-
|
|
1585
|
-
if (time.monotonic() - start) > settings.timeout:
|
|
2065
|
+
return verify_assertion(
|
|
2066
|
+
_assertion_value(seen.result), assertion_operator, assertion_expected, assertion_message or ''
|
|
2067
|
+
)
|
|
2068
|
+
except (AssertionError, TypeError) as mismatch:
|
|
2069
|
+
# A mismatch, or a value the operator cannot compare yet: keep polling.
|
|
2070
|
+
seen.mismatch = mismatch
|
|
2071
|
+
return _NOT_YET
|
|
2072
|
+
|
|
2073
|
+
def failure(seen: _Attempt, last_error: Exception | None) -> Exception:
|
|
2074
|
+
within = f'within timeout of {settings.timeout} seconds'
|
|
2075
|
+
if seen.result is _UNSEEN:
|
|
2076
|
+
# The evaluation raised, so there is no result to name.
|
|
1586
2077
|
if assertion_operator is None:
|
|
2078
|
+
message = f'Query {expression!r} did not become truthy {within}.'
|
|
2079
|
+
return ResultTypeError(_with_last_error(message, last_error))
|
|
2080
|
+
message = f'Query {expression!r} did not satisfy the assertion {within}.'
|
|
2081
|
+
return AssertionError(_with_last_error(message, last_error))
|
|
2082
|
+
if last_error is not None:
|
|
2083
|
+
# The expression was evaluated, and only the check raised.
|
|
2084
|
+
message = f'Query {expression!r} {_result_text(seen.result)} and could not be checked {within}.'
|
|
2085
|
+
return AssertionError(_with_last_error(message, last_error))
|
|
2086
|
+
if assertion_operator is None:
|
|
2087
|
+
message = f'Query {expression!r} {_result_text(seen.result)} and did not become truthy {within}.'
|
|
2088
|
+
return ResultTypeError(message)
|
|
2089
|
+
if isinstance(seen.mismatch, TypeError):
|
|
2090
|
+
return TypeError(f'Query {expression!r}: {seen.mismatch} ({within})')
|
|
2091
|
+
return AssertionError(f'{seen.mismatch} ({within})')
|
|
2092
|
+
|
|
2093
|
+
return _poll(self, settings, context, attempt, failure, discard_first=True)
|
|
2094
|
+
|
|
2095
|
+
@keyword
|
|
2096
|
+
def wait_until_attribute_value(
|
|
2097
|
+
self,
|
|
2098
|
+
descriptor: UiNodeDescriptor,
|
|
2099
|
+
attribute_name: str,
|
|
2100
|
+
assertion_operator: AssertionOperator | None = None,
|
|
2101
|
+
assertion_expected: Any = None,
|
|
2102
|
+
assertion_message: str | None = None,
|
|
2103
|
+
*,
|
|
2104
|
+
query_overrides: QuerySettingsDict | None = None,
|
|
2105
|
+
) -> Any:
|
|
2106
|
+
"""Wait until an attribute of an element has the value you expect, then return that value.
|
|
2107
|
+
|
|
2108
|
+
The waiting counterpart to `Get Attribute Value`: it reads the attribute every ``retry_interval``
|
|
2109
|
+
until its value satisfies the condition, and returns the value it had at that moment — or
|
|
2110
|
+
fails once ``timeout`` elapses. Reach for it after an action whose effect lands a moment
|
|
2111
|
+
later: a window that finishes maximizing, a label that shows a new count, a button that
|
|
2112
|
+
becomes enabled once a form is complete. `Get Attribute Value` reads and checks a value once, which
|
|
2113
|
+
suits a value that has already settled.
|
|
2114
|
+
|
|
2115
|
+
Give the element and the attribute as for `Get Attribute Value`: a selector or an element from
|
|
2116
|
+
`Query`, and the attribute name bare — ``Name``, ``IsEnabled`` — or with its ``app:`` or
|
|
2117
|
+
``native:`` prefix (see `Process attributes`). The condition takes the same assertion operators
|
|
2118
|
+
as `Get Attribute Value` and `Wait Until Query` (``==``, ``!=``, ``contains``, ``matches``, ``>``,
|
|
2119
|
+
``validate`` …; see [https://github.com/MarketSquare/AssertionEngine|AssertionEngine]). With no
|
|
2120
|
+
operator the keyword waits until the value is truthy — a true boolean, a non-zero number, a
|
|
2121
|
+
non-empty string. The ``then`` operator is not supported, since it transforms the value instead
|
|
2122
|
+
of checking it; use ``validate`` for a condition written as an expression. A ``validate``
|
|
2123
|
+
expression that raises ends the wait at once, so write it to cope with every value the
|
|
2124
|
+
attribute may have, as ``value.isdigit() and int(value) > 3`` does for a text that is not
|
|
2125
|
+
always a number.
|
|
2126
|
+
|
|
2127
|
+
A selector is looked up again on every attempt, so the keyword also waits for the element to
|
|
2128
|
+
appear and for an attribute the element does not report yet. An element from `Query` stays
|
|
2129
|
+
that element: it is read afresh on every attempt, and the keyword fails at once when the
|
|
2130
|
+
element is gone, because it can then never reach the value. When ``timeout`` elapses, the
|
|
2131
|
+
error says what the last attempt found — no element, no such attribute, or the value and why
|
|
2132
|
+
it did not satisfy the condition. Per-call waiting is tuned with ``query_overrides`` (see
|
|
2133
|
+
`Tuning the wait`).
|
|
2134
|
+
|
|
2135
|
+
The value comes back typed, as from `Get Attribute Value`: ``IsEnabled`` as a boolean, ``Bounds`` as
|
|
2136
|
+
a ``Rect``. It is always the attribute's value — with ``matches`` too, which elsewhere can hand
|
|
2137
|
+
back the groups the pattern captured.
|
|
2138
|
+
|
|
2139
|
+
Args:
|
|
2140
|
+
descriptor: The element to read — a selector or an element from `Query`.
|
|
2141
|
+
attribute_name: The attribute to wait on, written bare (or with an ``app:`` or ``native:`` prefix).
|
|
2142
|
+
assertion_operator: Optional AssertionEngine operator; without one the keyword waits
|
|
2143
|
+
for a truthy value.
|
|
2144
|
+
assertion_expected: The expected value the operator compares against.
|
|
2145
|
+
assertion_message: Optional custom failure message.
|
|
2146
|
+
query_overrides: Per-call query settings, e.g. ``{'timeout': 10}``.
|
|
2147
|
+
|
|
2148
|
+
Returns:
|
|
2149
|
+
The attribute's value in the attempt that satisfied the condition.
|
|
2150
|
+
|
|
2151
|
+
Examples:
|
|
2152
|
+
| `Maximize Window` Window[@Name="Editor"]
|
|
2153
|
+
| `Wait Until Attribute Value` Window[@Name="Editor"] IsMaximized == ${True}
|
|
2154
|
+
| `Wait Until Attribute Value` Window[@Name="Import"]//Button[@Id="next"] IsEnabled # until truthy
|
|
2155
|
+
| ${label}= `Query` Window[@Name="Import"]//*[@Id="status"] only_first=${True}
|
|
2156
|
+
| ${status}= `Wait Until Attribute Value` ${label} Name starts Imported
|
|
2157
|
+
| `Wait Until Attribute Value` ${label} Name == Done query_overrides={'timeout': 60}
|
|
2158
|
+
"""
|
|
2159
|
+
# ``then`` transforms rather than asserts, so it never reports a mismatch and cannot wait.
|
|
2160
|
+
if assertion_operator is not None and assertion_operator is AssertionOperator['then']:
|
|
2161
|
+
raise ResultTypeError(
|
|
2162
|
+
"Wait Until Attribute Value cannot wait on the 'then' operator (it transforms rather than "
|
|
2163
|
+
"asserts). Use 'validate' for a boolean wait condition, or a comparison operator."
|
|
2164
|
+
)
|
|
2165
|
+
namespace, name = _split_attribute_name(attribute_name)
|
|
2166
|
+
|
|
2167
|
+
settings = replace(self.query_settings, **query_overrides) if query_overrides else self.query_settings
|
|
2168
|
+
query = descriptor.query
|
|
2169
|
+
captured: UiNode | None = None
|
|
2170
|
+
if query is None:
|
|
2171
|
+
if not isinstance(descriptor.node, UiNode):
|
|
2172
|
+
raise NoQueryError('This element reference has no selector to look the element up with.')
|
|
2173
|
+
# A capture belongs to the runtime that produced it; one from another import cannot be
|
|
2174
|
+
# read here.
|
|
2175
|
+
captured = descriptor.node
|
|
2176
|
+
self.require_own_node(captured)
|
|
2177
|
+
|
|
2178
|
+
def attempt(context: UiNode | None, seen: _Attempt) -> Any:
|
|
2179
|
+
node: UiNode | None = None
|
|
2180
|
+
if query is not None:
|
|
2181
|
+
# A selector is evaluated afresh on every attempt and without an inner wait: the
|
|
2182
|
+
# element appearing is part of what this keyword waits for, within one deadline.
|
|
2183
|
+
result = self.runtime.evaluate_single(query, context)
|
|
2184
|
+
if result is not None and not isinstance(result, UiNode):
|
|
1587
2185
|
raise ResultTypeError(
|
|
1588
|
-
f'
|
|
1589
|
-
|
|
1590
|
-
# Final assertion outside the loop so AssertionEngine's actual-vs-expected message surfaces.
|
|
1591
|
-
self.runtime.clear_cache()
|
|
1592
|
-
result = self.runtime.evaluate_single(expression, ctx)
|
|
1593
|
-
try:
|
|
1594
|
-
verify_assertion(
|
|
1595
|
-
_assertion_value(result), assertion_operator, assertion_expected, assertion_message or ''
|
|
2186
|
+
f'Wait Until Attribute Value expects an element selector or a captured element; '
|
|
2187
|
+
f'query {query!r} returned a value. Use Wait Until Query for value conditions.'
|
|
1596
2188
|
)
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
)
|
|
1602
|
-
|
|
1603
|
-
|
|
2189
|
+
node = result
|
|
2190
|
+
elif captured is not None:
|
|
2191
|
+
# A capture stays the element it names: refresh it, and stop once it is gone.
|
|
2192
|
+
captured.invalidate()
|
|
2193
|
+
if not captured.is_valid():
|
|
2194
|
+
raise _pinned_element_gone(captured)
|
|
2195
|
+
node = captured
|
|
2196
|
+
seen.result = node
|
|
2197
|
+
if node is None:
|
|
2198
|
+
return _NOT_YET
|
|
2199
|
+
try:
|
|
2200
|
+
value = node.attribute(name, namespace)
|
|
2201
|
+
except AttributeNotFoundError:
|
|
2202
|
+
return _NOT_YET # the attribute has not appeared yet
|
|
2203
|
+
seen.value = value
|
|
2204
|
+
if assertion_operator is None:
|
|
2205
|
+
return value if value else _NOT_YET
|
|
2206
|
+
try:
|
|
2207
|
+
verify_assertion(value, assertion_operator, assertion_expected, assertion_message or '')
|
|
2208
|
+
except (AssertionError, TypeError) as mismatch:
|
|
2209
|
+
# A mismatch, or a value the operator cannot compare yet: keep polling.
|
|
2210
|
+
seen.mismatch = mismatch
|
|
2211
|
+
return _NOT_YET
|
|
2212
|
+
# The value itself, not verify_assertion's result: for ``matches`` that would be the
|
|
2213
|
+
# captured groups.
|
|
2214
|
+
return value
|
|
2215
|
+
|
|
2216
|
+
return _poll(
|
|
2217
|
+
self,
|
|
2218
|
+
settings,
|
|
2219
|
+
lambda: descriptor.context_node(self),
|
|
2220
|
+
attempt,
|
|
2221
|
+
lambda seen, last_error: _attribute_wait_error(
|
|
2222
|
+
seen, last_error, query, attribute_name, bool(assertion_message), settings.timeout
|
|
2223
|
+
),
|
|
2224
|
+
discard_first=True,
|
|
2225
|
+
)
|
|
1604
2226
|
|
|
1605
2227
|
# Internal helpers
|
|
1606
2228
|
def _maybe_bring_to_front(
|
|
1607
2229
|
self,
|
|
1608
2230
|
node: UiNode | None,
|
|
1609
2231
|
activate: bool | None,
|
|
2232
|
+
description: str | None = None,
|
|
1610
2233
|
) -> None:
|
|
1611
2234
|
"""Bring the target element's window to the foreground if activation is enabled.
|
|
1612
2235
|
|
|
2236
|
+
A failure is recorded at DEBUG and the action proceeds: activation is best effort, and
|
|
2237
|
+
normal for elements without a window, such as the desktop.
|
|
2238
|
+
|
|
1613
2239
|
Args:
|
|
1614
2240
|
node: Optional resolved element. If None, no action is taken.
|
|
1615
2241
|
activate: Override for auto_activate. If None, the library-level
|
|
1616
2242
|
``auto_activate`` setting is used.
|
|
2243
|
+
description: The element's description, when the keyword already built it.
|
|
1617
2244
|
"""
|
|
1618
2245
|
if node is None:
|
|
1619
2246
|
return
|
|
@@ -1625,15 +2252,20 @@ class BareMetal(OurDynamicCore):
|
|
|
1625
2252
|
raise # Critical error from the library/runtime; propagate it
|
|
1626
2253
|
except (KeyboardInterrupt, SystemExit):
|
|
1627
2254
|
raise # Don't interfere with user-initiated interrupts
|
|
1628
|
-
except Exception: # noqa: BLE001
|
|
1629
|
-
|
|
2255
|
+
except Exception as exc: # noqa: BLE001 (best-effort; don't block the action)
|
|
2256
|
+
if _LOG.isEnabledFor(logging.DEBUG):
|
|
2257
|
+
_LOG.debug(
|
|
2258
|
+
'could not bring %s to the front; the action proceeds without it (%s)',
|
|
2259
|
+
description if description is not None else _describe(node),
|
|
2260
|
+
exc,
|
|
2261
|
+
)
|
|
1630
2262
|
|
|
1631
2263
|
def _resolve_screen_point(
|
|
1632
2264
|
self,
|
|
1633
2265
|
target_node: UiNode | None,
|
|
1634
2266
|
x: float | None,
|
|
1635
2267
|
y: float | None,
|
|
1636
|
-
) -> Point | None:
|
|
2268
|
+
) -> tuple[Point | None, str]:
|
|
1637
2269
|
"""Resolve absolute screen coordinates from an optional element and x/y values.
|
|
1638
2270
|
|
|
1639
2271
|
Behavior:
|
|
@@ -1649,13 +2281,14 @@ class BareMetal(OurDynamicCore):
|
|
|
1649
2281
|
position" (pointer_click/press/release pass None through to the runtime).
|
|
1650
2282
|
|
|
1651
2283
|
Returns:
|
|
1652
|
-
-
|
|
2284
|
+
- The absolute screen coordinates, or None when no point can be resolved, and where
|
|
2285
|
+
they came from, for the keyword's action line.
|
|
1653
2286
|
"""
|
|
1654
2287
|
if (x is not None) != (y is not None):
|
|
1655
2288
|
raise ValueError('Both x and y coordinates must be provided together')
|
|
1656
2289
|
|
|
2290
|
+
source = _FROM_ABSOLUTE if x is not None else _AT_POINTER
|
|
1657
2291
|
if target_node is not None:
|
|
1658
|
-
|
|
1659
2292
|
# No coordinates provided: auto-resolve from node
|
|
1660
2293
|
if x is None and y is None:
|
|
1661
2294
|
try:
|
|
@@ -1666,6 +2299,7 @@ class BareMetal(OurDynamicCore):
|
|
|
1666
2299
|
if isinstance(activation_point, Point):
|
|
1667
2300
|
x = activation_point.x
|
|
1668
2301
|
y = activation_point.y
|
|
2302
|
+
source = _FROM_ACTIVATION_POINT
|
|
1669
2303
|
else:
|
|
1670
2304
|
# No ActivationPoint (e.g. containers/aggregates like Desktop):
|
|
1671
2305
|
# fall back to the center of the element's bounds.
|
|
@@ -1679,6 +2313,7 @@ class BareMetal(OurDynamicCore):
|
|
|
1679
2313
|
center = bounds.center()
|
|
1680
2314
|
x = center.x
|
|
1681
2315
|
y = center.y
|
|
2316
|
+
source = _FROM_BOUNDS_CENTER
|
|
1682
2317
|
|
|
1683
2318
|
# Relative coordinates provided: offset from node bounds
|
|
1684
2319
|
elif x is not None and y is not None:
|
|
@@ -1691,12 +2326,13 @@ class BareMetal(OurDynamicCore):
|
|
|
1691
2326
|
|
|
1692
2327
|
x = bounds.x + x
|
|
1693
2328
|
y = bounds.y + y
|
|
2329
|
+
source = _FROM_OFFSET
|
|
1694
2330
|
|
|
1695
2331
|
# At this point, x and y must be resolved
|
|
1696
2332
|
if x is None or y is None:
|
|
1697
|
-
return None
|
|
2333
|
+
return None, _AT_POINTER
|
|
1698
2334
|
|
|
1699
|
-
return Point(x, y)
|
|
2335
|
+
return Point(x, y), source
|
|
1700
2336
|
|
|
1701
2337
|
@keyword
|
|
1702
2338
|
def pointer_click(
|
|
@@ -1733,9 +2369,11 @@ class BareMetal(OurDynamicCore):
|
|
|
1733
2369
|
| `Pointer Click` Window[@Name="Settings"]//Button[@Name="OK"] activate=${False}
|
|
1734
2370
|
"""
|
|
1735
2371
|
node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
|
|
1736
|
-
|
|
1737
|
-
|
|
2372
|
+
description = _describe(node)
|
|
2373
|
+
self._maybe_bring_to_front(node, activate, description)
|
|
2374
|
+
point, source = self._resolve_screen_point(node, x, y)
|
|
1738
2375
|
self.runtime.pointer_click(point, button, overrides)
|
|
2376
|
+
_log_action('clicked', _pointer_target(description, point, source), f'button {_button_name(button)}, 1 click')
|
|
1739
2377
|
|
|
1740
2378
|
@keyword
|
|
1741
2379
|
def pointer_multi_click(
|
|
@@ -1768,9 +2406,15 @@ class BareMetal(OurDynamicCore):
|
|
|
1768
2406
|
| `Pointer Multi Click` Window[@Name="Files"]//Text[@Name="File"] clicks=${3}
|
|
1769
2407
|
"""
|
|
1770
2408
|
node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
|
|
1771
|
-
|
|
1772
|
-
|
|
2409
|
+
description = _describe(node)
|
|
2410
|
+
self._maybe_bring_to_front(node, activate, description)
|
|
2411
|
+
point, source = self._resolve_screen_point(node, x, y)
|
|
1773
2412
|
self.runtime.pointer_multi_click(point, clicks, button, overrides)
|
|
2413
|
+
_log_action(
|
|
2414
|
+
'clicked',
|
|
2415
|
+
_pointer_target(description, point, source),
|
|
2416
|
+
f'button {_button_name(button)}, {_plural(clicks, "click")}',
|
|
2417
|
+
)
|
|
1774
2418
|
|
|
1775
2419
|
@keyword
|
|
1776
2420
|
def pointer_press(
|
|
@@ -1799,9 +2443,11 @@ class BareMetal(OurDynamicCore):
|
|
|
1799
2443
|
| `Pointer Press` Window[@Name="Mixer"]//Slider x=${10} y=${5}
|
|
1800
2444
|
"""
|
|
1801
2445
|
node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
|
|
1802
|
-
|
|
1803
|
-
|
|
2446
|
+
description = _describe(node)
|
|
2447
|
+
self._maybe_bring_to_front(node, activate, description)
|
|
2448
|
+
point, source = self._resolve_screen_point(node, x, y)
|
|
1804
2449
|
self.runtime.pointer_press(point, button, overrides)
|
|
2450
|
+
_log_action('pressed', _pointer_target(description, point, source), f'button {_button_name(button)}')
|
|
1805
2451
|
|
|
1806
2452
|
@keyword
|
|
1807
2453
|
def pointer_release(
|
|
@@ -1834,9 +2480,11 @@ class BareMetal(OurDynamicCore):
|
|
|
1834
2480
|
| `Pointer Release` Window[@Name="Editor"]//Canvas x=${50} y=${50}
|
|
1835
2481
|
"""
|
|
1836
2482
|
node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
|
|
1837
|
-
|
|
1838
|
-
|
|
2483
|
+
description = _describe(node)
|
|
2484
|
+
self._maybe_bring_to_front(node, activate, description)
|
|
2485
|
+
point, source = self._resolve_screen_point(node, x, y)
|
|
1839
2486
|
self.runtime.pointer_release(point, button, overrides)
|
|
2487
|
+
_log_action('released', _pointer_target(description, point, source), f'button {_button_name(button)}')
|
|
1840
2488
|
|
|
1841
2489
|
@keyword
|
|
1842
2490
|
def pointer_move_to(
|
|
@@ -1864,12 +2512,14 @@ class BareMetal(OurDynamicCore):
|
|
|
1864
2512
|
| `Pointer Move To` Window[@Name="Settings"]//Button[@Name="OK"]
|
|
1865
2513
|
"""
|
|
1866
2514
|
node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
|
|
1867
|
-
|
|
1868
|
-
|
|
2515
|
+
description = _describe(node)
|
|
2516
|
+
self._maybe_bring_to_front(node, activate, description)
|
|
2517
|
+
point, source = self._resolve_screen_point(node, x, y)
|
|
1869
2518
|
if point is None:
|
|
1870
2519
|
raise ValueError('Coordinates x and y must be specified either directly or via node')
|
|
1871
2520
|
|
|
1872
2521
|
self.runtime.pointer_move_to(point, overrides)
|
|
2522
|
+
_log_action('moved the pointer to', _pointer_target(description, point, source))
|
|
1873
2523
|
|
|
1874
2524
|
@keyword
|
|
1875
2525
|
def pointer_scroll(
|
|
@@ -1913,11 +2563,13 @@ class BareMetal(OurDynamicCore):
|
|
|
1913
2563
|
| `Pointer Scroll` x=${400} y=${300} direction=UP
|
|
1914
2564
|
"""
|
|
1915
2565
|
node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
|
|
1916
|
-
|
|
1917
|
-
|
|
2566
|
+
description = _describe(node)
|
|
2567
|
+
self._maybe_bring_to_front(node, activate, description)
|
|
2568
|
+
point, source = self._resolve_screen_point(node, x, y)
|
|
1918
2569
|
if point is not None:
|
|
1919
2570
|
self.runtime.pointer_move_to(point, overrides)
|
|
1920
2571
|
self.runtime.pointer_scroll(_scroll_delta(direction, ticks), overrides)
|
|
2572
|
+
_log_action('scrolled', _pointer_target(description, point, source), f'{direction}, {_plural(ticks, "tick")}')
|
|
1921
2573
|
|
|
1922
2574
|
@keyword
|
|
1923
2575
|
@assertable
|
|
@@ -1978,8 +2630,10 @@ class BareMetal(OurDynamicCore):
|
|
|
1978
2630
|
| `Focus` Window[@Name="Browser"]//Edit[@Name="Search"]
|
|
1979
2631
|
"""
|
|
1980
2632
|
node = descriptor.resolve(self, query_overrides)
|
|
1981
|
-
|
|
2633
|
+
description = _describe(node)
|
|
2634
|
+
self._maybe_bring_to_front(node, activate, description)
|
|
1982
2635
|
self.runtime.focus(node)
|
|
2636
|
+
_log_action('focused', str(description))
|
|
1983
2637
|
|
|
1984
2638
|
@keyword
|
|
1985
2639
|
def restore_window(self, descriptor: UiNodeDescriptor, *, query_overrides: QuerySettingsDict | None = None) -> None:
|
|
@@ -1996,7 +2650,9 @@ class BareMetal(OurDynamicCore):
|
|
|
1996
2650
|
| `Restore Window` Window[@Name="Settings"]
|
|
1997
2651
|
"""
|
|
1998
2652
|
node = descriptor.resolve(self, query_overrides)
|
|
2653
|
+
description = _describe(node)
|
|
1999
2654
|
node.get_pattern(Restorable).restore()
|
|
2655
|
+
_log_action('restored', str(description))
|
|
2000
2656
|
|
|
2001
2657
|
@keyword
|
|
2002
2658
|
def maximize_window(
|
|
@@ -2014,7 +2670,9 @@ class BareMetal(OurDynamicCore):
|
|
|
2014
2670
|
| `Maximize Window` Window[@Name="Editor"]
|
|
2015
2671
|
"""
|
|
2016
2672
|
node = descriptor.resolve(self, query_overrides)
|
|
2673
|
+
description = _describe(node)
|
|
2017
2674
|
node.get_pattern(Maximizable).maximize()
|
|
2675
|
+
_log_action('maximized', str(description))
|
|
2018
2676
|
|
|
2019
2677
|
@keyword
|
|
2020
2678
|
def minimize_window(
|
|
@@ -2032,7 +2690,9 @@ class BareMetal(OurDynamicCore):
|
|
|
2032
2690
|
| `Minimize Window` Window[@Name="Editor"]
|
|
2033
2691
|
"""
|
|
2034
2692
|
node = descriptor.resolve(self, query_overrides)
|
|
2693
|
+
description = _describe(node)
|
|
2035
2694
|
node.get_pattern(Minimizable).minimize()
|
|
2695
|
+
_log_action('minimized', str(description))
|
|
2036
2696
|
|
|
2037
2697
|
@keyword
|
|
2038
2698
|
def close_window(self, descriptor: UiNodeDescriptor, *, query_overrides: QuerySettingsDict | None = None) -> None:
|
|
@@ -2048,7 +2708,9 @@ class BareMetal(OurDynamicCore):
|
|
|
2048
2708
|
| `Close Window` Window[@Name="Editor"]
|
|
2049
2709
|
"""
|
|
2050
2710
|
node = descriptor.resolve(self, query_overrides)
|
|
2711
|
+
description = _describe(node)
|
|
2051
2712
|
node.get_pattern(Closeable).close()
|
|
2713
|
+
_log_action('closed', str(description))
|
|
2052
2714
|
|
|
2053
2715
|
@keyword
|
|
2054
2716
|
def activate_window(
|
|
@@ -2056,8 +2718,10 @@ class BareMetal(OurDynamicCore):
|
|
|
2056
2718
|
) -> None:
|
|
2057
2719
|
"""Bring a window to the front and give it the keyboard focus.
|
|
2058
2720
|
|
|
2059
|
-
|
|
2060
|
-
|
|
2721
|
+
A minimized window comes back the way it was before it was minimized, and a maximized window
|
|
2722
|
+
stays maximized; use `Restore Window` to return a window to its floating size. Waits for its
|
|
2723
|
+
target like the other action keywords. The target must be a window that can be activated; the
|
|
2724
|
+
keyword fails if it cannot (see `Window control`).
|
|
2061
2725
|
|
|
2062
2726
|
Args:
|
|
2063
2727
|
descriptor: The window element to activate.
|
|
@@ -2066,7 +2730,9 @@ class BareMetal(OurDynamicCore):
|
|
|
2066
2730
|
| `Activate Window` Window[@Name="Editor"]
|
|
2067
2731
|
"""
|
|
2068
2732
|
node = descriptor.resolve(self, query_overrides)
|
|
2733
|
+
description = _describe(node)
|
|
2069
2734
|
node.get_pattern(Activatable).activate()
|
|
2735
|
+
_log_action('activated', str(description))
|
|
2070
2736
|
|
|
2071
2737
|
@keyword
|
|
2072
2738
|
def move_window(
|
|
@@ -2086,7 +2752,9 @@ class BareMetal(OurDynamicCore):
|
|
|
2086
2752
|
| `Move Window` Window[@Name="Editor"] 100 200
|
|
2087
2753
|
"""
|
|
2088
2754
|
node = descriptor.resolve(self, query_overrides)
|
|
2755
|
+
description = _describe(node)
|
|
2089
2756
|
node.get_pattern(Movable).move_to(x, y)
|
|
2757
|
+
_log_action('moved', f'{description} to {_point_text(Point(x, y))}')
|
|
2090
2758
|
|
|
2091
2759
|
@keyword
|
|
2092
2760
|
def resize_window(
|
|
@@ -2111,7 +2779,9 @@ class BareMetal(OurDynamicCore):
|
|
|
2111
2779
|
| `Resize Window` Window[@Name="Editor"] 800 600
|
|
2112
2780
|
"""
|
|
2113
2781
|
node = descriptor.resolve(self, query_overrides)
|
|
2782
|
+
description = _describe(node)
|
|
2114
2783
|
node.get_pattern(Resizable).resize(width, height)
|
|
2784
|
+
_log_action('resized', f'{description} to {_number(width)}x{_number(height)}')
|
|
2115
2785
|
|
|
2116
2786
|
@keyword
|
|
2117
2787
|
def move_and_resize_window(
|
|
@@ -2140,8 +2810,13 @@ class BareMetal(OurDynamicCore):
|
|
|
2140
2810
|
| `Move And Resize Window` Window[@Name="Editor"] 100 200 800 600
|
|
2141
2811
|
"""
|
|
2142
2812
|
node = descriptor.resolve(self, query_overrides)
|
|
2813
|
+
description = _describe(node)
|
|
2143
2814
|
node.get_pattern(Movable).move_to(x, y)
|
|
2144
2815
|
node.get_pattern(Resizable).resize(width, height)
|
|
2816
|
+
_log_action(
|
|
2817
|
+
'moved and resized',
|
|
2818
|
+
f'{description} to {_point_text(Point(x, y))}, {_number(width)}x{_number(height)}',
|
|
2819
|
+
)
|
|
2145
2820
|
|
|
2146
2821
|
@keyword
|
|
2147
2822
|
def bring_to_front(self, descriptor: UiNodeDescriptor, *, query_overrides: QuerySettingsDict | None = None) -> None:
|
|
@@ -2149,8 +2824,9 @@ class BareMetal(OurDynamicCore):
|
|
|
2149
2824
|
|
|
2150
2825
|
Pointer actions already do this when ``auto_activate`` is on (the default), so you rarely
|
|
2151
2826
|
need it directly — reach for it to raise a window deliberately, for example when
|
|
2152
|
-
``auto_activate`` is off. A minimized window
|
|
2153
|
-
|
|
2827
|
+
``auto_activate`` is off. A minimized window comes back the way it was before it was
|
|
2828
|
+
minimized, and a maximized window stays maximized. `Activate Window` does the same thing for
|
|
2829
|
+
a window you already have.
|
|
2154
2830
|
|
|
2155
2831
|
Args:
|
|
2156
2832
|
descriptor: The element whose window to bring to the front.
|
|
@@ -2159,41 +2835,96 @@ class BareMetal(OurDynamicCore):
|
|
|
2159
2835
|
| `Bring To Front` Window[@Name="Editor"]
|
|
2160
2836
|
"""
|
|
2161
2837
|
node = descriptor.resolve(self, query_overrides)
|
|
2838
|
+
description = _describe(node)
|
|
2162
2839
|
self.runtime.bring_to_front(node)
|
|
2840
|
+
_log_action('brought', f'{description} to the front')
|
|
2163
2841
|
|
|
2164
2842
|
@keyword
|
|
2165
2843
|
@assertable
|
|
2166
|
-
def
|
|
2844
|
+
def get_attribute_value(
|
|
2167
2845
|
self, descriptor: UiNodeDescriptor, attribute_name: str, *, query_overrides: QuerySettingsDict | None = None
|
|
2168
2846
|
) -> Any:
|
|
2169
2847
|
"""Read one attribute of one element, and optionally assert on it in the same call.
|
|
2170
2848
|
|
|
2171
2849
|
Pass the attribute name bare — ``Name``, ``IsEnabled``, ``Bounds`` — without the leading
|
|
2172
|
-
``@``;
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2850
|
+
``@``; an application's process attribute keeps its ``app:`` prefix, and a
|
|
2851
|
+
technology-specific value its ``native:`` prefix (see `Process attributes`). The value
|
|
2852
|
+
comes back typed: ``@IsEnabled`` as a boolean, ``@Bounds`` as a ``Rect``. Add an assertion
|
|
2853
|
+
operator and an expected value to check it, and the keyword fails if the check does not
|
|
2854
|
+
hold. The keyword waits for the element like the action keywords (see `Waiting for
|
|
2855
|
+
elements`), but reads and checks the value once, at that moment; to wait until the value
|
|
2856
|
+
holds, use `Wait Until Attribute Value`. For several values at once, or a computed one, use `Query`
|
|
2857
|
+
instead.
|
|
2176
2858
|
|
|
2177
2859
|
Args:
|
|
2178
2860
|
descriptor: The element to read from — a selector or an element from `Query`.
|
|
2179
|
-
attribute_name: The attribute to read, written bare (or with
|
|
2861
|
+
attribute_name: The attribute to read, written bare (or with an ``app:`` or ``native:`` prefix).
|
|
2180
2862
|
|
|
2181
2863
|
Examples:
|
|
2182
|
-
| ${enabled}= `Get Attribute` Window[@Name="Editor"]//Button[@Name="Save"] IsEnabled
|
|
2183
|
-
| `Get Attribute` Window[@Name="Editor"]//Button[@Name="Save"] IsEnabled == ${True}
|
|
2184
|
-
| ${bounds}= `Get Attribute` Window[@Name="Editor"]//Button[@Name="Save"] Bounds
|
|
2864
|
+
| ${enabled}= `Get Attribute Value` Window[@Name="Editor"]//Button[@Name="Save"] IsEnabled
|
|
2865
|
+
| `Get Attribute Value` Window[@Name="Editor"]//Button[@Name="Save"] IsEnabled == ${True}
|
|
2866
|
+
| ${bounds}= `Get Attribute Value` Window[@Name="Editor"]//Button[@Name="Save"] Bounds
|
|
2867
|
+
| ${user}= `Get Attribute Value` /app:Application[@ProcessId=${pid}] app:UserName
|
|
2868
|
+
"""
|
|
2869
|
+
return self._read_attribute(descriptor, attribute_name, query_overrides)
|
|
2870
|
+
|
|
2871
|
+
@keyword
|
|
2872
|
+
@assertable
|
|
2873
|
+
def get_attribute(
|
|
2874
|
+
self, descriptor: UiNodeDescriptor, attribute_name: str, *, query_overrides: QuerySettingsDict | None = None
|
|
2875
|
+
) -> Any:
|
|
2876
|
+
"""*DEPRECATED* Use `Get Attribute Value` instead; this alias will be removed before PlatynUI 1.0.
|
|
2877
|
+
|
|
2878
|
+
Behaves exactly like `Get Attribute Value`: the same arguments, the same value, the same check.
|
|
2185
2879
|
"""
|
|
2880
|
+
# The shared body, not the decorated keyword: calling `get_attribute_value` would check the
|
|
2881
|
+
# assertion a second time.
|
|
2882
|
+
return self._read_attribute(descriptor, attribute_name, query_overrides)
|
|
2883
|
+
|
|
2884
|
+
def _read_attribute(
|
|
2885
|
+
self, descriptor: UiNodeDescriptor, attribute_name: str, query_overrides: QuerySettingsDict | None
|
|
2886
|
+
) -> Any:
|
|
2887
|
+
"""Read one attribute of one element, for `Get Attribute Value` and its deprecated alias."""
|
|
2186
2888
|
namespace: str | None = None
|
|
2187
2889
|
if ':' in attribute_name:
|
|
2188
2890
|
namespace, attribute_name = attribute_name.split(':', 1)
|
|
2189
2891
|
node = descriptor.resolve(self, query_overrides)
|
|
2190
2892
|
return node.attribute(attribute_name, namespace)
|
|
2191
2893
|
|
|
2894
|
+
def _keyboard(
|
|
2895
|
+
self,
|
|
2896
|
+
action: Any,
|
|
2897
|
+
verb: str,
|
|
2898
|
+
descriptor: UiNodeDescriptor | None,
|
|
2899
|
+
text: KeyboardText,
|
|
2900
|
+
overrides: KeyboardOverridesLike | None,
|
|
2901
|
+
activate: bool | None,
|
|
2902
|
+
query_overrides: QuerySettingsDict | None,
|
|
2903
|
+
) -> None:
|
|
2904
|
+
"""Run a keyboard action, with a `Secret`'s value kept out of errors and the action line."""
|
|
2905
|
+
description = None
|
|
2906
|
+
if descriptor is not None:
|
|
2907
|
+
target_node = descriptor.resolve(self, query_overrides)
|
|
2908
|
+
description = _describe(target_node)
|
|
2909
|
+
self._maybe_bring_to_front(target_node, activate, description)
|
|
2910
|
+
self.runtime.focus(target_node)
|
|
2911
|
+
# A `Secret` is not a `str`; its error names the position and the kind of failure only.
|
|
2912
|
+
sensitive = not isinstance(text, str)
|
|
2913
|
+
sequence = text if isinstance(text, str) else text.value
|
|
2914
|
+
try:
|
|
2915
|
+
action(sequence, overrides=overrides, sensitive=sensitive)
|
|
2916
|
+
except KeyboardError as exc:
|
|
2917
|
+
hint = None if sensitive else _test_data_hint(str(exc))
|
|
2918
|
+
if hint is None:
|
|
2919
|
+
raise
|
|
2920
|
+
raise KeyboardError(f'{exc} {hint}') from exc
|
|
2921
|
+
_log_action(verb, _keyboard_target(description), _typed_length(text))
|
|
2922
|
+
|
|
2192
2923
|
@keyword
|
|
2193
2924
|
def keyboard_type(
|
|
2194
2925
|
self,
|
|
2195
2926
|
descriptor: UiNodeDescriptor | None,
|
|
2196
|
-
text:
|
|
2927
|
+
text: KeyboardText,
|
|
2197
2928
|
*,
|
|
2198
2929
|
overrides: KeyboardOverridesLike | None = None,
|
|
2199
2930
|
activate: bool | None = None,
|
|
@@ -2206,10 +2937,40 @@ class BareMetal(OurDynamicCore):
|
|
|
2206
2937
|
Sequences may include plain text and special keys wrapped in angle brackets.
|
|
2207
2938
|
Use ``+`` to combine modifiers with keys.
|
|
2208
2939
|
|
|
2940
|
+
A few characters have a meaning of their own in a sequence. ``<`` starts a key such as
|
|
2941
|
+
``<Return>`` or ``<Ctrl+S>``, so a literal ``<`` is written ``\<`` and a literal ``>`` ``\>``.
|
|
2942
|
+
``\\`` types a backslash. ``\xHH`` and ``\uHHHH`` type the character with that hexadecimal
|
|
2943
|
+
code, and fail unless exactly 2 or 4 hex digits follow. A backslash before any other character
|
|
2944
|
+
is dropped. Robot Framework removes a backslash before an unknown character itself, before the
|
|
2945
|
+
keyword runs, so in test data every one of these backslashes is doubled: ``\\<`` types a
|
|
2946
|
+
literal ``<``, ``\\\\`` a backslash. The whole syntax is described in
|
|
2947
|
+
[https://github.com/imbus/robotframework-PlatynUI/blob/main/dev-docs/keyboard-input.md|Keyboard input].
|
|
2948
|
+
|
|
2949
|
+
When the sequence cannot be typed, the error says where and why — the position in the text
|
|
2950
|
+
the keyword received, counted in characters from 1, and the character or key that could not
|
|
2951
|
+
be typed or the part of the syntax that is wrong — without repeating the text itself.
|
|
2952
|
+
|
|
2953
|
+
``text`` can also be a ``Secret`` (Robot Framework 7.4 or newer), for passwords and tokens. It
|
|
2954
|
+
is typed like a string and follows the same syntax, but no part of it shows in the log or in
|
|
2955
|
+
an error: an error gives only the position and the kind of failure. A ``Secret`` must be the
|
|
2956
|
+
whole argument — inside a longer argument Robot Framework puts the text ``<secret>`` in its
|
|
2957
|
+
place, which the sequence would read as a key. Type it on its own and the rest in a second
|
|
2958
|
+
call, or make the whole sequence the ``Secret``:
|
|
2959
|
+
|
|
2960
|
+
| VAR ${password: Secret} %{APP_PASSWORD}
|
|
2961
|
+
| `Keyboard Type` Window[@Name="Login"]//Edit[@Name="Password"] ${password}
|
|
2962
|
+
| `Keyboard Type` ${None} <Return>
|
|
2963
|
+
| VAR ${login: Secret} %{APP_PASSWORD}<Return>
|
|
2964
|
+
| `Keyboard Type` Window[@Name="Login"]//Edit[@Name="Password"] ${login}
|
|
2965
|
+
|
|
2966
|
+
At ``--loglevel DEBUG`` the keyword logs the element it typed into and the length of the
|
|
2967
|
+
sequence, or for a ``Secret`` only that it is one. With ``native_log_level=trace``, PlatynUI
|
|
2968
|
+
records every key it presses, those of a ``Secret`` included; such a log is not for sharing.
|
|
2969
|
+
|
|
2209
2970
|
Args:
|
|
2210
2971
|
descriptor: Optional element to focus before typing. Pass ``${None}`` to type
|
|
2211
2972
|
into the currently focused element without changing focus.
|
|
2212
|
-
text: The character/key sequence to send
|
|
2973
|
+
text: The character/key sequence to send, a string or a ``Secret``.
|
|
2213
2974
|
overrides: Per-call timing overrides, as a dict (see `Input timing and motion`).
|
|
2214
2975
|
activate: Bring the element's window to the front first; defaults to the library's
|
|
2215
2976
|
``auto_activate``.
|
|
@@ -2225,17 +2986,13 @@ class BareMetal(OurDynamicCore):
|
|
|
2225
2986
|
or the Python runtime method ``Runtime.keyboard_known_key_names()``.
|
|
2226
2987
|
- To omit the descriptor (no focus change), pass ``${None}`` as the first argument in Robot Framework.
|
|
2227
2988
|
"""
|
|
2228
|
-
|
|
2229
|
-
target_node = descriptor.resolve(self, query_overrides)
|
|
2230
|
-
self._maybe_bring_to_front(target_node, activate)
|
|
2231
|
-
self.runtime.focus(target_node)
|
|
2232
|
-
self.runtime.keyboard_type(text, overrides=overrides)
|
|
2989
|
+
self._keyboard(self.runtime.keyboard_type, 'typed into', descriptor, text, overrides, activate, query_overrides)
|
|
2233
2990
|
|
|
2234
2991
|
@keyword
|
|
2235
2992
|
def keyboard_press(
|
|
2236
2993
|
self,
|
|
2237
2994
|
descriptor: UiNodeDescriptor | None,
|
|
2238
|
-
text:
|
|
2995
|
+
text: KeyboardText,
|
|
2239
2996
|
*,
|
|
2240
2997
|
overrides: KeyboardOverridesLike | None = None,
|
|
2241
2998
|
activate: bool | None = None,
|
|
@@ -2246,6 +3003,8 @@ class BareMetal(OurDynamicCore):
|
|
|
2246
3003
|
Unlike ``Keyboard Type``, this sends only press events (no release). Use this to
|
|
2247
3004
|
hold modifiers or keys; pair with ``Keyboard Release`` to complete the action.
|
|
2248
3005
|
|
|
3006
|
+
The sequence follows the syntax of `Keyboard Type`, and may be a ``Secret`` as well.
|
|
3007
|
+
|
|
2249
3008
|
Args:
|
|
2250
3009
|
descriptor: Optional element to bring to front and focus before pressing.
|
|
2251
3010
|
text: Sequence of keys, e.g. ``<Ctrl+Alt+T>`` or ``<Shift>``.
|
|
@@ -2258,17 +3017,15 @@ class BareMetal(OurDynamicCore):
|
|
|
2258
3017
|
| `Keyboard Press` ${None} <Ctrl>
|
|
2259
3018
|
| `Keyboard Release` ${None} <Ctrl>
|
|
2260
3019
|
"""
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
self.runtime.focus(target_node)
|
|
2265
|
-
self.runtime.keyboard_press(text, overrides=overrides)
|
|
3020
|
+
self._keyboard(
|
|
3021
|
+
self.runtime.keyboard_press, 'pressed keys in', descriptor, text, overrides, activate, query_overrides
|
|
3022
|
+
)
|
|
2266
3023
|
|
|
2267
3024
|
@keyword
|
|
2268
3025
|
def keyboard_release(
|
|
2269
3026
|
self,
|
|
2270
3027
|
descriptor: UiNodeDescriptor | None,
|
|
2271
|
-
text:
|
|
3028
|
+
text: KeyboardText,
|
|
2272
3029
|
*,
|
|
2273
3030
|
overrides: KeyboardOverridesLike | None = None,
|
|
2274
3031
|
activate: bool | None = None,
|
|
@@ -2279,6 +3036,8 @@ class BareMetal(OurDynamicCore):
|
|
|
2279
3036
|
Complements ``Keyboard Press`` by releasing keys/modifiers. If you need a full
|
|
2280
3037
|
press→release cycle for characters or shortcuts, prefer ``Keyboard Type``.
|
|
2281
3038
|
|
|
3039
|
+
The sequence follows the syntax of `Keyboard Type`, and may be a ``Secret`` as well.
|
|
3040
|
+
|
|
2282
3041
|
Args:
|
|
2283
3042
|
descriptor: Optional element to bring to front and focus before releasing.
|
|
2284
3043
|
text: Sequence of keys to release, e.g. ``<Ctrl+Alt+T>`` or ``<Ctrl>``.
|
|
@@ -2291,11 +3050,9 @@ class BareMetal(OurDynamicCore):
|
|
|
2291
3050
|
| `Keyboard Release` Window[@Name="Terminal"] <Ctrl+Alt>
|
|
2292
3051
|
| `Keyboard Release` ${None} <Ctrl+Alt>
|
|
2293
3052
|
"""
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
self.runtime.focus(target_node)
|
|
2298
|
-
self.runtime.keyboard_release(text, overrides=overrides)
|
|
3053
|
+
self._keyboard(
|
|
3054
|
+
self.runtime.keyboard_release, 'released keys in', descriptor, text, overrides, activate, query_overrides
|
|
3055
|
+
)
|
|
2299
3056
|
|
|
2300
3057
|
@keyword
|
|
2301
3058
|
def take_screenshot(
|
|
@@ -2407,20 +3164,30 @@ class BareMetal(OurDynamicCore):
|
|
|
2407
3164
|
|
|
2408
3165
|
rects: list[Rect] = []
|
|
2409
3166
|
if descriptor_list:
|
|
3167
|
+
descriptions: list[str] = []
|
|
2410
3168
|
for d in descriptor_list:
|
|
3169
|
+
node = None
|
|
2411
3170
|
try:
|
|
2412
3171
|
node = d.resolve(self, query_overrides)
|
|
2413
|
-
|
|
3172
|
+
description = _describe(node)
|
|
3173
|
+
self._maybe_bring_to_front(node, activate, description)
|
|
2414
3174
|
r = cast(Rect, node.attribute('Bounds'))
|
|
2415
3175
|
rects.append(r)
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
)
|
|
3176
|
+
if description is not None:
|
|
3177
|
+
descriptions.append(description)
|
|
3178
|
+
except Exception as exc: # noqa: BLE001 (one unresolvable node must not drop the whole highlight)
|
|
3179
|
+
if _LOG.isEnabledFor(logging.DEBUG):
|
|
3180
|
+
what = _describe(node) if node is not None else repr(d.query)
|
|
3181
|
+
_LOG.debug('could not read the bounds of %s; it is not highlighted (%s)', what, exc)
|
|
2420
3182
|
continue
|
|
2421
3183
|
|
|
2422
3184
|
self.runtime.highlight(rects, duration * 1000)
|
|
3185
|
+
_log_action('highlighted', ', '.join(descriptions) or 'nothing', f'for {_number(duration)} s')
|
|
2423
3186
|
return
|
|
2424
3187
|
|
|
2425
3188
|
if rect is not None:
|
|
2426
3189
|
self.runtime.highlight(rect, duration * 1000) # duration in ms
|
|
3190
|
+
if _LOG.isEnabledFor(logging.DEBUG):
|
|
3191
|
+
rect_list = rect if isinstance(rect, list) else [rect]
|
|
3192
|
+
shown = ', '.join(_rect_text(Rect.from_like(r)) for r in rect_list)
|
|
3193
|
+
_log_action('highlighted', shown, f'for {_number(duration)} s')
|