From 85a6f04fb1d9deecbedd93eb3504d93c5dfd287d Mon Sep 17 00:00:00 2001 From: woan <798680981@qq.com> Date: Thu, 25 Jun 2026 14:29:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=20iOS=20=E9=80=89=E5=93=81=E7=B1=BB?= =?UTF-8?q?=E7=82=B9=E7=A9=BA:=E5=B1=8F=E5=A4=96=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E5=85=88=E6=BB=9A=E8=BF=9B=E5=8F=AF=E8=A7=86=E5=8C=BA=E5=86=8D?= =?UTF-8?q?=E7=82=B9=20+=20=E6=A0=A1=E9=AA=8C=E7=9C=9F=E8=BF=9B=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:WDA 返回屏外元素(品类常在 y=1192,屏高 844),旧代码直接点屏外坐标→点空没导航却 return true→relay 在目录页空按→添加失败("没点进入口")。 修复:① selectDeviceCategory 找到品类后先滚动送进可视区(y∈[0.10h,0.82h])再点,在下方下滑/上方上滑;② 点后用 "Add Manually"(目录页独有)是否消失校验真进流程,替代会误判的 includes(categoryName)。 验证:Robot Vacuum Cleaner S1 Plus 现可正确进入 Configuration wizard。 Co-Authored-By: Claude Opus 4.8 --- utils/common/device-add.helper.ts | 39 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/utils/common/device-add.helper.ts b/utils/common/device-add.helper.ts index 07468c2..1b3f12c 100644 --- a/utils/common/device-add.helper.ts +++ b/utils/common/device-add.helper.ts @@ -149,6 +149,10 @@ export async function selectDeviceCategory(driver: DeviceDriver, categoryName: s await driver.swipe(Math.round(catW / 2), Math.round(catH * 0.60), Math.round(catW / 2), Math.round(catH * 0.38), 0.4); await sleep(650); // 等动量沉降稳定再 find(短等待会在列表还在动时查 → 漏) }; + const slowScrollUp = async () => { + await driver.swipe(Math.round(catW / 2), Math.round(catH * 0.38), Math.round(catW / 2), Math.round(catH * 0.60), 0.4); + await sleep(650); + }; const iosFind = async (): Promise => { // 一条 predicate 覆盖 StaticText/Other/通用(name 或 label)。⚠️ 用**大小写不敏感** `==[c]`: // iOS 品类名是 Title Case(如 "RGBIC Neon Wire Rope Light"),用例常写小写 → 敏感匹配会"滚到底也找不到入口"。 @@ -168,27 +172,32 @@ export async function selectDeviceCategory(driver: DeviceDriver, categoryName: s if (scrollHint > 1 && !(await iosFind())) { for (let i = 0; i < scrollHint - 1; i++) { await slowScroll(); } } - for (let i = 0; i < 16; i++) { - let el = await iosFind(); + for (let i = 0; i < 24; i++) { + const el = await iosFind(); if (el) { - const visible = await driver.getElementAttribute(el, 'visible').catch(() => 'true'); - if (String(visible) !== 'true' && String(visible) !== '1') { - await slowScroll(); + const rect = await driver.getElementRect(el).catch(() => null); + if (rect && rect.width > 0) { + // ★ WDA 会返回**屏外元素**(实测品类常在 y=1192,屏高仅 844)→ 直接点屏外坐标无效="点了没进流程"。 + // 必须先把它**滚进可视区**(y 在 [0.10h, 0.82h])再点:在下方就下滑、在上方就上滑。 + if (rect.y < catH * 0.10 || rect.y + rect.height > catH * 0.82) { + if (rect.y > catH * 0.5) await slowScroll(); else await slowScrollUp(); + continue; + } + await driver.tapElement(el); await sleep(2500); + // ★ 校验真进了流程:**"Add Manually" 是 Add Device 目录页独有标志**,消失=已离开目录进流程 + // (不能用 includes(categoryName):目录页本就列着品类名 → 误判成功)。 + const after = await driver.getSource(); + const entered = !/Add Manually|Scanning for Bluetooth/i.test(after) + || /Next|Connect|Configuration|wizard|Before Using|press the button|hold the button|Disclaimer|配对|连接|下一步/i.test(after); + if (entered) return true; + console.log(`点 ${categoryName} 后仍在目录页(疑点空),重试`); + await sleep(500); continue; } - // 防贴底误点:卡片太靠下(y>700/844,易被底部栏挡或点到边缘)→ 先小幅上滑抬起,重取再点 - const rect = await driver.getElementRect(el).catch(() => null); - if (rect && rect.y > 700) { - await slowScroll(); - const el2 = await iosFind(); if (el2) el = el2; - } - await driver.tapElement(el); // 真实坐标 tap(比 /click 稳) - await sleep(3000); - return true; } await slowScroll(); } - console.log(`FAIL: no ${categoryName} option`); + console.log(`FAIL: no ${categoryName} option(或点击未进入流程)`); return false; }