Appium study 9: Monkey custom scripts practice

Custom stability test scripts

Monkey conventional test execution flow of random events, but if you just want Monkey test a particular scene this time you need to use a custom script, Monkey support the implementation of user-defined test scripts, users need only follow the script of the Monkey specification writing good scripts, stored on your phone, you can start the script by calling Monkey -f parameter.

Test Case

Start PubMed help app3.1.0, then skip the upgrade prompt and guide page, enter the login screen and enter your user name and password to log on.

demand analysis

• From the user perspective to think about the steps how to be?
• how the elements to operate on the positioning?
• How will the procedure into a test script?

Gets the element coordinate point

Monkey scripts only through coordinates to locate clicks and screen position event of way, where you need to get coordinate information in advance. Coordinate information acquired many ways, the easiest way is to open developer options in your phone, open the "Display pointer position." Subsequently, each operation on the screen will display the coordinate information on the navigation bar.

Monkey scripting API Introduction

LaunchActivity (pkg_name, cl_name): Activity start the application. Parameters: the package name and start the Activity.

Tap (x, y, tapDuration): Simulation of a finger click event. Parameters: x, y coordinates for the control, tapDuration for the duration of clicks, this parameter can be omitted.

UserWait (sleepTime): sleep for some time

DispatchPress (keyName): button. Parameters: keycode. RotateScreen (rotationDegree, persist): rotate the screen. Parameters: rotationDegree rotation angle, eg 1 representative of 90 degrees; the persist indicating whether fixed after the rotation, the rotated recovery represents 0, 0 indicates the non-fixed.

DispatchString (input): input string.

DispatchFlip (true / false): open or close the soft keyboard.

PressAndHold (x, y, pressDuration): Press event simulation.

Drag (xStart, yStart, xEnd, yEnd, stepCount): used to simulate a drag operation.

PinchZoom (x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End, stepCount): analog zoom gesture.

LongPress (): Press 2 seconds.

DeviceWakeUp (): wake up the screen.

PowerLog (power_log_type, test_case_status): Analog battery power information.

WriteLog (): the battery information into the sd card.

RunCmd (cmd): run shell commands.

DispatchPointer (downtime, eventTime, action, x, yxpressure, size, metastate, xPrecision, yPrecision, device, edgeFlags): the designated location, sending a single gesture.

DispatchPointer (downtime, eventTime, action, x, yxpressure, size, metastate, xPrecision, yPrecision, device, edgeFilags): sending a PUSH message.

LaunchInstrumentation (test_name, runner_name): Run a test instrumentation.

DispatchTrackball: analog transmission trackball events.

ProfileWait: Wait 5 seconds.

StartCaptureFramerate (): Gets the frame rate.

EndCaptureFramerate (input): Gets the end frame rate.

 

Monkey script format

Monkey script mainly consists of two parts, one is the header file information, the monkey is a specific part of the command.

type = raw events  
count = 1  
speed = 1.0  
//下面为monkey命令  
start data >>   
具体的monkey脚本内容 

 
Scripting
kyb.txt

#头文件信息

type = raw events 

count = 1

speed = 1.0

#启动测试
start data >>

LaunchActivity(com.tal.kaoyan,com.tal.kaoyan.ui.activity.SplashActivity)
UserWait(2000)

Tap(624,900,1000) #点击取消升级
UserWait(2000)

Tap(806,64,1000) #点击跳过
UserWait(2000)

Tap(217,378,1000) #点击用户名输入框
DispatchString(zxw1234)
UserWait(2000)

Tap(197,461,1000) #点击密码输入框
DispatchString(zxw123456)
UserWait(2000)

Tap(343,637,1000) #点击登录按钮

 

Execute the script
after script completion, spread on mobile devices, and then executed.

adb push C:\Users\Shuqing\Desktop\kyb1.txt /sdcard

adb shell monkey -f /sdcard/kyb1.txt -v 1

Results of the

C:\Users\Shuqing>adb shell monkey -f /sdcard/kyb.txt -v 1
:Monkey: seed=1524592021303 count=1
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
Replaying 0 events with speed 1.0
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.tal.kaoyan/.ui.activity.SplashActivity;end
    // Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.tal.kaoyan/.ui.activity.SplashActivity } in package com.tal.kaoyan
:Sending Touch (ACTION_DOWN): 0:(267.0,1233.0)
    // Allowing start of Intent { act=com.android.systemui.recent.action.TOGGLE_RECENTS cmp=com.android.systemui/.recent.RecentsActivity } in package com.android.systemui
:Sending Touch (ACTION_UP): 0:(267.0,1233.0)
Events injected: 5
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=7201ms (0ms mobile, 0ms wifi, 7201ms not connected)
// Monkey finished


Notes
header code written note "=" on both sides to reserve a space, otherwise it will appear as an error.

java.lang.NumberFormatException: Invalid int: ""

 

Published 200 original articles · won praise 9 · views 9655

Guess you like

Origin blog.csdn.net/up1292/article/details/104058807