AI_UIAutomation/utils/common/message.helper.ts

39 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 消息中心 helper —— Profile 右上角 btnMsgCenter → Notifications(消息中心)页。
*/
import { DeviceDriver } from '../../drivers/types';
import { sleep } from './element.helper';
import { goToProfile } from './auth.helper';
/** 打开消息中心:Profile → btnMsgCenter。返回是否到达 Notifications 页。 */
export async function openMessageCenter(driver: DeviceDriver): Promise<boolean> {
await goToProfile(driver);
await sleep(1000);
const btn = await driver.findElementRaw('id', 'com.theswitchbot.switchbot:id/btnMsgCenter');
if (!btn) { console.log('未找到 btnMsgCenter(消息中心入口)'); return false; }
await driver.tapElement(btn);
await sleep(2500);
// Notifications 页标志(标题/家庭筛选)
const src = await driver.getSource();
const ok = src.includes('Notifications') || src.includes('All Homes') || src.includes('消息') || src.includes('通知');
console.log(`消息中心已打开: ${ok}`);
return ok;
}
/**
* 点消息中心列表第一条消息右侧箭头 → 跳转到内容/详情页。返回是否成功跳转(离开 Notifications 列表)。
* 消息卡的跳转箭头是无 id/text 的 ViewGroup,appium getSource 读不到,故直接点坐标。
* 1080×2280:首条消息箭头中心 ≈ (959, 751)。
*/
export async function tapFirstMessage(driver: DeviceDriver): Promise<boolean> {
await sleep(1500); // 等列表渲染
const before = await driver.getSource();
if (!before.includes('All Homes')) { console.log('未在消息列表页,无法跳转'); return false; }
await driver.tap(959, 751); // 第一条消息右侧跳转箭头
await sleep(2500);
const jumped = !(await driver.getSource()).includes('All Homes'); // 离开列表 = 已跳内容页
console.log(`点第一条消息箭头 → 跳转内容页: ${jumped}`);
return jumped;
}