robotframework-platynui 0.13.0.dev2__py3-none-any.whl → 0.13.0.dev117__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.
@@ -1,4 +1,5 @@
1
1
  import base64
2
+ import re
2
3
  import time
3
4
  from dataclasses import dataclass, replace
4
5
  from functools import cached_property
@@ -65,6 +66,43 @@ class ElementStillPresentError(BareMetalError):
65
66
  """Raised when an element is still present/valid after a `Wait Until Gone` timeout elapses."""
66
67
 
67
68
 
69
+ class ForeignNodeError(BareMetalError):
70
+ """Raised when an element from one library import is used with another.
71
+
72
+ Element handles are not interchangeable: each belongs to the runtime whose provider
73
+ connection produced it (``UiNode.owner_id``). Using one with a different import would
74
+ evaluate against a connection that never created it.
75
+ """
76
+
77
+
78
+ class PinnedElementGoneError(BareMetalError):
79
+ """Raised when a reference pins an element that no longer exists and cannot be looked up again.
80
+
81
+ A captured element names one concrete element and carries no selector, so when the provider
82
+ reports it as gone there is nothing left to re-evaluate. Query it again, or use a selector —
83
+ which is what a reference re-evaluated on every use is for.
84
+ """
85
+
86
+
87
+ class UnsharableRootError(BareMetalError):
88
+ """Raised when a root pinning an element is set at a scope that outlives its runtime.
89
+
90
+ ``SUITES`` and ``GLOBAL`` hand the value to suites that get their own library instance,
91
+ and therefore their own runtime, in which a pinned element means nothing and cannot be
92
+ re-found. A selector can be shared at those scopes; an element cannot.
93
+ """
94
+
95
+
96
+ # Scope names and their mapping to Robot Framework's variable scopes, mirroring the `VAR`
97
+ # syntax (`robot/running/model.py`, `Var._get_scope`) so the vocabulary is RF's, not ours:
98
+ # `TASK` is an alias of `TEST`, and `SUITES` is the suite scope extended to child suites.
99
+ Scope = Literal['LOCAL', 'TEST', 'TASK', 'SUITE', 'SUITES', 'GLOBAL']
100
+
101
+ # Scopes that reach suites other than the one setting the value — those suites have their own
102
+ # library instance and runtime, so only re-resolvable data (a selector) may travel there.
103
+ _CROSS_SUITE_SCOPES: tuple[Scope, ...] = ('SUITES', 'GLOBAL')
104
+
105
+
68
106
  PLATYNUI_QUERY_SETTINGS = (
69
107
  'PLATYNUI_QUERY_SETTINGS' # Variable name for storing the current query settings in Robot Framework variables
70
108
  )
@@ -97,62 +135,138 @@ class QuerySettingsDict(TypedDict, total=False):
97
135
 
98
136
 
99
137
  class UiNodeDescriptor:
100
- """Descriptor wrapper allowing lazy resolution of a UiNode from a query string.
101
-
102
- The descriptor either holds a concrete UiNode or an expression string that will be
103
- evaluated using the associated BareMetal library instance when called.
138
+ """An element reference: either a selector or a captured element.
139
+
140
+ The two forms are deliberately distinct, because they answer different questions:
141
+
142
+ - A *selector* (``query`` set) says "whatever matches this path right now". It is pure
143
+ data — the path plus, for a stored root, the root chain it was set under — and is
144
+ re-evaluated on every use. It holds no resolved element between calls, so it always
145
+ follows the current root and the current state of the tree.
146
+ - A *capture* (``node`` set) names one concrete element. It is pinned to that element
147
+ and to the runtime whose provider connection produced it, and is never re-resolved.
148
+
149
+ Everything about the *call* — which library resolves it, with which query settings and
150
+ per-call overrides — is supplied by the caller, never stored here. That is what makes a
151
+ reference safe to hand between library imports: it is resolved by whoever is running,
152
+ against that instance's root and runtime.
153
+
154
+ One exception to "holds no resolved element": a selector used **as a root** keeps the element
155
+ it resolved to, reused while that element is still live and still belongs to the resolving
156
+ instance. A root is looked up once per keyword on top of the keyword's own target, so it is
157
+ repetition the suite never asked for — and unlike a target selector, whose re-evaluation *is*
158
+ the observation the keyword makes, a root names a container that was pinned on purpose. The
159
+ element is dropped as soon as it stops being valid, so a root still survives its window closing
160
+ and reopening. Note what this rests on: `platynui_native.UiNode.is_valid` is a provider-side
161
+ liveness check whose trait default is ``True`` — a provider that does not implement it gets a
162
+ root that is never looked up again.
104
163
  """
105
164
 
106
165
  def __init__(
107
166
  self,
108
167
  node: UiNode | None,
109
168
  query: str | None,
110
- library: 'BareMetal',
111
169
  parent: 'UiNodeDescriptor | None' = None,
112
170
  is_root_binding: bool = False,
113
171
  ) -> None:
114
172
  self.node = node
115
173
  self.query = query
116
- self.library = library
117
174
  # When this descriptor is used as a stored root, ``parent`` is the root that was effective
118
175
  # when it was set; a relative query then drills into it. ``is_root_binding`` marks a
119
176
  # descriptor created by ``set_root`` so that restoring a saved root keeps its chain as-is
120
177
  # instead of being re-parented.
121
178
  self.parent = parent
122
179
  self.is_root_binding = is_root_binding
123
- # Per-call query-settings override (partial), set from each wait keyword's query_overrides
124
- # argument before it resolves this descriptor — unconditionally, so a stale value never leaks
125
- # via the shared descriptor cache. Resolved against the scoped/default settings in __call__.
126
- self.overrides: QuerySettingsDict | None = None
180
+ # Whether the query needs a context node at all. A function of the query string alone, so
181
+ # it is safe to remember on a shared selector; ``None`` until first asked.
182
+ self._context_dependent: bool | None = None
183
+ # The element this selector last resolved to *as a root* (see the class docs). Safe here and
184
+ # nowhere else: `set_root` builds a fresh binding per call, so the object identity is the
185
+ # invalidation — unlike the shared per-query descriptors handed out by
186
+ # `descriptor_from_query`, where a cached element outlived the root it was found under.
187
+ self._root_node: UiNode | None = None
188
+
189
+ def needs_root(self, library: 'BareMetal') -> bool:
190
+ """Whether resolving this selector has to resolve the library's root first.
191
+
192
+ An absolute selector (``/`` or ``//``) starts at the document root and ignores the context
193
+ 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.
195
+ """
196
+ if self.query is None:
197
+ return False
198
+ if self._context_dependent is None:
199
+ try:
200
+ self._context_dependent = library.runtime.is_context_dependent(self.query)
201
+ except EvaluationError:
202
+ # Undecidable here; resolve the root and let the real evaluation report the error.
203
+ self._context_dependent = True
204
+ return self._context_dependent
205
+
206
+ @property
207
+ def owner_id(self) -> int | None:
208
+ """The runtime that produced this reference's element, or ``None`` for a selector."""
209
+ return self.node.owner_id if isinstance(self.node, UiNode) else None
127
210
 
128
- def __call__(self, no_root: bool = False) -> UiNode:
211
+ def resolve(
212
+ self,
213
+ library: 'BareMetal',
214
+ overrides: 'QuerySettingsDict | None' = None,
215
+ as_root: bool = False,
216
+ ) -> UiNode:
217
+ """Resolve to an element for ``library``, waiting per its effective query settings."""
129
218
  if isinstance(self.node, UiNode):
219
+ library.require_own_node(self.node)
130
220
  if self.node.is_valid():
131
221
  return self.node
222
+ if self.query is None:
223
+ raise PinnedElementGoneError(
224
+ f'The pinned element {self.node.runtime_id!r} is no longer available, and this '
225
+ f'reference holds no selector to look it up again. Query it again to get a '
226
+ f'current element, or use a selector, which is re-evaluated on every use.'
227
+ )
132
228
 
133
229
  if self.query is None:
134
230
  raise NoQueryError('UiNodeDescriptor has no query to resolve the node')
135
231
 
136
- # Resolving a stored root (no_root=True) evaluates the query against the captured parent
232
+ # A root is looked up once per keyword *in addition* to the keyword's own target, so it is
233
+ # the one repetition the suite did not ask for. Reuse it while it is live: a root names a
234
+ # container that was pinned deliberately, and skipping its lookup skips a descendant search
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).
238
+ if as_root and self._root_node is not None:
239
+ cached = self._root_node
240
+ # A selector root may legitimately be handed to another import, which then shares this
241
+ # object — so the owner is part of the question, not just liveness. Foreign or stale
242
+ # means: look it up again, which a selector can always do.
243
+ if cached.owner_id == library.runtime.instance_id and cached.is_valid():
244
+ return cached
245
+ self._root_node = None
246
+
247
+ # Resolving a stored root (as_root=True) evaluates the query against the captured parent
137
248
  # chain, so a relative root drills into the enclosing root while an absolute query ignores
