forked from organicmaps/organicmaps
[android, test] basic monkey runner
This commit is contained in:
parent
8dd7fdb88e
commit
d5c113a2db
3 changed files with 86 additions and 0 deletions
2
android/script/run_monkey.sh
Normal file
2
android/script/run_monkey.sh
Normal file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
monkeyrunner ../tests/monkey/mrunner.py $1
|
45
android/tests/monkey/mrunner.py
Executable file
45
android/tests/monkey/mrunner.py
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env monkeyrunner
|
||||
|
||||
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
|
||||
from random import randint, random
|
||||
import mutil as mu
|
||||
import sys, os
|
||||
|
||||
outputdir = '../tests/monkey/output'
|
||||
id = 'default'
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
#using specified id
|
||||
id = sys.argv[1]
|
||||
snapshotname = 'snapshot_%d_' + id +'.png'
|
||||
print 'Connecting to device %s' % id
|
||||
device = MonkeyRunner.waitForConnection(5, id)
|
||||
else :
|
||||
snapshotname = 'snapshot_%d.png'
|
||||
print 'Connecting ...'
|
||||
device = MonkeyRunner.waitForConnection(timeout=5)
|
||||
|
||||
if not device:
|
||||
sys.exit("Could not connect to device")
|
||||
else :
|
||||
print 'Connected'
|
||||
|
||||
apkPath = '../MapsWithMePro/bin/MapsWithMePro-debug.apk'
|
||||
package = 'com.mapswithme.maps.pro'
|
||||
activity = 'com.mapswithme.maps.DownloadResourcesActivity'
|
||||
|
||||
print 'Installing file %s' % apkPath
|
||||
device.installPackage(apkPath)
|
||||
device.wake()
|
||||
|
||||
runComponent = package + '/' + activity
|
||||
print 'Starting activity %s' % activity
|
||||
device.startActivity(component=runComponent)
|
||||
|
||||
mu.test(device, snapshotname)
|
||||
|
||||
#
|
||||
###
|
||||
####
|
||||
######
|
||||
|
39
android/tests/monkey/mutil.py
Normal file
39
android/tests/monkey/mutil.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
|
||||
from random import randint, random
|
||||
|
||||
def test(device, snapshotname):
|
||||
print 'Starting test at %s' % device
|
||||
MonkeyRunner.sleep(5)
|
||||
for i in range(0,20):
|
||||
MonkeyRunner.sleep(0.2)
|
||||
# atack!
|
||||
rswipe(device)
|
||||
rclick(device)
|
||||
# Give some time to render new tiles
|
||||
MonkeyRunner.sleep(0.4)
|
||||
result = device.takeSnapshot()
|
||||
result.writeToFile(snapshotname % i)
|
||||
print 'Done testing %s' % device
|
||||
|
||||
|
||||
def swipe(device, start, end):
|
||||
device.drag(start, end, 0.01, 100)
|
||||
|
||||
|
||||
def click(device,x,y):
|
||||
device.touch(x,y, 'DOWN_AND_UP')
|
||||
|
||||
|
||||
def rswipe(device):
|
||||
step = 400
|
||||
start = (200, 400)
|
||||
dX = step*randint(-4,4)
|
||||
dY = step*randint(-4,4)
|
||||
end = (start[0] + dX, start[1] + dY)
|
||||
swipe(device, start, end)
|
||||
|
||||
|
||||
def rclick(device):
|
||||
x = 800*random()
|
||||
y = 1000*random() + 100
|
||||
click(device, x, y)
|
Loading…
Add table
Reference in a new issue