美文网首页
iOS自动测试环境搭建(Appium)

iOS自动测试环境搭建(Appium)

作者: 阿呆0412 | 来源:发表于2019-02-18 18:21 被阅读0次

    简介

    本文简单记录一下iOS自动测试环境搭建的过程以及遇到的一些坑

    1. 安装homebrew

    • 由于之前的homebrew有点问题,这里记录一下卸载重装的操作,不需要重装直接看下一步:
      打开终端,输入一下命令并回车:
      /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
    • 如果需要完全卸载,可用下面的操作:
    $ cd `brew --prefix`
    $ rm -rf Cellar$ brew prune
    $ rm -rf Library .git .gitignore bin/brew README.md share/man/man1/brew
    $ rm -rf ~/Library/Caches/Homebrew
    
    • 打开终端,输入以下命令并回车:
      /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    2. 安装libimobiledevice

    • 打开终端,输入以下命令并回车:
      brew install libimobiledevice --HEAD
    • 安装的时候如果出现了报错Requested 'libusbmuxd >= 1.1.0' but version of libusbmuxd is 1.0.10, 修复操作如下:
    $ brew uninstall --ignore-dependencies libimobiledevice
    $ brew uninstall --ignore-dependencies usbmuxd
    $ brew install --HEAD usbmuxd
    $ brew unlink usbmuxd
    $ brew link usbmuxd
    
    

    3. 安装carthage

    4. 安装npm及cnpm

    • 打开终端,输入以下命令并回车:
      brew install -g node
      npm install -g cnpm --registry=https://registry.npm.taobao.org

    • 如果遇到类似gcc_4_0 is disabled的报错,请用命令brew upgrade升级homebrew,或参考文章开头的步骤重装homebrew,一般原因是homebrew有损坏或者版本不是最新

    5. 安装ios-deploy

    • 打开终端,输入以下命令并回车:
      cnpm install -g ios-deploy
    • 如果报错stderr: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance,执行sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer,原因是Xcode安装路径非系统指定路径.

    6. 安装xcpretty

    • 打开终端,输入以下命令并回车:
      gem install xcpretty

    7.通过npm install -g安装以下依赖:

    babel-eslint@^7.1.1
    eslint@^3.10.2
    eslint-plugin-import@^2.2.0
    eslint-plugin-mocha@^4.7.0
    eslint-plugin-promise@^3.3.1
    

    8.安装appium-xcuitest-driver

    • 打开终端,输入以下命令并回车:
      npm install -g appium-xcuitest-driver

    9.配置appium-xcuitest-driver依赖

    • 打开终端,输入以下命令并回车:
      cd /usr/local/lib/node_modules/appium-xcuitest-driver/WebDriverAgent (如果WebDriverAgent 所在路径和此不同,请自行查找)
      mkdir -p Resources/WebDriverAgent.bundle
      sh ./Scripts/bootstrap.sh
    • 此处如果没安装carthage会报错
    • 此处如果出现Unexpected token (67:6)类似报错,和 webpack 检测相对目录的根目录有关,解决方法见Appium运行 WebDriverAgent 输入./Scripts/bootstrap.sh 报错 ,实测可以打包成功

    10.编译WebDriverAgent 【复杂&重要】

    • 打开终端,输入以下命令并回车:
      cd /usr/local/lib/node_modules/appium-xcuitest-driver/WebDriverAgent
      open WebDriverAgent.xcodeproj
      如果装过xcode会直接打开为一个工程
    • (更改开发者签名项,改为公司开发者)
    • 编译WebDriverAgentLib
    • 编译WebDriverAgentRunner
    • build成功后关闭XCode

    11.建立WebDriverAgent服务(手机和MAC都在同一个网段下,且都能连接外网)

    • 将WebDriverAgentRunner编译到手机上:
    cd  /usr/local/lib/node_modules/appium-xcuitest-driver/WebDriverAgent
    
    xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=udid4phone
    

    (idevice_id --list 命令,可以查看当前连接的所有手机udid )

    12.安装appium

    • 打开终端,输入以下命令并回车:
      npm install -g appium

    • 安装完成后,打开终端执行:appium测试是否成功

    13.安装appium-desktop 客户端

    appium.io 上自行下载

    相关文章

      网友评论

          本文标题:iOS自动测试环境搭建(Appium)

          本文链接:https://www.haomeiwen.com/subject/jdrzeqtx.html