138
- # it. As a query target (no_root=False) it evaluates against the library's current root.
139
- context = (self.parent(True) if self.parent is not None else None) if no_root else self.library.root
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
140
254
 
141
255
  # Effective settings for this resolution: the scoped/default base, with this call's partial
142
256
  # override applied on top. Computed once — neither layer changes during a synchronous resolve.
143
- base = self.library.query_settings
144
- settings = replace(base, **self.overrides) if self.overrides else base
257
+ base = library.query_settings
258
+ settings = replace(base, **overrides) if overrides else base
145
259
 
146
260
  start_time = time.monotonic()
147
261
  result: UiNode | UiValue | EvaluatedAttribute | None = None
148
262
  while True:
149
263
  try:
150
- result = self.library.runtime.evaluate_single(self.query, context)
264
+ result = library.runtime.evaluate_single(self.query, context)
151
265
  except (SystemExit, KeyboardInterrupt):
152
266
  raise # Don't interfere with user-initiated interrupts
153
- except Exception as e:
267
+ except Exception:
154
268
  if not settings.ignore_exceptions:
155
- raise e
269
+ raise
156
270
  result = None # Swallow the error, but keep honouring the timeout below
157
271
  else:
158
272
  if result is not None:
@@ -167,19 +281,20 @@ class UiNodeDescriptor:
167
281
  )
168
282
 
169
283
  time.sleep(settings.retry_interval)
170
- self.library.runtime.clear_cache() # Clear runtime cache to attempt to resolve transient UI states
284
+ library.runtime.clear_cache() # Clear runtime cache to attempt to resolve transient UI states
171
285
 
172
286
  if not isinstance(result, UiNode):
173
287
  raise ResultTypeError(f'Query for UiNodeDescriptor {self.query!r} did not return a UiNode, got: {result!r}')
174
288
 
175
- self.node = result # Cache resolved node
289
+ if as_root:
290
+ self._root_node = result
176
291
 
177
292
  return result
178
293
 
179
294
  @staticmethod
180
295
  def convert(value: str | UiNode, library: 'BareMetal') -> 'UiNodeDescriptor':
181
296
  if isinstance(value, UiNode):
182
- return UiNodeDescriptor(value, None, library)
297
+ return UiNodeDescriptor(value, None)
183
298
  return library.descriptor_from_query(value)
184
299
 
185
300
 
@@ -187,6 +302,24 @@ PLATYNUI_ROOT_DESCRIPTOR = (
187
302
  'PLATYNUI_ROOT_DESCRIPTOR' # Variable name for storing the current root descriptor in Robot Framework variables
188
303
  )
189
304
 
305
+ # Robot Framework's own library identity — the name an unaliased import is registered under.
306
+ # It maps to the unsuffixed variable names, so the documented spelling keeps working.
307
+ _DEFAULT_LIBRARY_NAME = 'PlatynUI.BareMetal'
308
+
309
+
310
+ def _variable_suffix(library_name: str | None) -> str:
311
+ """Suffix identifying which import a scoped variable belongs to.
312
+
313
+ The registered library name is the identity Robot Framework itself uses: within a namespace it
314
+ maps one-to-one to an import (RF rejects a duplicate name), and unlike the instance — which is
315
+ rebuilt for every suite, the library being suite-scoped — it is readable in the variable table.
316
+ """
317
+ if library_name is None or library_name == _DEFAULT_LIBRARY_NAME:
318
+ return ''
319
+ # Anything outside [A-Z0-9_] would collide with Robot's extended variable syntax (``${a.b}``
320
+ # means attribute access), so a dotted or spaced alias has to be folded down.
321
+ return '_' + re.sub(r'[^A-Z0-9_]', '_', library_name.upper())
322
+
190
323
 
191
324
  def _assertion_value(result: Any) -> Any:
