第十期_appium 底层原理剖析_20190901

Appium Log分析

appium的常用andorid生态相关的命令

/Users/seveniruby/Library/Android/sdk/tools/bin/apkanalyzer manifest print ~/Downloads/com.xueqiu.android_11.28.1_227.apk | grep -A1 "<activity" | grep "android:name=" | awk -F\\" '{print $2}'

命令分类

  • appium的执行shell命令
  • webdriver命令
  • chromedriver日志

Adb命令

adb 记录

echo "# $$ "$(date "+%Y/%m/%d %H:%M:%S") >> /tmp/adb.log
echo "# ppid: $(ps -o command  $(ps -o ppid $$ | tail -1) | tail -1)" >> /tmp/adb.log
echo "adb $@" >> /tmp/adb.log
if echo "$@" | grep logcat; then
  echo "origin run" >> /tmp/adb.log
  exec /Users/seveniruby/Library/Android/sdk//platform-tools/adb.bak "$@"
else
  /Users/seveniruby/Library/Android/sdk//platform-tools/adb.bak "$@" | while read line;do
    echo "$line" >> /tmp/adb.log
    echo "$line"
  done
fi
echo "" >> /tmp/adb.log

adb架构

Shell mock

echo "# $$ "$(date "+%Y/%m/%d %H:%M:%S") >> /tmp/adb.log
echo "# ppid: $(ps -o command  $(ps -o ppid $$ | tail -1) | tail -1)" >> /tmp/adb.log
echo "adb $@" >> /tmp/adb.log
if echo "$@" | grep logcat; then
  echo "origin run" >> /tmp/adb.log
  exec /Users/seveniruby/Library/Android/sdk//platform-tools/adb.bak "$@"
  exit
elif echo "$@" | grep -E "exec|uiautomator runtest" &>/dev/null; then
  echo "origin run" >> /tmp/adb.log
  exec /Users/seveniruby/Library/Android/sdk//platform-tools/adb.bak "$@"
  exit
elif echo "$@" | grep "dumpsys package io.appium.settings" &>/dev/null; then
  cat /Users/seveniruby/temp/appium/package.mock
  exit
elif echo "$@" | grep "io\\.appium\\.settings" &>/dev/null;then
  echo "11111"
  exit
else
  /Users/seveniruby/Library/Android/sdk//platform-tools/adb.bak "$@" | while read line;do
    echo "$line" >> /tmp/adb.log
    echo "$line"
  done
fi
echo "" >> /tmp/adb.log

appium的webdriver请求

2019-09-01 02:17:31:657 [HTTP]
2019-09-01 02:17:31:661 [HTTP] --> POST /wd/hub/session/ec0a647f-0e8d-4d41-a2a0-c346e9d1b955/timeouts
2019-09-01 02:17:31:662 [HTTP] {"implicit":15000}
2019-09-01 02:17:31:666 [W3C (ec0a647f)] Calling AppiumDriver.timeouts() with args: [null,null,null,null,15000,"ec0a647f-0e8d-4d41-a2a0-c346e9d1b955"]
2019-09-01 02:17:31:888 [BaseDriver] W3C timeout argument: {"implicit":15000}}
2019-09-01 02:17:31:889 [BaseDriver] Set implicit wait to 15000ms
2019-09-01 02:17:31:891 [W3C (ec0a647f)] Responding to client with driver.timeouts() result: null
2019-09-01 02:17:31:893 [HTTP] <-- POST /wd/hub/session/ec0a647f-0e8d-4d41-a2a0-c346e9d1b955/timeouts 200 230 ms - 14

分析性能

MacBook-Pro-3:~ seveniruby$ grep "HTTP.*<\\-\\-" /tmp/appium.log
2019-09-01 02:17:31:656 [HTTP] <-- POST /wd/hub/session 200 20177 ms - 1348
2019-09-01 02:17:31:893 [HTTP] <-- POST /wd/hub/session/ec0a647f-0e8d-4d41-a2a0-c346e9d1b955/timeouts 200 230 ms - 14
2019-09-01 02:17:50:767 [HTTP] <-- POST /wd/hub/session/ec0a647f-0e8d-4d41-a2a0-c346e9d1b955/element 404 18871 ms - 437
MacBook-Pro-3:~ seveniruby$

WebDriver协议

curl 'http://127.0.0.1:4723/wd/hub/session' \\
-XPOST -H "Content-Type: Application/JSON" \\
-d '
{"capabilities":{"firstMatch":[{"platformName":"android","appium:deviceName":"hogwarts","appium:appPackage":"com.xueqiu.android","appium:appActivity":".view.WelcomeActivityAlias","appium:noReset":"true","appium:skipUnlock":true,"appium:skipLogcatCapture":true,"appium:disableAndroidWatchers":true,"appium:ignoreUnimportantViews":true,"appium:skipServerInstallation":true,"appium:systemPort":6790,"appium:chromedriverExecutable":"/Users/seveniruby/projects/chromedriver/2.20/chromedriver","appium:showChromedriverLog":true}]},"desiredCapabilities":{"platformName":"android","deviceName":"hogwarts","appPackage":"com.xueqiu.android","appActivity":".view.WelcomeActivityAlias","noReset":"true","skipUnlock":true,"skipLogcatCapture":true,"disableAndroidWatchers":true,"ignoreUnimportantViews":true,"skipServerInstallation":true,"systemPort":6790,"chromedriverExecutable":"/Users/seveniruby/projects/chromedriver/2.20/chromedriver","showChromedriverLog":true}}
'

session_id=$(curl 'http://127.0.0.1:4723/wd/hub/sessions'  | awk -F\\" '{print $6}')

curl "http://127.0.0.1:4723/wd/hub/session/${session_id}/element" \\
-XPOST -H "Content-Type: Application/JSON" \\
-d  '{"using":"id","value":"user_profile_icon"}'

Appium的组件

caps['showChromedriverLog']=True

定制Appium

  • nodejs源码修改
  • android uiautomator2 server修改

./gradlew clean  assembleServerDebug assembleServerDebugAndroidTest

find . -name "*.apk"
./app/build/outputs/apk/androidTest/server/debug/appium-uiautomator2-server-debug-androidTest.apk
./app/build/outputs/apk/server/debug/appium-uiautomator2-server-v3.7.0.apk

MacBook-Pro-3:appium-uiautomator2-server seveniruby$ find /usr/local/lib/node_modules/appium -name "*.apk"
/usr/local/lib/node_modules/appium/node_modules/_appium-base-driver@3.21.2@appium-base-driver/test/basedriver/fixtures/FakeAndroidApp.apk
/usr/local/lib/node_modules/appium/node_modules/_appium-uiautomator2-server@4.2.1@appium-uiautomator2-server/apks/appium-uiautomator2-server-v4.2.1.apk
/usr/local/lib/node_modules/appium/node_modules/_appium-uiautomator2-server@4.2.1@appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk
/usr/local/lib/node_modules/appium/node_modules/_appium-espresso-driver@1.15.1@appium-espresso-driver/espresso-server/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
/usr/local/lib/node_modules/appium/node_modules/_appium-selendroid-driver@1.13.4@appium-selendroid-driver/selendroid/selendroid-server.apk
/usr/local/lib/node_modules/appium/node_modules/_io.appium.settings@2.14.1@io.appium.settings/apks/settings_apk-debug.apk

课后作业

  • 提取appium中的所有shell命令,给出命令的解释说明,回帖并写成blog发出去
关闭