AI_UIAutomation/scripts/explore_bot_settings.ts

67 lines
2.3 KiB
TypeScript
Raw Permalink 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.

import { agentFromWebDriverAgent } from '@midscene/ios';
import * as dotenv from 'dotenv';
import * as path from 'path';
dotenv.config({ path: path.resolve(__dirname, '../.env') });
async function main() {
console.log('=== Claude Opus 模型测试点击 Bot 0F ===\n');
console.log(`Model: ${process.env.MIDSCENE_MODEL_NAME}`);
console.log(`Family: ${process.env.MIDSCENE_MODEL_FAMILY}`);
console.log('');
const agent = await agentFromWebDriverAgent({
wdaHost: process.env.WDA_HOST || 'localhost',
wdaPort: Number(process.env.WDA_PORT) || 8100,
});
try {
await agent.launch('com.wohand.wohand');
await new Promise((r) => setTimeout(r, 8000));
// 确认Bot 0F可见
const status = await agent.aiQuery('当前屏幕上有"Bot 0F"设备吗?描述它的位置和状态');
console.log('当前状态:', JSON.stringify(status, null, 2));
const hasBotVisible = await agent.aiBoolean('当前屏幕上有"Bot 0F"文字');
console.log('Bot 0F可见:', hasBotVisible);
if (!hasBotVisible) {
await agent.aiScroll(undefined, { direction: 'down', scrollType: 'singleAction', distance: 300 });
await new Promise((r) => setTimeout(r, 3000));
}
await new Promise((r) => setTimeout(r, 3000));
// 用Claude Opus点击Bot 0F
console.log('\n点击Bot 0F卡片...');
await agent.aiTap('"Bot 0F"设备卡片');
await new Promise((r) => setTimeout(r, 5000));
// 检查结果
const result = await agent.aiQuery('当前屏幕上有弹出菜单吗?如果有,列出菜单所有选项');
console.log('点击结果:', JSON.stringify(result, null, 2));
const hasPopup = await agent.aiBoolean('屏幕上有弹出的菜单或选项列表');
console.log('有弹框:', hasPopup);
if (hasPopup) {
console.log('\n✓ 成功弹出菜单点击Settings...');
await agent.aiTap('"Settings"按钮或选项');
await new Promise((r) => setTimeout(r, 3000));
const settings = await agent.aiQuery('列出当前页面所有设置选项的名称,从上到下');
console.log('设置页:', JSON.stringify(settings, null, 2));
}
console.log('\n=== 完成 ===');
await agent.destroy();
} catch (error: any) {
console.error('\n失败:', error.message);
await agent.destroy();
process.exit(1);
}
}
main();