192
325
  """Unwrap an evaluated query result to the value an assertion should apply to.
@@ -302,7 +435,7 @@ class BareMetal(OurDynamicCore):
302
435
 
303
436
  | = Prefix = | = Selects = |
304
437
  | ``control:`` | ordinary elements — the default |
305
- | ``item:`` | items inside containers: ``ListItem``, ``MenuItem``, ``TabItem``, ``TableCell`` ... |
438
+ | ``item:`` | items inside containers: ``ListItem``, ``TabItem``, ``TableCell`` ... |
306
439
  | ``app:`` | a running application (see `Targeting a specific application`) |
307
440
  | ``native:`` | raw, technology-specific roles and attributes |
308
441
 
@@ -513,19 +646,57 @@ class BareMetal(OurDynamicCore):
513
646
 
514
647
  == Scope ==
515
648
 
516
- A root lives as long as the Robot Framework variable it is kept in; ``scope`` chooses which, and
517
- each scope clears itself when it ends — no teardown to remember:
649
+ A root lives as long as the Robot Framework variable it is kept in; ``scope`` chooses which. All
650
+ of them except ``GLOBAL`` clear themselves when that scope ends, so there is no teardown to
651
+ remember:
518
652
 
519
653
  | = scope = | = The root applies to = |
520
654
  | ``LOCAL`` (default) | the current test or keyword, not the keywords it calls |
521
- | ``TEST`` | the whole test, including called keywords |
522
- | ``SUITE`` | every test in the suite |
655
+ | ``TEST`` (or ``TASK``) | the whole test, including called keywords |
656
+ | ``SUITE`` | every test in the suite, but not the suites below it |
657
+ | ``SUITES`` | the suite *and* every suite below it |
658
+ | ``GLOBAL`` | everywhere, for the rest of the run |
523
659
 
524
660
  | `Set Root` /app:Application[@Name="Editor"] scope=SUITE
525
661
 
526
- The root stores the *query*, not a fixed node, so it re-resolves against the live tree and keeps
527
- working even after its window closes and reopens. (It lives in ``${PLATYNUI_ROOT_DESCRIPTOR}``,
528
- but set it through `Set Root` — the raw variable holds an internal descriptor.)
662
+ These are Robot Framework's own scope names, with the same meanings its ``VAR`` syntax gives
663
+ them — including that ``SUITE`` stops at this suite while ``SUITES`` continues into the suites
664
+ below. ``SUITES`` is what makes a directory's ``__init__.robot`` usable as a fixture: launch the
665
+ application once and pin it as the root for every suite it contains.
666
+
667
+ Also Robot Framework's behavior: setting a value at a wider scope overwrites it in the narrower
668
+ ones. After a ``GLOBAL`` root, clearing it therefore leaves you at the desktop — an earlier
669
+ ``TEST`` or ``SUITE`` root does not come back. `Set Root` returns the root that was set at the
670
+ scope you name, so keep that return value if you want to restore it.
671
+
672
+ The root stores the *selector*, not a fixed element, so it re-resolves against the live tree and
673
+ keeps working even after its window closes and reopens. (It lives in
674
+ ``${PLATYNUI_ROOT_DESCRIPTOR}``, but set it through `Set Root` — the raw variable holds an
675
+ internal value.)
676
+
677
+ You can also pin one concrete element, by passing something you captured from `Query` instead of
678
+ a selector. That is fine at ``LOCAL``, ``TEST`` and ``SUITE``, but not at the two scopes that
679
+ leave this suite: a suite below builds its own runtime, in which a pinned element cannot be found
680
+ again, so a captured root at ``SUITES`` or ``GLOBAL`` is refused rather than stored.
681
+
682
+ == One root per import ==
683
+
684
+ The root belongs to the library import that set it. If you import the library more than once —
685
+ to drive two sessions, or with different settings — each import keeps its own root and its own
686
+ query settings, and neither sees the other's:
687
+
688
+ | Library PlatynUI.BareMetal AS APP
689
+ | Library PlatynUI.BareMetal config={'platform': {'x11': {'display': ':1'}}} AS REMOTE
690
+ | `APP.Set Root` /app:Application[@Name="Editor"] # REMOTE still starts at its desktop
691
+
692
+ Each import stores its root under its own variable, named after the import: the plain import
693
+ uses ``${PLATYNUI_ROOT_DESCRIPTOR}``, an import named ``APP`` uses
694
+ ``${PLATYNUI_ROOT_DESCRIPTOR_APP}`` (and likewise for ``${PLATYNUI_QUERY_SETTINGS}``).
695
+
696
+ Elements follow the same rule, and more strictly: an element you got from one import cannot be
697
+ used with another — it is a live handle into *that* import's session, and passing it elsewhere
698
+ fails rather than silently acting on the wrong session. Pass the *selector* instead, which any
699
+ import can resolve for itself.
529
700
 
530
701
  = Targeting a specific application =
531
702
 
@@ -604,9 +775,10 @@ class BareMetal(OurDynamicCore):
604
775
  | Library PlatynUI.BareMetal query_settings={'timeout': 60}
605
776
 
606
777
  *For a stretch of a test* that needs more (or less) patience than the rest — a slow login, say —
607
- with `Set Query Settings`. It works exactly like `Set Root`: the change lives as long as its
608
- ``LOCAL``/``TEST``/``SUITE`` scope and clears itself when that scope ends, so there is no teardown
609
- to remember.
778
+ with `Set Query Settings`. It works exactly like `Set Root` and takes the same ``scope`` names: a
779
+ change at ``LOCAL``, ``TEST``, ``SUITE`` or ``SUITES`` clears itself when that scope ends, so
780
+ there is no teardown to remember. ``GLOBAL`` is the exception — it lasts for the rest of the run
781
+ and has to be reset deliberately.
610
782
 
611
783
  | `Set Query Settings` {'timeout': 60} scope=TEST
612
784
 
@@ -796,16 +968,142 @@ class BareMetal(OurDynamicCore):
796
968
  self._pointer_settings = pointer_settings
797
969
  self._pointer_profile = pointer_profile
798
970
  self._descriptor_cache: dict[str, UiNodeDescriptor] = {}
971
+ self._variable_suffix_cache: str | None = None
799
972
 
800
973
  def descriptor_from_query(self, query: str) -> UiNodeDescriptor:
801
974
  descriptor = self._descriptor_cache.get(query)
802
975
  if descriptor is not None:
803
976
  return descriptor
804
977
 
805
- descriptor = UiNodeDescriptor(None, query, self)
978
+ descriptor = UiNodeDescriptor(None, query)
806
979
  self._descriptor_cache[query] = descriptor
807
980
  return descriptor
808
981
 
982
+ # ---- Per-import identity ------------------------------------------------------------
983
+
984
+ def _registered_name(self) -> str | None:
985
+ """The name this instance is registered under in the current Robot Framework namespace.
986
+
987
+ Reads ``_instance`` rather than the public ``instance`` property: that property *creates*
988
+ the library instance when the slot is empty, so walking the namespace through it would
989
+ instantiate every library the suite imported.
990
+ """
991
+ ctx = EXECUTION_CONTEXTS.current
992
+ if ctx is None:
993
+ return None
994
+ # Robot Framework ships no type information, so every attribute read below is
995
+ # untyped. Pin the namespace to `object` once: that stops the unknown type from
996
+ # propagating into each getattr() call, and forces the narrowing to be explicit.
997
+ namespace = cast(object, ctx.namespace)
998
+ kw_store: object = getattr(namespace, '_kw_store', None)
999
+ libraries = cast('dict[str, object] | None', getattr(kw_store, 'libraries', None))
1000
+ if not libraries:
1001
+ return None
1002
+ for name, lib in libraries.items():
1003
+ if getattr(lib, 'code', None) is type(self) and getattr(lib, '_instance', None) is self:
1004
+ return name
1005
+ return None
1006
+
1007
+ def _variable_suffix(self) -> str:
1008
+ """This import's variable-name suffix; resolved once, it cannot change for an instance.
1009
+
1010
+ Only a *successful* lookup is remembered. Falling back to the unsuffixed name when there is
1011
+ no namespace to resolve against is fine for that one call, but caching the miss would pin an
1012
+ aliased import to the default variable for the rest of its life — reintroducing the very
1013
+ leak this naming prevents, and silently.
1014
+ """
1015
+ if self._variable_suffix_cache is None:
1016
+ name = self._registered_name()
1017
+ if name is None:
1018
+ return ''
1019
+ self._variable_suffix_cache = _variable_suffix(name)
1020
+ return self._variable_suffix_cache
1021
+
1022
+ def _root_variable_name(self) -> str:
1023
+ return f'${{{PLATYNUI_ROOT_DESCRIPTOR}{self._variable_suffix()}}}'
1024
+
1025
+ def _query_settings_variable_name(self) -> str:
1026
+ return f'${{{PLATYNUI_QUERY_SETTINGS}{self._variable_suffix()}}}'
1027
+
1028
+ def _scoped_value(self, store: Any, name: str) -> Any:
1029
+ """Read a scoped value from a variable store.
1030
+
1031
+ ``store`` is a Robot Framework ``VariableStore`` — ``variables.current`` for a
1032
+ nearest-scope-wins read, or one specific scope's store. (The enclosing ``VariableScopes``
1033
+ object has no ``get``.)
1034
+ """
1035
+ return store.get(name, default=None)
1036
+
1037
+ # ---- Robot Framework variable scopes ------------------------------------------------
1038
+
1039
+ @staticmethod
1040
+ def _scope_store(variables: Any, scope: Scope) -> Any:
1041
+ """The variable store a value set at ``scope`` is read back from.
1042
+
1043
+ Read directly rather than through ``BuiltIn()``, so a same-scope restore is exact and
1044
+ nothing is logged in the wrong step context. Falls back to the innermost store while
1045
+ Robot Framework has no suite scope yet (i.e. outside keyword execution).
1046
+ """
1047
+ suite_vars = getattr(variables, '_suite', None)
1048
+ store: Any
1049
+ if scope == 'GLOBAL':
1050
+ store = getattr(variables, '_global', None)
1051
+ elif scope in ('SUITE', 'SUITES'):
1052
+ store = suite_vars
1053
+ elif scope in ('TEST', 'TASK'):
1054
+ test_vars = getattr(variables, '_test', None)
1055
+ store = test_vars if test_vars is not None else suite_vars
1056
+ else: # 'LOCAL'
1057
+ store = variables.current
1058
+ return store if store is not None else variables.current
1059
+
1060
+ @staticmethod
1061
+ def _write_scoped(variables: Any, scope: Scope, name: str, value: Any) -> None:
1062
+ """Store ``value`` under ``name`` at ``scope``, mirroring Robot Framework's own mapping.
1063
+
1064
+ Same table as the `VAR` syntax uses (`Var._get_scope`): ``TASK`` is ``TEST``, and
1065
+ ``SUITES`` is the suite scope with ``children=True``.
1066
+ """
1067
+ if scope == 'GLOBAL':
1068
+ variables.set_global(name, value)
1069
+ elif scope == 'SUITES':
1070
+ variables.set_suite(name, value, children=True)
1071
+ elif scope == 'SUITE':
1072
+ variables.set_suite(name, value)
1073
+ elif scope in ('TEST', 'TASK'):
1074
+ variables.set_test(name, value)
1075
+ else: # 'LOCAL'
1076
+ variables.set_local(name, value)
1077
+
1078
+ @staticmethod
1079
+ def _pinned_element(descriptor: UiNodeDescriptor) -> UiNode | None:
1080
+ """The first pinned element in this root chain, or ``None`` if it is pure selector data.
1081
+
1082
+ The whole chain matters: a selector root may drill into a captured element, which binds the
1083
+ chain to that element's runtime just as the capture itself is.
1084
+ """
1085
+ current: UiNodeDescriptor | None = descriptor
1086
+ while current is not None:
1087
+ if isinstance(current.node, UiNode):
1088
+ return current.node
1089
+ current = current.parent
1090
+ return None
1091
+
1092
+ def require_own_node(self, node: UiNode) -> None:
1093
+ """Reject an element produced by another import's runtime.
1094
+
1095
+ Element handles are not interchangeable — each is bound to the provider connection that
1096
+ created it — and nothing about the element says so: ``runtime_id`` is provider-stable, so
1097
+ two imports driving the same session report the same value for the same element.
1098
+ """
1099
+ owner = node.owner_id
1100
+ if owner != self.runtime.instance_id:
1101
+ raise ForeignNodeError(
1102
+ f'Element {node.runtime_id!r} belongs to a different library instance '
1103
+ f'(runtime {owner}, this import drives runtime {self.runtime.instance_id}). '
1104
+ f'Resolve it through the import that produced it, or use a selector instead.'
1105
+ )
1106
+
809
1107
  def _create_runtime(self) -> Runtime:
810
1108
  """Create and return the PlatynUI runtime instance.
