Skip to content

Commit 23d793b

Browse files
committed
Capture browser eval failures in contenteditable XCUITest
1 parent 0fd8c45 commit 23d793b

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

cmuxUITests/BrowserPaneNavigationKeybindUITests.swift

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,8 +1693,9 @@ final class BrowserPaneNavigationKeybindUITests: XCTestCase {
16931693

16941694
var lastDiagnostic = "nil"
16951695
let didMatch = waitForCondition(timeout: timeout) {
1696-
guard let payload = self.browserEvalDict(surfaceId: surfaceId, script: script) else {
1697-
lastDiagnostic = "nil"
1696+
let outcome = self.browserEvalOutcome(surfaceId: surfaceId, script: script)
1697+
guard let payload = outcome.value as? [String: Any] else {
1698+
lastDiagnostic = outcome.diagnostic
16981699
return false
16991700
}
17001701
lastDiagnostic = String(describing: payload)
@@ -1762,10 +1763,14 @@ final class BrowserPaneNavigationKeybindUITests: XCTestCase {
17621763
}
17631764

17641765
private func browserEvalDict(surfaceId: String, script: String) -> [String: Any]? {
1765-
browserEvalValue(surfaceId: surfaceId, script: script) as? [String: Any]
1766+
browserEvalOutcome(surfaceId: surfaceId, script: script).value as? [String: Any]
17661767
}
17671768

17681769
private func browserEvalValue(surfaceId: String, script: String) -> Any? {
1770+
browserEvalOutcome(surfaceId: surfaceId, script: script).value
1771+
}
1772+
1773+
private func browserEvalOutcome(surfaceId: String, script: String) -> BrowserEvalOutcome {
17691774
let client = ControlSocketClient(path: socketPath, responseTimeout: 10.0)
17701775
let request: [String: Any] = [
17711776
"id": UUID().uuidString,
@@ -1775,13 +1780,19 @@ final class BrowserPaneNavigationKeybindUITests: XCTestCase {
17751780
"script": script
17761781
]
17771782
]
1778-
guard let response = client.sendJSON(request),
1779-
let ok = response["ok"] as? Bool,
1780-
ok,
1781-
let result = response["result"] as? [String: Any] else {
1782-
return nil
1783+
guard let response = client.sendJSON(request) else {
1784+
return BrowserEvalOutcome(value: nil, diagnostic: "no_response")
1785+
}
1786+
guard let ok = response["ok"] as? Bool else {
1787+
return BrowserEvalOutcome(value: nil, diagnostic: "missing_ok response=\(response)")
1788+
}
1789+
guard ok else {
1790+
return BrowserEvalOutcome(value: nil, diagnostic: "not_ok response=\(response)")
17831791
}
1784-
return result["value"]
1792+
guard let result = response["result"] as? [String: Any] else {
1793+
return BrowserEvalOutcome(value: nil, diagnostic: "missing_result response=\(response)")
1794+
}
1795+
return BrowserEvalOutcome(value: result["value"], diagnostic: "ok")
17851796
}
17861797

17871798
private func loadData() -> [String: String]? {
@@ -1927,6 +1938,11 @@ final class BrowserPaneNavigationKeybindUITests: XCTestCase {
19271938
let diagnostic: String
19281939
}
19291940

1941+
private struct BrowserEvalOutcome {
1942+
let value: Any?
1943+
let diagnostic: String
1944+
}
1945+
19301946
private struct BrowserContentEditableSnapshot {
19311947
let activeId: String
19321948
let downCount: Int

0 commit comments

Comments
 (0)