是";猴子赛跑者“;测试人员直接在Android应用程序中准备测试用例是否有用?
我已经通过了“猴子赛跑者”的以下链接 它有很多Java代码。我无法理解创建测试用例的代码。是否只有开发人员或测试人员才能彻底测试应用程序。通过代码创建测试用例还有其他模式吗?有人能给我提同样的建议吗是";猴子赛跑者“;测试人员直接在Android应用程序中准备测试用例是否有用?,android,unit-testing,testing,bug-tracking,monkeyrunner,Android,Unit Testing,Testing,Bug Tracking,Monkeyrunner,我已经通过了“猴子赛跑者”的以下链接 它有很多Java代码。我无法理解创建测试用例的代码。是否只有开发人员或测试人员才能彻底测试应用程序。通过代码创建测试用例还有其他模式吗?有人能给我提同样的建议吗 谢谢。看看我的MonkeyRunner代码。应该比Java更容易。更改路径以保存文件,并替换电话号码。我只有一个问题。我不能挂断电话 #! /usr/bin/env monkeyrunner ''' Created on Apr 1, 2011 @author: sj
谢谢。看看我的MonkeyRunner代码。应该比Java更容易。更改路径以保存文件,并替换电话号码。我只有一个问题。我不能挂断电话
#! /usr/bin/env monkeyrunner
'''
Created on Apr 1, 2011
@author: sj
'''
import sys
# import the MonkeyRunners modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
def browse(d):
d.broadcastIntent("http://www.google.com/", "ACTION_MAIN")
#d.startActivity(component="com.android.browser/.BrowserActivity")
def debug(device):
print" package:%s" % device.getProperty('am.current.package')
print" action:%s" % device.getProperty('am.current.action')
print" comp.class:%s" % device.getProperty('am.current.comp.class')
print" comp.package:%s" % device.getProperty('am.current.comp.package')
print device.getProperty('display.width'), device.getProperty('display.height')
def screenshot(d):
MonkeyRunner.sleep(1.0)
result = d.takeSnapshot()
MonkeyRunner.sleep(1.0)
result.writeToFile('/yourPath/device.png', 'png')
def call(d):
d.startActivity(component="com.android.contacts/.TwelveKeyDialer")
print "Start Activity"
MonkeyRunner.sleep(1.0)
d.type("+XXXXXXXX")
# Call number.
print "Call"
d.touch(190, 800, 'DOWN_AND_UP');
# not working device.press('KEYCODE_CALL', 'DOWN_AND_UP')
print "Wait 10 sec"
MonkeyRunner.sleep(10.0)
# HangUp Call
#device.press('KEYCODE_ENDCALL', 'DOWN_AND_UP')
print "Hang Up"
#x1 = 215
#x2 = 230
#y = 700
#start = (x1,y)
#end = (x2, y)
#steps = 2
#pause = 0.2
#device.drag(start, end, pause, steps)
d.startActivity(component="com.android.phone/.InCallScreen")
#device.touch(230, 700, "DOWN");
MonkeyRunner.sleep(1.0)
#device.touch(230, 700, "UP");
d.touch(230, 700, 'DOWN_AND_UP');
#device.touch(270, 650, 'DOWN_AND_UP');
def main():
print "Start"
# Connect to the current device returning the MonkeyDevice object
device = MonkeyRunner.waitForConnection()
#MonkeyRunner.alert("Starting Activity", "monkeyrunner", "OK")
if not device:
print "Couldn't get connection"
sys.exit()
print "Found device"
#call(device)
browse(device)
debug(device)
screenshot(device)
device.press('KEYCODE_ENDCALL', 'DOWN_AND_UP')
MonkeyRunner.sleep(10.0)
if __name__ == '__main__':
main()
我通过这个小指南学习了monkeyrunner。 您不必使用java,而是从python开始。对于ide,您可以使用pycharm,这将使您在python中创建类时有一个更好的开始 正如@Boris_Ivanov展示的代码一样,这是一个好的开始,但我会删除“MonkeyImage”-因为您没有使用它。如果需要使用,将测试用例推送到不同的文件中会提高速度 有一件事要说:
Connect to the current device returning the MonkeyDevice object
device = MonkeyRunner.waitForConnection()
#MonkeyRunner.alert("Starting Activity", "monkeyrunner", "OK")
我使用的是这样的东西,它一直都很有效:
device = MonkeyRunner.waitForConnection(60)
if not device:
raise Exception('Can not connect to device')
祝你好运