diff --git a/crates/ictl-wda/src/elements.rs b/crates/ictl-wda/src/elements.rs index a7b8be6..6ef51c2 100644 --- a/crates/ictl-wda/src/elements.rs +++ b/crates/ictl-wda/src/elements.rs @@ -438,6 +438,8 @@ struct Open { group: usize, /// 这一层子节点的原始坐标要加上的偏移(小组件内部用的是相对小组件的坐标) offset: (f64, f64), + /// 自己是 WebView 或在 WebView 里 + in_web: bool, in_status_bar: bool, kind: String, kept: Option, @@ -504,10 +506,14 @@ pub fn parse_tree(xml: &str, view: impl Into) -> Tree { let full_kind = attr.get("type").cloned().unwrap_or(tag); let kind = full_kind.strip_prefix("XCUIElementType").unwrap_or(&full_kind).to_owned(); - // 小组件的内容:某个节点在 (0,0) 且和父节点一样大,而父节点不在 (0,0)——从它开始坐标是相对父节点的 + // 小组件的内容:某个节点在 (0,0) 且和父节点一样大,而父节点不在 (0,0)——从它开始坐标是相对父节点的。 + // 网页里不算:WKWebView 内部有一层节点也报 (0,0)、和 WebView 一样大,但网页元素用的是屏幕坐标, + // 加上偏移会把整页错开 WebView 的 y(App 内浏览器、小程序在导航栏下面时约 100 点) let parent = stack.last(); + let in_web = kind == "WebView" || parent.is_some_and(|p| p.in_web); let mut offset = parent.map_or((0.0, 0.0), |p| p.offset); if let Some(p) = parent + && !p.in_web && raw.x == 0.0 && raw.y == 0.0 && (raw.w - p.abs.w).abs() < 1.0 @@ -625,6 +631,7 @@ pub fn parse_tree(xml: &str, view: impl Into) -> Tree { group, kind: kind_for_children, offset, + in_web, in_status_bar, kept, blocker, @@ -1036,6 +1043,35 @@ mod tests { assert!(clock.center.1 > 400); } + /// 真机(iOS 26,App 内浏览器):WebView 在原生导航栏下面 (0,100),WKWebView 内部那层报 (0,0) 且和 WebView + /// 一样大,看着像小组件;但网页元素给的是屏幕坐标,不能再加 WebView 的偏移 + #[test] + fn web_contents_keep_screen_coordinates() { + let xml = r#" + + + + + + + + + + + + + + + + + + "#; + let els = parse(xml, SCREEN); + let text = els.iter().find(|e| e.label == "Getting started").unwrap(); + // 截图上就在这里,不是错开 100 点的 (59,488) + assert_eq!(text.center, (59, 388)); + } + #[test] fn close_to_tolerates_small_drift_only() { let t = parse_tree(SETTINGS_IOS27, SCREEN); diff --git a/docs/dev/regression-cases.md b/docs/dev/regression-cases.md index 5f0a9f3..32dd917 100644 --- a/docs/dev/regression-cases.md +++ b/docs/dev/regression-cases.md @@ -149,3 +149,4 @@ | 143 | 原生:Spotlight 打开时选中上次的搜索词,再粘贴同样的词会把它替换成自己,输入框的值不变,`iphone_type_text` 报「粘贴了…但输入框里没有这段文字」(带 `submit` 时还不按回车),其实已经输进去了 | 「允许粘贴」点过之后,输入框原来就有这段文字、1.5 秒不变,算输入成功并提示截图确认;没点过「允许粘贴」时仍报错 | 单测 `a_paste_that_replaced_the_same_text_is_told_apart_from_one_that_missed` + 真机(Spotlight 留着「设置」时再输入「设置」,`run.py` 连跑两遍);真机脚本 `scenarios.py typing` | | 144 | 设备闲置时自动锁屏,下一个操作先自动解锁(iPad 经 WDA 约 15 秒,iPhone 原生约 9 秒),结果和事件日志都没说,看着像「切换设备后第一个操作慢」 | 结果第一行(截图在说明里、出错时在报错里)写「手机锁着,先自动解锁了,用时 X 秒」,事件日志记「已自动解锁」 | 单测 `an_unlock_first_is_said_on_the_answers_first_line` + 真机(锁屏后按名字点击、截图,两台设备);真机脚本 `scenarios.py lock` | | 145 | WDA 的短探测已正常应答或返回远端错误,却不清零超时计数,三个独立慢请求仍会触发重启;连接失败反而清零。日志还把长请求和短探测均未应答写成「连续 3 次」、宣称尚未检查的 `/status` 正常,请求超时本身缺端点日志 | 只有正常响应或远端错误清零,连接失败不清零;连续无应答和长请求后的失败探测分别记录原因及实际次数;超时诊断记录方法、短路径和耗时,不记录查询参数或正文 | 单测 `answered_probe_resets_stall_count_after_each_slow_request`、`connection_error_does_not_reset_unanswered_count`、`long_request_and_failed_probe_keep_the_actual_count_and_reason`、`three_short_unanswered_requests_report_a_consecutive_stall`、`answered_session_delete_does_not_mask_a_failed_probe`、`failed_request_log_keeps_endpoint_and_time_without_query`、`successful_request_log_does_not_include_response_body`;真机:同一 iPad、同一 WDA,把只读业务请求的客户端时限缩短到 20ms,短探测保留 5s,对照修复前后各 3 轮 | +| 146 | App 内浏览器(WebView 在导航栏下面,y≈100)里元素坐标整体偏下一个 WebView 的 y:WKWebView 内部有一层节点报 (0,0)、和 WebView 一样大,被当成小组件、之后的子节点都加上偏移,按文字点击点到下面那一行(Safari 全屏的 WebView 从 0 开始,看不出来) | WebView 和它里面的节点不按小组件的相对坐标处理,用元素树里的屏幕坐标 | 单测 `web_contents_keep_screen_coordinates` + 真机(App 内浏览器页面:元素坐标和截图对上,按文字点击点中) |