811
1109
 
@@ -852,10 +1150,12 @@ class BareMetal(OurDynamicCore):
852
1150
 
853
1151
  This is the default context for queries when no root is specified.
854
1152
  """
855
- if PLATYNUI_ROOT_DESCRIPTOR in EXECUTION_CONTEXTS.current.variables: # pyright: ignore[reportOptionalMemberAccess]
856
- r = EXECUTION_CONTEXTS.current.variables[f'${{{PLATYNUI_ROOT_DESCRIPTOR}}}'] # pyright: ignore[reportOptionalMemberAccess]
857
- if isinstance(r, UiNodeDescriptor):
858
- return r(True)
1153
+ ctx = EXECUTION_CONTEXTS.current
1154
+ if ctx is None:
1155
+ return None
1156
+ r = self._scoped_value(ctx.variables.current, self._root_variable_name())
1157
+ if isinstance(r, UiNodeDescriptor):
1158
+ return r.resolve(self, as_root=True)
859
1159
 
860
1160
  return None
861
1161
 
@@ -866,19 +1166,20 @@ class BareMetal(OurDynamicCore):
866
1166
 
867
1167
  `Set Query Settings` stores a full `QuerySettings` instance in ``${PLATYNUI_QUERY_SETTINGS}``
868
1168
  at the chosen scope, so Robot Framework's own nearest-scope-wins resolution provides the
869
- precedence (LOCAL over TEST over SUITE) and clears each scope when it ends. This is the base
870
- the wait loop uses; a descriptor's per-call ``overrides`` are applied on top.
1169
+ precedence (LOCAL over TEST over SUITE/SUITES over GLOBAL) and clears each scope when it
1170
+ ends. This is the base the wait loop uses; a descriptor's per-call ``overrides`` are applied
1171
+ on top.
871
1172
  """
872
1173
  ctx = EXECUTION_CONTEXTS.current
873
- if ctx is not None and PLATYNUI_QUERY_SETTINGS in ctx.variables:
874
- settings = ctx.variables[f'${{{PLATYNUI_QUERY_SETTINGS}}}']
1174
+ if ctx is not None:
1175
+ settings = self._scoped_value(ctx.variables.current, self._query_settings_variable_name())
875
1176
  if isinstance(settings, QuerySettings):
876
1177
  return settings
877
1178
  return self._default_query_settings
878
1179
 
879
1180
  @keyword
880
1181
  def set_root(
881
- self, descriptor: UiNodeDescriptor | None, scope: Literal['LOCAL', 'TEST', 'SUITE'] = 'LOCAL'
1182
+ self, descriptor: UiNodeDescriptor | None, scope: Scope = 'LOCAL'
882
1183
  ) -> UiNodeDescriptor | None:
883
1184
  """Set the default root that subsequent *relative* selectors resolve against.
884
1185
 
@@ -888,11 +1189,19 @@ class BareMetal(OurDynamicCore):
888
1189
  desktop. See `Scoping queries to a container` for the full picture, including scope.
889
1190
 
890
1191
  Args:
891
- descriptor: The new root — a selector string, a ``UiNode`` or descriptor (e.g. one
892
- returned by another query), or a root previously returned by this keyword (restored
893
- unchanged). Pass ``${None}`` to reset to the desktop.
894
- scope: Lifetime of the root: ``LOCAL`` (default, current test/keyword only), ``TEST``
895
- (whole test, including called keywords) or ``SUITE`` (every test in the suite).
1192
+ descriptor: The new root — a selector string, an element (e.g. one returned by a
1193
+ query), or a root previously returned by this keyword (restored unchanged). Pass
1194
+ ``${None}`` to reset to the desktop. A selector re-resolves against the live tree,
1195
+ so it survives the window closing and reopening; an element pins that one element
1196
+ and must come from this same library import — as must a restored root that pins
1197
+ one, which is rejected here rather than on the next lookup.
1198
+ scope: Lifetime of the root — the same names Robot Framework's `VAR` syntax uses:
1199
+ ``LOCAL`` (default, current test/keyword only), ``TEST`` (or ``TASK``: the whole
1200
+ test, including called keywords), ``SUITE`` (every test in the suite, not the
1201
+ suites below), ``SUITES`` (the suite *and* the suites below it) or ``GLOBAL``
1202
+ (everywhere). ``SUITES`` and ``GLOBAL`` reach suites that build their own runtime,
1203
+ so only a selector may be set there — an element cannot be re-found in another
1204
+ runtime and is rejected.
896
1205
 
897
1206
  Returns:
898
1207
  UiNodeDescriptor | None: The root set at the same ``scope`` before this call (``None`` if
@@ -900,30 +1209,23 @@ class BareMetal(OurDynamicCore):
900
1209
 
901
1210
  Examples:
902
1211
  | `Set Root` /app:Application[@Name="Editor"] scope=SUITE # whole suite runs in the Editor
1212
+ | `Set Root` /app:Application[@Name="Editor"] scope=SUITES # …and every suite below
903
1213
  | `Set Root` .//Dialog[@Name="Save"] # drill into the Save dialog
904
1214
  | `Pointer Click` .//Button[@Name="OK"] # acts relative to the dialog
905
1215
  | `Set Root` ${None} # reset to the desktop
906
1216
  """
907
1217
  variables = EXECUTION_CONTEXTS.current.variables # pyright: ignore[reportOptionalMemberAccess]
908
- name = f'${{{PLATYNUI_ROOT_DESCRIPTOR}}}'
909
-
910
- # Set the scope variables directly rather than via BuiltIn(), which would log in the wrong
911
- # step context and run the selector through Robot's variable-syntax resolution.
912
- suite_vars = getattr(variables, '_suite', None) # pyright: ignore[reportUnknownArgumentType]
913
- test_vars = getattr(variables, '_test', None) # pyright: ignore[reportUnknownArgumentType]
914
- if scope == 'LOCAL':
915
- scope_store = variables.current
916
- elif scope == 'TEST':
917
- scope_store = test_vars if test_vars is not None else suite_vars
918
- else: # 'SUITE'
919
- scope_store = suite_vars
920
- if scope_store is None: # only if Robot has no suite scope yet (not during keyword execution)
921
- scope_store = variables.current
1218
+ name = self._root_variable_name()
1219
+ scope_store = self._scope_store(variables, scope)
922
1220
 
923
1221
  # old_root is read from the requested scope (so a same-scope restore is exact); effective_root
924
1222
  # is the currently visible root that relative drilling resolves against.
