Android monkeyrunner中的操作不可靠 问题:
我的应用程序有一个类似于地图的画布,用户可以通过拖动地图来移动它。我要做的是把地图移到100px的右边,然后再移到100px的左边,检查中间的位置是否相同 代码如下:Android monkeyrunner中的操作不可靠 问题:,android,python,monkeyrunner,Android,Python,Monkeyrunner,我的应用程序有一个类似于地图的画布,用户可以通过拖动地图来移动它。我要做的是把地图移到100px的右边,然后再移到100px的左边,检查中间的位置是否相同 代码如下: device.drag((640, 360), (640 - 100, 360)) device.drag((640, 360), (640 + 100, 360)) # check 这并不是每次都能可靠地将地图带到同一个地方。有时设备挂起或运行缓慢,移动的像素很少;其他一些时候,在最后一步,它走得更快,给它动力 有没有办法精确
device.drag((640, 360), (640 - 100, 360))
device.drag((640, 360), (640 + 100, 360))
# check
这并不是每次都能可靠地将地图带到同一个地方。有时设备挂起或运行缓慢,移动的像素很少;其他一些时候,在最后一步,它走得更快,给它动力
有没有办法精确拖动屏幕上一定数量的像素?如果设备挂起或运行缓慢,则无所谓,只要最后的移动是正确的
我的尝试
我试图调整第三个(duration
)和第四个(steps
)参数,但没有效果
我还尝试通过以下方式实现我的自定义拖动代码:
# Touch down screen
device.touch(100, 500, MonkeyDevice.DOWN)
# Move from 100, 500 to 200, 500
for i in range(1, 11):
device.touch(100 + 10 * i, 500, MonkeyDevice.MOVE)
time.sleep(0.1)
# Extra sleep to avoid momentum
time.sleep(0.2)
# Remove finger from screen
device.touch(200, 500, MonkeyDevice.UP)
然后到另一边:
# Touch down screen
device.touch(200, 500, MonkeyDevice.DOWN)
# Move from 200, 500 to 100, 500
for i in range(1, 11):
device.touch(200 - 10 * i, 500, MonkeyDevice.MOVE)
time.sleep(0.1)
# Extra sleep to avoid momentum
time.sleep(0.2)
# Remove finger from screen
device.touch(100, 500, MonkeyDevice.UP)
以类似的方式,我还尝试使用以下工具测试我的游戏键盘键:
for _ in range(0, 10):
device.press('KEYCODE_DPAD_RIGHT', MonkeyDevice.DOWN_AND_UP)
time.sleep(0.1)
for _ in range(0, 10):
device.press('KEYCODE_DPAD_LEFT', MonkeyDevice.DOWN_AND_UP)
time.sleep(0.1)
甚至有时“代码> MunKields将跳过事件或不考虑UP事件,从而导致长时间按下(相当于“继续在地图上移动”)。 有用的参考资料:
- 问得好。
读完后,我也很好奇,我想知道这个问题是否也会影响到我(哪个更可靠)
然而,正如下面的步骤所表明的,它可能更多地与地图的移动方式有关,而不是与发送环境的不同协议的可靠性有关。此外,还提供了一种自动化测试的方法,正如您提到的,您正在对结果进行视觉比较
我认为分享这一点会很有帮助,它可能会给你更多的想法来测试你的应用程序
首先使用创建测试
然后,我稍微编辑了测试,将点作为因子,并添加了相反的阻力
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2016 Diego Torres Milano
Created on 2017-03-04 by Culebra
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
|/ \_/ \_/ \_/ \ o \
\_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''
import re
import sys
import os
import unittest
try:
sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
import pkg_resources
pkg_resources.require('androidviewclient>=13.0.0')
from com.dtmilano.android.viewclient import ViewClient, CulebraTestCase
from com.dtmilano.android.uiautomator.uiautomatorhelper import UiAutomatorHelper, UiScrollable, UiObject, UiObject2
TAG = 'CULEBRA'
class CulebraTests(CulebraTestCase):
@classmethod
def setUpClass(cls):
cls.kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
cls.kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True}
cls.options = {'start-activity': None, 'concertina': False, 'device-art': None, 'use-jar': False, 'multi-device': False, 'unit-test-class': True, 'save-screenshot': None, 'use-dictionary': False, 'glare': False, 'dictionary-keys-from': 'id', 'scale': 1, 'find-views-with-content-description': True, 'window': -1, 'orientation-locked': None, 'save-view-screenshots': None, 'find-views-by-id': True, 'log-actions': False, 'use-regexps': False, 'null-back-end': False, 'auto-regexps': None, 'do-not-verify-screen-dump': True, 'verbose-comments': False, 'gui': False, 'find-views-with-text': True, 'prepend-to-sys-path': False, 'install-apk': None, 'drop-shadow': False, 'output': None, 'unit-test-method': None, 'interactive': False}
cls.sleep = 5
def setUp(self):
super(CulebraTests, self).setUp()
def tearDown(self):
super(CulebraTests, self).tearDown()
def preconditions(self):
if not super(CulebraTests, self).preconditions():
return False
return True
def testSomething(self):
if not self.preconditions():
self.fail('Preconditions failed')
_s = CulebraTests.sleep
_v = CulebraTests.verbose
d = '/tmp/'
p = (377.14, 380.86)
q = (175.14, 380.86)
self.vc.writeImageToFile(d + 'map-start.png')
# Each step execution is throttled to 5ms per step
# So for a 400 steps, the swipe will take about 2 second to complete
steps = 400
duration = 2000
# Let's give some extra delay.
sleep = 3
for n in range(10):
print n
self.device.dragDip(p, q, duration, steps)
self.vc.sleep(sleep)
self.device.dragDip(q, p, duration, steps)
self.vc.sleep(sleep)
self.vc.writeImageToFile(d + 'map-finish.png')
self.device.compare(d + 'map-finish.png', d + 'map-start.png', d + 'map-compare.png')
if __name__ == '__main__':
CulebraTests.main()
#/usr/bin/env python
#-*-编码:utf-8-*-
'''
版权所有(C)2013-2016迭戈·托雷斯·米兰
库莱布拉于2017-03-04创建
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
|/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\_____/--<
@作者:迭戈·托雷斯·米兰
@作者:Jennifer E.Swofford(ascii艺术蛇)
'''
进口稀土
导入系统
导入操作系统
导入单元测试
尝试:
sys.path.insert(0,os.path.join(os.environ['ANDROID\u VIEW\u CLIENT\u HOME','src'))
除:
通过
导入pkg_资源
pkg_resources.require('androidviewclient>=13.0.0')
从com.dtmilano.android.viewclient导入viewclient,CulebraTestCase
从com.dtmilano.android.uiautomator.uiautomatorhelper导入uiautomatorhelper、UiScrollable、UiObject、UiObject2
标签='CULEBRA'
CulebraTests类(CulebraTestCase):
@类方法
def设置等级(cls):
cls.kwargs1={'ignoreversioncheck':False,'verbose':False,'ignoresecuredevice':False}
cls.kwargs2={'forceviewserveruse':False,'useuiautomatorhelper':False,'ignoreuiautomatorkilled':True,'autodump':False,'startviewserver':True,'compresseddump':True}
cls.options={'start-activity':None,'concertina':False,'device art':None,'use jar':False,'multi-device':False,'unit test class':True,'save screenshot':None,'use dictionary':False,'dictionary key from':'id','scale':1,'find view with content description':True,'window':-1,'orientation locked':None,'save view“:None,'find views by id':True,'log actions':False,'use regexps':False,'null back end':False,'auto regexps':None,'do verbose comments':False,'gui':False,'find views with text':True,'prepend to sys path':False,'install apk':None,'drop shadow':False,'output':None,'unit test method':None,'interactive':False}
cls.sleep=5
def设置(自):
super(CulebraTests,self).setUp()
def拆卸(自):
super(CulebraTests,self).tearDown()
def先决条件(自身):
如果不是超级(CulebraTests,self)。前提条件():
返回错误
返回真值
def testSomething(self):
如果不是self.prepositions():
self.fail('先决条件失败')
_s=睡眠
_v=冗长的测试
d='/tmp/'
p=(377.14380.86)
q=(175.14380.86)
self.vc.writeImageToFile(d+'map start.png')
#每个步骤的执行限制为每个步骤5ms
#因此,对于400步,刷卡大约需要2秒钟才能完成
步数=400
持续时间=2000年
#让我们多耽搁一会儿。
睡眠=3
对于范围(10)内的n:
印刷品
self.device.dragDip(p、q、持续时间、步长)
self.vc.sleep(睡眠)
self.device.dragDip(q,p,持续时间,步长)
self.vc.sleep(睡眠)
self.vc.writeImageToFile(d+'map finish.png')
self.device.compare(d+'map finish.png',d+'map start.png',d+'map compare.png')
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
CulebraTests.main()
一旦运行它,这些就是迭代前后的结果
在最后一张图片中,你可以看到视觉对比,它显示了一个轻微的移动。然而,我认为这可能正是地图所做的
我还使用了一个基于UiAutomator的完全不同的后端,同样的问题也出现了。所以我认为这不是一个与拖动有关的好问题。
读完后,我也很好奇,我想知道这个问题是否也会影响到我(哪个更可靠)
但是,正如以下步骤所示,它可能与路线图更相关