Appium在接收到客户端脚本的连接之后的初始化准备工作列表(细节部分详细叙述,只说重点): 下面提到的有关目录是自己的本地目录,需要注意。
1,检查app包是否存在,检查adb工具是否可用,检查java工具包版本。
2,确定设备,用命令 adb.exe devices 选择指定udid的设备
3,确定设备是否准备好,命令 - <p style="box-sizing: inherit; margin-top: 16px; margin-bottom: 14px; line-height: 28px;">adb.exe -s 16144573 wait-for-device</p><p style="box-sizing: inherit; margin-top: 16px; margin-bottom: 14px; line-height: 28px;">adb.exe -s 16144573 shell "echo 'ready'"</p>
复制代码如果命令行输出ready,则表示准备好
4,检查设备的API版本号,命令 - adb.exe -s 16144573 shell "getprop ro.build.version.sdk"
复制代码如果>=17,则可用
5,语言设置 获取设备当前使用语言(一般返回zh) - adb.exe -s 16144573 shell "getprop persist.sys.language"
复制代码生成string.json - java -jar "C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "E:\workspace\appium-test\sample\apps\ContactManager\ContactManager.apk" "C:\Users\ADMINI~1\AppData\Local\Temp\com.example.android.contactmanager" zh
复制代码如果报错,则执行下面,生成string.json - java -jar "C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "E:\workspace\appium-test\sample\apps\ContactManager\ContactManager.apk" "C:\Users\ADMINI~1\AppData\Local\Temp\com.example.android.contactmanager"
复制代码然后从string.json设置成默认语言 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 push "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\com.example.android.contactmanager\\strings.json" /data/local/tmp
复制代码
6,检查aapt工具,并且用aapt工具分析apk包。 - D:\soft\android-sdk-windows\build-tools\23.0.1\aapt.exe dump xmltree E:\workspace\appium-test\sample\apps\ContactManager\ContactManager.apk AndroidManifest.xml
复制代码获取到apk的进程名称:com.example.android.contactmanager,(如果指定的话,则没必要获取)。 和开始的activity:.ContactManager,(如果指定的话,没必要去获取)。
7,注册认证apk包 - java -jar "C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\jars\verify.jar" E:\workspace\appium-test\sample\apps\ContactManager\ContactManager.apk
复制代码
8,压缩apk包(Zip-aligning),并且放入手机中,这个过程有点儿复杂。 - D:\soft\android-sdk-windows\build-tools\23.0.1\zipalign.exe -f 4 E:\workspace\appium-test\sample\apps\ContactManager\ContactManager.apk C:\Users\ADMINI~1\AppData\Local\Temp\116530-6572-vjd4bu\appium.tmp
复制代码获取MD5 - MD5 for app is b2d2916bb5388e1dc281ec3e71ef1234
复制代码查看apk是否存在 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "ls /data/local/tmp/b2d2916bb5388e1dc281ec3e71ef1234.apk"
复制代码查看apk是否安装 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "pm list packages -3 com.example.android.contactmanager"
复制代码创建文件夹 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "mkdir -p /data/local/tmp/"
复制代码查看存在的apk - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "ls /data/local/tmp/*.apk"
复制代码删除存在的apk - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell rm "/data/local/tmp/29649242b53e9a67ba855b067422713c.apk"
复制代码放入手机中 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 push "E:\\workspace\\appium-test\\sample\\apps\\ContactManager\\ContactManager.apk" /data/local/tmp/b2d2916bb5388e1dc281ec3e71ef1234.apk
复制代码停止之前运行的 - <p style="box-sizing: inherit; margin-top: 16px; margin-bottom: 14px; line-height: 28px;">D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "am force-stop com.example.android.contactmanager"</p><p style="box-sizing: inherit; margin-top: 16px; margin-bottom: 14px; line-height: 28px;">D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "pm clear com.example.android.contactmanager"</p>
复制代码卸载之前运行的 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 uninstall com.example.android.contactmanager
复制代码安装新apk包 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "pm install -r /data/local/tmp/b2d2916bb5388e1dc281ec3e71ef1234.apk"
复制代码
9,绑定本机和boostrap通信的端口号 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 forward tcp:4724 tcp:4724
复制代码
10,将bootstrap.jar放入手机中 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 push "C:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/
复制代码
11,让Unicode键盘可用 将Unicode输入法push到手机中 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unicode_ime_apk\UnicodeIME-debug.apk"
复制代码获取手机当前的输入法,测试之后要恢复这个输入法 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "settings get secure default_input_method"
复制代码设置unicode键盘可用,并且为当前系统的默认输入法 - <p style="box-sizing: inherit; margin-top: 16px; margin-bottom: 14px; line-height: 28px;">D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "ime enable io.appium.android.ime/.UnicodeIME"</p><p style="box-sizing: inherit; margin-top: 16px; margin-bottom: 14px; line-height: 28px;">D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "ime set io.appium.android.ime/.UnicodeIME"</p>
复制代码
12,安装appiium的setting和unlock测试包 unlock - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
复制代码Setting - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 install "C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
复制代码
13,启动手机上的bootstrap。 首先停止手机上之前的boostrap: 获取当前运行的boostrap - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "ps 'uiautomator'"
复制代码获取到进程号16324,然后杀死 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "kill 16324"
复制代码然后开始当前的boostrap - D:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.example.android.contactmanager -e disableAndroidWatchers false
复制代码
14,然后就可以用socket和手机通信了,通信的前三步 第一步: 向手机端发送:{"cmd":"action","action":"wake","params":{}} 使手机觉醒,并且判断锁屏的情况(这个有待研究),如果锁屏,运行unlock可以解锁 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s NVY9AUSO5SAELRSC shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n io.appium.unlock/.Unlock"
复制代码
第二步: 向手机发送:{"cmd":"action","action":"getDataDir","params":{}} 获取数据存放路径,正常返回{"value":"\/data\/local\/tmp","status":0},好像没啥用 再发送 {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}} 返回{"value":false,"status":0} 是某个支持项。
第三步: 启动要测试的apk - D:\soft\android-sdk-windows\platform-tools\adb.exe -s NVY9AUSO5SAELRSC shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.example.android.contactmanager/.ContactManager"
复制代码
让app获得当前的焦点 - D:\soft\android-sdk-windows\platform-tools\adb.exe -s NVY9AUSO5SAELRSC shell "dumpsys window windows"
复制代码
|