iOS 自动化 UI 测试方案

By on
  • 使用 Instruments 下的 Automation
    • Using UIAScript,类似于 JavaScript
    • 打开后选择 Add Script,编写需要测试的测试用例
    • 右侧 Scripts 有需要运行的列表
    • 编写完成后点击下面的 Run 即可
    • 在每个 Trace Log 中都能明确展示出出现的问题
  • Example:对于 HomeVC 进行每个 Cell 的 UI 测试用例
    • Code:略
    • Logs:
      • UIALogger.logStart(testName);
      • UIALogger.logPass(testName);
      • UIALogger.logFail(testName);
      • UIATarget.localTarget().logElementTree();
    • Get Elements:
      • App: UIATarget.localTarget().frontMostApp();
      • MainWindow:UIATarget.localTarget().frontMostApp().mainWindow();
      • .buttons();
      • .collectionViews();
      • .cells();
      • etc…
    • Gestures:
      • .tap({x: 100, y: 200});
      • .doubleTap({x: 100, y: 200});
      • .twoFingerTap({x: 100, y: 200});
      • .dragFromToForDuration({x: 160, y: 200}, {x: 160, y: 400}, 1);
      • .scrollToElementWithPredicate();
    • Timing:
      • .timeout();
      • .setTimeout();
      • .pushTimeout();
      • .popTimeout();
      • .delay();
  • References: