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