最近升级appium server版本至v1.7.1,目前github上最新是v1.7.2,一路走来,有许多东西都想总结下来,益自己、益他人
环境
appium server: v1.7.1
appium desktop: v1.2.7
相关资源
appium server github:
https://github.com/appium/appium
appium desktop github:
https://github.com/appium/appium-desktop/releases/tag/v1.4.1
Appium Client Libraries 官网:
http://appium.io/downloads.html,
可根据熟悉的语言下载对应库
创建远程连接过程【android为例】
前言
进入appium文件夹下,查找 android-helpers.js
文件,发现存在2个文件夹,分别为:
..\appium-android-driver\build\lib\android-helpers.js
..\appium-android-driver\lib\android-helpers.js
阅读完 android-helpers.js
文件,大概可知道执行的整个过程做了什么?但这里有点不太明白什么时候调用 \lib\android-helpers.js
,什么时候调用 \build\lib\android-helpers.js
大概过程
- 获取java环境,
getJavaVersion
- 确认待测设备信息,如
prepareEmulator
、ensureDeviceLocale
等 - 检查caps值,
getDeviceInfoFromCaps
- 初始化辅助工具,这里主要为
initUnicodeKeyboard
、pushSettingsApp
、pushUnlock
- 启动
UiAutomator
,通过'AppiumBootstrap.jar'
,解锁,执行操作
这里特别说一下辅助app的功能
UnicodeIME
: appium 自定义输入法,主要功能隐藏输入法界面及可输入中文
setting
:设置网络等
Unlock
:解锁
以上就是执行的整个过程,但会出现一个现象,每次运行脚本,辅助工具均会重新卸载再安装一遍,对于各个厂商手机,安装权限问题比较头疼
现换一种方式运行脚本执行,如下
方案
测试用例脚本运行之前,自定义安装方法实现安装相应辅助app,禁止appium脚本安装
实现
-
禁止appium脚本安装辅助app
【注意】不同appium server版本修改的文件夹位置不同
修改文件 ..\appium-android-driver\build\lib\android-helpers.js
文件
#安装Unicode keyboard并设置
helpers.initUnicodeKeyboard = function callee$0$0(adb) {
var defaultIME, appiumIME;
return _regeneratorRuntime.async(function callee$0$0$(context$1$0) {
while (1) switch (context$1$0.prev = context$1$0.next) {
case 0:
_logger2['default'].debug('Enabling Unicode keyboard support');
_logger2['default'].debug("Pushing unicode ime to device...");
context$1$0.next = 4;
//return _regeneratorRuntime.awrap(adb.install(_appiumAndroidIme.path, false)); //注释这一行
#安装SettingsApp
helpers.pushSettingsApp = function callee$0$0(adb) {
var throwError = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
var startOpts;
return _regeneratorRuntime.async(function callee$0$0$(context$1$0) {
while (1) switch (context$1$0.prev = context$1$0.next) {
case 0:
_logger2['default'].debug("Pushing settings apk to device...");
context$1$0.prev = 1;
context$1$0.next = 4;
//return _regeneratorRuntime.awrap(adb.installOrUpgrade(_ioAppiumSettings.path, SETTINGS_HELPER_PKG_ID, true));//注释这一行
#安装Unlock app
helpers.pushUnlock = function callee$0$0(adb) {
return _regeneratorRuntime.async(function callee$0$0$(context$1$0) {
while (1) switch (context$1$0.prev = context$1$0.next) {
case 0:
_logger2['default'].debug("Pushing unlock helper app to device...");
context$1$0.next = 3;
//return _regeneratorRuntime.awrap(adb.install(_appiumUnlock.path, false));//注释这一行
-
自定义安装方法
这个地方尝试使用过很多方法,不过均使用了多线程,一个线程监控弹框,一个线程执行安装,对于权限弹框的处理,试过uiautomator操作、appium client api操作、dump当前xml文件并解析找到特定的元素点击,经测试,发现dump当前xml文件并解析找到特定的元素点击的这种方式效率更好,故采用此方法,特地申明:这个方式参考了某个大神的博客,感谢
网友评论