Overseas access: www.kdjingpai.com
Bookmark Us
Current Position:fig. beginning " AI Answers

Midscene.js的JavaScript SDK如何进行断言和数据提取?

2025-09-10 1.8 K

SDK高级功能详解

对于开发人员,Midscene.js提供了功能完善的JavaScript SDK,支持编程式地构建复杂测试流程。

核心API使用

  • ai()基础操作::
    await ai('滚动到页面底部');
    await ai('在#email输入框输入test@demo.com');
  • aiQuery()数据提取::
    // 提取指定结构数据
    const products = await aiQuery(
      '{name: string, rating: number}[]',
      '获取所有产品名称和评分'
    );
  • aiAssert()智能断言::
    // 自然语言断言
    await aiAssert('当前用户应显示为"高级会员"');
    await aiAssert('购物车总数应大于3');

best practice

  1. 结合try-catch处理异常流程
  2. 通过.env文件配置AI模型参数
  3. 使用async/await保证操作顺序执行
  4. 将常用操作封装为可复用函数

对于复杂的测试场景,建议配合YAML脚本实现操作步骤与测试逻辑的分离。

Recommended

Can't find AI tools? Try here!

Just type in the keyword Accessibility Bing SearchYou can quickly find all the AI tools on this site.

Top

en_USEnglish