@aarwitz/tapp 0.35.6 → 0.35.8
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.
- package/.claude-plugin/plugin.json +2 -2
- package/AGENTS.md +13 -1
- package/Harness/OCQAHarnessUITests/ExplorerTests.swift +242 -32
- package/bin/tapp.js +96 -1
- package/browser/app.css +90 -1
- package/browser/app.js +295 -14
- package/browser/index.html +36 -1
- package/browser/product-contract.js +11 -0
- package/browser/view-model.js +185 -0
- package/docs/BROWSER-PRODUCT.md +54 -8
- package/mcp-server/src/account-store.js +46 -2
- package/mcp-server/src/android-flow.js +5 -0
- package/mcp-server/src/browser-product.js +136 -3
- package/mcp-server/src/flow-recording.js +27 -3
- package/mcp-server/src/flow-runtime.js +20 -2
- package/mcp-server/src/index.js +5 -4
- package/mcp-server/src/journeys.js +29 -1
- package/mcp-server/src/macos-flow.js +2 -0
- package/mcp-server/src/sim-recorder.js +273 -0
- package/mcp-server/src/studio-client.js +47 -1
- package/mcp-server/src/web-audit.js +2 -2
- package/mcp-server/src/web-explorer.js +51 -3
- package/mcp-server/src/web-flow.js +120 -5
- package/package.json +2 -2
- package/scripts/ci-gate.sh +1 -1
- package/scripts/flow_lib.py +4 -1
- package/scripts/quick-capture.sh +44 -24
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tapp",
|
|
3
3
|
"description": "Give Claude hands and eyes on iOS, Android, and web apps, with exploration, replayable flows, evidence, and deterministic CI gates.",
|
|
4
|
-
"version": "0.35.
|
|
4
|
+
"version": "0.35.8",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aaron Horowitz",
|
|
7
7
|
"url": "https://github.com/aarwitz"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"command": "npx",
|
|
25
25
|
"args": [
|
|
26
26
|
"-y",
|
|
27
|
-
"@aarwitz/tapp@0.35.
|
|
27
|
+
"@aarwitz/tapp@0.35.8",
|
|
28
28
|
"mcp"
|
|
29
29
|
],
|
|
30
30
|
"cwd": "${CLAUDE_PROJECT_DIR}"
|
package/AGENTS.md
CHANGED
|
@@ -58,7 +58,19 @@ Tapp's current action and pointer; the overlay is omitted from evidence screensh
|
|
|
58
58
|
drive the person's existing/default browser profile.
|
|
59
59
|
|
|
60
60
|
The interactive session/record loop is MCP-only (it needs a long-lived process). Flow replay is
|
|
61
|
-
also available in the CLI.
|
|
61
|
+
also available in the CLI.
|
|
62
|
+
|
|
63
|
+
To film an iOS Flow, `tapp run <flow.yml> --record take.mp4 [--hold 3s]` records the simulator and
|
|
64
|
+
writes `take.steps.json` beside it: every step in the video's own seconds, so a cut can be made by
|
|
65
|
+
step name instead of off a contact sheet. `--hold` keeps the last screen on screen for that long —
|
|
66
|
+
it has to be added to the file afterwards, because the simulator records changes rather than
|
|
67
|
+
frames and a motionless screen records nothing. Needs ffmpeg on the machine.
|
|
68
|
+
|
|
69
|
+
A one-time system alert ("Allow notifications", "You have changed the icon") belongs to iOS rather
|
|
70
|
+
than to the app, so a Flow's own `tap:` reaches it only by its exact button label. `alerts: allow`
|
|
71
|
+
or `alerts: dismiss` at the top of an iOS Flow clears whichever one appears and records which
|
|
72
|
+
button was pressed, which is what keeps a journey replayable when the alert shows up on some runs
|
|
73
|
+
and not others. The rest of this playbook assumes the `tapp_*` MCP tools are connected. With
|
|
62
74
|
MCP, the no-bundle-id path is: `tapp_build {projectDir}` (auto-detects + builds +
|
|
63
75
|
installs, returns the bundle id) → `tapp_explore {appBundleId}`.
|
|
64
76
|
|
|
@@ -12,6 +12,17 @@ import XCTest
|
|
|
12
12
|
/// - testDumpUITree: One-shot accessibility tree dump
|
|
13
13
|
/// - testTapAtCoordinate / testTapById: Single action for engine control
|
|
14
14
|
/// - testScreenshot: Capture and attach a screenshot
|
|
15
|
+
extension XCUIElementQuery {
|
|
16
|
+
/// XCUITest raises NSInternalInconsistencyException for an identifier subscript longer than
|
|
17
|
+
/// 128 characters, which ends the whole run. Longer text is matched with a predicate on
|
|
18
|
+
/// label, value, title or identifier instead, so it is found like short text.
|
|
19
|
+
func byText(_ text: String) -> XCUIElement {
|
|
20
|
+
if text.count <= 128 { return self[text] }
|
|
21
|
+
let predicate = NSPredicate(format: "label == %@ OR value == %@ OR title == %@ OR identifier == %@", text, text, text, text)
|
|
22
|
+
return matching(predicate).firstMatch
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
class ExplorerTests: XCTestCase {
|
|
16
27
|
|
|
17
28
|
private struct InputDescriptor {
|
|
@@ -154,7 +165,7 @@ class ExplorerTests: XCTestCase {
|
|
|
154
165
|
addUIInterruptionMonitor(withDescription: "System Alert") { alert in
|
|
155
166
|
let allowLabels = ["Allow", "Allow While Using App", "OK", "Continue", "Allow Full Access"]
|
|
156
167
|
for label in allowLabels {
|
|
157
|
-
let btn = alert.buttons
|
|
168
|
+
let btn = alert.buttons.byText(label)
|
|
158
169
|
if btn.exists {
|
|
159
170
|
btn.tap()
|
|
160
171
|
return true
|
|
@@ -229,7 +240,7 @@ class ExplorerTests: XCTestCase {
|
|
|
229
240
|
app.links, app.switches, app.textFields
|
|
230
241
|
]
|
|
231
242
|
for query in queries {
|
|
232
|
-
let element = query
|
|
243
|
+
let element = query.byText(identifier)
|
|
233
244
|
if element.exists && element.isHittable {
|
|
234
245
|
if !waitForEnabled(element) {
|
|
235
246
|
print("OCQA_ACTION:{\"type\":\"tap\",\"identifier\":\"\(identifier)\",\"status\":\"disabled\"}")
|
|
@@ -282,14 +293,14 @@ class ExplorerTests: XCTestCase {
|
|
|
282
293
|
}
|
|
283
294
|
let identifier = resolve("OCQA_TYPE_ID")
|
|
284
295
|
if !identifier.isEmpty {
|
|
285
|
-
let field = app.textFields
|
|
296
|
+
let field = app.textFields.byText(identifier)
|
|
286
297
|
if field.exists {
|
|
287
298
|
field.tap()
|
|
288
299
|
field.typeText(text)
|
|
289
300
|
print("OCQA_ACTION:{\"type\":\"typeText\",\"identifier\":\"\(identifier)\"}")
|
|
290
301
|
return
|
|
291
302
|
}
|
|
292
|
-
let secure = app.secureTextFields
|
|
303
|
+
let secure = app.secureTextFields.byText(identifier)
|
|
293
304
|
if secure.exists {
|
|
294
305
|
secure.tap()
|
|
295
306
|
secure.typeText(text)
|
|
@@ -487,12 +498,85 @@ class ExplorerTests: XCTestCase {
|
|
|
487
498
|
|
|
488
499
|
private var backTitleHistory: [String] = []
|
|
489
500
|
|
|
501
|
+
/// A system alert belongs to SpringBoard, not to the app, so a Flow's `tap: OK` cannot reach it
|
|
502
|
+
/// and the step fails on a button the author can plainly see. A field case: changing an app's
|
|
503
|
+
/// theme switched its icon, iOS asked "You have changed the icon for <app>", and the flow for
|
|
504
|
+
/// that screen stopped after one choice.
|
|
505
|
+
private func systemAlertButton(labelled label: String) -> XCUIElement? {
|
|
506
|
+
let alert = XCUIApplication(bundleIdentifier: "com.apple.springboard").alerts.firstMatch
|
|
507
|
+
guard alert.exists else { return nil }
|
|
508
|
+
// By label, not by subscript: `alert.buttons["Allow"]` matched "Allow Once" on an alert
|
|
509
|
+
// that has no "Allow" at all, so a flow asking for a button that is not there pressed a
|
|
510
|
+
// different one and passed.
|
|
511
|
+
let wanted = alertLabelKey(label)
|
|
512
|
+
return alert.buttons.allElementsBoundByIndex
|
|
513
|
+
.first { alertLabelKey($0.label) == wanted && $0.exists && $0.isHittable }
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/// The labels an `alerts:` setting will press, and nothing else.
|
|
517
|
+
///
|
|
518
|
+
/// Matched through `alertLabelKey`, because iOS writes "Don\u{2019}t Allow" with a typographic
|
|
519
|
+
/// apostrophe: a list spelled with the ASCII one matched nothing at all, the dismiss mode
|
|
520
|
+
/// silently did nothing, and the run still reported a pass (found by running it against Maps).
|
|
521
|
+
private static let alertAllowLabels = ["Allow While Using App", "Allow Once", "Allow", "OK", "Continue"]
|
|
522
|
+
private static let alertDismissLabels = ["Don't Allow", "Not Now", "Cancel", "Dismiss", "Later"]
|
|
523
|
+
|
|
524
|
+
/// Compare alert labels the way a person reads them: either apostrophe, any case.
|
|
525
|
+
private func alertLabelKey(_ label: String) -> String {
|
|
526
|
+
label.replacingOccurrences(of: "\u{2019}", with: "'")
|
|
527
|
+
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
528
|
+
.lowercased()
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/// Clear a one-time system alert standing between the flow and the app (TM-497).
|
|
532
|
+
///
|
|
533
|
+
/// Three of the eight takes on 11/7 were re-recorded because of these. Returns the button it
|
|
534
|
+
/// pressed, so the run records that it diverged from the script rather than quietly doing it.
|
|
535
|
+
///
|
|
536
|
+
/// Only a recognised label, or a single-button alert. An unrecognised alert with a choice in it
|
|
537
|
+
/// is left alone and the step fails naming its buttons: guessing on a dialog about permissions,
|
|
538
|
+
/// money or deletion is worse than stopping.
|
|
539
|
+
private func handleSystemAlert(mode: String) -> String? {
|
|
540
|
+
let alert = XCUIApplication(bundleIdentifier: "com.apple.springboard").alerts.firstMatch
|
|
541
|
+
guard alert.exists else { return nil }
|
|
542
|
+
let wanted = (mode == "dismiss" ? Self.alertDismissLabels : Self.alertAllowLabels).map(alertLabelKey)
|
|
543
|
+
let present = alert.buttons.allElementsBoundByIndex
|
|
544
|
+
for key in wanted {
|
|
545
|
+
if let button = present.first(where: { alertLabelKey($0.label) == key && $0.exists && $0.isHittable }) {
|
|
546
|
+
let label = button.label
|
|
547
|
+
button.tap()
|
|
548
|
+
waitForUIStability(timeout: 1.5)
|
|
549
|
+
return label
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if alert.buttons.count == 1 {
|
|
553
|
+
let button = alert.buttons.element(boundBy: 0)
|
|
554
|
+
let label = button.label
|
|
555
|
+
button.tap()
|
|
556
|
+
waitForUIStability(timeout: 1.5)
|
|
557
|
+
return label
|
|
558
|
+
}
|
|
559
|
+
return nil
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/// What a system alert offers, for a failure message that names the way out.
|
|
563
|
+
private func systemAlertButtonLabels() -> [String] {
|
|
564
|
+
let alert = XCUIApplication(bundleIdentifier: "com.apple.springboard").alerts.firstMatch
|
|
565
|
+
guard alert.exists else { return [] }
|
|
566
|
+
return alert.buttons.allElementsBoundByIndex.map { $0.label }.filter { !$0.isEmpty }
|
|
567
|
+
}
|
|
568
|
+
|
|
490
569
|
private func sessionTapById(_ identifier: String) -> String {
|
|
491
570
|
var existedButNotHittable = false
|
|
492
571
|
var existedButDisabled = false
|
|
572
|
+
var existedButCovered = false
|
|
493
573
|
func tryTap(_ el: XCUIElement) -> Bool {
|
|
494
574
|
guard el.exists else { return false }
|
|
495
575
|
if !waitForEnabled(el) { existedButDisabled = true; return false }
|
|
576
|
+
// TM-897: isHittable is true for an element only partly under the tab bar, and the
|
|
577
|
+
// touch at its centre then lands on the tab bar. Treat that as not reachable so the
|
|
578
|
+
// scroll below runs, and a tap that still cannot clear the bar fails, never passes.
|
|
579
|
+
if el.isHittable && coveredByTabBar(el) { existedButCovered = true; existedButNotHittable = true; return false }
|
|
496
580
|
if el.isHittable { el.tap(); return true }
|
|
497
581
|
// Often covered by the keyboard (a submit button below filled fields) — dismiss + retry,
|
|
498
582
|
// like Playwright auto-scrolls a target into view.
|
|
@@ -502,7 +586,18 @@ class ExplorerTests: XCTestCase {
|
|
|
502
586
|
return false
|
|
503
587
|
}
|
|
504
588
|
let queries: [XCUIElementQuery] = [app.buttons, app.staticTexts, app.cells, app.links, app.switches, app.textFields, app.secureTextFields, app.textViews]
|
|
505
|
-
|
|
589
|
+
// TM-922: enumerate rather than subscript. subscripting a query by identifier resolves to ONE element, and
|
|
590
|
+
// when a screen hidden under a full-screen cover shares the identifier XCTest aborts the run
|
|
591
|
+
// with "Multiple matching elements found". Enumerating lets the visible one win.
|
|
592
|
+
lastAmbiguity = ""
|
|
593
|
+
func tryTapNamed(_ query: XCUIElementQuery) -> Bool {
|
|
594
|
+
guard let el = preferVisible(query.matching(identifier: identifier).allElementsBoundByIndex, name: identifier) else { return false }
|
|
595
|
+
return tryTap(el)
|
|
596
|
+
}
|
|
597
|
+
for query in queries {
|
|
598
|
+
if tryTapNamed(query) { return "ok" }
|
|
599
|
+
if !lastAmbiguity.isEmpty { return "ambiguous" }
|
|
600
|
+
}
|
|
506
601
|
// Exact label, then a forgiving case-insensitive "contains" match so callers can tap by the
|
|
507
602
|
// visible text they see in the tree without an exact accessibility id.
|
|
508
603
|
let exactMatches = app.descendants(matching: .any).matching(NSPredicate(format: "label == %@", identifier)).allElementsBoundByIndex
|
|
@@ -516,7 +611,10 @@ class ExplorerTests: XCTestCase {
|
|
|
516
611
|
for _ in 0..<3 {
|
|
517
612
|
app.swipeUp()
|
|
518
613
|
Thread.sleep(forTimeInterval: 0.25)
|
|
519
|
-
for query in queries
|
|
614
|
+
for query in queries {
|
|
615
|
+
if tryTapNamed(query) { return "ok" }
|
|
616
|
+
if !lastAmbiguity.isEmpty { return "ambiguous" }
|
|
617
|
+
}
|
|
520
618
|
let scrolledExact = app.descendants(matching: .any).matching(NSPredicate(format: "label == %@", identifier)).allElementsBoundByIndex
|
|
521
619
|
for match in scrolledExact where tryTap(match) { return "ok" }
|
|
522
620
|
let scrolledContains = app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS[c] %@", identifier)).allElementsBoundByIndex
|
|
@@ -527,12 +625,53 @@ class ExplorerTests: XCTestCase {
|
|
|
527
625
|
// label) — "Password" must reach the secureTextField or a later `type` lands in whatever
|
|
528
626
|
// field still has keyboard focus.
|
|
529
627
|
if let field = resolveFieldByHint(identifier), tryTap(field) { return "ok" }
|
|
628
|
+
if !lastAmbiguity.isEmpty { return "ambiguous" }
|
|
530
629
|
// "disabled" outranks the others: the control was found and refused to act, which
|
|
531
630
|
// is a different answer from "it is not here" and needs a different fix.
|
|
532
631
|
if existedButDisabled { return "disabled" }
|
|
632
|
+
if existedButCovered { return "covered" }
|
|
533
633
|
return existedButNotHittable ? "not_hittable" : "not_found"
|
|
534
634
|
}
|
|
535
635
|
|
|
636
|
+
/// TM-922: what the last lookup could not choose between, in plain words. Empty when it chose.
|
|
637
|
+
private var lastAmbiguity = ""
|
|
638
|
+
|
|
639
|
+
/// Of several elements sharing one name, the one the person can see. A box on a screen hidden
|
|
640
|
+
/// under a full-screen cover keeps its accessibility identifier but is not hittable, so the
|
|
641
|
+
/// visible one wins. With none visible the first is returned (the caller reports why it can't
|
|
642
|
+
/// be reached); with two visible at different places this sets `lastAmbiguity` and returns nil.
|
|
643
|
+
private func preferVisible(_ matches: [XCUIElement], name: String) -> XCUIElement? {
|
|
644
|
+
let live = matches.filter { $0.exists }
|
|
645
|
+
guard live.count > 1 else { return live.first }
|
|
646
|
+
let visible = live.filter { $0.isHittable }
|
|
647
|
+
if visible.count == 1 { return visible[0] }
|
|
648
|
+
if visible.isEmpty { return live[0] }
|
|
649
|
+
var distinct: [XCUIElement] = []
|
|
650
|
+
for el in visible where !distinct.contains(where: { $0.frame == el.frame }) { distinct.append(el) }
|
|
651
|
+
if distinct.count == 1 { return distinct[0] }
|
|
652
|
+
let described = distinct.map { el -> String in
|
|
653
|
+
let f = el.frame
|
|
654
|
+
return "‘\(fieldDesc(el))’ at \(Int(f.minX)),\(Int(f.minY))"
|
|
655
|
+
}.joined(separator: " and ")
|
|
656
|
+
lastAmbiguity = "‘\(name)’ matches \(distinct.count) boxes that are all on screen — \(described) — so tapp cannot tell which one you mean; give the one you want a more specific name"
|
|
657
|
+
return nil
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/// True when the point a tap would touch (the element's centre) sits under the app's tab bar
|
|
661
|
+
/// and the element is not itself a tab bar item (TM-897).
|
|
662
|
+
private func coveredByTabBar(_ el: XCUIElement) -> Bool {
|
|
663
|
+
let bar = app.tabBars.firstMatch
|
|
664
|
+
guard bar.exists, bar.isHittable, let elFrame = (try? el.snapshot())?.frame else { return false }
|
|
665
|
+
let barFrame = bar.frame
|
|
666
|
+
guard barFrame.height > 0,
|
|
667
|
+
barFrame.contains(CGPoint(x: elFrame.midX, y: elFrame.midY)) else { return false }
|
|
668
|
+
let isTabItem = bar.descendants(matching: .any).allElementsBoundByIndex.contains {
|
|
669
|
+
guard let f = (try? $0.snapshot())?.frame else { return false }
|
|
670
|
+
return f == elFrame
|
|
671
|
+
}
|
|
672
|
+
return !isTabItem
|
|
673
|
+
}
|
|
674
|
+
|
|
536
675
|
/// Resolve a text/secure field by accessibility id, label, or placeholder (exact first, then
|
|
537
676
|
/// case-insensitive contains), then by semantic keyword ("password" → first secure field;
|
|
538
677
|
/// "email"/"username" → first plain text field). Subscript queries miss placeholder-named
|
|
@@ -564,10 +703,18 @@ class ExplorerTests: XCTestCase {
|
|
|
564
703
|
// highest on screen, so a field whose label happens to equal the hint would beat the
|
|
565
704
|
// field actually named that — precedence the identifier subscripts used to provide, and
|
|
566
705
|
// which was lost when this resolver moved in front of them (caught in review, TM-496).
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
706
|
+
// TM-922: a tier can match several boxes (a sign-in screen still sitting under a full-screen
|
|
707
|
+
// cover). The visible one wins; two visible ones is reported, not guessed at.
|
|
708
|
+
lastAmbiguity = ""
|
|
709
|
+
let tiers: [((identifier: String, label: String, placeholder: String)) -> Bool] = [
|
|
710
|
+
{ $0.identifier == h }, { $0.label == h }, { $0.placeholder == h },
|
|
711
|
+
{ "\($0.identifier) \($0.label) \($0.placeholder)".contains(h) },
|
|
712
|
+
]
|
|
713
|
+
for tier in tiers {
|
|
714
|
+
let hits = described.filter { tier(($0.identifier, $0.label, $0.placeholder)) }.map { $0.element }
|
|
715
|
+
if hits.isEmpty { continue }
|
|
716
|
+
return preferVisible(hits, name: hint)
|
|
717
|
+
}
|
|
571
718
|
if h.contains("password") {
|
|
572
719
|
let secure = app.secureTextFields.firstMatch
|
|
573
720
|
if secure.exists { return secure }
|
|
@@ -611,7 +758,7 @@ class ExplorerTests: XCTestCase {
|
|
|
611
758
|
// SwiftUI apps don't resign focus on background taps by default.
|
|
612
759
|
let kb = app.keyboards.firstMatch
|
|
613
760
|
for label in ["Done", "done", "Return", "return", "Go", "go"] {
|
|
614
|
-
let key = kb.buttons
|
|
761
|
+
let key = kb.buttons.byText(label)
|
|
615
762
|
if key.exists && key.isHittable {
|
|
616
763
|
key.tap()
|
|
617
764
|
Thread.sleep(forTimeInterval: 0.4)
|
|
@@ -648,7 +795,7 @@ class ExplorerTests: XCTestCase {
|
|
|
648
795
|
let deadline = Date().addingTimeInterval(Double(timeoutMs) / 1000.0)
|
|
649
796
|
repeat {
|
|
650
797
|
let queries: [XCUIElementQuery] = [app.buttons, app.staticTexts, app.cells, app.links, app.switches, app.textFields, app.otherElements]
|
|
651
|
-
for q in queries where q
|
|
798
|
+
for q in queries where q.byText(target).exists { return true }
|
|
652
799
|
if app.descendants(matching: .any).matching(NSPredicate(format: "label == %@ OR label CONTAINS[c] %@", target, target)).firstMatch.exists { return true }
|
|
653
800
|
Thread.sleep(forTimeInterval: 0.3)
|
|
654
801
|
} while Date() < deadline
|
|
@@ -669,7 +816,7 @@ class ExplorerTests: XCTestCase {
|
|
|
669
816
|
// submits, and append-on-retry turns "Lemonade" into "LemonadeLemonade" — a malformed
|
|
670
817
|
// credential the server rejects with no visible cause.
|
|
671
818
|
if let id = id, !id.isEmpty {
|
|
672
|
-
// Enumerate before subscripting. `app.textFields
|
|
819
|
+
// Enumerate before subscripting. `app.textFields.byText(hint)` builds a query against
|
|
673
820
|
// IDENTIFIERS, and resolving one of those against a SwiftUI `TextField(axis:
|
|
674
821
|
// .vertical)` raises "Failed to get matching snapshot … Automation type mismatch:
|
|
675
822
|
// computed TextField from legacy attrib", which aborts the whole run instead of
|
|
@@ -680,7 +827,8 @@ class ExplorerTests: XCTestCase {
|
|
|
680
827
|
guard replaceText(on: field, with: text) else { return false }
|
|
681
828
|
lastTypedInto = fieldDesc(field); return true
|
|
682
829
|
}
|
|
683
|
-
|
|
830
|
+
if !lastAmbiguity.isEmpty { lastTypeFailure = lastAmbiguity; return false }
|
|
831
|
+
for field in [app.textFields.byText(id), app.secureTextFields.byText(id), app.textViews.byText(id)] where field.exists {
|
|
684
832
|
guard replaceText(on: field, with: text) else { return false }
|
|
685
833
|
lastTypedInto = fieldDesc(field); return true
|
|
686
834
|
}
|
|
@@ -755,7 +903,7 @@ class ExplorerTests: XCTestCase {
|
|
|
755
903
|
// iOS offers to save the password after a successful sign-in — never wanted
|
|
756
904
|
// in QA; decline so login lands on the app's real post-auth screen.
|
|
757
905
|
for label in ["Not Now", "Not now", "Never", "Never for This Website"] {
|
|
758
|
-
let b = app.buttons
|
|
906
|
+
let b = app.buttons.byText(label)
|
|
759
907
|
if b.exists && b.isHittable {
|
|
760
908
|
b.tap()
|
|
761
909
|
waitForAnimationsToSettle()
|
|
@@ -875,7 +1023,7 @@ class ExplorerTests: XCTestCase {
|
|
|
875
1023
|
}
|
|
876
1024
|
// 1. An explicit dismissal control, in the app and in SpringBoard (extensions live there).
|
|
877
1025
|
for label in ["Close", "Cancel", "Done", "Dismiss"] {
|
|
878
|
-
for candidate in [app.buttons
|
|
1026
|
+
for candidate in [app.buttons.byText(label), XCUIApplication(bundleIdentifier: "com.apple.springboard").buttons.byText(label)] {
|
|
879
1027
|
if candidate.exists && candidate.isHittable {
|
|
880
1028
|
candidate.tap()
|
|
881
1029
|
waitForUIStability(timeout: 1.5)
|
|
@@ -907,7 +1055,7 @@ class ExplorerTests: XCTestCase {
|
|
|
907
1055
|
private func tapSystemSheetButton(_ identifier: String) -> Bool {
|
|
908
1056
|
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
|
|
909
1057
|
for query in [springboard.buttons, springboard.staticTexts] {
|
|
910
|
-
let element = query
|
|
1058
|
+
let element = query.byText(identifier)
|
|
911
1059
|
if element.exists && element.isHittable { element.tap(); return true }
|
|
912
1060
|
}
|
|
913
1061
|
let matches = springboard.descendants(matching: .any)
|
|
@@ -1046,6 +1194,10 @@ class ExplorerTests: XCTestCase {
|
|
|
1046
1194
|
// Per-flow wait default (field issue #20): a splash that prefetches for ~8s makes the
|
|
1047
1195
|
// fixed 6s wait_for fail on a healthy app. Steps may still override individually.
|
|
1048
1196
|
let flowDefaultTimeoutMs = (flow["timeoutMs"] as? Int) ?? (flow["timeout"] as? Int) ?? 6000
|
|
1197
|
+
// `alerts: allow|dismiss` (TM-497). One-time system alerts — "Allow notifications", "You
|
|
1198
|
+
// have changed the icon" — appear on some runs and not others and belong to SpringBoard,
|
|
1199
|
+
// not the app, so without this they stop the flow dead on a screen nobody scripted.
|
|
1200
|
+
let alertMode = ((flow["alerts"] as? String) ?? "").lowercased()
|
|
1049
1201
|
// XCTest runs teardown blocks even when a step aborts unexpectedly. Keep the final
|
|
1050
1202
|
// visible frame inspectable for both successful and failing replays (public issue #26).
|
|
1051
1203
|
addTeardownBlock { [self] in recordFlowScreenshot(name: "flow-final") }
|
|
@@ -1088,6 +1240,16 @@ class ExplorerTests: XCTestCase {
|
|
|
1088
1240
|
var failed = 0
|
|
1089
1241
|
var executed = 0
|
|
1090
1242
|
var aiIndex = 0
|
|
1243
|
+
// TM-497: every step says when it happened, in milliseconds from the flow's start, so a
|
|
1244
|
+
// recording can be cut by step name. The JavaScript runners have carried this since the
|
|
1245
|
+
// first half of the story; iOS has its own loop and did not, which meant the one platform
|
|
1246
|
+
// the demo videos are made on was the one platform whose steps had no times.
|
|
1247
|
+
//
|
|
1248
|
+
// Contiguous by construction: a step starts where the previous one ended, so its window
|
|
1249
|
+
// carries its own settling and waiting — the seconds an editor is looking for.
|
|
1250
|
+
let flowStartedAt = Date()
|
|
1251
|
+
print("OCQA_FLOW_CLOCK:{\"startedAtEpochMs\":\(Int(flowStartedAt.timeIntervalSince1970 * 1000))}")
|
|
1252
|
+
var stepStartMs = 0
|
|
1091
1253
|
for (i, raw) in steps.enumerated() {
|
|
1092
1254
|
let idx = i + 1
|
|
1093
1255
|
executed = idx
|
|
@@ -1100,10 +1262,22 @@ class ExplorerTests: XCTestCase {
|
|
|
1100
1262
|
let timeoutMs = (step["timeoutMs"] as? Int) ?? (step["timeout"] as? Int) ?? flowDefaultTimeoutMs
|
|
1101
1263
|
var status = "pass"
|
|
1102
1264
|
var detail = ""
|
|
1265
|
+
// Before the step, not after: an alert on screen is what makes the step fail.
|
|
1266
|
+
var alertNote = ""
|
|
1267
|
+
if alertMode == "allow" || alertMode == "dismiss", let pressed = handleSystemAlert(mode: alertMode) {
|
|
1268
|
+
alertNote = "a system alert was \(alertMode == "dismiss" ? "dismissed" : "allowed") first: pressed ‘\(escapeJSON(pressed))’"
|
|
1269
|
+
}
|
|
1103
1270
|
|
|
1104
1271
|
switch action {
|
|
1105
1272
|
case "tap":
|
|
1106
|
-
|
|
1273
|
+
var tapStatus = sessionTapById(target)
|
|
1274
|
+
// TM-686: the button really is on screen, it just belongs to SpringBoard.
|
|
1275
|
+
if tapStatus != "ok", let alertButton = systemAlertButton(labelled: target) {
|
|
1276
|
+
alertButton.tap()
|
|
1277
|
+
waitForUIStability(timeout: 1.5)
|
|
1278
|
+
tapStatus = "ok"
|
|
1279
|
+
detail = "‘\(escapeJSON(target))’ is a system alert's button, not the app's"
|
|
1280
|
+
}
|
|
1107
1281
|
status = tapStatus == "ok" ? "pass" : "fail"
|
|
1108
1282
|
if status == "fail" {
|
|
1109
1283
|
// Name which of the three it was. "Disabled" in particular sends the
|
|
@@ -1112,9 +1286,15 @@ class ExplorerTests: XCTestCase {
|
|
|
1112
1286
|
// whatever guards it.
|
|
1113
1287
|
switch tapStatus {
|
|
1114
1288
|
case "disabled": detail = "‘\(target)’ is on screen but disabled — an earlier step has not met whatever enables it"
|
|
1289
|
+
case "covered": detail = "‘\(target)’ is on screen but sits under the tab bar, and scrolling did not clear it — a tap there would open a tab instead"
|
|
1115
1290
|
case "not_hittable": detail = "‘\(target)’ exists but could not be reached, even after dismissing the keyboard and scrolling"
|
|
1291
|
+
case "ambiguous": detail = lastAmbiguity
|
|
1116
1292
|
default: detail = "could not find ‘\(target)’ on this screen"
|
|
1117
1293
|
}
|
|
1294
|
+
let alertButtons = systemAlertButtonLabels()
|
|
1295
|
+
if !alertButtons.isEmpty {
|
|
1296
|
+
detail += " — a system alert is in the way, offering \(escapeJSON(alertButtons.joined(separator: ", "))); add `alerts: allow` or `alerts: dismiss` to the flow, or tap one of them"
|
|
1297
|
+
}
|
|
1118
1298
|
}
|
|
1119
1299
|
case "type":
|
|
1120
1300
|
status = sessionType(value, id: target.isEmpty ? nil : target) ? "pass" : "fail"
|
|
@@ -1131,6 +1311,13 @@ class ExplorerTests: XCTestCase {
|
|
|
1131
1311
|
if detail.lowercased().contains("accessing the keychain") {
|
|
1132
1312
|
detail += " — simulator keychain is stale; `xcrun simctl erase <udid>` (or Device ▸ Erase All Content and Settings) usually fixes Firebase keychain errors"
|
|
1133
1313
|
}
|
|
1314
|
+
} else if let pressed = handleSystemAlert(mode: "dismiss") {
|
|
1315
|
+
// TM-996: iOS's own "Save Password?" offer follows a real sign-in
|
|
1316
|
+
// unpredictably — only some runs, regardless of the flow's own `alerts:`
|
|
1317
|
+
// setting, since no flow author expects it. Checked here, once, right
|
|
1318
|
+
// after login succeeds, rather than asking every flow to anticipate it.
|
|
1319
|
+
let loginAlertNote = "a system alert was dismissed after signing in: pressed ‘\(escapeJSON(pressed))’"
|
|
1320
|
+
alertNote = alertNote.isEmpty ? loginAlertNote : "\(alertNote); \(loginAlertNote)"
|
|
1134
1321
|
}
|
|
1135
1322
|
case "swipe":
|
|
1136
1323
|
switch target.lowercased() { case "down": app.swipeDown(); case "left": app.swipeLeft(); case "right": app.swipeRight(); default: app.swipeUp() }
|
|
@@ -1140,6 +1327,23 @@ class ExplorerTests: XCTestCase {
|
|
|
1140
1327
|
// screen and fail somewhere unrelated.
|
|
1141
1328
|
status = sessionBack() == "ok" ? "pass" : "fail"
|
|
1142
1329
|
if status == "fail" { detail = "back did not navigate: no back control on this screen, or tapping it did not change the screen\(visibleLabelsHint())" }
|
|
1330
|
+
case "open_url":
|
|
1331
|
+
// A journey starting from an email link ("tap the sign-in link in your receipt")
|
|
1332
|
+
// opens it the way the system would hand it to the app under test — not a debug
|
|
1333
|
+
// hook or a shell wrapper that writes a token into the app's defaults before launch.
|
|
1334
|
+
if let url = URL(string: target), !target.isEmpty {
|
|
1335
|
+
if #available(iOS 16.4, *) {
|
|
1336
|
+
XCUIDevice.shared.system.open(url)
|
|
1337
|
+
waitForUIStability(timeout: 1.5)
|
|
1338
|
+
status = "pass"
|
|
1339
|
+
} else {
|
|
1340
|
+
status = "fail"
|
|
1341
|
+
detail = "open_url needs iOS 16.4 or later on the simulator/device running this Flow"
|
|
1342
|
+
}
|
|
1343
|
+
} else {
|
|
1344
|
+
status = "fail"
|
|
1345
|
+
detail = "‘\(target)’ is not a URL open_url can open"
|
|
1346
|
+
}
|
|
1143
1347
|
case "wait":
|
|
1144
1348
|
Thread.sleep(forTimeInterval: Double(timeoutMs) / 1000.0)
|
|
1145
1349
|
case "wait_for":
|
|
@@ -1181,7 +1385,13 @@ class ExplorerTests: XCTestCase {
|
|
|
1181
1385
|
let isAssert = action.hasPrefix("assert_")
|
|
1182
1386
|
let taskEvidence = taskName.isEmpty ? "" : ",\"task\":\"\(escapeJSON(taskName))\""
|
|
1183
1387
|
let contractEvidence = contractName.isEmpty ? "" : ",\"contract\":\"\(escapeJSON(contractName))\""
|
|
1184
|
-
|
|
1388
|
+
// Kept whatever the step then did: the first version wrote it into `detail` and the
|
|
1389
|
+
// tap-failure branch overwrote it, so a run that handled an alert and then failed said
|
|
1390
|
+
// nothing about the alert at all.
|
|
1391
|
+
if !alertNote.isEmpty { detail = detail.isEmpty ? alertNote : "\(alertNote); \(detail)" }
|
|
1392
|
+
let stepEndMs = Int(Date().timeIntervalSince(flowStartedAt) * 1000)
|
|
1393
|
+
print("OCQA_FLOW_STEP:{\"index\":\(idx),\"action\":\"\(escapeJSON(action))\",\"target\":\"\(escapeJSON(target.isEmpty ? value : target))\",\"assert\":\(isAssert),\"status\":\"\(status)\",\"detail\":\"\(escapeJSON(detail))\",\"startMs\":\(stepStartMs),\"endMs\":\(stepEndMs)\(taskEvidence)\(contractEvidence)}")
|
|
1394
|
+
stepStartMs = stepEndMs
|
|
1185
1395
|
if status == "fail" {
|
|
1186
1396
|
failed += 1
|
|
1187
1397
|
// Web and Android flows write flow-failure-N.png next to the log; iOS buried the
|
|
@@ -1246,7 +1456,7 @@ class ExplorerTests: XCTestCase {
|
|
|
1246
1456
|
private func elementPresent(_ target: String) -> Bool {
|
|
1247
1457
|
guard !target.isEmpty else { return false }
|
|
1248
1458
|
let queries: [XCUIElementQuery] = [app.buttons, app.staticTexts, app.cells, app.links, app.switches, app.textFields, app.otherElements]
|
|
1249
|
-
for q in queries where q
|
|
1459
|
+
for q in queries where q.byText(target).exists { return true }
|
|
1250
1460
|
return app.descendants(matching: .any).matching(NSPredicate(format: "label == %@ OR label CONTAINS[c] %@", target, target)).firstMatch.exists
|
|
1251
1461
|
}
|
|
1252
1462
|
|
|
@@ -1453,7 +1663,7 @@ class ExplorerTests: XCTestCase {
|
|
|
1453
1663
|
if allSecureFields.count > 1 {
|
|
1454
1664
|
let existingAccountLabels = ["Back to login", "Back to Login", "Already have an account?", "Sign in instead", "Log in instead"]
|
|
1455
1665
|
for label in existingAccountLabels {
|
|
1456
|
-
let control = app.buttons
|
|
1666
|
+
let control = app.buttons.byText(label).exists ? app.buttons.byText(label) : app.staticTexts.byText(label)
|
|
1457
1667
|
if control.exists && control.isHittable {
|
|
1458
1668
|
control.tap()
|
|
1459
1669
|
print("OCQA_STATE:login_preamble_switched_from_signup")
|
|
@@ -1547,13 +1757,13 @@ class ExplorerTests: XCTestCase {
|
|
|
1547
1757
|
let loginLabels = ["Log In", "Login", "Sign In", "Sign in", "log in", "LOG IN", "SIGN IN"]
|
|
1548
1758
|
var tappedLogin = false
|
|
1549
1759
|
for label in loginLabels {
|
|
1550
|
-
let btn = app.buttons
|
|
1760
|
+
let btn = app.buttons.byText(label)
|
|
1551
1761
|
if btn.exists && btn.isHittable {
|
|
1552
1762
|
btn.tap()
|
|
1553
1763
|
tappedLogin = true
|
|
1554
1764
|
break
|
|
1555
1765
|
}
|
|
1556
|
-
let st = app.staticTexts
|
|
1766
|
+
let st = app.staticTexts.byText(label)
|
|
1557
1767
|
if st.exists && st.isHittable {
|
|
1558
1768
|
st.tap()
|
|
1559
1769
|
tappedLogin = true
|
|
@@ -1569,7 +1779,7 @@ class ExplorerTests: XCTestCase {
|
|
|
1569
1779
|
let continueLabels = ["Continue", "Next", "Submit", "Proceed", "Get Started"]
|
|
1570
1780
|
var tappedContinue = false
|
|
1571
1781
|
for label in continueLabels {
|
|
1572
|
-
let btn = app.buttons
|
|
1782
|
+
let btn = app.buttons.byText(label)
|
|
1573
1783
|
if btn.exists && btn.isHittable {
|
|
1574
1784
|
btn.tap()
|
|
1575
1785
|
tappedContinue = true
|
|
@@ -1587,7 +1797,7 @@ class ExplorerTests: XCTestCase {
|
|
|
1587
1797
|
passFieldAfter.typeText(preamblePassword)
|
|
1588
1798
|
Thread.sleep(forTimeInterval: 0.3)
|
|
1589
1799
|
for label in loginLabels + continueLabels {
|
|
1590
|
-
let btn = app.buttons
|
|
1800
|
+
let btn = app.buttons.byText(label)
|
|
1591
1801
|
if btn.exists && btn.isHittable {
|
|
1592
1802
|
btn.tap()
|
|
1593
1803
|
print("OCQA_STATE:login_preamble_two_step_submitted")
|
|
@@ -1617,7 +1827,7 @@ class ExplorerTests: XCTestCase {
|
|
|
1617
1827
|
print("OCQA_STATE:otp_entered")
|
|
1618
1828
|
Thread.sleep(forTimeInterval: 0.3)
|
|
1619
1829
|
for label in ["Verify", "Continue", "Submit", "Confirm"] {
|
|
1620
|
-
let btn = app.buttons
|
|
1830
|
+
let btn = app.buttons.byText(label)
|
|
1621
1831
|
if btn.exists && btn.isHittable { btn.tap(); break }
|
|
1622
1832
|
}
|
|
1623
1833
|
Thread.sleep(forTimeInterval: 2.0)
|
|
@@ -1647,7 +1857,7 @@ class ExplorerTests: XCTestCase {
|
|
|
1647
1857
|
let startupAlert = XCUIApplication(bundleIdentifier: "com.apple.springboard").alerts.firstMatch
|
|
1648
1858
|
if startupAlert.exists {
|
|
1649
1859
|
for label in ["Allow While Using App", "Allow Once", "OK", "Allow", "Don't Allow"] {
|
|
1650
|
-
let button = startupAlert.buttons
|
|
1860
|
+
let button = startupAlert.buttons.byText(label)
|
|
1651
1861
|
if button.exists && button.isHittable {
|
|
1652
1862
|
button.tap()
|
|
1653
1863
|
waitForAnimationsToSettle()
|
|
@@ -3311,7 +3521,7 @@ class ExplorerTests: XCTestCase {
|
|
|
3311
3521
|
}
|
|
3312
3522
|
var tappedLabel: String? = nil
|
|
3313
3523
|
for label in candidates {
|
|
3314
|
-
let btn = app.buttons
|
|
3524
|
+
let btn = app.buttons.byText(label)
|
|
3315
3525
|
if btn.exists && btn.isHittable {
|
|
3316
3526
|
btn.tap()
|
|
3317
3527
|
Thread.sleep(forTimeInterval: 0.5)
|
|
@@ -3713,7 +3923,7 @@ class ExplorerTests: XCTestCase {
|
|
|
3713
3923
|
let deadline = Date().addingTimeInterval(max(0, timeoutSeconds))
|
|
3714
3924
|
repeat {
|
|
3715
3925
|
for query in [app.buttons, app.cells, app.links, app.staticTexts] {
|
|
3716
|
-
let el = query
|
|
3926
|
+
let el = query.byText(trimmed)
|
|
3717
3927
|
if el.exists && el.isHittable { el.tap(); return true }
|
|
3718
3928
|
}
|
|
3719
3929
|
let exact = app.descendants(matching: .any).matching(NSPredicate(format: "label == %@", trimmed)).allElementsBoundByIndex
|
|
@@ -3979,9 +4189,9 @@ class ExplorerTests: XCTestCase {
|
|
|
3979
4189
|
|
|
3980
4190
|
private func resolveTextElement(for element: SimpleElement, in app: XCUIApplication) -> XCUIElement? {
|
|
3981
4191
|
if !element.identifier.isEmpty {
|
|
3982
|
-
let tf = app.textFields
|
|
4192
|
+
let tf = app.textFields.byText(element.identifier)
|
|
3983
4193
|
if tf.exists { return tf }
|
|
3984
|
-
let stf = app.secureTextFields
|
|
4194
|
+
let stf = app.secureTextFields.byText(element.identifier)
|
|
3985
4195
|
if stf.exists { return stf }
|
|
3986
4196
|
}
|
|
3987
4197
|
|
|
@@ -4202,7 +4412,7 @@ class ExplorerTests: XCTestCase {
|
|
|
4202
4412
|
}
|
|
4203
4413
|
// Try common dismiss buttons (expanded set)
|
|
4204
4414
|
for label in ["Close", "Cancel", "Done", "Dismiss", "Back", "X", "close"] {
|
|
4205
|
-
let btn = app.buttons
|
|
4415
|
+
let btn = app.buttons.byText(label)
|
|
4206
4416
|
if btn.exists && btn.isHittable {
|
|
4207
4417
|
btn.tap()
|
|
4208
4418
|
Thread.sleep(forTimeInterval: 0.5)
|