@capagents/forgeqe 3.0.9 → 3.1.1

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.
Files changed (198) hide show
  1. package/HOW_TO_USE.md +35 -22
  2. package/bin/bundle.js +3 -3
  3. package/bin/forgeqe.js +3 -3
  4. package/bin/license.js +1 -1
  5. package/dist/docs-site/CREDITS.md +11 -4
  6. package/dist/docs-site/LICENSE.dm-sans.txt +93 -0
  7. package/dist/docs-site/LICENSE.jetbrains-mono.txt +93 -0
  8. package/dist/docs-site/app-look.css +62 -0
  9. package/dist/docs-site/architecture-map/arch-fill.js +56 -0
  10. package/dist/docs-site/architecture-map/arch-theme.css +203 -0
  11. package/dist/docs-site/architecture-map/arch.css +0 -5
  12. package/dist/docs-site/architecture-map/index.html +57 -43
  13. package/dist/docs-site/docs/app-theme.css +166 -0
  14. package/dist/docs-site/docs/architecture/index.html +14 -11
  15. package/dist/docs-site/docs/containers/index.html +14 -11
  16. package/dist/docs-site/docs/cost-architecture/index.html +14 -11
  17. package/dist/docs-site/docs/custom-agents-first-run/index.html +14 -11
  18. package/dist/docs-site/docs/desktop/index.html +14 -11
  19. package/dist/docs-site/docs/desktop-ci/index.html +14 -11
  20. package/dist/docs-site/docs/docs.css +0 -7
  21. package/dist/docs-site/docs/evidence/index.html +14 -11
  22. package/dist/docs-site/docs/feature-test-prompts/index.html +14 -11
  23. package/dist/docs-site/docs/graphify/index.html +14 -11
  24. package/dist/docs-site/docs/guardrails/index.html +14 -11
  25. package/dist/docs-site/docs/index.html +96 -40
  26. package/dist/docs-site/docs/mobile/index.html +56 -18
  27. package/dist/docs-site/docs/model-routing/index.html +14 -11
  28. package/dist/docs-site/docs/product-graph/index.html +14 -11
  29. package/dist/docs-site/docs/product-knowledge/index.html +14 -11
  30. package/dist/docs-site/docs/product-views/index.html +14 -11
  31. package/dist/docs-site/docs/search.js +1 -1
  32. package/dist/docs-site/docs/web-app/index.html +14 -11
  33. package/dist/docs-site/img/wordmark.webp +0 -0
  34. package/dist/docs-site/site-header.css +0 -5
  35. package/dist/forgeqe.js +2225 -1867
  36. package/dist/template.html +14 -14
  37. package/dist/web/assets/{AgentWork-BhepbEeU.js → AgentWork-DwAI0_Of.js} +1 -1
  38. package/dist/web/assets/ApiTests-C0vFSHmM.js +10 -0
  39. package/dist/web/assets/Browse-5jfdtRc5.js +2 -0
  40. package/dist/web/assets/Chat-B3uhI94O.js +3 -0
  41. package/dist/web/assets/{CommandPalette-DMAmXPq1.js → CommandPalette-D2J4nf5y.js} +1 -1
  42. package/dist/web/assets/{Compare-DJNSrM2v.js → Compare-CN75w1p9.js} +1 -1
  43. package/dist/web/assets/{Cost-CEOZgbPs.js → Cost-QoxyjR95.js} +1 -1
  44. package/dist/web/assets/{Data-COFRpcJn.js → Data-BAvkcBVt.js} +4 -4
  45. package/dist/web/assets/Desktop-BXdOIalN.js +1 -0
  46. package/dist/web/assets/DesktopReview-Bl2SrPP0.js +1 -0
  47. package/dist/web/assets/{Evidence-DTrdEz3M.js → Evidence-BJ_I52CD.js} +1 -1
  48. package/dist/web/assets/{Explore-DDXgQj5Q.js → Explore-D9AuyTip.js} +2 -2
  49. package/dist/web/assets/Features-CusGMDR9.js +1 -0
  50. package/dist/web/assets/Flags-CycGFuUP.js +2 -0
  51. package/dist/web/assets/Flaky-BcSzJogN.js +1 -0
  52. package/dist/web/assets/Impact-CJHnyZ21.js +3 -0
  53. package/dist/web/assets/Jobs-4xcFzEFo.js +5 -0
  54. package/dist/web/assets/KindPage-BielEIej.js +6 -0
  55. package/dist/web/assets/Migration-NwanKpJg.js +2 -0
  56. package/dist/web/assets/PageAgent-CNw4NXva.js +1 -0
  57. package/dist/web/assets/Product-DS3LJZ4P.js +7 -0
  58. package/dist/web/assets/Production-D3zsyNIS.js +1 -0
  59. package/dist/web/assets/{Quality-DgNo4H0u.js → Quality-Ctj2YpC4.js} +1 -1
  60. package/dist/web/assets/{Readiness--GiTxFZo.js → Readiness-DGcRr_co.js} +1 -1
  61. package/dist/web/assets/Record-Cc-wGe_Y.js +1 -0
  62. package/dist/web/assets/Regression-DcsbrRa1.js +5 -0
  63. package/dist/web/assets/{Reports-C-NSlVAn.js → Reports-BkCn0-Sf.js} +2 -2
  64. package/dist/web/assets/Response-BP0UwQcW.js +9 -0
  65. package/dist/web/assets/Responsive-C8U7dumd.js +3 -0
  66. package/dist/web/assets/{RunDiff-CIdQD95y.js → RunDiff-BhABuhF_.js} +1 -1
  67. package/dist/web/assets/Runs-OwdWEYBv.js +2 -0
  68. package/dist/web/assets/Steps-BvzbQyoD.js +2 -0
  69. package/dist/web/assets/{TestCases-D-ZRb2N7.js → TestCases-CLq_6JA5.js} +1 -1
  70. package/dist/web/assets/{TestData-kXWCn7uZ.js → TestData-B0oKAhp6.js} +2 -2
  71. package/dist/web/assets/TestDebt-8NLQ5YV_.js +1 -0
  72. package/dist/web/assets/TestManagement-2LYQ7vsN.js +1 -0
  73. package/dist/web/assets/Tosca-DfvMpPTG.js +3 -0
  74. package/dist/web/assets/{WhatsNew-DpJWNec7.js → WhatsNew-BGFNGwqN.js} +1 -1
  75. package/dist/web/assets/families-DYlN5v0i.js +1 -0
  76. package/dist/web/assets/filters-faaSnoIq.js +1 -0
  77. package/dist/web/assets/{fold-BRxvbN9r.js → fold-CUjwWAK3.js} +1 -1
  78. package/dist/web/assets/frame-BLPdAXUq.js +13 -0
  79. package/dist/web/assets/head-CsTxBsO0.js +1 -0
  80. package/dist/web/assets/index-CxiCvGZq.js +78 -0
  81. package/dist/web/assets/index-dOIsrzhD.css +2 -0
  82. package/dist/web/assets/line-icons-CwZWt93L.js +1 -0
  83. package/dist/web/assets/logos-dGuc1jIM.js +1 -0
  84. package/dist/web/assets/{markdown-CWisJbSJ.js → markdown-BI3F-SJ1.js} +5 -5
  85. package/dist/web/assets/paletteCommands-QJiCuUEr.js +1 -0
  86. package/dist/web/assets/parts-CdF1f7yS.js +1 -0
  87. package/dist/web/assets/{productParts-BxdHuSBa.js → productParts-hNLD9fN0.js} +1 -1
  88. package/dist/web/assets/qualityParts-CT25lBWU.js +1 -0
  89. package/dist/web/assets/{recordTest-CcplpTS6.js → recordTest-P792aBUt.js} +1 -1
  90. package/dist/web/index.html +6 -6
  91. package/docs/ForgeQE-Client-Overview.pdf +0 -0
  92. package/docs/ForgeQE-Installation-Guide.pdf +0 -0
  93. package/docs/MOBILE.md +42 -7
  94. package/docs/user-guide.html +65 -12
  95. package/package.json +1 -1
  96. package/prompts/brain.md +1 -0
  97. package/prompts/responsive-review.md +38 -0
  98. package/prompts/responsive-split.md +40 -0
  99. package/prompts/responsive.md +42 -0
  100. package/py/forgeqe_data/connect.py +3 -1
  101. package/py/forgeqe_data/flows.py +1 -1
  102. package/py/forgeqe_data/service.py +1 -1
  103. package/py/forgeqe_data/streams.py +1 -1
  104. package/py/forgeqe_data/testdata.py +1 -1
  105. package/py/forgeqe_desktop/replay.py +43 -1
  106. package/py/forgeqe_desktop/service.py +2 -0
  107. package/py/forgeqe_desktop/workflow.py +77 -15
  108. package/py/forgeqe_engine/brand.py +1 -1
  109. package/py/forgeqe_engine/browser.py +2 -1
  110. package/py/forgeqe_engine/diagnostics.py +1 -1
  111. package/py/forgeqe_engine/memory.py +2 -1
  112. package/py/forgeqe_engine/neutral_log.py +1 -1
  113. package/py/forgeqe_engine/otp.py +127 -12
  114. package/py/forgeqe_engine/pwlaunch.mjs +1 -1
  115. package/py/forgeqe_engine/recordsession.py +13 -3
  116. package/py/forgeqe_engine/webrecord.py +20 -0
  117. package/py/forgeqe_mobile/appium_driver.py +225 -10
  118. package/py/forgeqe_mobile/locators.py +277 -0
  119. package/py/forgeqe_mobile/maestro.py +28 -1
  120. package/py/forgeqe_mobile/magiclink.py +79 -0
  121. package/py/forgeqe_mobile/record.py +284 -67
  122. package/py/forgeqe_mobile/service.py +9 -0
  123. package/py/forgeqe_mobile/webview.py +142 -0
  124. package/py/forgeqe_tosca/ntir.py +45 -6
  125. package/dist/docs-site/LICENSE.ubuntu.txt +0 -96
  126. package/dist/docs-site/img/icons/api.svg +0 -1
  127. package/dist/docs-site/img/icons/architecture.svg +0 -1
  128. package/dist/docs-site/img/icons/branch.svg +0 -1
  129. package/dist/docs-site/img/icons/browser-agent.svg +0 -1
  130. package/dist/docs-site/img/icons/case.svg +0 -1
  131. package/dist/docs-site/img/icons/container.svg +0 -1
  132. package/dist/docs-site/img/icons/context-engine.svg +0 -1
  133. package/dist/docs-site/img/icons/desktop.svg +0 -1
  134. package/dist/docs-site/img/icons/download.svg +0 -1
  135. package/dist/docs-site/img/icons/explorer.svg +0 -1
  136. package/dist/docs-site/img/icons/feature.svg +0 -1
  137. package/dist/docs-site/img/icons/healer.svg +0 -1
  138. package/dist/docs-site/img/icons/knowledge-base.svg +0 -1
  139. package/dist/docs-site/img/icons/mail.svg +0 -1
  140. package/dist/docs-site/img/icons/mobile.svg +0 -1
  141. package/dist/docs-site/img/icons/model.svg +0 -1
  142. package/dist/docs-site/img/icons/network.svg +0 -1
  143. package/dist/docs-site/img/icons/orchestrator.svg +0 -1
  144. package/dist/docs-site/img/icons/plug.svg +0 -1
  145. package/dist/docs-site/img/icons/pr-reviewer.svg +0 -1
  146. package/dist/docs-site/img/icons/replay.svg +0 -1
  147. package/dist/docs-site/img/icons/report.svg +0 -1
  148. package/dist/docs-site/img/icons/result.svg +0 -1
  149. package/dist/docs-site/img/icons/rule.svg +0 -1
  150. package/dist/docs-site/img/icons/scribe.svg +0 -1
  151. package/dist/docs-site/img/icons/shield.svg +0 -1
  152. package/dist/docs-site/img/icons/specs.svg +0 -1
  153. package/dist/docs-site/img/icons/speed.svg +0 -1
  154. package/dist/docs-site/img/icons/stories.svg +0 -1
  155. package/dist/docs-site/img/icons/terminal.svg +0 -1
  156. package/dist/docs-site/img/icons/test-finder.svg +0 -1
  157. package/dist/docs-site/img/icons/visual.svg +0 -1
  158. package/dist/docs-site/img/icons/web.svg +0 -1
  159. package/dist/docs-site/img/icons/wikis.svg +0 -1
  160. package/dist/web/assets/Agent-MlW7cfAm.js +0 -7
  161. package/dist/web/assets/ApiTests-mxUkUZvv.js +0 -10
  162. package/dist/web/assets/Browse-DENLuv4C.js +0 -2
  163. package/dist/web/assets/Chat-jxak1jci.js +0 -3
  164. package/dist/web/assets/Desktop-DGNdy7iS.js +0 -1
  165. package/dist/web/assets/DesktopReview-SdAwvi9y.js +0 -1
  166. package/dist/web/assets/Features-BM5iXhOR.js +0 -1
  167. package/dist/web/assets/Flags-CkKp4bbv.js +0 -2
  168. package/dist/web/assets/Flaky-BqUHVLao.js +0 -1
  169. package/dist/web/assets/Impact-CA6s3POt.js +0 -3
  170. package/dist/web/assets/Jobs-B59p1qvn.js +0 -5
  171. package/dist/web/assets/KindPage-DPADNnwH.js +0 -6
  172. package/dist/web/assets/Migration-DtynahwR.js +0 -2
  173. package/dist/web/assets/PageAgent-CB8HtdGd.js +0 -1
  174. package/dist/web/assets/Product-wWMz2Nnk.js +0 -7
  175. package/dist/web/assets/Production-Nst6__N7.js +0 -1
  176. package/dist/web/assets/Record-a4whC1jV.js +0 -1
  177. package/dist/web/assets/Regression-hesOlN4G.js +0 -5
  178. package/dist/web/assets/RelationGraph-C3Re0M1N.js +0 -1
  179. package/dist/web/assets/Response-CzX2rQEZ.js +0 -9
  180. package/dist/web/assets/Runs-DIDCOhbK.js +0 -2
  181. package/dist/web/assets/Steps-BOWDBzu4.js +0 -2
  182. package/dist/web/assets/TestDebt-BvP3w7ye.js +0 -1
  183. package/dist/web/assets/TestManagement-CphGo9DZ.js +0 -1
  184. package/dist/web/assets/Tosca-dhFuqYxV.js +0 -3
  185. package/dist/web/assets/agentTabs-BO5l3zw2.js +0 -1
  186. package/dist/web/assets/dataParts-DeUdfjjv.js +0 -3
  187. package/dist/web/assets/diff-D1_Qo2h1.js +0 -2
  188. package/dist/web/assets/families-DWilSDct.js +0 -1
  189. package/dist/web/assets/filters-CVzIOjPG.js +0 -1
  190. package/dist/web/assets/frame-VTMu7MoC.js +0 -13
  191. package/dist/web/assets/index-CKRa-K2y.css +0 -2
  192. package/dist/web/assets/index-nuLrB-Rb.js +0 -69
  193. package/dist/web/assets/line-icons-C_amZ5-o.js +0 -1
  194. package/dist/web/assets/logos-J6txZkKc.js +0 -1
  195. package/dist/web/assets/paletteCommands-BmYmp6YY.js +0 -1
  196. package/dist/web/assets/parts-CDBCk_Xz.js +0 -1
  197. package/dist/web/assets/qualityParts-CGKSK9Dq.js +0 -1
  198. package/dist/web/assets/rows-yPc39hV7.js +0 -1
