robotframework-platynui 0.0.1__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/ButtonKeywords.py +9 -0
- PlatynUI/TextKeywords.py +7 -0
- PlatynUI/__about__.py +4 -0
- PlatynUI/__init__.py +34 -0
- PlatynUI/core/__init__.py +13 -0
- PlatynUI/core/adapter.py +152 -0
- PlatynUI/core/adapterfactory.py +51 -0
- PlatynUI/core/adapterproxy.py +168 -0
- PlatynUI/core/contextbase.py +586 -0
- PlatynUI/core/exceptions.py +77 -0
- PlatynUI/core/internal/__init__.py +0 -0
- PlatynUI/core/internal/decorator.py +148 -0
- PlatynUI/core/locatorbase.py +197 -0
- PlatynUI/core/locatorscope.py +17 -0
- PlatynUI/core/predicate.py +15 -0
- PlatynUI/core/settings.py +63 -0
- PlatynUI/core/strategies/__init__.py +1 -0
- PlatynUI/core/strategies/strategies.py +26 -0
- PlatynUI/core/strategybase.py +8 -0
- PlatynUI/core/strategyimpl.py +102 -0
- PlatynUI/core/technology.py +25 -0
- PlatynUI/core/types.py +421 -0
- PlatynUI/core/wait_for.py +47 -0
- PlatynUI/core/weight_calculator.py +110 -0
- PlatynUI/py.typed +0 -0
- PlatynUI/robot/__init__.py +0 -0
- PlatynUI/robot/reporting.py +74 -0
- PlatynUI/technology/__init__.py +0 -0
- PlatynUI/technology/uiautomation/.gitignore +1 -0
- PlatynUI/technology/uiautomation/__init__.py +4 -0
- PlatynUI/technology/uiautomation/core/adapterfactory.py +88 -0
- PlatynUI/technology/uiautomation/core/displaydevice.py +23 -0
- PlatynUI/technology/uiautomation/core/impls/__init__.py +2 -0
- PlatynUI/technology/uiautomation/core/impls/control.py +31 -0
- PlatynUI/technology/uiautomation/core/impls/window.py +83 -0
- PlatynUI/technology/uiautomation/core/keyboarddevice.py +21 -0
- PlatynUI/technology/uiautomation/core/loader.py +117 -0
- PlatynUI/technology/uiautomation/core/mousedevice.py +29 -0
- PlatynUI/technology/uiautomation/core/technology.py +61 -0
- PlatynUI/technology/uiautomation/core/uiaadapter.py +197 -0
- PlatynUI/technology/uiautomation/core/uiabase.py +19 -0
- PlatynUI/technology/uiautomation/desktop.py +11 -0
- PlatynUI/technology/uiautomation/locator.py +435 -0
- PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Core.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Platform.Core.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Platform.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/Microsoft.Xaml.Behaviors.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.deps.json +266 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.exe +0 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.runtimeconfig.json +19 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/System.ComponentModel.Composition.dll +0 -0
- PlatynUI/technology/uiautomation/spy/__init__.py +0 -0
- PlatynUI/technology/uiautomation/spy/__main__.py +24 -0
- PlatynUI/ui/__init__.py +65 -0
- PlatynUI/ui/application.py +27 -0
- PlatynUI/ui/buttons.py +82 -0
- PlatynUI/ui/combobox.py +149 -0
- PlatynUI/ui/container.py +9 -0
- PlatynUI/ui/control.py +49 -0
- PlatynUI/ui/core/__init__.py +3 -0
- PlatynUI/ui/core/devices/__init__.py +6 -0
- PlatynUI/ui/core/devices/basedisplaydevice.py +25 -0
- PlatynUI/ui/core/devices/basekeyboarddevice.py +64 -0
- PlatynUI/ui/core/devices/basemousedevice.py +30 -0
- PlatynUI/ui/core/devices/basescreendevice.py +16 -0
- PlatynUI/ui/core/devices/displaydevice.py +113 -0
- PlatynUI/ui/core/devices/inputdevice.py +24 -0
- PlatynUI/ui/core/devices/keyboarddevice.py +279 -0
- PlatynUI/ui/core/devices/keyboardproxy.py +69 -0
- PlatynUI/ui/core/devices/mousebutton.py +11 -0
- PlatynUI/ui/core/devices/mousedevice.py +279 -0
- PlatynUI/ui/core/devices/mouseproxy.py +178 -0
- PlatynUI/ui/core/ui_technology.py +31 -0
- PlatynUI/ui/core/window_manager.py +59 -0
- PlatynUI/ui/desktopbase.py +56 -0
- PlatynUI/ui/dialog.py +10 -0
- PlatynUI/ui/edit.py +48 -0
- PlatynUI/ui/element.py +265 -0
- PlatynUI/ui/graphic.py +14 -0
- PlatynUI/ui/header.py +33 -0
- PlatynUI/ui/item.py +100 -0
- PlatynUI/ui/lists.py +37 -0
- PlatynUI/ui/menus.py +42 -0
- PlatynUI/ui/orientation.py +9 -0
- PlatynUI/ui/pane.py +14 -0
- PlatynUI/ui/proxies/__init__.py +4 -0
- PlatynUI/ui/proxies/standardproxies.py +391 -0
- PlatynUI/ui/scrollbar.py +9 -0
- PlatynUI/ui/strategies/__init__.py +19 -0
- PlatynUI/ui/strategies/activatable.py +27 -0
- PlatynUI/ui/strategies/application.py +28 -0
- PlatynUI/ui/strategies/closeable.py +22 -0
- PlatynUI/ui/strategies/control.py +16 -0
- PlatynUI/ui/strategies/editable.py +13 -0
- PlatynUI/ui/strategies/element.py +65 -0
- PlatynUI/ui/strategies/expandable.py +27 -0
- PlatynUI/ui/strategies/hasnativewindowhandle.py +14 -0
- PlatynUI/ui/strategies/hasorientation.py +15 -0
- PlatynUI/ui/strategies/maximizeable.py +27 -0
- PlatynUI/ui/strategies/minimizeable.py +27 -0
- PlatynUI/ui/strategies/movable.py +14 -0
- PlatynUI/ui/strategies/resizable.py +13 -0
- PlatynUI/ui/strategies/restorable.py +13 -0
- PlatynUI/ui/strategies/selectable.py +27 -0
- PlatynUI/ui/strategies/text.py +55 -0
- PlatynUI/ui/strategies/title.py +14 -0
- PlatynUI/ui/strategies/toggleable.py +23 -0
- PlatynUI/ui/strategies/value.py +15 -0
- PlatynUI/ui/table.py +56 -0
- PlatynUI/ui/tabs.py +28 -0
- PlatynUI/ui/text.py +14 -0
- PlatynUI/ui/togglestate.py +12 -0
- PlatynUI/ui/tree.py +99 -0
- PlatynUI/ui/unknown.py +9 -0
- PlatynUI/ui/window.py +177 -0
- robotframework_platynui-0.0.1.dist-info/METADATA +49 -0
- robotframework_platynui-0.0.1.dist-info/RECORD +122 -0
- robotframework_platynui-0.0.1.dist-info/WHEEL +4 -0
- robotframework_platynui-0.0.1.dist-info/entry_points.txt +2 -0
- robotframework_platynui-0.0.1.dist-info/licenses/LICENSE.txt +73 -0
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
import time
|
|
3
|
+
import weakref
|
|
4
|
+
from abc import ABCMeta
|
|
5
|
+
from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Type, TypeVar, Union, overload
|
|
6
|
+
|
|
7
|
+
from typing_extensions import Self
|
|
8
|
+
|
|
9
|
+
from .adapter import Adapter
|
|
10
|
+
from .exceptions import CannotEnsureError, NoLocatorDefinedError, PlatynUiFatalError, PlatyUiError
|
|
11
|
+
from .locatorbase import LocatorBase
|
|
12
|
+
from .locatorscope import LocatorScope
|
|
13
|
+
from .predicate import predicate
|
|
14
|
+
from .settings import Settings
|
|
15
|
+
from .strategies import NativeProperties, Properties
|
|
16
|
+
from .weight_calculator import WeightCalculator
|
|
17
|
+
|
|
18
|
+
__all__ = ["ContextBase", "TContextBase", "context", "UnknownContext", "ContextFactory"]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ContextBase(metaclass=ABCMeta):
|
|
22
|
+
default_role: Optional[str] = None
|
|
23
|
+
default_prefix: Optional[str] = None
|
|
24
|
+
|
|
25
|
+
_locator: Optional[LocatorBase] = None
|
|
26
|
+
__context_parent: Optional["ContextBase"] = None
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
locator: LocatorBase = None,
|
|
31
|
+
context_parent: Optional["ContextBase"] = None,
|
|
32
|
+
adapter: Optional[Adapter] = None,
|
|
33
|
+
) -> None:
|
|
34
|
+
self._context_children: weakref.WeakSet["ContextBase"] = weakref.WeakSet()
|
|
35
|
+
|
|
36
|
+
if locator is not None:
|
|
37
|
+
self._locator = locator.copy_from(self._locator)
|
|
38
|
+
else:
|
|
39
|
+
self._locator = self._locator.copy() if self._locator is not None else None
|
|
40
|
+
|
|
41
|
+
if self._locator is not None:
|
|
42
|
+
self._locator.context = self
|
|
43
|
+
|
|
44
|
+
self.__context_parent = context_parent
|
|
45
|
+
if context_parent is not None and isinstance(context_parent, ContextBase):
|
|
46
|
+
context_parent._context_children.add(self)
|
|
47
|
+
|
|
48
|
+
self._adapter = adapter
|
|
49
|
+
|
|
50
|
+
def __repr__(self) -> str:
|
|
51
|
+
return "%s(locator=%s)" % (self.__class__.__name__, self.locator)
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def locator(self) -> LocatorBase:
|
|
55
|
+
if self._locator is None:
|
|
56
|
+
raise NoLocatorDefinedError(f"no locator defined for {self:r}")
|
|
57
|
+
|
|
58
|
+
return self._locator
|
|
59
|
+
|
|
60
|
+
@locator.setter
|
|
61
|
+
def locator(self, v: LocatorBase) -> None:
|
|
62
|
+
self.invalidate()
|
|
63
|
+
self._locator = v
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def context_parent(self) -> Optional["ContextBase"]:
|
|
67
|
+
return self.__context_parent
|
|
68
|
+
|
|
69
|
+
@context_parent.setter
|
|
70
|
+
def context_parent(self, v: Optional["ContextBase"]) -> None:
|
|
71
|
+
if self.context_parent is not None and isinstance(self.context_parent, ContextBase):
|
|
72
|
+
self.context_parent._context_children.remove(self)
|
|
73
|
+
self.__context_parent = v
|
|
74
|
+
self.invalidate()
|
|
75
|
+
if self.context_parent is not None and isinstance(self.context_parent, ContextBase):
|
|
76
|
+
self.context_parent._context_children.add(self)
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
def adapter(self) -> Adapter:
|
|
80
|
+
self.ensure_that(self._adapter_exists)
|
|
81
|
+
|
|
82
|
+
result = self._try_get_adapter(True)
|
|
83
|
+
|
|
84
|
+
if result is None:
|
|
85
|
+
raise PlatynUiFatalError("adapter is not valid")
|
|
86
|
+
|
|
87
|
+
return result
|
|
88
|
+
|
|
89
|
+
@adapter.setter
|
|
90
|
+
def adapter(self, v: Adapter) -> None:
|
|
91
|
+
self._adapter = v
|
|
92
|
+
|
|
93
|
+
def _try_get_adapter(self, raise_exception: bool = False) -> Optional[Adapter]:
|
|
94
|
+
if self._adapter is not None and not self._adapter.valid:
|
|
95
|
+
self.invalidate()
|
|
96
|
+
if self._adapter is None:
|
|
97
|
+
self._adapter = self._get_adapter(raise_exception)
|
|
98
|
+
return self._adapter
|
|
99
|
+
|
|
100
|
+
def invalidate(self) -> None:
|
|
101
|
+
for c in self._context_children:
|
|
102
|
+
c.invalidate()
|
|
103
|
+
self._adapter = None
|
|
104
|
+
|
|
105
|
+
def _get_adapter(self, raise_exception: bool) -> Optional[Adapter]:
|
|
106
|
+
self.ensure_that(self._parent_exists)
|
|
107
|
+
|
|
108
|
+
if self._locator is not None:
|
|
109
|
+
return self.locator.technology.adapter_factory.get_adapter(
|
|
110
|
+
self.locator, self.context_parent, type(self), raise_exception
|
|
111
|
+
)
|
|
112
|
+
return None
|
|
113
|
+
|
|
114
|
+
def full_repr(self) -> str:
|
|
115
|
+
result = repr(self)
|
|
116
|
+
if self.context_parent is not None:
|
|
117
|
+
return self.context_parent.full_repr() + "." + result
|
|
118
|
+
return result
|
|
119
|
+
|
|
120
|
+
@predicate("{0} exists")
|
|
121
|
+
def _adapter_exists(self, raise_exception: bool = False) -> bool:
|
|
122
|
+
self.ensure_that(self._parent_exists)
|
|
123
|
+
|
|
124
|
+
a = self._try_get_adapter(raise_exception)
|
|
125
|
+
|
|
126
|
+
return a is not None and a.valid
|
|
127
|
+
|
|
128
|
+
@predicate("parent for {0} exists")
|
|
129
|
+
def _parent_exists(self) -> bool:
|
|
130
|
+
if self.context_parent is None:
|
|
131
|
+
return True
|
|
132
|
+
|
|
133
|
+
return self.context_parent._adapter_exists(True)
|
|
134
|
+
|
|
135
|
+
__ensure_that_hooks: List[Callable[["ContextBase"], None]] = []
|
|
136
|
+
|
|
137
|
+
@classmethod
|
|
138
|
+
def add_ensure_hook(cls, hook: Callable[["ContextBase"], None]) -> None:
|
|
139
|
+
cls.__ensure_that_hooks.append(hook)
|
|
140
|
+
|
|
141
|
+
@classmethod
|
|
142
|
+
def __exec_ensure_that_hooks(cls, the_context: "ContextBase") -> None:
|
|
143
|
+
for hook in cls.__ensure_that_hooks:
|
|
144
|
+
hook(the_context)
|
|
145
|
+
|
|
146
|
+
class _ContextBaseLocal(threading.local):
|
|
147
|
+
def __init__(self) -> None:
|
|
148
|
+
self.ensure_that_start_time: Optional[float] = None
|
|
149
|
+
self.ensure_that_raise_exception: Optional[bool] = None
|
|
150
|
+
self.in_ensure_that: int = 0
|
|
151
|
+
self.succeeded_predicates: List[Callable[..., Any]] = []
|
|
152
|
+
self.ensure_timeout: Optional[float] = None
|
|
153
|
+
|
|
154
|
+
__thread_local = _ContextBaseLocal()
|
|
155
|
+
|
|
156
|
+
def ensure_that(
|
|
157
|
+
self,
|
|
158
|
+
*predicates: Optional[Callable[[], bool]],
|
|
159
|
+
timeout: Optional[float] = None,
|
|
160
|
+
raise_exception: Optional[bool] = None,
|
|
161
|
+
) -> bool:
|
|
162
|
+
return ContextBase._ensure_that(
|
|
163
|
+
self, *predicates, timeout=timeout, raise_exception=raise_exception, failed_func=self.invalidate
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
@staticmethod
|
|
167
|
+
def _ensure_that(
|
|
168
|
+
context: "ContextBase",
|
|
169
|
+
*predicates: Optional[Callable[[], bool]],
|
|
170
|
+
timeout: Optional[float] = None,
|
|
171
|
+
raise_exception: Optional[bool] = None,
|
|
172
|
+
failed_func: Optional[Callable[[], None]] = None,
|
|
173
|
+
) -> bool:
|
|
174
|
+
if timeout is None:
|
|
175
|
+
timeout = Settings.current().ensure_timeout
|
|
176
|
+
|
|
177
|
+
ContextBase.__thread_local.in_ensure_that += 1
|
|
178
|
+
try:
|
|
179
|
+
if ContextBase.__thread_local.in_ensure_that == 1:
|
|
180
|
+
ContextBase.__thread_local.succeeded_predicates = []
|
|
181
|
+
ContextBase.__thread_local.ensure_that_raise_exception = raise_exception
|
|
182
|
+
ContextBase.__thread_local.ensure_timeout = timeout
|
|
183
|
+
else:
|
|
184
|
+
raise_exception = ContextBase.__thread_local.ensure_that_raise_exception
|
|
185
|
+
|
|
186
|
+
if raise_exception is None:
|
|
187
|
+
raise_exception = True
|
|
188
|
+
|
|
189
|
+
result = False
|
|
190
|
+
set_start_time = False
|
|
191
|
+
if ContextBase.__thread_local.ensure_that_start_time is None:
|
|
192
|
+
ContextBase.__thread_local.ensure_that_start_time = time.time()
|
|
193
|
+
set_start_time = True
|
|
194
|
+
|
|
195
|
+
last_exception = None
|
|
196
|
+
last_predicate = None
|
|
197
|
+
|
|
198
|
+
try:
|
|
199
|
+
while not result:
|
|
200
|
+
for p in predicates:
|
|
201
|
+
# skip empty predicates
|
|
202
|
+
if p is None:
|
|
203
|
+
continue
|
|
204
|
+
|
|
205
|
+
if not callable(p):
|
|
206
|
+
raise PlatynUiFatalError("%s is not callable " % p)
|
|
207
|
+
|
|
208
|
+
if p in ContextBase.__thread_local.succeeded_predicates:
|
|
209
|
+
result = True
|
|
210
|
+
continue
|
|
211
|
+
|
|
212
|
+
last_predicate = p
|
|
213
|
+
try:
|
|
214
|
+
ContextBase.__exec_ensure_that_hooks(context)
|
|
215
|
+
|
|
216
|
+
result = p()
|
|
217
|
+
|
|
218
|
+
if not result:
|
|
219
|
+
ContextBase.__thread_local.succeeded_predicates.clear()
|
|
220
|
+
break
|
|
221
|
+
|
|
222
|
+
ContextBase.__thread_local.succeeded_predicates.append(p)
|
|
223
|
+
|
|
224
|
+
except (PlatynUiFatalError, KeyboardInterrupt, SystemExit):
|
|
225
|
+
raise
|
|
226
|
+
except BaseException as e:
|
|
227
|
+
last_exception = e
|
|
228
|
+
result = False
|
|
229
|
+
break
|
|
230
|
+
|
|
231
|
+
if result:
|
|
232
|
+
break
|
|
233
|
+
|
|
234
|
+
thread_ensure_that_start_time = ContextBase.__thread_local.ensure_that_start_time
|
|
235
|
+
thread_local_ensure_timeout = ContextBase.__thread_local.ensure_timeout
|
|
236
|
+
|
|
237
|
+
if thread_local_ensure_timeout is None or thread_ensure_that_start_time is None:
|
|
238
|
+
raise PlatyUiError("fatal")
|
|
239
|
+
|
|
240
|
+
if time.time() - thread_ensure_that_start_time > thread_local_ensure_timeout:
|
|
241
|
+
break
|
|
242
|
+
|
|
243
|
+
if not result:
|
|
244
|
+
time.sleep(Settings.current().ensure_delay)
|
|
245
|
+
|
|
246
|
+
if failed_func is not None:
|
|
247
|
+
failed_func()
|
|
248
|
+
|
|
249
|
+
finally:
|
|
250
|
+
if set_start_time:
|
|
251
|
+
ContextBase.__thread_local.ensure_that_start_time = None
|
|
252
|
+
|
|
253
|
+
if not result and raise_exception:
|
|
254
|
+
raise CannotEnsureError(
|
|
255
|
+
"cannot ensure that %s%s"
|
|
256
|
+
% (
|
|
257
|
+
(
|
|
258
|
+
"%s" % last_predicate.message.format(context.full_repr())
|
|
259
|
+
if last_predicate is not None and hasattr(last_predicate, "message")
|
|
260
|
+
else "%s for %s" % (last_predicate, context)
|
|
261
|
+
),
|
|
262
|
+
(
|
|
263
|
+
",\n because %s"
|
|
264
|
+
% (last_exception if str(last_exception).strip() != "" else repr(last_exception))
|
|
265
|
+
if last_exception is not None
|
|
266
|
+
else ""
|
|
267
|
+
),
|
|
268
|
+
)
|
|
269
|
+
) from last_exception
|
|
270
|
+
|
|
271
|
+
return result
|
|
272
|
+
finally:
|
|
273
|
+
ContextBase.__thread_local.in_ensure_that -= 1
|
|
274
|
+
assert ContextBase.__thread_local.in_ensure_that >= 0
|
|
275
|
+
|
|
276
|
+
@property
|
|
277
|
+
def is_valid(self) -> bool:
|
|
278
|
+
return self._adapter is not None and self._adapter.valid
|
|
279
|
+
|
|
280
|
+
def exists(self, timeout: Optional[float] = None, raise_exception: bool = False) -> bool:
|
|
281
|
+
if timeout is None:
|
|
282
|
+
timeout = Settings.current().exists_timeout
|
|
283
|
+
|
|
284
|
+
return self.ensure_that(self._adapter_exists, timeout=timeout, raise_exception=raise_exception)
|
|
285
|
+
|
|
286
|
+
@property
|
|
287
|
+
def name(self) -> str:
|
|
288
|
+
return self.adapter.name
|
|
289
|
+
|
|
290
|
+
@property
|
|
291
|
+
def class_name(self) -> str:
|
|
292
|
+
return self.adapter.class_name
|
|
293
|
+
|
|
294
|
+
@property
|
|
295
|
+
def tag_name(self) -> str:
|
|
296
|
+
return self.adapter.tag_name
|
|
297
|
+
|
|
298
|
+
@property
|
|
299
|
+
def role(self) -> str:
|
|
300
|
+
return self.adapter.role
|
|
301
|
+
|
|
302
|
+
@property
|
|
303
|
+
def supported_roles(self) -> Set[str]:
|
|
304
|
+
return self.adapter.supported_roles
|
|
305
|
+
|
|
306
|
+
@property
|
|
307
|
+
def supported_strategies(self) -> Set[str]:
|
|
308
|
+
return self.adapter.supported_strategies
|
|
309
|
+
|
|
310
|
+
@property
|
|
311
|
+
def framework_id(self) -> str:
|
|
312
|
+
return self.adapter.framework_id
|
|
313
|
+
|
|
314
|
+
@property
|
|
315
|
+
def runtime_id(self) -> Any:
|
|
316
|
+
self.ensure_that(self._adapter_exists, raise_exception=False)
|
|
317
|
+
|
|
318
|
+
if not self.is_valid:
|
|
319
|
+
return self
|
|
320
|
+
|
|
321
|
+
return self.adapter.runtime_id
|
|
322
|
+
|
|
323
|
+
def __enter__(self) -> "Self":
|
|
324
|
+
return self
|
|
325
|
+
|
|
326
|
+
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> False:
|
|
327
|
+
pass
|
|
328
|
+
|
|
329
|
+
def get(
|
|
330
|
+
self, context_class: Optional[Type["TContextBase"]], *args: Any, locator: LocatorBase = None, **kwargs: Any
|
|
331
|
+
) -> "TContextBase":
|
|
332
|
+
if locator is None:
|
|
333
|
+
if self.locator is None:
|
|
334
|
+
raise NoLocatorDefinedError("no locator defined for %s" % self)
|
|
335
|
+
|
|
336
|
+
locator = self.locator.create_children_locator(*args, **kwargs)
|
|
337
|
+
|
|
338
|
+
return locator.copy().create_context(self, context_class)
|
|
339
|
+
|
|
340
|
+
def ancestor(
|
|
341
|
+
self, context_class: Optional[Type["TContextBase"]], *args: Any, locator: LocatorBase = None, **kwargs: Any
|
|
342
|
+
) -> "TContextBase":
|
|
343
|
+
return self.get(context_class, scope=LocatorScope.Ancestor, locator=locator, *args, **kwargs)
|
|
344
|
+
|
|
345
|
+
def ancestors(
|
|
346
|
+
self, context_class: Optional[Type["TContextBase"]], *args: Any, locator: LocatorBase = None, **kwargs: Any
|
|
347
|
+
) -> List["TContextBase"]:
|
|
348
|
+
return self.get_all(context_class, scope=LocatorScope.Ancestor, locator=locator, *args, **kwargs)
|
|
349
|
+
|
|
350
|
+
def get_child(
|
|
351
|
+
self, context_class: Optional[Type["TContextBase"]], *args: Any, locator: LocatorBase = None, **kwargs: Any
|
|
352
|
+
) -> "TContextBase":
|
|
353
|
+
return self.get(context_class, scope=LocatorScope.Children, locator=locator, *args, **kwargs)
|
|
354
|
+
|
|
355
|
+
def iter_all(
|
|
356
|
+
self,
|
|
357
|
+
context_class: Optional[Type["TContextBase"]],
|
|
358
|
+
*args: Any,
|
|
359
|
+
locator: Optional[LocatorBase] = None,
|
|
360
|
+
**kwargs: Any,
|
|
361
|
+
) -> Iterator["TContextBase"]:
|
|
362
|
+
if locator is None:
|
|
363
|
+
if self.locator is None:
|
|
364
|
+
raise NoLocatorDefinedError("no locator defined for %s" % self)
|
|
365
|
+
|
|
366
|
+
locator = self.locator.create_children_locator(*args, **kwargs)
|
|
367
|
+
|
|
368
|
+
children = self.locator.technology.adapter_factory.get_children_adapters(self, context_class, locator)
|
|
369
|
+
|
|
370
|
+
for a in children:
|
|
371
|
+
loc = locator.make_unique_locator(a)
|
|
372
|
+
res = loc.create_context(self, ContextFactory.find_context_class_for(a, context_class))
|
|
373
|
+
res.adapter = a
|
|
374
|
+
if context_class is None or isinstance(res, context_class):
|
|
375
|
+
yield res
|
|
376
|
+
|
|
377
|
+
def get_all(
|
|
378
|
+
self, context_class: Optional[Type["TContextBase"]], *args: Any, locator: LocatorBase = None, **kwargs: Any
|
|
379
|
+
) -> List["TContextBase"]:
|
|
380
|
+
return list(self.iter_all(context_class, *args, locator=locator, **kwargs))
|
|
381
|
+
|
|
382
|
+
def get_children(
|
|
383
|
+
self, context_class: Optional[Type["TContextBase"]], *args: Any, locator: LocatorBase = None, **kwargs: Any
|
|
384
|
+
) -> List["TContextBase"]:
|
|
385
|
+
return self.get_all(context_class, scope=LocatorScope.Children, locator=locator, *args, **kwargs)
|
|
386
|
+
|
|
387
|
+
@property
|
|
388
|
+
def parent(self) -> Optional["ContextBase"]:
|
|
389
|
+
adapter = self.adapter
|
|
390
|
+
|
|
391
|
+
if adapter is None or not adapter.valid:
|
|
392
|
+
return None
|
|
393
|
+
|
|
394
|
+
parent = adapter.parent
|
|
395
|
+
if parent is None:
|
|
396
|
+
return None
|
|
397
|
+
|
|
398
|
+
loc = self.locator.create_parent_locator(parent)
|
|
399
|
+
|
|
400
|
+
result: "ContextBase" = loc.create_context(self, ContextFactory.find_context_class_for(parent))
|
|
401
|
+
result.adapter = parent
|
|
402
|
+
|
|
403
|
+
return result
|
|
404
|
+
|
|
405
|
+
def __iter__(self) -> Iterator["ContextBase"]:
|
|
406
|
+
adapter = self.adapter
|
|
407
|
+
|
|
408
|
+
if adapter is None or not adapter.valid:
|
|
409
|
+
return
|
|
410
|
+
|
|
411
|
+
if self.locator is not None:
|
|
412
|
+
|
|
413
|
+
for a in adapter.children:
|
|
414
|
+
loc = self.locator.create_child_locator(a)
|
|
415
|
+
res: ContextBase = loc.create_context(self, ContextFactory.find_context_class_for(a))
|
|
416
|
+
res.adapter = a
|
|
417
|
+
yield res
|
|
418
|
+
|
|
419
|
+
@property
|
|
420
|
+
def children(self) -> List["ContextBase"]:
|
|
421
|
+
return list(self)
|
|
422
|
+
|
|
423
|
+
def get_properties(self) -> List[str]:
|
|
424
|
+
self.ensure_that(self._adapter_exists)
|
|
425
|
+
|
|
426
|
+
return self.adapter.get_strategy(Properties).get_property_names()
|
|
427
|
+
|
|
428
|
+
def get_property_value(self, name: str) -> Any:
|
|
429
|
+
self.ensure_that(self._adapter_exists)
|
|
430
|
+
|
|
431
|
+
return self.adapter.get_strategy(Properties).get_property_value(name)
|
|
432
|
+
|
|
433
|
+
def get_native_properties(self) -> List[str]:
|
|
434
|
+
self.ensure_that(self._adapter_exists)
|
|
435
|
+
|
|
436
|
+
return self.adapter.get_strategy(NativeProperties).get_native_property_names()
|
|
437
|
+
|
|
438
|
+
def get_native_property_value(self, name: str) -> Any:
|
|
439
|
+
self.ensure_that(self._adapter_exists)
|
|
440
|
+
|
|
441
|
+
return self.adapter.get_strategy(NativeProperties).get_native_property_value(name)
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
class UnknownContext(ContextBase):
|
|
445
|
+
pass
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
TContextBase = TypeVar("TContextBase", bound=ContextBase)
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
class ContextFactory:
|
|
452
|
+
class Entry:
|
|
453
|
+
def __init__(self, proxy_type: Type[ContextBase], criterias: Dict[str, object]):
|
|
454
|
+
self.proxy_type = proxy_type
|
|
455
|
+
self.criterias = criterias
|
|
456
|
+
|
|
457
|
+
registered_adapters: List[Entry] = []
|
|
458
|
+
|
|
459
|
+
@classmethod
|
|
460
|
+
def register_context(cls, adapter_cls: Type[ContextBase], criterias: Dict[str, Any]) -> None:
|
|
461
|
+
cls.registered_adapters.append(ContextFactory.Entry(adapter_cls, criterias.copy()))
|
|
462
|
+
|
|
463
|
+
@overload
|
|
464
|
+
@classmethod
|
|
465
|
+
def find_context_class_for(cls, adapter: Adapter, context_type: Optional[Type[TContextBase]]) -> Type[TContextBase]:
|
|
466
|
+
pass
|
|
467
|
+
|
|
468
|
+
@overload
|
|
469
|
+
@classmethod
|
|
470
|
+
def find_context_class_for(cls, adapter: Adapter) -> Type[ContextBase]:
|
|
471
|
+
pass
|
|
472
|
+
|
|
473
|
+
@classmethod
|
|
474
|
+
def find_context_class_for(
|
|
475
|
+
cls, adapter: Adapter, context_type: Optional[Type[TContextBase]] = None
|
|
476
|
+
) -> Type[Union[TContextBase, ContextBase]]:
|
|
477
|
+
|
|
478
|
+
if context_type is not None:
|
|
479
|
+
return context_type
|
|
480
|
+
|
|
481
|
+
weights = []
|
|
482
|
+
calculator = WeightCalculator(adapter)
|
|
483
|
+
|
|
484
|
+
for e in cls.registered_adapters:
|
|
485
|
+
weights.append((calculator.calculate(e.criterias), e.proxy_type))
|
|
486
|
+
|
|
487
|
+
if len(weights) > 0:
|
|
488
|
+
last = sorted(weights, key=lambda x: x[0])[-1]
|
|
489
|
+
|
|
490
|
+
if last[0] > 0:
|
|
491
|
+
return last[1]
|
|
492
|
+
|
|
493
|
+
return UnknownContext
|
|
494
|
+
|
|
495
|
+
@overload
|
|
496
|
+
@classmethod
|
|
497
|
+
def create_context(
|
|
498
|
+
cls,
|
|
499
|
+
locator: "LocatorBase",
|
|
500
|
+
context_type: Optional[Type[TContextBase]],
|
|
501
|
+
parent: Optional["ContextBase"] = None,
|
|
502
|
+
) -> TContextBase:
|
|
503
|
+
pass
|
|
504
|
+
|
|
505
|
+
@overload
|
|
506
|
+
@classmethod
|
|
507
|
+
def create_context(
|
|
508
|
+
cls,
|
|
509
|
+
locator: "LocatorBase",
|
|
510
|
+
context_type: Optional[Type[TContextBase]] = None,
|
|
511
|
+
parent: Optional["ContextBase"] = None,
|
|
512
|
+
) -> TContextBase:
|
|
513
|
+
pass
|
|
514
|
+
|
|
515
|
+
@classmethod
|
|
516
|
+
def create_context(
|
|
517
|
+
cls,
|
|
518
|
+
locator: "LocatorBase",
|
|
519
|
+
context_type: Optional[Type[TContextBase]] = None,
|
|
520
|
+
parent: Optional["ContextBase"] = None,
|
|
521
|
+
raise_error: bool = True,
|
|
522
|
+
) -> Optional[TContextBase]:
|
|
523
|
+
adapter = locator.technology.adapter_factory.get_adapter(locator, parent, context_type, raise_error)
|
|
524
|
+
if adapter is None:
|
|
525
|
+
return None
|
|
526
|
+
|
|
527
|
+
context_type = cls.find_context_class_for(adapter, context_type)
|
|
528
|
+
|
|
529
|
+
return context_type(locator, parent, adapter)
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
@overload
|
|
533
|
+
def context(__cls: Type[TContextBase]) -> Type[TContextBase]: ...
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
@overload
|
|
537
|
+
def context(
|
|
538
|
+
*,
|
|
539
|
+
role: Optional[str] = None,
|
|
540
|
+
framework_id: Optional[str] = None,
|
|
541
|
+
class_name: Optional[str] = None,
|
|
542
|
+
tag_name: Optional[str] = None,
|
|
543
|
+
properties: Optional[Dict[str, str]] = None,
|
|
544
|
+
native_properties: Optional[Dict[str, str]] = None,
|
|
545
|
+
**decorator_kwargs: Any,
|
|
546
|
+
) -> Callable[[Type[TContextBase]], Type[TContextBase]]: ...
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def context(
|
|
550
|
+
__cls: Optional[Type[TContextBase]] = None,
|
|
551
|
+
*,
|
|
552
|
+
role: Optional[str] = None,
|
|
553
|
+
framework_id: Optional[str] = None,
|
|
554
|
+
class_name: Optional[str] = None,
|
|
555
|
+
tag_name: Optional[str] = None,
|
|
556
|
+
properties: Optional[Dict[str, str]] = None,
|
|
557
|
+
native_properties: Optional[Dict[str, str]] = None,
|
|
558
|
+
prefix: Optional[str] = None,
|
|
559
|
+
**decorator_kwargs: Any,
|
|
560
|
+
) -> Union[Type[TContextBase], Callable[[Type[TContextBase]], Type[TContextBase]]]:
|
|
561
|
+
def decorator(cls: Type[TContextBase]) -> Type[TContextBase]:
|
|
562
|
+
|
|
563
|
+
setattr(cls, "default_role", role or cls.__name__)
|
|
564
|
+
|
|
565
|
+
if prefix is not None:
|
|
566
|
+
setattr(cls, "default_prefix", prefix)
|
|
567
|
+
|
|
568
|
+
ContextFactory.register_context(
|
|
569
|
+
cls,
|
|
570
|
+
{
|
|
571
|
+
"role": cls.__name__ if role is None else role,
|
|
572
|
+
"framework_id": framework_id,
|
|
573
|
+
"class_name": class_name,
|
|
574
|
+
"tag_name": tag_name,
|
|
575
|
+
"properties": properties,
|
|
576
|
+
"native_properties": native_properties,
|
|
577
|
+
**decorator_kwargs,
|
|
578
|
+
},
|
|
579
|
+
)
|
|
580
|
+
|
|
581
|
+
return cls
|
|
582
|
+
|
|
583
|
+
if __cls is None:
|
|
584
|
+
return decorator
|
|
585
|
+
|
|
586
|
+
return decorator(__cls)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
__all__ = [
|
|
2
|
+
"NotSupportedError",
|
|
3
|
+
"InvalidArgumentError",
|
|
4
|
+
"PlatynUiException",
|
|
5
|
+
"PlatyUiError",
|
|
6
|
+
"PlatynUiFatalError",
|
|
7
|
+
"AdapterNotValidError",
|
|
8
|
+
"AdapterNotFoundError",
|
|
9
|
+
"AdapterNotFoundFatalError",
|
|
10
|
+
"NotAStrategyTypeError",
|
|
11
|
+
"AdapterNotSupportsStrategyError",
|
|
12
|
+
"CannotEnsureError",
|
|
13
|
+
"NoKeyboardProxyError",
|
|
14
|
+
"NoMouseProxyError",
|
|
15
|
+
"NoDisplayProxyError",
|
|
16
|
+
"NoLocatorDefinedError",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class NotSupportedError(Exception):
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class InvalidArgumentError(Exception):
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class PlatynUiException(Exception): # noqa: N818
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class PlatyUiError(PlatynUiException):
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class PlatynUiFatalError(PlatynUiException):
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class AdapterNotValidError(PlatynUiException):
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class AdapterNotFoundError(PlatynUiException):
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class AdapterNotFoundFatalError(PlatynUiFatalError):
|
|
49
|
+
pass
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class NotAStrategyTypeError(PlatyUiError):
|
|
53
|
+
pass
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class AdapterNotSupportsStrategyError(PlatyUiError):
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class CannotEnsureError(PlatyUiError):
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class NoKeyboardProxyError(PlatyUiError):
|
|
65
|
+
pass
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class NoDisplayProxyError(PlatyUiError):
|
|
69
|
+
pass
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class NoMouseProxyError(PlatyUiError):
|
|
73
|
+
pass
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class NoLocatorDefinedError(PlatyUiError):
|
|
77
|
+
pass
|
|
File without changes
|