From dfee4daff283bc10c264e6b86b702c38c413958f Mon Sep 17 00:00:00 2001 From: Dmitry Kunin Date: Fri, 12 Jul 2013 15:25:26 +0300 Subject: [PATCH] [android, test] monkey improved --- android/tests/monkey/mutil.py | 70 +++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/android/tests/monkey/mutil.py b/android/tests/monkey/mutil.py index f19374cd3b..76098d023d 100644 --- a/android/tests/monkey/mutil.py +++ b/android/tests/monkey/mutil.py @@ -1,39 +1,63 @@ from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice from random import randint, random +# for notification bar +defYoffset = 50 + + +class DeviceInfo: + width = 0 + height = 0 + model = 'UnknownDevice' + + def __init__(self, device): + self.width = int(device.getProperty('display.width')) + self.height = int(device.getProperty('display.height')) + self.model = str(device.getProperty('build.model')) + + def dump(self): + return '%s_%sx%sx' % (self.model, self.height, self.width) + + def test(device, snapshotname): - print 'Starting test at %s' % device - MonkeyRunner.sleep(5) - for i in range(0,20): - MonkeyRunner.sleep(0.2) + di = DeviceInfo(device) + print 'Starting test at %s' % di.dump() + MonkeyRunner.sleep(10) + testSteps = 100 + for i in range(0, testSteps): # atack! - rswipe(device) - rclick(device) + randswipe(device, di) + randclick(device, di, 3) # Give some time to render new tiles - MonkeyRunner.sleep(0.4) - result = device.takeSnapshot() - result.writeToFile(snapshotname % i) - print 'Done testing %s' % device + MonkeyRunner.sleep(0.3) + device.takeSnapshot().writeToFile(snapshotname % i) + print 'Done testing %s' % di.dump() 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 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 randswipe(device, di=None, count=1): + if not di: + di = DeviceInfo(device) + for x in range(0, count): + step = randint(di.width, di.height) + start = (randint(0, di.width), randint(defYoffset, di.height)) + end = (randint(0, di.width), randint(defYoffset, di.height)) + print 's=%s e=%s' % (start, end) + swipe(device, start, end) -def rclick(device): - x = 800*random() - y = 1000*random() + 100 - click(device, x, y) +def randclick(device, di=None, count=1): + if not di: + di = DeviceInfo(device) + for x in range(0, count): + x = randint(0, di.width) + y = randint(defYoffset, di.height) + print 'x=%d y=%d' % (x, y) + click(device, x, y)