Skip to content

DSL 示例

基础:登录测试

yaml
id: login-test
platform: android
steps:
  - launch: { package: com.example.app, force: true, clearData: true }
  - waitStable: { timeoutMs: 5000 }
  - dismissModal: { maxRounds: 3 }
  - tap: Login
  - input: admin@example.com
  - tap: Password
  - input: "123456"
  - tap: Submit
  - waitStable: { timeoutMs: 3000 }
  - assert: Welcome

变量:参数化测试

yaml
id: parameterized-login
platform: android
vars:
  APP: com.example.app
  USER: admin@test.com
  PASS: secret123
steps:
  - launch: { package: "${APP}", force: true }
  - waitStable: { timeoutMs: 5000 }
  - input: "${USER}"
  - tap: Next
  - input: "${PASS}"
  - tap: Login
  - assert: "${USER}"

运行时覆盖变量:

bash
# 代码层面
parseScript(yaml, { runtimeVars: { USER: "other@test.com" } })

循环:遍历导航 Tab

yaml
id: tab-navigation
platform: android
steps:
  - launch: { package: com.example.app, force: true }
  - waitStable: { timeoutMs: 5000 }
  - forEach:
      var: TAB
      values: [Home, Search, Profile, Settings]
      steps:
        - tap: "${TAB}"
        - waitStable: { timeoutMs: 2000 }
        - assert: "${TAB}"

条件:处理弹窗

yaml
id: conditional-test
platform: android
steps:
  - launch: { package: com.example.app, force: true }
  - waitStable: { timeoutMs: 5000 }
  - ifExists:
      pattern: "允许"
      then:
        - tap: 允许
        - waitStable: { timeoutMs: 2000 }
      else:
        - wait: 500
  - assert: Home

视觉断言:Canvas 内容

yaml
id: terminal-test
platform: android
steps:
  - launch: { package: com.termai.termai, force: true }
  - waitStable: { timeoutMs: 8000 }
  - tap: SSH
  - tap: Connect
  - waitStable: { timeoutMs: 5000 }
  - assertVisual: 终端显示了 SSH 连接成功的提示,出现 shell 提示符
  - input: ls
  - press: KEYCODE_ENTER
  - waitStable: { timeoutMs: 3000 }
  - assertVisual: 终端显示了 ls 命令的输出结果

多语言截图

yaml
id: appstore-screenshots
platform: android
vars:
  APP: com.example.app
steps:
  - launch: { package: "${APP}", force: true }
  - waitStable: { timeoutMs: 5000 }
  - saveScreenshot: home
  - tap: Profile
  - waitStable: { timeoutMs: 2000 }
  - saveScreenshot: profile
  - tap: Settings
  - waitStable: { timeoutMs: 2000 }
  - saveScreenshot: settings
bash
# 多语言运行
node --experimental-strip-types scripts/generate-screenshots.ts \
  appstore-screenshots --locales en-US,zh-CN,ja-JP

Released under MIT License.