当前位置:   article > 正文

shell+adb自动化_adb shell实现自动化测试

adb shell实现自动化测试

注意:Windows下执行shell命令,可以借助Git Bash Here进行执行
在这里插入图片描述

向上滑动

adb shell "input swipe 540 1000 540 500 1000"
while true;do adb shell "input swipe 540 1000 540 500 1000";done
  • 1
  • 2

向下滑动

while true;do adb shell "input swipe 540 1000 540 2000 1000";done
  • 1

获取内存信息,可以查看是否有内存泄漏

while true;do adb shell dumpsys meminfo com.bs.finance | grep "Dalvik Heap";done
  Dalvik Heap    21634    21608        0      365    31127    15564    15563
  Dalvik Heap    14610    14544        0      284    30798    15399    15399
  Dalvik Heap    14458    14392        0      284    30825    15413    15412
  Dalvik Heap    14458    14392        0      284    30797    15399    15398


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

执行点击操作

shenyf@DESKTOP-5N7A05K MINGW64 /e
click(){
local index=1
[ -n "$2" ] && index=$2
adb shell input tap \
$(
adb shell "uiautomator dump --compressed && cat /sdcard/window_dump.xml" \
| sed 's#<node#^<node>#g' \
| awk 'BEGIN{RS="^"}{print $0}' \
| grep "$1" \
| sed -n "$index"p \
| awk 'BEGIN{FS=",|\\[|\\]"}{print ($2+$5)/2,($3+$6)/2}'
)
}

shenyf@DESKTOP-5N7A05K MINGW64 /e
$ click 广东
shenyf@DESKTOP-5N7A05K MINGW64 /e
$ while true;do click 推荐;click 机构;done

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

输入

input(){
adb shell input text 123
}
  • 1
  • 2
  • 3

滑动

shenyf@DESKTOP-5N7A05K MINGW64 /e
swipe(){
width=$(adb shell wm size | grep -oE "[0-9]+" | head -1)
height=$(adb shell wm size | grep -oE "[0-9]+" | tail -1)
adb shell 'input swipe $(awk "BEGIN{print '$width'*'$1'}") $(awk "BEGIN{print '$height'*'$2'}") $(awk "BEGIN{print '$width'*'$3'}") $(awk "BEGIN{print '$height'*'$4'}") 1000'
}

# 向下滑动
shenyf@DESKTOP-5N7A05K MINGW64 /e
$ swipe 0.5 0.5 0.8 0.8

# 向上滑动
shenyf@DESKTOP-5N7A05K MINGW64 /e
$ swipe 0.8 0.8 0.2 0.2

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

案例

Windows平台需要安装gnuplot,并配置path路径

shenyf@DESKTOP-5N7A05K MINGW64 /d/gnuplot/bin
$ for i in $(seq 20);do adb shell dumpsys meminfo com.bs.finance | grep "Dalvik Heap" | awk '{print $4}';sleep 1;done | gnuplot -e "set terminal dumb;plot '<cat' using 1 with line"


  13800 +------------------------------------------------------------------+
        |      +     +      +      +      +     +      +      +     +      |
  13600 |-+                                         '<cat' using 1 *******-|
        |                                                           *      |
  13400 |-+                                                         **   +-|
        |                                                          * *     |
  13200 |-+                                                        *  *  +-|
        |                                                          *  *    |
  13000 |-+                                                        *   * +-|
        |                                                          *   *   |
  12800 |-+                                                        *    *+-|
        |                                                         *     *  |
  12600 |-+                                                       *      +-|
        |                                                         *        |
  12400 |-+                                                       *      +-|
        |                                                         *        |
  12200 |-+                                                       *      +-|
        |                                                        *         |
  12000 |**                                                      *       +-|
        |  *******************************************************  +      |
  11800 +------------------------------------------------------------------+
        0      2     4      6      8      10    12     14     16    18     20


shenyf@DESKTOP-5N7A05K MINGW64 /d/gnuplot/bin
$

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号