925
- old_root: UiNodeDescriptor | None = scope_store.get(name)
926
- effective_root = variables.current.get(name)
1223
+ old = scope_store.get(name, default=None)
1224
+ old_root: UiNodeDescriptor | None = old if isinstance(old, UiNodeDescriptor) else None
1225
+ current_root = self._scoped_value(variables.current, name)
1226
+ effective_root: UiNodeDescriptor | None = (
1227
+ current_root if isinstance(current_root, UiNodeDescriptor) else None
1228
+ )
927
1229
 
928
1230
  if descriptor is None:
929
1231
  new_root: UiNodeDescriptor | None = None
@@ -937,18 +1239,30 @@ class BareMetal(OurDynamicCore):
937
1239
  context_dependent = query is not None and self.runtime.is_context_dependent(query)
938
1240
  except EvaluationError as e:
939
1241
  raise InvalidSelectorError(f'Invalid selector for Set Root: {query!r} ({e})') from e
940
- parent = effective_root if context_dependent and isinstance(effective_root, UiNodeDescriptor) else None
941
- # A query binding must re-resolve against its captured parent, so never copy the shared
942
- # descriptor's cached node into it; keep a concrete node only when there is no query.
1242
+ parent = effective_root if context_dependent else None
1243
+ # A selector root re-resolves against its captured parent; only a capture carries a node.
943
1244
  node = descriptor.node if descriptor.query is None else None
944
- new_root = UiNodeDescriptor(node, descriptor.query, self, parent=parent, is_root_binding=True)
1245
+ new_root = UiNodeDescriptor(node, descriptor.query, parent=parent, is_root_binding=True)
1246
+
1247
+ # Both checks below concern a root that pins an element — a handle into one runtime — and
1248
+ # both run on the chain, for every form the argument can take: a fresh capture, a restored
1249
+ # root binding, or a selector root drilling into either.
1250
+ pinned = self._pinned_element(new_root) if new_root is not None else None
1251
+ if pinned is not None:
1252
+ # Ours to begin with? Storing another import's element would fail on every read.
1253
+ self.require_own_node(pinned)
1254
+ # And the scopes below hand the root to suites that build their own instance — and with
1255
+ # it their own runtime. Refuse where the choice is made, rather than leaving a root that
1256
+ # fails on read in suites that never set it.
1257
+ if scope in _CROSS_SUITE_SCOPES:
1258
+ raise UnsharableRootError(
1259
+ f'Cannot set a root that pins an element at scope={scope}: the element belongs '
1260
+ f'to runtime {pinned.owner_id}, while every suite below builds its own runtime '
1261
+ f'and cannot find it again. Pass a selector instead, which each suite '
1262
+ f're-resolves for itself.'
1263
+ )
945
1264
 
946
- if scope == 'LOCAL':
947
- variables.set_local(name, new_root)
948
- elif scope == 'TEST':
949
- variables.set_test(name, new_root)
950
- else: # 'SUITE'
951
- variables.set_suite(name, new_root)
1265
+ self._write_scoped(variables, scope, name, new_root)
952
1266
 
953
1267
  return old_root
954
1268
 
@@ -956,7 +1270,7 @@ class BareMetal(OurDynamicCore):
956
1270
  def set_query_settings(
957
1271
  self,
958
1272
  overrides: QuerySettingsDict | QuerySettings | None = None,
959
- scope: Literal['LOCAL', 'TEST', 'SUITE'] = 'LOCAL',
1273
+ scope: Scope = 'LOCAL',
960
1274
  ) -> QuerySettings | None:
961
1275
  """Set the query wait/retry settings for the given Robot Framework scope.
962
1276
 
@@ -965,20 +1279,22 @@ class BareMetal(OurDynamicCore):
965
1279
  pause between attempts) and ``ignore_exceptions`` (swallow evaluation errors instead of
966
1280
  failing). Name only the fields you want to change — they are applied over the settings already
967
1281
  in effect at that scope, so the rest are inherited. The result lives as long as its variable
968
- ``scope`` and clears itself when that scope ends, exactly like `Set Root` — no teardown to
969
- remember.
1282
+ ``scope``, exactly like `Set Root`: every scope but ``GLOBAL`` clears itself when it ends, so
1283
+ there is no teardown to remember.
970
1284
 
971
1285
  Like a root, scopes nest: a value set at ``LOCAL`` shadows one at ``TEST`` shadows one at
972
- ``SUITE`` shadows the library-import defaults. Settings set this way apply to *every* lookup,
973
- including the re-resolution of a `Set Root` root; a per-keyword ``query_overrides`` only tunes
974
- that one keyword's own target.
1286
+ ``SUITE``/``SUITES`` shadows one at ``GLOBAL`` shadows the library-import defaults. Settings
1287
+ set this way apply to *every* lookup, including the re-resolution of a `Set Root` root; a
1288
+ per-keyword ``query_overrides`` only tunes that one keyword's own target.
975
1289
 
976
1290
  Args:
977
1291
  overrides: The fields to change, as a dict (e.g. ``{'timeout': 60}``), or a value returned
978
1292
  by this keyword to restore it exactly. Pass ``${None}`` to drop this scope's settings
979
1293
  and fall back to the enclosing scope (the analog of ``Set Root ${None}``).
980
- scope: Lifetime of the settings: ``LOCAL`` (default, current test/keyword only), ``TEST``
981
- (whole test, including called keywords) or ``SUITE`` (every test in the suite).
1294
+ scope: Lifetime of the settings — the same names as `Set Root` and Robot Framework's
1295
+ `VAR` syntax: ``LOCAL`` (default), ``TEST``/``TASK``, ``SUITE``, ``SUITES`` (the
1296
+ suite and the suites below it) or ``GLOBAL``. Settings are plain data, so every
1297
+ scope is available here.
982
1298
 
983
1299
  Returns:
984
1300
  QuerySettings | None: The settings set at the same ``scope`` before this call (``None`` if
@@ -991,23 +1307,10 @@ class BareMetal(OurDynamicCore):
991
1307
  | `Set Query Settings` ${None} # drop this scope's settings
992
1308
  """
993
1309
  variables = EXECUTION_CONTEXTS.current.variables # pyright: ignore[reportOptionalMemberAccess]
994
- name = f'${{{PLATYNUI_QUERY_SETTINGS}}}'
995
-
996
- # Read the previous value from the requested scope (so a same-scope restore is exact), mirroring
997
- # the scope selection in set_root. Setting the scope variables directly avoids BuiltIn() logging
998
- # in the wrong step context.
999
- suite_vars = getattr(variables, '_suite', None) # pyright: ignore[reportUnknownArgumentType]
1000
- test_vars = getattr(variables, '_test', None) # pyright: ignore[reportUnknownArgumentType]
1001
- if scope == 'LOCAL':
1002
- scope_store = variables.current
1003
- elif scope == 'TEST':
1004
- scope_store = test_vars if test_vars is not None else suite_vars
1005
- else: # 'SUITE'
1006
- scope_store = suite_vars
1007
- if scope_store is None: # only if Robot has no suite scope yet (not during keyword execution)
1008
- scope_store = variables.current
1009
-
1010
- old: QuerySettings | None = scope_store.get(name)
1310
+ name = self._query_settings_variable_name()
1311
+ scope_store = self._scope_store(variables, scope)
1312
+
1313
+ old = scope_store.get(name, default=None)
1011
1314
  old = old if isinstance(old, QuerySettings) else None
1012
1315
 
1013
1316
  new: QuerySettings | None
@@ -1027,12 +1330,8 @@ class BareMetal(OurDynamicCore):
1027
1330
  base = old if old is not None else self._default_query_settings
1028
1331
  new = replace(base, **overrides) # partial dict -> full instance
1029
1332
 
1030
- if scope == 'LOCAL':
1031
- variables.set_local(name, new)
1032
- elif scope == 'TEST':
1033
- variables.set_test(name, new)
1034
- else: # 'SUITE'
1035
- variables.set_suite(name, new)
1333
+ # Settings are pure data — every instance can apply them, so no scope is off limits here.
1334
+ self._write_scoped(variables, scope, name, new)
1036
1335
 
1037
1336
  return old
1038
1337
 
