windows配置
略
Mac配置
安装Java
官网下载 Java,下载对应版本安装,完成后配置环境变量vi ~/.bash_profile
,如果安装了zsh操作vi ~/.zshrc
JAVA_HOME=`/usr/libexec/java_home`
export JAVA_HOME
保存后 source ~/.bash_profile
终端输入java -version
出现安装版本号等信息,表示配置正确
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
安装appium
下载appium,建议安装appium-desktop版本,以支持iOS 9.0+系统测试;官方下载地址,dmg安装包直接安装。
配置Android开发环境
简洁的办法通过安装Android studio安装,官网下载安装Android Studio,安装完成后打开Android studio,按照引导下载安装Android sdk,
export ANDROID_HOME=/Users/修改为自己的用户名/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
配置完成后 source ~/.bash_profile
终端adb命令可用表示,Android环境配置完成
Xcode安装
App Store安装Xcode 9.1以上版本
配置iOS真机测试环境
为了可以支持测试机9.0以上系统,环境要求Xcode8+ MAC系统10.11+
安装Xcode
安装Xcode 8+版本,App Store直接可以下载安装9.1,其他版本到https://developer.apple.com/xcode/查找下载。
如果有其他需要可以安装多个版本Xcode,具体方法:
下载不同版本xcode,重命名不同的名字安装,
切换不同版本的xcode,
sudo xcode-select -switch /Applications/Xcode***.app
gcc --version
可以查看当前Xcode版本安装相关的依赖
没有安装brew 官网方式/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安装brew
brew install carthage
brew install libimobiledevice --HEAD
brew install ideviceinstaller
穿插一下ideviceinstaller的用法
ideviceinstaller -l
列出安装应用列表
ideviceinstaller -i ~/****/Im.ipa
安装应用
ideviceinstaller -U com.Im.Im
卸载应用
idevicescreenshot
截图到当前目录
如果有报错Could not connect to lockdownd, error code -21
的问题
可以通过sudo chmod -R 777 /var/db/lockdown
解决,
or 前者操作问题未解决可以如下操作
brew uninstall ideviceinstaller
brew uninstall libimobiledevice
brew install --HEAD libimobiledevice
brew link --overwrite libimobiledevice
brew install ideviceinstaller
brew link --overwrite ideviceinstaller
- 配置WebDriverAgent
在appium目录/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/
下找到WebDriverAgent,因为WebDriverAgent需提前编译运行通过才能使用,先将此文件夹移除,git clone https://github.com/facebook/WebDriverAgent.git
到此目录,双击WebDriverAgent.xcodeproj通过Xcode编译运行wda
打开项目后设置以下内容:
通过Preference->Accounts添加apple ID个人账号即可,下载证书;
设置Bundle Identifier 设置一个复杂的名称避免被别人使用过
终端进入项目(WebDriverAgent)目录,分别执行
mkdir -p Resources/WebDriverAgent.bundle
./Scripts/bootstrap.sh -d
./Scripts/bootstrap.sh
没有报错继续往下走,如有问题,需按具体问题查对应的解决办法。
常遇到的一个报错如下:
ERROR in ./js/app.js
Module parse failed: /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/js/app.js Unexpected token (67:6)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (67:6)
at Parser.pp$4.raise (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp.unexpected (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:603:10)
at Parser.pp$3.parseExprAtom (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1822:12)
at Parser.pp$3.parseExprSubscripts (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1715:21)
at Parser.pp$3.parseMaybeUnary (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1692:19)
at Parser.pp$3.parseExprOps (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1637:21)
at Parser.pp$3.parseMaybeConditional (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1620:21)
at Parser.pp$3.parseMaybeAssign (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1597:21)
at Parser.pp$3.parseParenAndDistinguishExpression (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1861:32)
at Parser.pp$3.parseExprAtom (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1796:19)
at Parser.pp$3.parseExprSubscripts (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1715:21)
at Parser.pp$3.parseMaybeUnary (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1692:19)
at Parser.pp$3.parseExprOps (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1637:21)
at Parser.pp$3.parseMaybeConditional (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1620:21)
at Parser.pp$3.parseMaybeAssign (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1597:21)
at Parser.pp$3.parseExpression (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1573:21)
at Parser.pp$1.parseReturnStatement (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:839:33)
at Parser.pp$1.parseStatement (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:699:34)
at Parser.pp$1.parseBlock (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:981:25)
at Parser.pp$3.parseFunctionBody (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:2105:24)
at Parser.pp$3.parseMethod (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:2075:10)
at Parser.pp$1.parseClassMethod (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1137:25)
at Parser.pp$1.parseClass (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:1118:14)
at Parser.pp$1.parseStatement (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:697:19)
at Parser.pp$1.parseTopLevel (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:638:25)
at Parser.parse (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:516:17)
at Object.parse (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/node_modules/acorn/dist/acorn.js:3098:39)
at Parser.parse (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/lib/Parser.js:902:15)
at NormalModule.<anonymous> (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack/lib/NormalModule.js:104:16)
at NormalModule.onModuleBuild (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
@ multi main
Done
解决办法:
修改vi /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Inspector/webpack.config.js
文件
module: {
loaders: [
// { test: /\.js?$/, loaders: ['babel-loader'], exclude: /node_modules/ }, //修改此行 删除', exclude: /node_modules/'
{ test: /\.js?$/, loaders: ['babel-loader'] },
{ test: /\.css?$/, loader: 'style-loader!css-loader' },
]
},
解决问题直到./Scripts/bootstrap.sh
没有报错信息
USB连接iOS真机,获取设备udid,idevice_id -l
可以获取到或者通过iTunes拿到;
编译WebDriverAgent,进入到项目目录
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=替换获取到的udid' test
第一次运行会报错,需要打开手机设置-通用-设备管理(描述文件)验证apple id,验证通过后再次执行
Test Suite 'All tests' started at 2018-07-15 17:49:16.142
Test Suite 'WebDriverAgentRunner.xctest' started at 2018-07-15 17:49:16.143
Test Suite 'UITestingUITests' started at 2018-07-15 17:49:16.143
Test Case '-[UITestingUITests testRunner]' started.
t = 0.00s Start Test at 2018-07-15 17:49:16.145
t = 0.00s Set Up
2018-07-15 17:49:16.160133+0800 WebDriverAgentRunner-Runner[3707:502461] Built at Jul 15 2018 17:41:42
2018-07-15 17:49:16.201221+0800 WebDriverAgentRunner-Runner[3707:502461] ServerURLHere->http://10.154.23.100:8100<-ServerURLHere
表示WebDriverAgent编译启动通过。
WebDriverAgent也可以通过Xcode编译运行(过程略)
appium 开发环境可以到github下载源码,可以参考https://testerhome.com/topics/2037这篇帖子。
安装appium client
appium是一个web接口,他接受http请求,各个语言都可以自己封装发送请求与appium server进行交互进而操作测试机进行测试
官方对应各个语言的client 选择自己所用语言的client进入到GitHub页面,点击选择release标签下载安装包安装。
启动appium server 进行测试
- Android
可以通过appium ui的界面启动server 也可以通过命令去启动,
node /Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js --no-reset -U device_id
具体对应的参数意义可以查看官方的说明
默认监听端口4723 appium通信端口4724(android)
启动server后,测试启动Android app参数示例:
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True # 设置用appium的输入法
desired_caps['newCommandTimeout'] = 240
desired_caps['platformName'] = 'android' # 测试平台
desired_caps['appPackage'] = 'Im.chen'
desired_caps['appActivity'] = 'com.Im.StartFlashActivity'
desired_caps['version'] = '7.0' # 系统版本
desired_caps['deviceName'] = 'deviceid' # 测试机设备号
desired_caps['app'] = '/path/pro.Im.apk' # 被测的apk的位置
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
- iOS
- 需启动appium server
node /Applications/Appium.app/Contents/Resources/app/node_modules/appium/build/lib/main.js --no-reset -U udid
- 启动WebDriverAgent
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=udid' test
启好后,需要转发8100端口iproxy 8100 8100
,完成后浏览器访问http://localhost:8100/status
得到json数据表示ok
准备工作完成后,测试iOS应用参数示例:
desired_caps={}
desired_caps['automationName'] = 'XCUITest'
desired_caps['userable'] = 'yes'
desired_caps['enabel'] = 'yes'
desired_caps['newCommandTimeout'] = 20000
desired_caps['platformName'] = 'ios'
desired_caps['platformVersion'] = '10.3.3'
desired_caps['deviceName'] = 'iPhone 6s'
desired_caps['bundleId'] = 'com.Im.Im'
desired_caps['udid'] = 'udid'
desired_caps['xcodeOrgId'] = '******'
# 这个参数可以在Xcode上获取,也可以在启动WebDriverAgent后找到应用的内容
desired_caps['webDriverAgentUrl'] = "http://localhost:8100"
desired_caps['app'] = "/path/"
self.driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)