App自动化技术基础

Android Studio

SDK

  • 使用国内源
  • 使用代理

Android Update Site
https://dl.google.com/android/repository/repository2-3.xml

true Android Automotive System Images https://dl.google.com/android/repository/sys-img/android-automotive/sys-img2-3.xml
true Android Desktop System Images https://dl.google.com/android/repository/sys-img/android-desktop/sys-img2-3.xml
true Android Repository https://dl.google.com/android/repository/repository2-3.xml
true Android Repository v2 https://dl.google.com/android/repository/repository2-2.xml
true Android System Images https://dl.google.com/android/repository/sys-img/android/sys-img2-3.xml
true Android TV System Images https://dl.google.com/android/repository/sys-img/android-tv/sys-img2-3.xml
true Android Wear System Images https://dl.google.com/android/repository/sys-img/android-wear/sys-img2-3.xml
true Android Wear for China System Images https://dl.google.com/android/repository/sys-img/android-wear-cn/sys-img2-3.xml
true Automated Test Device System Images https://dl.google.com/android/repository/sys-img/aosp_atd/sys-img2-3.xml
true Automated Test Device System Images With Google API https://dl.google.com/android/repository/sys-img/google_atd/sys-img2-3.xml
true Glass Development Kit, Google Inc. https://dl.google.com/android/repository/glass/addon2-3.xml
true Google API add-on System Images https://dl.google.com/android/repository/sys-img/google_apis/sys-img2-3.xml
true Google API with Playstore System Images https://dl.google.com/android/repository/sys-img/google_apis_playstore/sys-img2-3.xml
true Google Inc. https://dl.google.com/android/repository/addon2-3.xml
true Google TV System Images https://dl.google.com/android/repository/sys-img/google-tv/sys-img2-3.xml
true Intel HAXM https://dl.google.com/android/repository/extras/intel/addon2-3.xml
curl https://dl.google.com/android/repository/repository2-3.xml
curl -i https://dl.google.com/android/repository/android-22_r02.zip

环境变量

export ANDROID_HOME=/Users/seveniruby/Library/Android/sdk
export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$PATH

Android命令行工具文档

https://developer.android.com/studio/command-line?hl=zh-cn

Emulator

  • intel芯片 x86指令集 pc win+intel mac+intel mac+m1
  • arm芯片 arm指令集 arm
  • app exe apk lib/armeabi-v7a/

App

  • Java Kotlin 模拟器通用
  • Native 使用了so,如果lib包含arm,说明支持arm模拟器
  • Native 使用了so,如果lib包含x86,说明支持x86模拟器
  • mac m1 本身有一些环境判断的bug,可能会导致arm指令集的应用无法运行

Adb

adb基本概念

#adb client 用来执行一些指令
hogwarts: ~ seveniruby$ adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached
emulator-5554	offline

#adb server  维持与手机的连接,usb或者tcp/ip
hogwarts: ~ seveniruby$ ps -ef  | grep adb
  503 45969     1   0  3:05PM ??         0:00.01 adb -L tcp:5037 fork-server server --reply-fd 4

#adbd 维持与pc等外部连接的通讯 执行指令
hogwarts: ~ seveniruby$ adb shell "ps | grep adb"
root      902   1     15012  760   poll_sched 00004383b0 S /sbin/adbd

adb通讯拦截

  • 定位问题
  • mock

mitmproxy代理工具

https://mitmproxy.org/

通讯中转

adb -P 8080  devices

使用mitmproxy监听通讯

hogwarts: ~ seveniruby$ mitmdump -m reverse:127.0.0.1:5037 --flow-detail 4
Proxy server listening at *:8080
127.0.0.1:57419: client connect
127.0.0.1:57419: server connect 127.0.0.1:5037
127.0.0.1:57419 -> tcp -> 127.0.0.1:5037

    000chost:version

127.0.0.1:57419 <- tcp <- 127.0.0.1:5037

    OKAY00040029

127.0.0.1:57419: client disconnect
127.0.0.1:57419: server disconnect 127.0.0.1:5037
127.0.0.1:57421: client connect
127.0.0.1:57421: server connect 127.0.0.1:5037
127.0.0.1:57421 -> tcp -> 127.0.0.1:5037

    000chost:devices

