appium --- adb shell input analog operation Series

  android as adb Debug Bridge, and in doing automation app has great utility that can help us solve the problem, the main understanding adb shell input today

adb shell input 

We first enter cmd What have adb shell input

$ adb shell input
Usage: input [<source>] <command> [<arg>...]

The sources are:
      mouse
      keyboard
      joystick
      touchnavigation
      touchpad
      trackball
      stylus
      dpad
      touchscreen
      gamepad

The commands and default sources are:
      text <string> (Default: touchscreen)
      keyevent [--longpress] <key code number or name> ... (Default: keyboard)
      tap <x> <y> (Default: touchscreen)
      swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
      press (Default: trackball)
      roll <dx> <dy> (Default: trackball)

Above in the end talk so much of what?

In fact, it means support what content

1, text: supports input text (does not support Chinese)

2, keyevent: analog button

3, tap: Click

4, swipe: sliding

5, press: Press trackball

6, roll: trackball scroll

text

Directly open input terminal

# Input Chinese characters 
adb shell input text 1111

keyevent

Open the thrust directly input

# Analog phone keypad Home 
adb shell KeyEvent the INPUT 3

tap

Select the coordinates on the phone and direct input

# tap点击
 adb shell input tap 454 204

How the coordinates: view coordinate [393,140] [516,268] by uiautomatorviewer.bat positioning tool, and obtains the middle value [454204]

 

swipe

Like tap and select two slides coordinates, the coordinates of the selected side is quiet (x * 1/2 Y * 3/4 ​​x * 1/2 Y * 1/4)

Code input

Above so many are knocked out in cmd, really sure you want to automate the code, we can for these common adb commands encapsulated

import os
class input(object):

  # 输入文字  
    def text(self,text):
        adb = 'adb shell input text %s'%text
        os.popen(adb)

  # 滑动  
    def swipe(self,x,y,x1,y1):
        adb = 'adb shell input swipe %s %s %s %s '%(x,y,x1,y1)
        os.popen(adb)

    # 模拟按键
    def keyevent(self,k):
        adb = 'adb shell input keyevent %s'%k
        os.popen(adb)

if __name__ == '__main__':
    adb = input()
    adb.text(1111)
    adb.swipe(280,720,280,240)
    adb.keyevent(3)

 

PS: In fact, writing so many will find that there are many ways, with a specific kind of depends on what you use it more convenient to use which.

 

Guess you like

Origin www.cnblogs.com/qican/p/12589941.html