Links to automated test history articles

Android Monkey stress test 2.Android Monkey advanced parameter application 3.Android MonkeyScript command simple application 4 The application of UiAutomator2.0

MonkeyRunner

The API used by MonkeyRunner

MonkeyRunner API – alert

Void alert(string message,string tilte,string okTitle)Copy the code

Take a chestnut

#! /usr/bin/python # -*- coding: utf-8 -* from com.android .monkeyrunner import MonkeyRunner MonkeyRunner.alert('Hello Monkey','Monkey','OK')Copy the code

Create a new file and name it hello.py. Go to the monkeyRunner directory and run the following command

monkeyrunner F:\python\monkey\hello.py
Copy the code

The effects are as follows (make sure the Python environment is available, and environment variables are configured)

Run the script method

monkeyrunner  <script-file path>
Copy the code

MonkeyRunner API – waitForConnect

WaitForConnection (Float Timeout, String Deviceid)Copy the code

MonkeyDevice API – drag

Drag (tuple start,tuple end,float duration,integer steps) start Start position, end end position, duration Duration of gesture step Number of interpolating steps, default 10Copy the code

MonkeyDevice API – press

Press (String Keycode, Dictionary type) Keycode name,DOWN, UP, DOWN_AND_UPCopy the code

MonkeyDevice API – startActivity

Start startActivity (package + '/' + activity)Copy the code

MonkeyDevice API – touch

Click touch(INTEGER x,integer y, INTEGER Type) for the x coordinate value and for the Y coordinate value type:DOWN, UP, DOWN_AND_UPCopy the code

MonkeyDevice API – type

Input type (string message)Copy the code

MonkeyImage API – takeSnapshot

Screenshots MonkeyImage takeSnapshot ()Copy the code

MonkeyImage API -sameAs

Boolean sameAs(MonkeyImage other,float Percent)Copy the code

MonkeyImage API -writeToFile

Void writeToFile(String Path, String Format)Copy the code

As shown above, we now need to simulate A series of events through MonkeyRunner: 1) open the application; 2) click Receiver broadcast; 3) Click REGISTER A Receiver; 4) Enter Hello in the edit box. 5) Click SEND A RECEIVER 6) Click UNREGISTER A RECEIVER 7) Click CLEAR to CLEAR the edit box 8) Return to exit and return to the home page. You need to complete the 8 processes. Create A new file named monkey.py and edit the following code to see the effect

#! /usr/bin/python # -*- coding: Utf-8 - * from com. Android. Monkeyrunner import monkeyrunner, MonkeyDevice, MonkeyImage device = # connection device MonkeyRunner. WaitForConnection (# 3, "emulator - 5554)" to start the App device. The startActivity (" me. Peace. Ka/me. Peace. Ka. MainActivity ") MonkeyRunner. Sleep (2) # Click Receiver to broadcast device.touch(100,400,"DOWN_AND_UP" Device.touch (100,600,"DOWN_AND_UP") MonkeyRunner. Sleep (1) MonkeyRunner. Sleep (1) # image = device.takesnapshot () Image.writetofile ("D:/test.png"," PNG ") # Return key hide keyboard device.press("KEYCODE_BACK","DOWN_AND_UP") MonkeyRunner A RECEIVER device.touch(100,400,"DOWN_AND_UP") MonkeyRunner. Sleep (1 Touch (100,800,"DOWN_AND_UP") MonkeyRunner. Sleep (1) Press ("KEYCODE_BACK","DOWN_AND_UP" device.press("KEYCODE_BACK","DOWN_AND_UP") MonkeyRunner.sleep(5)Copy the code

If you liked this article or helped you, please give me a Star

https://github.com/peace710/AJLife