127.0.0.1:57421 <- tcp <- 127.0.0.1:5037

    OKAY0015emulator-5554	device

127.0.0.1:57421: client disconnect
127.0.0.1:57421: server disconnect 127.0.0.1:5037

Monkey

https://developer.android.com/studio/test/other-testing-tools/monkey?hl=zh-cn

Appium

npm install -g appium

Appium Inspector

[
  {
    "key": "elementId",
    "value": "00000000-0000-0001-7fff-ffff0000001c",
    "name": "elementId"
  },
  {
    "key": "index",
    "value": "2",
    "name": "index"
  },
  {
    "key": "package",
    "value": "com.android.calculator2",
    "name": "package"
  },
  {
    "key": "class",
    "value": "android.widget.Button",
    "name": "class"
  },
  {
    "key": "text",
    "value": "9",
    "name": "text"
  },
  {
    "key": "resource-id",
    "value": "com.android.calculator2:id/digit_9",
    "name": "resource-id"
  },
  {
    "key": "checkable",
    "value": "false",
    "name": "checkable"
  },
  {
    "key": "checked",
    "value": "false",
    "name": "checked"
  },
  {
    "key": "clickable",
    "value": "true",
    "name": "clickable"
  },
  {
    "key": "enabled",
    "value": "true",
    "name": "enabled"
  },
  {
    "key": "focusable",
    "value": "true",
    "name": "focusable"
  },
  {
    "key": "focused",
    "value": "false",
    "name": "focused"
  },
  {
    "key": "long-clickable",
    "value": "false",
    "name": "long-clickable"
  },
  {
    "key": "password",
    "value": "false",
    "name": "password"
  },
  {
    "key": "scrollable",
    "value": "false",
    "name": "scrollable"
  },
  {
    "key": "selected",
    "value": "false",
    "name": "selected"
  },
  {
    "key": "bounds",
    "value": "[527,672][747,920]",
    "name": "bounds"
  },
  {
    "key": "displayed",
    "value": "true",
    "name": "displayed"
  }
]

[
  {
    "key": "elementId",
    "value": "00000000-0000-0001-7fff-ffff00000001",
    "name": "elementId"
  },
  {
    "key": "index",
    "value": "0",
    "name": "index"
  },
  {
    "key": "package",
    "value": "com.android.calculator2",
    "name": "package"
  },
  {
    "key": "class",
    "value": "android.widget.EditText",
    "name": "class"
  },
  {
    "key": "text",
    "value": "",
    "name": "text"
  },
  {
    "key": "resource-id",
    "value": "com.android.calculator2:id/formula",
    "name": "resource-id"
  },
  {
    "key": "checkable",
    "value": "false",
    "name": "checkable"
  },
  {
    "key": "checked",
    "value": "false",
    "name": "checked"
  },
  {
    "key": "clickable",
    "value": "true",
    "name": "clickable"
  },
  {
    "key": "enabled",
    "value": "true",
    "name": "enabled"
  },
  {
    "key": "focusable",
    "value": "true",
    "name": "focusable"
  },
  {
    "key": "focused",
    "value": "true",
    "name": "focused"
  },
  {
    "key": "long-clickable",
    "value": "true",
    "name": "long-clickable"
  },
  {
    "key": "password",
    "value": "false",
    "name": "password"
  },
  {
    "key": "scrollable",
    "value": "false",
    "name": "scrollable"
  },
  {
    "key": "selected",
    "value": "false",
    "name": "selected"
  },
  {
    "key": "bounds",
    "value": "[0,63][1080,372]",
    "name": "bounds"
  },
  {
    "key": "displayed",
    "value": "true",
    "name": "displayed"
  }
]

Appium启动Log

作业

  • 分析Appium Log
  • 提取所有的Adb执行命令
  • 对每个命令进行说明
  • 发帖到论坛
#作用说明注释
adb -P 5037 -s emulator-5554 shell dumpsys window

#作用说明注释
adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.uiautomator2.server