shell+adb自动化

注意: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

向下滑动

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

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

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


执行点击操作

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

输入

input(){
adb shell input text 123
}

滑动

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

案例

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
$

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值