@@ -1061,6 +1360,8 @@ class BareMetal(OurDynamicCore):
1061
1360
 
1062
1361
  if root is None:
1063
1362
  root = self.root
1363
+ else:
1364
+ self.require_own_node(root)
1064
1365
 
1065
1366
  self.runtime.clear_cache()
1066
1367
  return self.runtime.evaluate_single(expression, root) if only_first else self.runtime.evaluate(expression, root)
@@ -1094,10 +1395,9 @@ class BareMetal(OurDynamicCore):
1094
1395
  | ${dialog}= `Wait Until Exists` Window[@Name="Save As"]
1095
1396
  | `Wait Until Exists` //control:ProgressBar[@Name="Importing"] query_overrides={'timeout': 60}
1096
1397
  """
1097
- descriptor.overrides = query_overrides
1098
1398
  settings = replace(self.query_settings, **query_overrides) if query_overrides else self.query_settings
1099
1399
  try:
1100
- return descriptor()
1400
+ return descriptor.resolve(self, query_overrides)
1101
1401
  except ElementNotFoundError:
1102
1402
  raise ElementNotFoundError(
1103
1403
  f'No element matched {descriptor.query!r} within timeout of {settings.timeout} seconds.'
@@ -1115,6 +1415,11 @@ class BareMetal(OurDynamicCore):
1115
1415
  re-evaluated on every attempt — or a *captured element* from `Query` to wait until it
1116
1416
  becomes invalid.
1117
1417
 
1418
+ The difference matters when something equivalent takes the target's place: a selector then
1419
+ matches the replacement and keeps waiting, while a captured element reports itself gone
1420
+ because the element *it* named is no longer there. Pick the one that expresses what you
1421
+ mean.
1422
+
1118
1423
  Whether a captured element ever reports itself gone depends on the accessibility
1119
1424
  provider's liveness check. For a *value* condition — a count dropping to zero, say — use
1120
1425
  `Wait Until Query`; a value-producing selector (``count(...)``) is rejected here rather
@@ -1123,7 +1428,8 @@ class BareMetal(OurDynamicCore):
1123
1428
 
1124
1429
  Args:
1125
1430
  descriptor: The target whose disappearance to wait for — a selector or an element
1126
- from `Query`.
1431
+ from `Query`. An element must come from this same library import; one from
1432
+ another import is rejected rather than reported gone.
1127
1433
  query_overrides: Per-call query settings, e.g. ``{'timeout': 10}``.
1128
1434
 
1129
1435
  Examples:
@@ -1134,15 +1440,20 @@ class BareMetal(OurDynamicCore):
1134
1440
  """
1135
1441
  settings = replace(self.query_settings, **query_overrides) if query_overrides else self.query_settings
1136
1442
  query = descriptor.query
1443
+ if query is None and isinstance(descriptor.node, UiNode):
1444
+ # A capture belongs to the runtime that produced it; one from another import can
1445
+ # neither be polled here nor be honestly called gone.
1446
+ self.require_own_node(descriptor.node)
1137
1447
  start = time.monotonic()
1138
1448
  while True:
1139
1449
  gone = False
1140
1450
  try:
1141
1451
  if query is not None:
1142
- # Selector: re-evaluate fresh every attempt; never trust descriptor.node
1143
- # (it may be a node cached on the shared descriptor by a prior keyword).
1452
+ # A selector is re-evaluated every attempt — it never carries a resolved
1453
+ # element between calls, so there is nothing stale to distrust.
1144
1454
  self.runtime.clear_cache()
1145
- result = self.runtime.evaluate_single(query, self.root)
1455
+ root = self.root if descriptor.needs_root(self) else None
1456
+ result = self.runtime.evaluate_single(query, root)
1146
1457
  if result is not None and not isinstance(result, UiNode):
