appium是移动端的一个开源测试框架,由于跨平台、支持多语言等特点,使其在移动端自动化领域不断地发展壮大。以mac系统为例,appium的相关部署介绍如下。
首先,要检查环境。在命令窗口输入命令“brew -v”、“npm -v”,检查homebrew、npm的安装情况,这一步是为了方便使用这两个工具安装接下来使用到的工具。若有返回对应版本号,则表示已安装,若未安装,则自行安装该工具,当然java jdk请先自行安装好。
现在正式开始安装appium。appium需要依赖node.js,所以需要使用“brew install node"安装该依赖包。革命的道路总是曲折的,报错了,错误如下:
/usr/local/Homebrew/Library/Homebrew/brew.rb:12:in `': Homebrew must be run under Ruby 2.3! You're running 2.0.0. (RuntimeError)。
很明显,当前安装的node.js要求2.3版本以上的ruby。于是去升级ruby版本。升级步骤如下:1.查看ruby可升级版本,使用命令”rvm list known“,结果如下:
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.7]
[ruby-]2.3[.4]
[ruby-]2.4[.1]
ruby-head
......(这里省略其他返回结果)
选择一个版本进行安装,我们这里选择2.3.4版本。使用rvm命令安装:rvm install 2.3.4。没错,又遇到拦路虎了,报了一个错:
......(这里省略一些无关紧要的返回信息)
Installing required packages: autoconf, automake, libtool, pkg-config, coreutils, libyaml, readline, libksba..There were package installation errors, make sure to read the log.-Try `brew tap --repair` and make sure `brew doctor` looks reasonable.Check Homebrew requirements https://github.com/Homebrew/homebrew/wiki/Installation..Error running 'requirements_osx_brew_libs_install autoconf automake libtool pkg-config coreutils libyaml readline libksba',please read /Users/chenzepeng/.rvm/log/1524469165_ruby-2.3.4/package_install_autoconf_automake_libtool_pkg-config_coreutils_libyaml_readline_libksba.logRequirements installation failed with status:
1.造成上面错误的原因有很多个,百度到几个原因:brew或其他工具版本过低或未安装导致、xcode命令行工具未安装、一些依赖包被墙导致下载失败等。这里是因为没有安装xcode命令行工具导致的,于是通过终端命令”xcode-select --install“安装该工具(Ps:如果是使用brew install ruby@2.3.4则会更明显的提示出错原因,例如报如下错误:Error: Xcode alone is not sufficient on El Capitan.Install the Command Line Tools:xcode-select --install,直接告诉你要安装Xcode-select)。
安装完毕后,重新执行命令”rvm install 2.3.4“,ruby升级成功。然后继续安装node.js。node安装完毕后,就可以开始安装appium了。这里提供两种方式安装。
第一种,命令行安装。输入命令”npm install -g appium“。
第二种,下载桌面版appium安装。建议到官方网站下载最新版本,网址为”appium.io“。下载到本地后,和安装其他程序一样正常安装即可(这里建议使用桌面版,体验比较好)。
安装appium成功后,就可以使用appium-doctor检查环境是否部署成功了。首先使用”npm install -g appium-doctor“安装appium-doctor。成功后,执行命令”appium-doctor“,若返回结果所有项都检查通过,则appium环境部署完毕。结果如下:
info AppiumDoctor Appium Doctor v.1.4.3info AppiumDoctor
### Diagnostic starting
###info AppiumDoctor ✔
The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor ✔ Node version is 9.11.1
info AppiumDoctor ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor ✔ Xcode Command Line Tools are installed.
info AppiumDoctor ✔ DevToolsSecurity is enabled.
info AppiumDoctor ✔ The Authorization DB is set up properly.
WARN AppiumDoctor ✖ Carthage was NOT found!
info AppiumDoctor ✔ HOME is set to: /Users/chenzepeng
info AppiumDoctor ✔ ANDROID_HOME is set to: /Users/chenzepeng/sdk/android-sdk-macosx
info AppiumDoctor ✔ JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
info AppiumDoctor ✔ adb exists at: /Users/chenzepeng/sdk/android-sdk-macosx/platform-tools/adb
info AppiumDoctor ✔ android exists at: /Users/chenzepeng/sdk/android-sdk-macosx/tools/android
info AppiumDoctor ✔ emulator exists at: /Users/chenzepeng/sdk/android-sdk-macosx/tools/emulator
WARN AppiumDoctor ✖ Bin directory for $JAVA_HOME is not set
info AppiumDoctor ### Diagnostic completed, 2 fixes needed.
###info AppiumDoctor info AppiumDoctor
### Manual Fixes Needed
###info AppiumDoctor
The configuration cannot be automatically fixed, please do the following first:
WARN AppiumDoctor - Please install Carthage. Visit https://github.com/Carthage/Carthage#installing-carthage for more information.
WARN AppiumDoctor - Add '$JAVA_HOME/bin' to your PATH environment
info AppiumDoctor ###info AppiumDoctor info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!info AppiumDoctor
上面信息表明有两项不通过(Carthage未安装、java_home未设置),根据检查结果更改后,再次检查,直到所有项都检查通过即完成appium环境部署。