移动UI自动化测试中,很多人用appium这个开源框架。
发现很多人在安装时,安装过程中出现各种问题,花费很多时间。特别是团队开始用时。每个人都在这上面踩坑,得不偿失。
我写了一个脚本来自动实现这个安装环境。当时我的shell能力也很一般,如果有改进的地方,可以指出来。
Appium是一款开源的跨平台测试自动化工具,适用于本地,混合和移动网络和桌面应用程序。支持模拟器(iOS、Android)和真实设备(iOS,Android,Windows,Mac)。
准备工具
· Xcode
· PyCharm
· Command Line Tool
· HomeBrew 、Node 、npm ...
这里以mac环境为例,讲讲如何准备appium环境。
首先你得检测你的java环境是否装好。
1.安装Homebrew
Homebrew是MACOSX的软件管理工具,粗俗点说就是ma界的qq软件助手之类的东西。所以通过brew,安装什么chrome浏览器啊、atom编辑器之类的可视化工具也是可以的。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.安装Node
brew install node
3.安装npm
npm 是node.js界的程序/模块管理工具,也就是说npm只管理那些服务于JavaScript社区的程序。而且跨平台,只要有node环境,windows和osx,以及其他unix like操作系统都可以使用
切换淘宝镜像安装npm
npm install -g cnpm --registry=https://registry.npm.taobao.org
4.安装carthage
类似cocoapods管理第三方代码,自动将工程编译为动态库,仅支持iOS8以上。
brew install carthage
5.安装其他工具
libimobiledevice 使用指南:
brew install libimobiledevice --HEAD
ideviceinstaller 负责给iOS设备安装卸载应用或者备份应用。该工具是基于libmobiledevice的,因此首先要完成libmobiledevice的编译安装。
brew install ideviceinstaller
### 6.安装Appium-Python-Client
如果我们用python语言来写appim,还需要安装Appium-Python-Client
pip install Appium-Python-Client
6.安装appium
npm install -g appium
当然,你可以切换淘宝镜像
7.安装appiumappium-doctor
npm install -g appium-doctor
运行appium-doctor来检测你的环境
God! 太多了,能不能有简便的方法。
我写了一个脚本,执行一下,能干上面所有事情。
#!/bin/bash
# get the java version
java_version=`java -version`
if [[ $check_results =~ "1.8." ]]
then
echo "java version is 1.8, it seems not need to install java again."
else
echo "It is going to install jdk 1.8 version"
fi
# add JAVA_HOME in env
java_location=`ls -lrt /usr/bin/java | awk '{print $NF}'`
profile_location="/Users/anderson/.bash_profile"`sed -i '$a export JAVA_HOME=${java_location} export PATH=$PATH:$JAVA_HOME/bin' ${profile_location}`
if [ $? -eq 0 ]; then
echo "add java env success"
else
echo "add java env fail"
fi
# check homebrew
check_results=`brew -v | grep "Homebrew"`echo "brew version is: ${check_results}"
if [[ $check_results =~ "Homebrew" ]]
then
echo "package Homebrew has already installed. "
else
echo "This is going to install package Homebrew"
`/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`
if [ $? -eq 0 ]; then
echo "Install brew success"
else
echo "Install brew fail"
fi
fi
#install node
check_results=`node -v`echo "node version is: ${check_results}"
if [[ $check_results =~ "\d+" ]]
then
echo "node has already installed. "
echo "will upgrade node"
`brew upgrade node`
else
echo "This is going to install package node"
`brew install node`
if [ $? -eq 0 ]; then
echo "Install node success" else
echo "Install node fail"
fi
fi
#install appium
check_results=`appium -v`echo "appium version is: ${check_results}"
if [[ $check_results =~ "\d+" ]]
then
echo "appium has already installed. "
else
echo "This is going to install package appium"
`npm install -g appium --registry http://registry.npm.taobao.org`
if [ $? -eq 0 ]; then
echo "Install appium success"
else
echo "Install appium fail"
fi
fi
cmd_list=( "npm install wd"
"pip install Appium-Python-Client"
"npm install -g appium-doctor --registry http://registry.npm.taobao.org"
"brew install carthage"
"brew install libimobiledevice --HEAD"
"brew install ideviceinstaller"
"brew install upgrade ideviceinstaller"
"gem install xcpretty"
"npm install app-inspector -g"
"appium-doctor"
)
function install(){
echo "will install $@"
result = $($@)
if [ $? -eq 0 ]; then
echo "Install $1 success"
else
echo "Install $1 fail"
fi
}
for ((i=0; i< ${#cmd_list[*]}; i++))
do
echo "start to install ${cmd_list[$i]} \n"
install ${cmd_list[$i]}
done
用shell来处理环境,效率会高很多,还不会出错。
还可以练练shell, 一举多得。