@@ -34,19 +34,16 @@ import xml.etree.ElementTree as ET
34
34
  from pathlib import Path
35
35
  from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple
36
36
 
37
- from forgeqe_desktop.record import _mask, target_of
37
+ from forgeqe_desktop.record import _mask
38
38
  from forgeqe_desktop.workflow import MAX_WAIT_SECONDS, MOBILE_FORMAT, MOBILE_KEYS, SWIPE_DIRECTIONS, WorkflowError, save, validate
39
39
 
40
- from .appium_driver import IOS_PERMISSION_ANSWERS, _walk, element_props
40
+ from .appium_driver import IOS_PERMISSION_ANSWERS, _walk, element_props, locator_query
41
+ from .locators import ScreenIndex, locate as best_locator, pairs, parents_of, tried
41
42
 
42
43
  MAX_ELEMENTS = 400
43
44
  MAX_STEPS = 500
44
45
  MAX_TEXT = 2000
45
46
  MAX_CHECK_TEXT = 200
46
- # A control's name longer than this is its content, not a label (explore's rule): left out when it has an id.
47
- MAX_NAME = 80
48
- # A name longer than this is never a locator: a control named only by a paragraph is not recorded.
49
- MAX_LOCATOR_NAME = 300
50
47
  MAX_LABEL = 80
