forked from organicmaps/organicmaps
More détails on monkey.
This commit is contained in:
parent
1f466460ee
commit
1c22406c82
3 changed files with 83 additions and 28 deletions
32
android/tests/monkey/mapswithme.py
Normal file
32
android/tests/monkey/mapswithme.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# coding=utf-8
|
||||
|
||||
from mutil import DeviceInfo
|
||||
from com.android.monkeyrunner import MonkeyRunner
|
||||
|
||||
apkPath = '../MapsWithMeTest/bin/MapsWithMeTest-release.apk'
|
||||
package = 'com.mapswithme.maps.pro'
|
||||
activity = 'com.mapswithme.maps.DownloadResourcesActivity'
|
||||
mapactivity = 'com.mapswithme.maps.MWMActivity'
|
||||
|
||||
sampleUris = ([
|
||||
('ge0://o4aXJl2FbJ/TNT_Rock_Club', 0),
|
||||
('ge0://o4aXJlDxJj/Newman', 1),
|
||||
('ge0://Q4CNu8AejK/Paris', 2),
|
||||
('ge0://04aXJfyIVr/Опоп-69', 3),
|
||||
('ge0://jwDj9dKFgF/Port_Harcourt', 4)
|
||||
])
|
||||
|
||||
|
||||
def follow_path(device, path):
|
||||
MonkeyRunner.sleep(10)
|
||||
for x in range(0, len(path)):
|
||||
print path[x]
|
||||
sendUrl(device, path[x][0], path[x][1])
|
||||
|
||||
|
||||
def sendUrl(device, geoUri, index=0):
|
||||
device.broadcastIntent(action='mwmtest', extras={'uri': geoUri})
|
||||
MonkeyRunner.sleep(1)
|
||||
device.wake()
|
||||
di = DeviceInfo(device)
|
||||
device.takeSnapshot().writeToFile(di.get_screenshot_path(index))
|
|
@ -1,22 +1,18 @@
|
|||
#!/usr/bin/env monkeyrunner
|
||||
|
||||
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
|
||||
from random import randint, random
|
||||
import mutil as mu
|
||||
import sys
|
||||
import os
|
||||
|
||||
outputdir = '../tests/monkey/output'
|
||||
id = 'default'
|
||||
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
|
||||
from mapswithme import activity
|
||||
import mapswithme as mwm
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
@ -25,11 +21,12 @@ if not device:
|
|||
else:
|
||||
print 'Connected'
|
||||
|
||||
apkPath = '../MapsWithMePro/bin/MapsWithMePro-debug.apk'
|
||||
package = 'com.mapswithme.maps.pro'
|
||||
activity = 'com.mapswithme.maps.DownloadResourcesActivity'
|
||||
apkPath = mwm.apkPath
|
||||
activity = mwm.activity
|
||||
package = mwm.package
|
||||
|
||||
print 'Installing file %s' % apkPath
|
||||
|
||||
device.installPackage(apkPath)
|
||||
device.wake()
|
||||
|
||||
|
@ -37,4 +34,5 @@ runComponent = package + '/' + activity
|
|||
print 'Starting activity %s' % activity
|
||||
device.startActivity(component=runComponent)
|
||||
|
||||
mu.test(device, snapshotname)
|
||||
#mu.dumb_test(device, package)
|
||||
mwm.follow_path(device, mwm.sampleUris)
|
|
@ -1,5 +1,8 @@
|
|||
from random import randint
|
||||
import os
|
||||
|
||||
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
|
||||
from random import randint, random
|
||||
|
||||
|
||||
# for notification bar
|
||||
defYoffset = 50
|
||||
|
@ -9,29 +12,34 @@ class DeviceInfo:
|
|||
width = 0
|
||||
height = 0
|
||||
model = 'UnknownDevice'
|
||||
lang = 'NA'
|
||||
country = 'na'
|
||||
|
||||
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'))
|
||||
self.lang = str(device.shell('getprop persist.sys.language')).rstrip()
|
||||
self.country = str(device.shell('getprop persist.sys.country')).rstrip()
|
||||
|
||||
def dump(self):
|
||||
return '%s_%sx%sx' % (self.model, self.height, self.width)
|
||||
return '%s_%s_%s_%sx%sx' % (self.model, self.lang, self.country, self.height, self.width)
|
||||
|
||||
def get_screenshot_dir(self):
|
||||
dirname = self.dump()
|
||||
if not os.path.exists(dirname):
|
||||
os.makedirs(dirname)
|
||||
return dirname
|
||||
|
||||
def get_screenshot_path(self, tag):
|
||||
dirname = self.get_screenshot_dir()
|
||||
return '%s/screenshot-%s.png' % (dirname, tag)
|
||||
|
||||
|
||||
def test(device, snapshotname):
|
||||
di = DeviceInfo(device)
|
||||
print 'Starting test at %s' % di.dump()
|
||||
MonkeyRunner.sleep(10)
|
||||
testSteps = 100
|
||||
for i in range(0, testSteps):
|
||||
# atack!
|
||||
randswipe(device, di)
|
||||
randclick(device, di, 3)
|
||||
# Give some time to render new tiles
|
||||
MonkeyRunner.sleep(0.3)
|
||||
device.takeSnapshot().writeToFile(snapshotname % i)
|
||||
print 'Done testing %s' % di.dump()
|
||||
def is_still_running(device, package):
|
||||
curPack = str(device.getProperty('am.current.package'))
|
||||
print curPack
|
||||
return package == curPack
|
||||
|
||||
|
||||
def swipe(device, start, end):
|
||||
|
@ -46,7 +54,6 @@ 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)
|
||||
|
@ -61,3 +68,21 @@ def randclick(device, di=None, count=1):
|
|||
y = randint(defYoffset, di.height)
|
||||
print 'x=%d y=%d' % (x, y)
|
||||
click(device, x, y)
|
||||
|
||||
|
||||
def dumb_test(device, package):
|
||||
di = DeviceInfo(device)
|
||||
print 'Starting test at %s' % di.dump()
|
||||
MonkeyRunner.sleep(10)
|
||||
testSteps = 100
|
||||
for i in range(0, testSteps):
|
||||
if is_still_running(device, package):
|
||||
# atack!
|
||||
randswipe(device, di)
|
||||
randclick(device, di, 3)
|
||||
# Give some time to render new tiles
|
||||
MonkeyRunner.sleep(0.5)
|
||||
device.takeSnapshot().writeToFile(di.get_screenshot_path(i))
|
||||
else:
|
||||
print 'Where is MapsWithMe?'
|
||||
print 'Done testing %s' % di.dump()
|
Loading…
Add table
Reference in a new issue