import { agentFromWebDriverAgent, IOSAgent } from '@midscene/ios'; import { APP_CONFIG } from '../config/app.config'; let agent: IOSAgent | null = null; export async function getAgent(): Promise { if (!agent) { agent = await agentFromWebDriverAgent({ wdaHost: process.env.WDA_HOST || 'localhost', wdaPort: Number(process.env.WDA_PORT) || 8100, }); } return agent; } export async function destroyAgent(): Promise { if (agent) { await agent.destroy(); agent = null; } } export async function launchApp(): Promise { const a = await getAgent(); await a.launch(APP_CONFIG.ios.bundleId); return a; } export async function backToHomepage(a: IOSAgent): Promise { await a.aiAct('点击底部导航栏的首页tab或Home tab'); await a.aiWaitFor('首页设备列表已显示', { timeoutMs: APP_CONFIG.timeouts.pageLoad }); } export async function scrollToBot(a: IOSAgent, botName: string): Promise { const visible = await a.aiBoolean(`当前屏幕上能看到包含"${botName}"文字的设备卡片`); if (!visible) { await a.aiAct(`向下滑动页面直到看到"${botName}"设备卡片`); } } export async function sleep(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); }