1147
1458
  raise ResultTypeError(
1148
1459
  f'Wait Until Gone expects an element selector or a captured element; query '
@@ -1162,9 +1473,9 @@ class BareMetal(OurDynamicCore):
1162
1473
  raise # usage error — surface immediately, regardless of ignore_exceptions
1163
1474
  except (SystemExit, KeyboardInterrupt):
1164
1475
  raise
1165
- except Exception as e:
1476
+ except Exception:
1166
1477
  if not settings.ignore_exceptions:
1167
- raise e
1478
+ raise
1168
1479
  gone = False # swallowed error => cannot confirm gone => keep waiting
1169
1480
 
1170
1481
  if gone:
@@ -1263,9 +1574,9 @@ class BareMetal(OurDynamicCore):
1263
1574
  raise # unknown operator — a programming error, surface immediately
1264
1575
  except (AssertionError, TypeError):
1265
1576
  satisfied = False # mismatch, or not-yet-comparable early value — keep polling
1266
- except Exception as e:
1577
+ except Exception:
1267
1578
  if not settings.ignore_exceptions:
1268
- raise e
1579
+ raise
1269
1580
  satisfied = False
1270
1581
 
1271
1582
  if satisfied:
@@ -1294,46 +1605,46 @@ class BareMetal(OurDynamicCore):
1294
1605
  # Internal helpers
1295
1606
  def _maybe_bring_to_front(
1296
1607
  self,
1297
- descriptor: 'UiNodeDescriptor | None',
1608
+ node: UiNode | None,
1298
1609
  activate: bool | None,
1299
1610
  ) -> None:
1300
1611
  """Bring the target element's window to the foreground if activation is enabled.
1301
1612
 
1302
1613
  Args:
1303
- descriptor: Optional element descriptor. If None, no action is taken.
1614
+ node: Optional resolved element. If None, no action is taken.
1304
1615
  activate: Override for auto_activate. If None, the library-level
1305
1616
  ``auto_activate`` setting is used.
1306
1617
  """
1307
- if descriptor is None:
1618
+ if node is None:
1308
1619
  return
1309
1620
  should_activate = activate if activate is not None else self.auto_activate
1310
1621
  if should_activate:
1311
1622
  try:
1312
- self.runtime.bring_to_front(descriptor())
1623
+ self.runtime.bring_to_front(node)
1313
1624
  except BareMetalError:
1314
1625
  raise # Critical error from the library/runtime; propagate it
1315
1626
  except (KeyboardInterrupt, SystemExit):
1316
1627
  raise # Don't interfere with user-initiated interrupts
1317
- except Exception:
1318
- pass # Best-effort; don't block the pointer action
1628
+ except Exception: # noqa: BLE001, S110 (best-effort; don't block the pointer action)
1629
+ pass
1319
1630
 
1320
1631
  def _resolve_screen_point(
1321
1632
  self,
1322
- descriptor: 'UiNodeDescriptor | None',
1633
+ target_node: UiNode | None,
1323
1634
  x: float | None,
1324
1635
  y: float | None,
1325
1636
  ) -> Point | None:
1326
- """Resolve absolute screen coordinates from optional descriptor and x/y values.
1637
+ """Resolve absolute screen coordinates from an optional element and x/y values.
1327
1638
 
1328
1639
  Behavior:
1329
1640
  - If only one of x or y is provided, raises ValueError.
1330
- - If a descriptor is provided and x/y are None: uses ActivationPoint when available,
1641
+ - If an element is provided and x/y are None: uses ActivationPoint when available,
1331
1642
  otherwise the center of Bounds.
1332
- - If a descriptor is provided and x/y are given: treats (x, y) as offsets relative
1643
+ - If an element is provided and x/y are given: treats (x, y) as offsets relative
1333
1644
  to the element's top-left Bounds origin.
1334
- - If no descriptor is provided and x/y are given: treats (x, y) as absolute screen
1645
+ - If no element is provided and x/y are given: treats (x, y) as absolute screen
1335
1646
  coordinates.
1336
- - If neither descriptor nor x/y are provided: returns None. Callers decide whether a
1647
+ - If neither element nor x/y are provided: returns None. Callers decide whether a
1337
1648
  missing point is an error (pointer_move_to raises) or means "current pointer
1338
1649
  position" (pointer_click/press/release pass None through to the runtime).
1339
1650
 
@@ -1343,8 +1654,7 @@ class BareMetal(OurDynamicCore):
1343
1654
  if (x is not None) != (y is not None):
1344
1655
  raise ValueError('Both x and y coordinates must be provided together')
1345
1656
 
1346
- if descriptor is not None:
1347
- target_node = descriptor()
1657
+ if target_node is not None:
1348
1658
 
1349
1659
  # No coordinates provided: auto-resolve from node
1350
1660
  if x is None and y is None:
@@ -1364,7 +1674,7 @@ class BareMetal(OurDynamicCore):
1364
1674
  except AttributeNotFoundError:
1365
1675
  bounds = None
1366
1676
  if not isinstance(bounds, Rect):
1367
- raise ValueError('Node has neither an ActivationPoint nor Bounds to target')
1677
+ raise TypeError('Node has neither an ActivationPoint nor Bounds to target')
1368
1678
 
1369
1679
  center = bounds.center()
1370
1680
  x = center.x
@@ -1422,10 +1732,9 @@ class BareMetal(OurDynamicCore):
1422
1732
  | `Pointer Click` x=${100} y=${200}
1423
1733
  | `Pointer Click` Window[@Name="Settings"]//Button[@Name="OK"] activate=${False}
1424
1734
  """
1425
- if descriptor is not None:
1426
- descriptor.overrides = query_overrides
1427
- self._maybe_bring_to_front(descriptor, activate)
1428
- point = self._resolve_screen_point(descriptor, x, y)
1735
+ node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
1736
+ self._maybe_bring_to_front(node, activate)
1737
+ point = self._resolve_screen_point(node, x, y)
1429
1738
  self.runtime.pointer_click(point, button, overrides)
1430
1739
 
1431
1740
  @keyword
@@ -1458,10 +1767,9 @@ class BareMetal(OurDynamicCore):
1458
1767
  | `Pointer Multi Click` x=${100} y=${200}
1459
1768
  | `Pointer Multi Click` Window[@Name="Files"]//Text[@Name="File"] clicks=${3}
1460
1769
  """
1461
- if descriptor is not None:
1462
- descriptor.overrides = query_overrides
1463
- self._maybe_bring_to_front(descriptor, activate)
1464
- point = self._resolve_screen_point(descriptor, x, y)
1770
+ node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
1771
+ self._maybe_bring_to_front(node, activate)
1772
+ point = self._resolve_screen_point(node, x, y)
1465
1773
  self.runtime.pointer_multi_click(point, clicks, button, overrides)
1466
1774
 
1467
1775
  @keyword
@@ -1490,10 +1798,9 @@ class BareMetal(OurDynamicCore):
1490
1798
  Examples:
1491
1799
  | `Pointer Press` Window[@Name="Mixer"]//Slider x=${10} y=${5}
1492
1800
  """
1493
- if descriptor is not None:
1494
- descriptor.overrides = query_overrides
1495
- self._maybe_bring_to_front(descriptor, activate)
1496
- point = self._resolve_screen_point(descriptor, x, y)
1801
+ node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
1802
+ self._maybe_bring_to_front(node, activate)
1803
+ point = self._resolve_screen_point(node, x, y)
1497
1804
  self.runtime.pointer_press(point, button, overrides)
1498
1805
 
1499
1806
  @keyword
@@ -1526,10 +1833,9 @@ class BareMetal(OurDynamicCore):
1526
1833
  | `Pointer Release`
1527
1834
  | `Pointer Release` Window[@Name="Editor"]//Canvas x=${50} y=${50}
1528
1835
  """
1529
- if descriptor is not None:
1530
- descriptor.overrides = query_overrides
1531
- self._maybe_bring_to_front(descriptor, activate)
1532
- point = self._resolve_screen_point(descriptor, x, y)
1836
+ node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
1837
+ self._maybe_bring_to_front(node, activate)
1838
+ point = self._resolve_screen_point(node, x, y)
1533
1839
  self.runtime.pointer_release(point, button, overrides)
1534
1840
 
1535
1841
  @keyword
@@ -1557,10 +1863,9 @@ class BareMetal(OurDynamicCore):
1557
1863
  | `Pointer Move To` x=${400} y=${300}
1558
1864
  | `Pointer Move To` Window[@Name="Settings"]//Button[@Name="OK"]
1559
1865
  """
1560
- if descriptor is not None:
1561
- descriptor.overrides = query_overrides
1562
- self._maybe_bring_to_front(descriptor, activate)
1563
- point = self._resolve_screen_point(descriptor, x, y)
1866
+ node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
1867
+ self._maybe_bring_to_front(node, activate)
1868
+ point = self._resolve_screen_point(node, x, y)
1564
1869
  if point is None:
1565
1870
  raise ValueError('Coordinates x and y must be specified either directly or via node')
1566
1871
 
@@ -1607,10 +1912,9 @@ class BareMetal(OurDynamicCore):
1607
1912
  | `Pointer Scroll` ${None} direction=RIGHT ticks=${2} # at the current position
1608
1913
  | `Pointer Scroll` x=${400} y=${300} direction=UP
1609
1914
  """
1610
- if descriptor is not None:
1611
- descriptor.overrides = query_overrides
1612
- self._maybe_bring_to_front(descriptor, activate)
1613
- point = self._resolve_screen_point(descriptor, x, y)
1915
+ node = descriptor.resolve(self, query_overrides) if descriptor is not None else None
1916
+ self._maybe_bring_to_front(node, activate)
1917
+ point = self._resolve_screen_point(node, x, y)
1614
1918
  if point is not None:
1615
1919
  self.runtime.pointer_move_to(point, overrides)
1616
1920
  self.runtime.pointer_scroll(_scroll_delta(direction, ticks), overrides)
@@ -1630,16 +1934,23 @@ class BareMetal(OurDynamicCore):
1630
1934
 
1631
1935
  @keyword
1632
1936
  def get_element_at_point(self, x: float, y: float) -> Any:
1633
- """Resolve the deepest UI element at the given screen coordinates.
1937
+ """Get the element that is under a point on the screen.
1634
1938
 
1635
- Uses the platform hit-test: UI Automation ``ElementFromPoint`` on Windows;
1636
- window-manager window selection plus AT-SPI descent on Linux. Returns the
1637
- resolved ``UiNode``, or ``None`` when nothing is at the point. Raises if the
1638
- active platform cannot hit-test (e.g. a generic Wayland session).
1939
+ Returns the element under the given screen coordinates — the widget itself, not a
1940
+ surrounding container — or ``${None}`` when nothing is there. The keyword does not
1941
+ wait.
1639
1942
 
1640
1943
  Args:
1641
1944
  x: Screen X coordinate.
1642
1945
  y: Screen Y coordinate.
1946
+
1947
+ Returns:
1948
+ UiNode: The element at the point, or ``${None}`` if there is none.
1949
+
1950
+ Examples:
1951
+ | ${el}= `Get Element At Point` ${400} ${300}
1952
+ | ${pos}= `Get Pointer Position`
1953
+ | ${el}= `Get Element At Point` ${pos.x} ${pos.y}
1643
1954
  """
1644
1955
  return self.runtime.element_at_point(float(x), float(y))
1645
1956
 
@@ -1666,9 +1977,9 @@ class BareMetal(OurDynamicCore):
1666
1977
  Examples:
1667
1978
  | `Focus` Window[@Name="Browser"]//Edit[@Name="Search"]
1668
1979
  """
1669
- descriptor.overrides = query_overrides
1670
- self._maybe_bring_to_front(descriptor, activate)
1671
- self.runtime.focus(descriptor())
1980
+ node = descriptor.resolve(self, query_overrides)
1981
+ self._maybe_bring_to_front(node, activate)
1982
+ self.runtime.focus(node)
1672
1983
 
1673
1984
  @keyword
1674
1985
  def restore_window(self, descriptor: UiNodeDescriptor, *, query_overrides: QuerySettingsDict | None = None) -> None:
@@ -1684,8 +1995,7 @@ class BareMetal(OurDynamicCore):
1684
1995
  Examples:
1685
1996
  | `Restore Window` Window[@Name="Settings"]
1686
1997
  """
1687
- descriptor.overrides = query_overrides
1688
- node = descriptor()
1998
+ node = descriptor.resolve(self, query_overrides)
1689
1999
  node.get_pattern(Restorable).restore()
1690
2000
 
1691
2001
  @keyword
@@ -1703,8 +2013,7 @@ class BareMetal(OurDynamicCore):
1703
2013
  Examples:
1704
2014
  | `Maximize Window` Window[@Name="Editor"]
1705
2015
  """
1706
- descriptor.overrides = query_overrides
1707
- node = descriptor()
2016
+ node = descriptor.resolve(self, query_overrides)
1708
2017
  node.get_pattern(Maximizable).maximize()
1709
2018
 
1710
2019
  @keyword
@@ -1722,8 +2031,7 @@ class BareMetal(OurDynamicCore):
1722
2031
  Examples:
1723
2032
  | `Minimize Window` Window[@Name="Editor"]
1724
2033
  """
1725
- descriptor.overrides = query_overrides
1726
- node = descriptor()
2034
+ node = descriptor.resolve(self, query_overrides)
1727
2035
  node.get_pattern(Minimizable).minimize()
1728
2036
 
1729
2037
  @keyword
@@ -1739,8 +2047,7 @@ class BareMetal(OurDynamicCore):
1739
2047
  Examples:
1740
2048
  | `Close Window` Window[@Name="Editor"]
1741
2049
  """
1742
- descriptor.overrides = query_overrides
1743
- node = descriptor()
2050
+ node = descriptor.resolve(self, query_overrides)
1744
2051
  node.get_pattern(Closeable).close()
1745
2052
 
1746
2053
  @keyword
@@ -1758,8 +2065,7 @@ class BareMetal(OurDynamicCore):
1758
2065
  Examples:
1759
2066
  | `Activate Window` Window[@Name="Editor"]
1760
2067
  """
1761
- descriptor.overrides = query_overrides
1762
- node = descriptor()
2068
+ node = descriptor.resolve(self, query_overrides)
1763
2069
  node.get_pattern(Activatable).activate()
1764
2070
 
1765
2071
  @keyword
@@ -1779,8 +2085,7 @@ class BareMetal(OurDynamicCore):
1779
2085
  Examples:
1780
2086
  | `Move Window` Window[@Name="Editor"] 100 200
1781
2087
  """
1782
- descriptor.overrides = query_overrides
1783
- node = descriptor()
2088
+ node = descriptor.resolve(self, query_overrides)
1784
2089
  node.get_pattern(Movable).move_to(x, y)
1785
2090
 
1786
2091
  @keyword
@@ -1805,8 +2110,7 @@ class BareMetal(OurDynamicCore):
1805
2110
  Examples:
1806
2111
  | `Resize Window` Window[@Name="Editor"] 800 600
1807
2112
  """
1808
- descriptor.overrides = query_overrides
1809
- node = descriptor()
2113
+ node = descriptor.resolve(self, query_overrides)
1810
2114
  node.get_pattern(Resizable).resize(width, height)
1811
2115
 
1812
2116
  @keyword
@@ -1835,8 +2139,7 @@ class BareMetal(OurDynamicCore):
1835
2139
  Examples:
1836
2140
  | `Move And Resize Window` Window[@Name="Editor"] 100 200 800 600
1837
2141
  """
1838
- descriptor.overrides = query_overrides
1839
- node = descriptor()
2142
+ node = descriptor.resolve(self, query_overrides)
1840
2143
  node.get_pattern(Movable).move_to(x, y)
1841
2144
  node.get_pattern(Resizable).resize(width, height)
1842
2145
 
@@ -1855,8 +2158,7 @@ class BareMetal(OurDynamicCore):
1855
2158
  Examples:
1856
2159
  | `Bring To Front` Window[@Name="Editor"]
1857
2160
  """
1858
- descriptor.overrides = query_overrides
1859
- node = descriptor()
2161
+ node = descriptor.resolve(self, query_overrides)
1860
2162
  self.runtime.bring_to_front(node)
1861
2163
 
1862
2164
  @keyword
@@ -1884,8 +2186,7 @@ class BareMetal(OurDynamicCore):
1884
2186
  namespace: str | None = None
1885
2187
  if ':' in attribute_name:
1886
2188
  namespace, attribute_name = attribute_name.split(':', 1)
1887
- descriptor.overrides = query_overrides
1888
- node = descriptor()
2189
+ node = descriptor.resolve(self, query_overrides)
1889
2190
  return node.attribute(attribute_name, namespace)
1890
2191
 
1891
2192
  @keyword
@@ -1925,9 +2226,8 @@ class BareMetal(OurDynamicCore):
1925
2226
  - To omit the descriptor (no focus change), pass ``${None}`` as the first argument in Robot Framework.
1926
2227
  """
1927
2228
  if descriptor is not None:
1928
- descriptor.overrides = query_overrides
1929
- self._maybe_bring_to_front(descriptor, activate)
1930
- target_node = descriptor()
2229
+ target_node = descriptor.resolve(self, query_overrides)
2230
+ self._maybe_bring_to_front(target_node, activate)
1931
2231
  self.runtime.focus(target_node)
1932
2232
  self.runtime.keyboard_type(text, overrides=overrides)
1933
2233
 
@@ -1959,9 +2259,8 @@ class BareMetal(OurDynamicCore):
1959
2259
  | `Keyboard Release` ${None} <Ctrl>
1960
2260
  """
1961
2261
  if descriptor is not None:
1962
- descriptor.overrides = query_overrides
1963
- self._maybe_bring_to_front(descriptor, activate)
1964
- target_node = descriptor()
2262
+ target_node = descriptor.resolve(self, query_overrides)
2263
+ self._maybe_bring_to_front(target_node, activate)
1965
2264
  self.runtime.focus(target_node)
1966
2265
  self.runtime.keyboard_press(text, overrides=overrides)
1967
2266
 
@@ -1993,9 +2292,8 @@ class BareMetal(OurDynamicCore):
1993
2292
  | `Keyboard Release` ${None} <Ctrl+Alt>
1994
2293
  """
1995
2294
  if descriptor is not None:
1996
- descriptor.overrides = query_overrides
1997
- self._maybe_bring_to_front(descriptor, activate)
1998
- target_node = descriptor()
2295
+ target_node = descriptor.resolve(self, query_overrides)
2296
+ self._maybe_bring_to_front(target_node, activate)
1999
2297
  self.runtime.focus(target_node)
2000
2298
  self.runtime.keyboard_release(text, overrides=overrides)
2001
2299
 
@@ -2032,9 +2330,8 @@ class BareMetal(OurDynamicCore):
2032
2330
  | `Take Screenshot` Window[@Name="Settings"] filename=settings_window.png
2033
2331
  """
2034
2332
  if descriptor is not None:
2035
- descriptor.overrides = query_overrides
2036
- self._maybe_bring_to_front(descriptor, activate)
2037
- node = descriptor()
2333
+ node = descriptor.resolve(self, query_overrides)
2334
+ self._maybe_bring_to_front(node, activate)
2038
2335
  node_rect = cast(Rect, node.attribute('Bounds'))
2039
2336
  if rect is not None:
2040
2337
  rect = Rect.from_like(rect)
@@ -2111,12 +2408,12 @@ class BareMetal(OurDynamicCore):
2111
2408
  rects: list[Rect] = []
2112
2409
  if descriptor_list:
2113
2410
  for d in descriptor_list:
2114
- d.overrides = query_overrides
2115
2411
  try:
2116
- self._maybe_bring_to_front(d, activate)
2117
- r = cast(Rect, d().attribute('Bounds'))
2412
+ node = d.resolve(self, query_overrides)
2413
+ self._maybe_bring_to_front(node, activate)
2414
+ r = cast(Rect, node.attribute('Bounds'))
2118
2415
  rects.append(r)
2119
- except Exception:
2416
+ except Exception: # noqa: BLE001 (one unresolvable node must not drop the whole highlight)
2120
2417
  logger.trace(
2121
2418
  f'Could not retrieve bounds for descriptor {d.node!r}, skipping highlight for this node'
2122
2419
  )