From d5c113a2dbd96c0e416ed1aed4cfc32b068e2e0c Mon Sep 17 00:00:00 2001 From: Dmitry Kunin Date: Thu, 11 Jul 2013 18:10:03 +0300 Subject: [PATCH] [android, test] basic monkey runner --- android/script/run_monkey.sh | 2 ++ android/tests/monkey/mrunner.py | 45 +++++++++++++++++++++++++++++++++ android/tests/monkey/mutil.py | 39 ++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 android/script/run_monkey.sh create mode 100755 android/tests/monkey/mrunner.py create mode 100644 android/tests/monkey/mutil.py diff --git a/android/script/run_monkey.sh b/android/script/run_monkey.sh new file mode 100644 index 0000000000..498208d5cc --- /dev/null +++ b/android/script/run_monkey.sh @@ -0,0 +1,2 @@ +#!/bin/bash +monkeyrunner ../tests/monkey/mrunner.py $1 diff --git a/android/tests/monkey/mrunner.py b/android/tests/monkey/mrunner.py new file mode 100755 index 0000000000..21dcbea9eb --- /dev/null +++ b/android/tests/monkey/mrunner.py @@ -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) + +# +### +#### +###### + diff --git a/android/tests/monkey/mutil.py b/android/tests/monkey/mutil.py new file mode 100644 index 0000000000..f19374cd3b --- /dev/null +++ b/android/tests/monkey/mutil.py @@ -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)