小小糖 发表于 2019-1-25 15:52:45

appium通信分析(appium的初始化准备工作)

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.jsonjava -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.jsonjava -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获取MD5MD5 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/"查看存在的apkD:\soft\android-sdk-windows\platform-tools\adb.exe -s 16144573 shell "ls /data/local/tmp/*.apk"删除存在的apkD:\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测试包unlockD:\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"SettingD:\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"然后开始当前的boostrapD:\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}是某个支持项。
第三步:启动要测试的apkD:\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"

页: [1]
查看完整版本: appium通信分析(appium的初始化准备工作)