Linux基本知識(四):Android常用自動化コマンド

6498 ワード

共通コマンド
adb shell "uiautomator dump --compressed && cat /sdcard/window_dump.xml

input text abc
input text 123
input tap 1000 600
input text 123
input tap 1000 600
input swipe 100 1500 800 500                        
input swipe 100 1500 800 500
input swipe 100 1500 800 500
input swipe 100 1500 800 500

コメント#以降の文は、shellが複数行のコメントを解析しない場合は、<<パラメータ伝達
$0:実行を示すプログラムは、実行ディレクトリに対するパス$1,$2,$3:がいくつか目のパラメータであり、デフォルトshellは9つのパラメータのみをサポートし、shiftを使用してより多くのパラメータ@,@,@::すべてのパラメータを伝えることができ、$0 KaTeX parse error:Expected'}',got'#'at position 2:{#̲*}と{#@}が位置パラメータを表す個数は、∗:1:3,{*:1:3},∗:1:3,{.$#}で複数のパラメータを表す
関数#カンスウ#
[function]name(){
...
}

Functionは省略できます.スクリプトファイルで関数を使用するほか、shellで定義することもできます.これらの定義は、今回のshellが終了すると消えます.returnがない場合、戻り値は最後の命令の戻り値です.
Android SDKをインストールし、adbサービスを見つけます
       
adb devices
adb shell
top |     
top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [ -t ] [ -h ]
    -m num  Maximum number of processes to display.
    -n num  Updates to show before exiting.
    -d num  Seconds to wait between updates.
    -s col  Column to sort by (cpu,vss,rss,thr).
    -t      Show threads instead of processes.
    -h      Display this help screen.

デバッグの実行
実例パッケージ関数
click(){
adb shell input tap $( adb shell "uiautomator dump --compressed && cat /sdcard/window_dump.xml"  | sed 's# | tr ^ '
'
| grep "$@" | awk -F '\\[|\\]|,' '{print ($(NF-2)
+$(NF-5))/2, ($(NF-1)+$(NF-4))/2 }') } send_keys(){ adb shell input text "$@" } swipe(){ size=$(adb shell wm size) start=$(echo "$size" | awk -v x=$1 -v y=$2 -F ' |x' '{print $(NF-1)*x, $NF*y}') end=$(echo "$size" | awk -v x=$3 -v y=$4 -F ' |x' '{print $(NF-1)*x, $NF*y}') adb shell input swipe $start $end }

スクリプトの実行
#        
localhost:~ seveniruby$ click     
localhost:~ seveniruby$ click       
localhost:~ seveniruby$ send
send_keys  sendmail
localhost:~ seveniruby$ send_keys 11111111
localhost:~ seveniruby$ click       
localhost:~ seveniruby$ send_keys 1234
localhost:~ seveniruby$ click '"  "

#       
localhost:~ seveniruby$ swipe 0.1 0.8 0.9 0.3
localhost:~ seveniruby$ swipe 0.1 0.8 0.9 0.3
localhost:~ seveniruby$ swipe 0.9 0.8 0.1 0.3
localhost:~ seveniruby$ swipe 0.9 0.8 0.1 0.3