51
48
  # How long an action's control is looked for: it was on screen a moment ago.
52
49
  FIND_SECONDS = 8.0
@@ -67,10 +64,42 @@ ANDROID_FIELDS = ("android.widget.EditText", "android.widget.AutoCompleteTextVie
67
64
  IOS_FIELDS = ("XCUIElementTypeTextField", "XCUIElementTypeSecureTextField", "XCUIElementTypeTextView", "XCUIElementTypeSearchField")
68
65
  # iOS controls a tap is meant for: the page source has no "clickable" there.
69
66
  IOS_TAPPABLE = ("XCUIElementTypeButton", "XCUIElementTypeCell", "XCUIElementTypeSwitch", "XCUIElementTypeLink", "XCUIElementTypeSegmentedControl", "XCUIElementTypeTab", "XCUIElementTypeMenuItem", "XCUIElementTypeKey")
67
+ # A web page inside the app, as Android's and iOS's accessibility trees name it.
68
+ WEBVIEWS = ("android.webkit.WebView", "XCUIElementTypeWebView")
69
+ # Lists a drop-down's or a menu's items sit in, and controls that are a dialog's buttons rather than items.
70
+ ANDROID_LISTS = ("android.widget.ListView", "androidx.recyclerview.widget.RecyclerView", "android.widget.GridView", "android.widget.ExpandableListView")
71
+ ANDROID_BUTTONS = ("android.widget.Button", "android.widget.ImageButton")
72
+ # A window this much smaller than the screen floats over the app: a drop-down's list, a menu, a dialog.
73
+ FLOATING_SHARE = 0.8
74
+
75
+
76
+ def _floating(root: ET.Element, platform: str, size: Optional[Tuple[int, int]]) -> bool:
77
+ """Whether the screen read is a floating window (UiAutomator gives only the window in front): none of its top
78
+ nodes covers most of the screen."""
79
+ if platform != "android" or not size or size[0] <= 0 or size[1] <= 0:
80
+ return False
81
+ tops = [b for b in (_box(n, platform) for n in list(root)) if b]
82
+ return bool(tops) and all(b[2] * b[3] < size[0] * size[1] * FLOATING_SHARE for b in tops)
83
+
84
+
85
+ # iOS controls that are on or off: their value says 1 or 0.
86
+ IOS_CHECKABLE = ("XCUIElementTypeSwitch", "XCUIElementTypeCheckBox", "XCUIElementTypeToggle")
87
+
88
+
89
+ def checked_state(node: ET.Element, platform: str) -> Optional[bool]:
90
+ """Whether a checkbox, switch or radio button is on, from the page source; None for any other control."""
91
+ a = node.attrib
92
+ if platform == "android":
93
+ return a.get("checked") == "true" if a.get("checkable") == "true" else None
94
+ if (a.get("type") or node.tag) in IOS_CHECKABLE:
95
+ return str(a.get("value") or "").strip().lower() in ("1", "true", "on")
96
+ return None
97
+
98
+
70
99
  # A drop-down: a tap on it and then on one of its items is one select step (the item by its text), not two taps.
71
100
  def is_dropdown(kind: str) -> bool:
72
101
  k = kind.rsplit(".", 1)[-1].lower()
73
- return "spinner" in k or "dropdown" in k or k == "xcuielementtypepopupbutton"
102
+ return "spinner" in k or "dropdown" in k or k in ("xcuielementtypepopupbutton", "popupbutton")
74
103
 
75
104
 
76
105
  # A box larger than this share of the screen is a layout, not a control, unless it can be tapped.
@@ -78,8 +107,12 @@ LAYOUT_SHARE = 0.5
78
107
  _BOUNDS = re.compile(r"^\[(-?\d+),(-?\d+)\]\[(-?\d+),(-?\d+)\]$")
79
108
  _CONTROL_CHARS = re.compile(r"[\u0000-\u001f\u007f]")
80
109
 
110
+ # The most fallbacks a step's target keeps (the workflow's limit).
111
+ MAX_TARGET_FALLBACKS = 4
112
+ # Steps on a control that scrolls just before them fold into (a scroll_to that control).
113
+ FOLD_OPS = ("tap", "double_tap", "long_press", "type", "expect", "wait_for", "select", "set_checked")
81
114
  ELEMENT_COMMANDS = ("tap", "double_tap", "long_press", "type", "check", "wait_for")
82
- COMMANDS = (*ELEMENT_COMMANDS, "swipe", "scroll", "back", "hide_keyboard", "keys", "wait", "undo", "delete", "refresh", "stop")
115
+ COMMANDS = (*ELEMENT_COMMANDS, "tap_at", "magic_link", "swipe", "scroll", "back", "hide_keyboard", "keys", "wait", "undo", "delete", "refresh", "stop")
83
116
 
84
117
 
85
118
  class RecordRefused(ValueError):
@@ -110,39 +143,7 @@ def _box(node: ET.Element, platform: str) -> Optional[List[int]]:
110
143
  return box if box[2] > 0 and box[3] > 0 else None
111
144
 
112
145
 
113
- def _locator(props: Mapping[str, str]) -> Optional[Dict[str, Any]]:
114
- target = target_of(props)
115
- if target is None:
116
- return None
117
- name = str(target.get("name") or "")
118
- if target.get("automation_id") and len(name) > MAX_NAME:
119
- target.pop("name", None)
120
- elif len(name) > MAX_LOCATOR_NAME or _CONTROL_CHARS.search(name):
121
- return None
122
- return target
123
-
124
-
125
- def _matches(props: Mapping[str, str], node: ET.Element, target: Mapping[str, Any], platform: str) -> bool:
126
- """Whether ``node`` is one the target's XPath finds (appium_driver.target_xpath), from its attributes."""
127
- a = node.attrib
128
- aid, name, kind = target.get("automation_id"), target.get("name"), target.get("control_type")
129
- if platform == "android":
130
- rid = a.get("resource-id", "")
131
- if aid and not (rid == aid or rid.endswith(":id/" + str(aid))):
132
- return False
133
- if name and name not in (a.get("text"), a.get("content-desc")):
134
- return False
135
- return not kind or a.get("class") == kind
136
- if a.get("visible") != "true":
137
- return False
138
- if aid and a.get("name") != aid:
139
- return False
140
- if name and name not in (a.get("label"), a.get("name"), a.get("value")):
141
- return False
142
- return not kind or a.get("type") == kind
143
-
144
-
145
- def parse_screen(source: str, platform: str, app_id: str) -> List[Dict[str, Any]]:
146
+ def parse_screen(source: str, platform: str, app_id: str, size: Optional[Tuple[int, int]] = None) -> List[Dict[str, Any]]:
146
147
  """
147
148
  The controls on screen, in document order, each with where it is (``box``: x, y, width, height in the page
148
149
  source's units), its locator (``target``, with ``index`` when an earlier control matches it too, or None when it
@@ -162,20 +163,43 @@ def parse_screen(source: str, platform: str, app_id: str) -> List[Dict[str, Any]
162
163
  def is_field(kind: str) -> bool:
163
164
  return (kind in ANDROID_FIELDS or "EditText" in kind) if platform == "android" else kind in IOS_FIELDS
164
165
 
166
+ shown = [n for n, _, _ in nodes]
167
+ parents = parents_of(root)
168
+ index = ScreenIndex(shown, platform)
169
+ floating = _floating(root, platform, size)
170
+
171
+ def webview_box(node: ET.Element) -> Optional[List[int]]:
172
+ """The box of the web page (WebView) the node is inside, or None."""
173
+ up = parents.get(node)
174
+ while up is not None:
175
+ if (up.attrib.get("class") or up.attrib.get("type") or up.tag) in WEBVIEWS:
176
+ return _box(up, platform)
177
+ up = parents.get(up)
178
+ return None
179
+
180
+ def in_menu(node: ET.Element, kind: str) -> bool:
181
+ """An item of the list a drop-down or a menu opened: one inside a list of a floating window (Android) or a menu (iOS)."""
182
+ if platform == "android":
183
+ if not floating or kind in ANDROID_BUTTONS:
184
+ return False
185
+ up = parents.get(node)
186
+ while up is not None:
187
+ if (up.attrib.get("class") or up.tag) in ANDROID_LISTS:
188
+ return True
189
+ up = parents.get(up)
190
+ return False
191
+ if kind == "XCUIElementTypeMenuItem":
192
+ return True
193
+ up = parents.get(node)
194
+ while up is not None:
195
+ if (up.attrib.get("type") or up.tag) in ("XCUIElementTypeMenu", "XCUIElementTypeMenuBar"):
196
+ return True
197
+ up = parents.get(up)
198
+ return False
199
+
165
200
  def locate(node: ET.Element, props: Mapping[str, str]) -> Optional[Dict[str, Any]]:
166
- target = _locator(props)
167
- if target is None:
168
- return None
169
- if target.get("automation_id") and is_field(props.get("control_type", "")):
170
- # A field's text is its hint now and what is typed later: its id alone finds it either way.
171
- target.pop("name", None)
172
- earlier = 0
173
- for other, _, other_props in nodes:
174
- if other is node:
175
- break
176
- if _matches(other_props, other, target, platform):
177
- earlier += 1
178
- return {**target, **({"index": earlier} if earlier else {})}
201
+ # The best locator that is unique on this screen, with the others as fallbacks (locators.py).
202
+ return best_locator(node, shown, parents, platform, is_field(props.get("control_type", "")), index)
179
203
 
180
204
  def tappable(node: ET.Element) -> bool:
181
205
  a = node.attrib
@@ -209,7 +233,13 @@ def parse_screen(source: str, platform: str, app_id: str) -> List[Dict[str, Any]
209
233
  # What the tester sees named is the text inside it.
210
234
  props = {**props, **{k: v for k, v in cprops.items() if k in ("name", "automation_id")}}
211
235
  break
212
- field = is_field(kind)
236
+ picker = platform == "ios" and kind == "XCUIElementTypePickerWheel"
237
+ field = is_field(kind) or picker
238
+ checked = checked_state(node, platform)
239
+ menu = in_menu(node, kind)
240
+ # A web page's control: one that can be tapped, typed into or shows a text, never a container standing in for
241
+ # whatever is at its centre.
242
+ web_box = webview_box(node) if (tappable(node) or field or (props.get("text") or "").strip()) else None
213
243
  if platform == "android":
214
244
  secure = node.attrib.get("password") == "true"
215
245
  prompt = props.get("package", "") in PERMISSION_PACKAGES
@@ -227,7 +257,18 @@ def parse_screen(source: str, platform: str, app_id: str) -> List[Dict[str, Any]
227
257
  # What it shows, for a check added in the review (steps/NNN.json); never sent to the live page.
228
258
  "text": (props.get("text") or "").replace("\n", " ").strip()[:MAX_CHECK_TEXT],
229
259
  "kind": kind.rsplit(".", 1)[-1].replace("XCUIElementType", "")[:40],
260
+ # What the review's picture says the control is (steps/NNN.json), whatever its locator: its id, name and type
261
+ # (a field's text is a hint, so a field with an id is not named by it).
262
+ "props": {k: props[k] for k in ("automation_id", "name", "control_type") if props.get(k) and not (k == "name" and field and props.get("automation_id"))},
230
263
  **({"field": True} if field else {}),
264
+ # An iOS picker wheel: chosen by the value it shows (a select step), as a field is typed into.
265
+ **({"picker": True} if picker else {}),
266
+ # Inside a web page of the app: where that page is on the screen, to ask it which element is there.
267
+ **({"webview": web_box} if web_box else {}),
268
+ # An item of an opened drop-down or menu: a tap on it right after a tap is one select step.
269
+ **({"menu": True} if menu else {}),
270
+ # A checkbox, switch or radio button, and whether it is on: a tap on it is "leave it on/off".
271
+ **({"checkable": True, "checked": checked} if checked is not None else {}),
231
272
  **({"secure": True} if secure else {}),
232
273
  **({"prompt": True} if prompt else {}),
233
274
  **({"inner": True} if via else {}),
@@ -248,10 +289,18 @@ def _int(cmd: Mapping[str, Any], key: str, lo: int, hi: int) -> int:
248
289
  class MobileRecorder:
249
290
  """One recording: the device session, the screen last sent, and the steps so far."""
250
291
 
251
- def __init__(self, driver: Any, spec: Any, name: str, secrets: Mapping[str, str], out_dir: Path, emit: Callable[[Dict[str, Any]], None], log: Callable[..., None], settle: float = SETTLE, sleep: Callable[[float], None] = time.sleep) -> None:
292
+ def __init__(self, driver: Any, spec: Any, name: str, secrets: Mapping[str, str], out_dir: Path, emit: Callable[[Dict[str, Any]], None], log: Callable[..., None], settle: float = SETTLE, sleep: Callable[[float], None] = time.sleep, links: Any = None, clock: Callable[[], float] = time.time) -> None:
252
293
  self.driver = driver
253
294
  self.spec = spec
254
295
  self.name = name
296
+ # The kind of control the last tap was on: a tap on a drop-down's item after it is one select step.
297
+ self.last_kind = ""
298
+ # Told once: the app's web page could not be read, so its controls are found by what the screen shows.
299
+ self.web_unreadable = False
300
+ # Logins whose magic links can be read from their mailbox (magiclink.LinkOpener), and when the last command began.
301
+ self.links = links
302
+ self.clock = clock
303
+ self.cmd_at = clock()
255
304
  # name → value, of mobile.secrets that are set: typed by name, matched to keep plain text from holding one.
256
305
  self.secrets = {k: v for k, v in secrets.items() if v}
257
306
  self.out = out_dir
@@ -288,12 +337,12 @@ class MobileRecorder:
288
337
  png = self.driver.screenshot_png() or b""
289
338
  source = self.driver.source()
290
339
  platform = self.spec.platform
291
- elements = parse_screen(source, platform, self.spec.app_id)
292
340
  size = png_size(png)
293
341
  if platform == "ios" or size is None:
294
342
  # XCUITest's page source is in points, its screenshot in pixels: boxes are drawn over the window's size.
295
343
  r = self.driver.window_size()
296
344
  size = (int(r.get("width", 0)), int(r.get("height", 0)))
345
+ elements = parse_screen(source, platform, self.spec.app_id, size)
297
346
  if not self.seq or elements != self.elements or size != self.size:
298
347
  self.seq += 1
299
348
  self.recent[self.seq] = elements
@@ -319,7 +368,7 @@ class MobileRecorder:
319
368
  "width": size[0],
320
369
  "height": size[1],
321
370
  "image": bool(png),
322
- "elements": [{"box": e["box"], "label": e["label"], "kind": e["kind"], "usable": e["target"] is not None, **{k: True for k in ("field", "secure", "prompt", "inner", "other_app") if e.get(k)}} for e in self.elements],
371
+ "elements": [{"box": e["box"], "label": e["label"], "kind": e["kind"], "usable": e["target"] is not None or bool(e.get("webview")), **{k: True for k in ("field", "secure", "prompt", "inner", "other_app", "picker") if e.get(k)}} for e in self.elements],
323
372
  })
324
373
 
325
374
  def _element(self, cmd: Mapping[str, Any]) -> Dict[str, Any]:
@@ -345,10 +394,13 @@ class MobileRecorder:
345
394
  target = step["target"]
346
395
  if target not in self.dismiss:
347
396
  self.dismiss.append(target)
348
- self.emit({"type": "recorded", "index": 0, "op": "dismiss", "target": target})
397
+ self.emit(self._event(0, {"op": "dismiss", "target": target}))
349
398
  return
350
399
  if len(self.steps) >= MAX_STEPS:
351
400
  raise RecordRefused(f"A recording holds at most {MAX_STEPS} steps: stop it and record the rest as another.")
401
+ if self._fold_scrolls(step):
402
+ # The scrolls are one scroll_to now: the page's list is told the new numbers before this step is added.
403
+ self._renumber()
352
404
  self.steps.append(step)
353
405
  # The screen it was done on, until the screen after it is read (command()).
354
406
  kept = (shot, self._controls()) if shot else None
@@ -356,7 +408,79 @@ class MobileRecorder:
356
408
  index = len(self.steps)
357
409
  self._write_shot(index, kept)
358
410
  self.fresh = index
359
- self.emit({"type": "recorded", "index": index, "op": step["op"], **({"target": step["target"]} if step.get("target") else {}), **({"value": step["text"]} if isinstance(step.get("text"), str) else {}), **({"keys": step["keys"]} if step.get("keys") else {}), **({"direction": step["direction"]} if step.get("direction") else {}), **({"seconds": step["seconds"]} if step.get("seconds") is not None else {})})
411
+ if step["op"] != "tap":
412
+ self.last_kind = ""
413
+ self.emit(self._event(index, step))
414
+
415
+ def _event(self, index: int, step: Mapping[str, Any]) -> Dict[str, Any]:
416
+ """A step as the page is told it: what it does, and each locator a replay tries, as the driver sends it."""
417
+ return {"type": "recorded", **self._step_view(index, step)}
418
+
419
+ def _step_view(self, index: int, s: Mapping[str, Any]) -> Dict[str, Any]:
420
+ target = s.get("target")
421
+ return {
422
+ "index": index,
423
+ "op": s["op"],
424
+ **({"target": target} if target else {}),
425
+ **({"locators": [{"kind": using, "value": value} for using, value in pairs(target, locator_query, self.spec.platform)]} if isinstance(target, Mapping) else {}),
426
+ **({"value": s["text"]} if isinstance(s.get("text"), str) else {"value": s["value"]} if isinstance(s.get("value"), str) else {}),
427
+ **({"keys": s["keys"]} if s.get("keys") else {}),
428
+ **({"direction": s["direction"]} if s.get("direction") else {}),
429
+ **({"seconds": s["seconds"]} if s.get("seconds") is not None else {}),
430
+ **({"checked": s["checked"]} if isinstance(s.get("checked"), bool) else {}),
431
+ **({"at": list(s["at"])} if isinstance(s.get("at"), list) else {}),
432
+ **({"login": s["login"]} if isinstance(s.get("login"), str) else {}),
433
+ }
434
+
435
+ def _fold_scrolls(self, step: Mapping[str, Any]) -> bool:
436
+ """
437
+ The scrolls the tester made just before acting on a control (all the same way, on the screen, not on a control)
438
+ become one ``scroll_to`` that control: a replay scrolls until it shows, however tall the device's screen is,
439
+ instead of scrolling as far as this one needed. True when steps were folded.
440
+ """
441
+ target = step.get("target")
442
+ if step.get("op") not in FOLD_OPS or not isinstance(target, Mapping):
443
+ return False
444
+ n = 0
445
+ while n < len(self.steps) - 1:
446
+ s = self.steps[-1 - n]
447
+ if s.get("op") != "scroll" or s.get("target") or (n and s.get("direction") != self.steps[-1]["direction"]):
448
+ break
449
+ n += 1
450
+ if not n:
451
+ return False
452
+ direction = self.steps[-1]["direction"]
453
+ shot = self.shots[-1]
454
+ del self.steps[-n:]
455
+ del self.shots[-n:]
456
+ self.steps.append({"op": "scroll_to", "target": dict(target), "direction": direction})
457
+ self.shots.append(shot)
458
+ self.log(f"{n} scroll{'s' if n > 1 else ''} {direction} kept as one step: scroll {direction} until {_describe(target)} shows.")
459
+ return True
460
+
461
+ def _web_target(self, el: Mapping[str, Any], native: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]]:
462
+ """
463
+ A control inside a web page of the app: the page's own locators for the element at its centre (a test id, an
464
+ id, a field's name, a label…), each found only it, then its native locators as fallbacks. When the page
465
+ cannot be read (its web debugging is off in this build), the native locators alone, and the log says why.
466
+ """
467
+ bx, by, bw, bh = el["webview"]
468
+ x, y, w, h = el["box"]
469
+ if bw <= 0 or bh <= 0:
470
+ return native
471
+ fx, fy = (x + w / 2 - bx) / bw, (y + h / 2 - by) / bh
472
+ try:
473
+ webs = list(self.driver.web_locators(min(1.0, max(0.0, fx)), min(1.0, max(0.0, fy))))
474
+ except Exception as e: # noqa: BLE001 - the step is kept by what the screen shows, and the tester told
475
+ if not self.web_unreadable:
476
+ self.web_unreadable = True
477
+ self.log(f"The web page in the app could not be read ({str(e)[:160]}): its controls are found by what the screen shows. A build with web debugging on (WebView.setWebContentsDebuggingEnabled, or a debuggable WKWebView) lets them be found as a web page's elements.", level="warn")
478
+ return native
479
+ if not webs:
480
+ return native
481
+ natives = tried(native) if native else []
482
+ rest = [{"web": w} for w in webs[1:3]] + natives
483
+ return {"web": webs[0], **({"fallbacks": rest[:MAX_TARGET_FALLBACKS]} if rest else {})}
360
484
 
361
485
  def _renumber(self) -> None:
362
486
  """After a step was removed: the step pictures by their new numbers, and the page's list again."""
@@ -364,7 +488,7 @@ class MobileRecorder:
364
488
  f.unlink()
365
489
  for i, kept in enumerate(self.shots, 1):
366
490
  self._write_shot(i, kept)
367
- self.emit({"type": "renumbered", "steps": [{"index": i, "op": s["op"], **({"target": s["target"]} if s.get("target") else {}), **({"value": s["text"]} if isinstance(s.get("text"), str) else {"value": s["value"]} if isinstance(s.get("value"), str) else {}), **({"keys": s["keys"]} if s.get("keys") else {}), **({"direction": s["direction"]} if s.get("direction") else {})} for i, s in enumerate(self.steps, 1)]})
491
+ self.emit({"type": "renumbered", "steps": [self._step_view(i, s) for i, s in enumerate(self.steps, 1)]})
368
492
 
369
493
  def _controls(self) -> str:
370
494
  """The controls on the screen shown, as the review reads them (steps/NNN.json: its size and each control's box,
@@ -378,7 +502,7 @@ class MobileRecorder:
378
502
  x, y, bw, bh = e["box"]
379
503
  if x < 0 or y < 0 or x + bw > w or y + bh > h:
380
504
  continue
381
- controls.append({"x": x, "y": y, "w": bw, "h": bh, **{k: t[k] for k in ("automation_id", "name", "control_type") if t.get(k)}, **({"text": e["text"]} if e.get("text") else {})})
505
+ controls.append({"x": x, "y": y, "w": bw, "h": bh, **(e.get("props") or {}), **({"text": e["text"]} if e.get("text") else {})})
382
506
  return json.dumps({"w": w, "h": h, "controls": controls[:300]}, ensure_ascii=False)
383
507
 
384
508
  def _write_shot(self, index: int, kept: Optional[Tuple[bytes, str]]) -> None:
@@ -405,6 +529,8 @@ class MobileRecorder:
405
529
  raise RecordRefused("The recorder does not take that command.")
406
530
  if op == "stop":
407
531
  return False
532
+ # When the command before this one began: a magic link is the one sent since the step that asked for it.
533
+ since, self.cmd_at = self.cmd_at, self.clock()
408
534
  if op == "refresh":
409
535
  self.snapshot()
410
536
  return True
@@ -430,10 +556,17 @@ class MobileRecorder:
430
556
  if op in ELEMENT_COMMANDS:
431
557
  el = self._element(cmd)
432
558
  target = el["target"]
559
+ if el.get("webview"):
560
+ # A control of a web page inside the app: found as a web page's element first (webview.py).
561
+ target = self._web_target(el, target)
433
562
  if target is None:
434
563
  self.skipped.append({"action": f"{op} on {el['label'] or el['kind'] or 'a control'}", "reason": "it has neither an id nor a text, so a replay could not find it"})
435
564
  raise RecordRefused("That control has neither an id nor a text, so a replay could not find it: tap something with a label, or ask the app's developers for an accessibility id.")
436
565
  self._element_command(op, cmd, el, target, shot)
566
+ elif op == "tap_at":
567
+ self._tap_at(cmd, shot)
568
+ elif op == "magic_link":
569
+ self._magic_link(cmd, since, shot)
437
570
  elif op in ("swipe", "scroll"):
438
571
  direction = cmd.get("direction")
439
572
  if direction not in SWIPE_DIRECTIONS:
@@ -467,7 +600,54 @@ class MobileRecorder:
467
600
  self.snapshot()
468
601
  return True
469
602
 
603
+ def _magic_link(self, cmd: Mapping[str, Any], since: float, shot: Optional[bytes]) -> None:
604
+ """
605
+ The magic link a login's site sent since the step before (read from its mailbox), opened on the device; kept as
606
+ ``open_link: {login}``, so a replay reads the mailbox again. The link never leaves this process.
607
+ """
608
+ login = cmd.get("login")
609
+ if self.links is None or not isinstance(login, str) or login not in self.links.names():
610
+ raise RecordRefused("That login has no mailbox to read a link from: give it code: email settings and its sites in Settings › Logins.")
611
+ self.log(f"Waiting for the link {login}'s site sends to its mailbox…")
612
+ try:
613
+ self.links.open(login, since)
614
+ except WorkflowError as e:
615
+ raise RecordRefused(str(e)) from None
616
+ except Exception as e: # noqa: BLE001 - the device would not open it: said without the link
617
+ raise RecordRefused(f"The device did not open the link ({type(e).__name__}): does the app take its site's links (an App Link or Universal Link)?") from None
618
+ self.last_kind = ""
619
+ self._record({"op": "open_link", "login": login}, shot)
620
+ self.log(f"Opened the magic link from {login}'s mailbox on the device.")
621
+
622
+ def _tap_at(self, cmd: Mapping[str, Any], shot: Optional[bytes]) -> None:
623
+ """
624
+ A tap on a point where the app draws something with no control of its own (a canvas, a chart, a custom view):
625
+ kept as a tap inside the smallest control there that can be located, at its place inside it in thousandths
626
+ of its width and height (``at``), so a replay taps the same spot on any screen size.
627
+ """
628
+ seq = _int(cmd, "seq", 1, 10**9)
629
+ if seq != self.seq:
630
+ raise RecordRefused("The screen changed before that reached the device: do it again on the screen shown now.")
631
+ x, y = _int(cmd, "x", 0, 100_000), _int(cmd, "y", 0, 100_000)
632
+ inside = [e for e in self.elements if e["target"] is not None and e["box"][0] <= x < e["box"][0] + e["box"][2] and e["box"][1] <= y < e["box"][1] + e["box"][3]]
633
+ if not inside:
634
+ raise RecordRefused("Nothing there has an id or a text to tap a point inside, so a replay could not find the spot again: tap a control, or ask the app's developers for an accessibility id.")
635
+ el = min(inside, key=lambda e: e["box"][2] * e["box"][3])
636
+ bx, by, bw, bh = el["box"]
637
+ at = [min(1000, max(0, round((x - bx) * 1000 / bw))), min(1000, max(0, round((y - by) * 1000 / bh)))]
638
+ target = el["target"]
639
+ self.driver.tap_point(self._find(target), at)
640
+ self.last_kind = ""
641
+ self._record({"op": "tap", "target": target, "at": at}, shot)
642
+ self.log(f"Tap inside {_describe(target)} at {at[0] / 10:g}% across, {at[1] / 10:g}% down.")
643
+
470
644
  def _element_command(self, op: str, cmd: Mapping[str, Any], el: Mapping[str, Any], target: Dict[str, Any], shot: Optional[bytes]) -> None:
645
+ if op == "check" and el.get("checkable"):
646
+ control = self._find(target)
647
+ on = bool(self.driver.is_checked(control))
648
+ self._record({"op": "expect", "target": target, "checked": on}, shot)
649
+ self.log(f"Check: {_describe(target)} is {'on' if on else 'off'}")
650
+ return
471
651
  if op == "check":
472
652
  control = self._find(target)
473
653
  text = (self.driver.text_of(control) or "").split("\n")[0].strip()
@@ -482,6 +662,16 @@ class MobileRecorder:
482
662
  self._find(target)
483
663
  self._record({"op": "wait_for", "target": target}, shot)
484
664
  return
665
+ if op == "type" and el.get("picker"):
666
+ # An iOS picker wheel: turned to the value given, as it shows it; kept as one select step.
667
+ raw = cmd.get("text")
668
+ if cmd.get("secret") is not None or not isinstance(raw, str) or not raw.strip() or len(raw) > MAX_CHECK_TEXT or _CONTROL_CHARS.search(raw) or "{{" in raw or "}}" in raw:
669
+ raise RecordRefused("Choose a value of one line as the wheel shows it.")
670
+ value = raw.strip()
671
+ self.driver.select(self._find(target), value)
672
+ self._record({"op": "select", "target": target, "value": value}, shot)
673
+ self.log(f"Choose “{value}” in {_describe(target)}.")
674
+ return
485
675
  if op == "type":
486
676
  if not el.get("field"):
487
677
  raise RecordRefused("That is not a text field: tap the field to type into.")
@@ -509,6 +699,24 @@ class MobileRecorder:
509
699
  self._record({"op": "type", "target": target, "text": text}, shot)
510
700
  return
511
701
  control = self._find(target)
702
+ last_step = self.steps[-1] if len(self.steps) > 1 else None
703
+ # A drop-down's or a menu's item can say it is checkable (Android's CheckedTextView): it is picked, not turned on.
704
+ picking = bool(el.get("menu")) or (last_step is not None and last_step["op"] == "tap" and is_dropdown(self.last_kind))
705
+ if op == "tap" and el.get("checkable") and not el.get("prompt") and not picking:
706
+ # Left on or off, not toggled: a replay that finds it so already leaves it alone, and checks it took. The
707
+ # state is read again after the tap: a radio button already on stays on, and is kept as a plain tap.
708
+ before = bool(self.driver.is_checked(control))
709
+ self.driver.click(control)
710
+ self.last_kind = ""
711
+ self.sleep(min(self.settle, 0.5))
712
+ after = bool(self.driver.is_checked(control))
713
+ if after == before:
714
+ self._record({"op": "tap", "target": target}, shot)
715
+ self.log(f"{_describe(target)} stayed {'on' if after else 'off'} (a radio button already chosen): kept as a tap.")
716
+ return
717
+ self._record({"op": "set_checked", "target": target, "checked": after}, shot)
718
+ self.log(f"{_describe(target)} turned {'on' if after else 'off'}: kept as “leave it {'on' if after else 'off'}”.")
719
+ return
512
720
  if op == "tap":
513
721
  self.driver.click(control)
514
722
  elif op == "double_tap":
@@ -516,13 +724,19 @@ class MobileRecorder:
516
724
  else:
517
725
  self.driver.long_press(control)
518
726
  last = self.steps[-1] if len(self.steps) > 1 else None
519
- if op == "tap" and not el.get("prompt") and last and last["op"] == "tap" and is_dropdown(str(last["target"].get("control_type") or "")) and isinstance(target.get("name"), str) and target["name"].strip():
727
+ # The item's text: what a replay picks it by (its locator may be its id).
728
+ item = str(target.get("name") or el.get("text") or el.get("label") or "").strip()
729
+ # The tap before opened a drop-down (its kind says so), or this item is in the list or menu it opened.
730
+ opened = last is not None and last["op"] == "tap" and (is_dropdown(self.last_kind) or bool(el.get("menu")))
731
+ self.last_kind = str(el.get("kind") or "") if op == "tap" else ""
732
+ if op == "tap" and not el.get("prompt") and opened and item:
520
733
  # The item picked in the drop-down the last step opened: one step that picks it by its text.
521
- self.steps[-1] = {"op": "select", "target": last["target"], "value": target["name"]}
734
+ self.steps[-1] = {"op": "select", "target": last["target"], "value": item}
522
735
  index = len(self.steps)
523
736
  self.fresh = index
524
- self.emit({"type": "recorded", "index": index, "op": "select", "target": last["target"], "value": target["name"]})
525
- self.log(f"Choose “{target['name']}” in {_describe(last['target'])}: kept as one step.")
737
+ self.last_kind = ""
738
+ self.emit(self._event(index, self.steps[-1]))
739
+ self.log(f"Choose “{item}” in {_describe(last['target'])}: kept as one step.")
526
740
  elif op == "tap" and el.get("prompt"):
527
741
  self._record({"op": "tap", "target": target}, shot, dismiss=True)
528
742
  self.log(f"“{el['label']}” answers a system prompt: kept in the workflow's dismiss list, tapped whenever a replay is asked.")
@@ -553,7 +767,10 @@ def run_record(req: Mapping[str, Any], events: Any, stop: Any, commands: "queue.
553
767
  try:
554
768
  events.log(f"Starting {app} on the device (a device cloud can take a minute or two)…")
555
769
  driver.launch(spec)
556
- recorder = MobileRecorder(driver, spec, name, secrets, out, events.emit, events.log, settle=settle, sleep=sleep)
770
+ from .magiclink import LinkOpener, mail_logins
771
+
772
+ logins = mail_logins(req.get("logins"))
773
+ recorder = MobileRecorder(driver, spec, name, secrets, out, events.emit, events.log, settle=settle, sleep=sleep, links=LinkOpener(driver, logins, sleep=sleep) if logins else None)
557
774
  recorder.snapshot()
558
775
  events.log("Recording: tap, type and swipe on the screen here; each action is done on the device and becomes a step.")
559
776
  while not stop.is_set():
@@ -89,6 +89,14 @@ def _maestro_env(req: Mapping[str, Any], names: List[str], secrets: Mapping[str,
89
89
  return env
90
90
 
91
91
 
92
+ def _link_opener(driver: Any, req: Mapping[str, Any]) -> Optional[Callable[[str, float], None]]:
93
+ """Opens a login's magic link from its mailbox (magiclink.py), when the request has logins with one."""
94
+ from .magiclink import LinkOpener, mail_logins
95
+
96
+ logins = mail_logins(req.get("logins"))
97
+ return LinkOpener(driver, logins).open if logins else None
98
+
99
+
92
100
  def run_replay(req: Mapping[str, Any], events: Events, stop: threading.Event, driver_factory: Optional[Callable[[], Any]] = None, model_factory: Optional[Callable[..., Any]] = None, maestro_run: Optional[Callable[..., Any]] = None, cloud_run: Optional[Callable[..., Any]] = None) -> Dict[str, Any]:
93
101
  out = _out_dir(req)
94
102
  mobile = _mobile(req)
@@ -169,6 +177,7 @@ def run_replay(req: Mapping[str, Any], events: Events, stop: threading.Event, dr
169
177
  on_step=on_step,
170
178
  should_stop=stop.is_set,
171
179
  compare_image=image_checker(workflow_file, out, update=bool(req.get("update_baselines"))),
180
+ open_link=_link_opener(driver, req),
172
181
  )
173
182
  settle = getattr(heal, "settle", None)
174
183
  if settle is not None: