You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jenkins/CircleCI上用模拟器执行iOS Appium脚本?是否仅支持真机?

在Jenkins/CircleCI上用iOS模拟器执行Appium自动化测试

一、Jenkins实现方案

Jenkins节点必须是macOS机器(iOS模拟器仅支持macOS环境),先完成基础环境配置:

  • 安装Xcode,并通过xcode-select --switch /Applications/Xcode.app/Contents/Developer配置命令行工具
  • 安装Node.js、Appium(npm install -g appium),并安装XCUITest驱动(appium driver install xcuitest)
  • 确保Jenkins有足够权限操作模拟器和执行shell命令

具体执行步骤:

  1. 创建Jenkins任务(自由风格或流水线均可),配置代码仓库拉取逻辑,确保Appium测试脚本、iOS项目代码(或预编译的.app包)能被拉取到节点
  2. 构建前准备:
    • 启动Appium服务:可以在shell步骤中执行appium --log-level info &(后台运行),或者在测试脚本中通过AppiumService自动启动
    • 可选:手动启动指定模拟器,命令为xcrun simctl boot "iPhone 14"(先通过xcrun simctl list devices查看可用设备名称)
  3. 编译iOS应用(如果没有预编译包):
    xcodebuild build-for-testing -workspace YourApp.xcworkspace -scheme YourAppScheme -destination 'platform=iOS Simulator,name=iPhone 14'
    
    编译完成后会在指定路径生成.app文件
  4. 执行Appium测试脚本:
    • 确保脚本的Desired Capabilities配置正确,核心参数示例:
      {
        platformName: 'iOS',
        deviceName: 'iPhone 14',
        app: '/Users/jenkins/workspace/YourJob/DerivedData/Products/Debug-iphonesimulator/YourApp.app',
        automationName: 'XCUITest',
        noReset: true // 根据测试需求调整
      }
      
    • 执行测试命令,比如JS项目用npm test,Python项目用pytest
  5. 构建后清理:
    • 关闭模拟器:xcrun simctl shutdown "iPhone 14"
    • 停止Appium服务:pkill -f appium

二、CircleCI实现方案

CircleCI提供macOS执行器,可直接利用其预装的Xcode环境,只需补充配置Appium相关依赖:

核心配置(.circleci/config.yml)示例

version: 2.1
jobs:
  appium-ios-test:
    macos:
      xcode: 15.0.0 # 指定Xcode版本,按需选择
    steps:
      - checkout
      - run:
          name: 安装依赖
          command: |
            npm install
            npm install -g appium
            appium driver install xcuitest
      - run:
          name: 准备模拟器
          command: |
            # 创建新模拟器(可选,也可用现有模拟器)
            xcrun simctl create TestSim com.apple.CoreSimulator.SimDeviceType.iPhone-14 com.apple.CoreSimulator.SimRuntime.iOS-17-0
            xcrun simctl boot TestSim
      - run:
          name: 编译iOS应用
          command: |
            xcodebuild build-for-testing -workspace YourApp.xcworkspace -scheme YourAppScheme -destination 'platform=iOS Simulator,name=TestSim'
      - run:
          name: 执行Appium测试
          command: npm test
      - run:
          name: 清理环境
          command: |
            xcrun simctl shutdown TestSim
            pkill -f appium
workflows:
  test-workflow:
    jobs:
      - appium-ios-test

三、是否必须用真实iOS设备?

不需要。iOS模拟器完全可以支撑绝大多数Appium自动化测试场景:

  • 覆盖常规UI交互、业务功能测试
  • 无需额外购买设备,降低测试成本
  • 启动速度快,适合持续集成的快速迭代测试

但以下场景建议使用真实设备:

  • 涉及硬件功能测试:摄像头、Touch ID/Face ID、蓝牙、NFC等
  • 推送通知、系统深层权限的真实场景验证
  • 需要测试App Store正式版本的兼容性

内容的提问来源于stack exchange,提问作者rb automation

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 11:50:23