AndroidViewClient能否与Monkeyrunner一起使用?

时间:2018-04-01 10:23:40

标签: androidviewclient

我正在使用AndroidClientView进行自动化测试。我发现当手机进入新页面时,ViewClient应该转储整个视图。我想如果有一种方法可以加快测试过程,例如页面只是一个转移的页面,我不需要获取所有小部件的特定ID,我只想点击一个坐标快速通过。所以我尝试将Monkeyrunner与AndroidViewClient一起使用,但我尝试了很多方法,总是出现错误。比如“语法错误”“导入错误”或其他错误..

1 个答案:

答案 0 :(得分:0)

如果您不想识别新屏幕的任何元素,并且您确切知道要点击的点的坐标,则无需调用dump()。< / p>

例如,这是一个稍微修改过的culebra生成的测试。它使用Calculator来输入操作并验证结果,但是我们知道按钮没有改变,我们可以注释掉所有dumpsleep,结果是相同的,但是测试执行得更快。

def testSomething(self):
    if not self.preconditions():
        self.fail('Preconditions failed')

    _s = CulebraTests.sleep
    _v = CulebraTests.verbose

    self.vc.dump(window=-1)
    self.vc.findViewWithContentDescriptionOrRaise(u'''clear''').longTouch()
    #self.vc.sleep(_s)
    #self.vc.dump(window=-1)
    self.vc.findViewByIdOrRaise(u'com.google.android.calculator:id/digit_1').touch()
    #self.vc.sleep(_s)
    #self.vc.dump(window=-1)
    self.vc.findViewWithContentDescriptionOrRaise(u'''plus''').touch()
    #self.vc.sleep(_s)
    #self.vc.dump(window=-1)
    self.vc.findViewByIdOrRaise(u'com.google.android.calculator:id/digit_2').touch()
    #self.vc.sleep(_s)
    #self.vc.dump(window=-1)
    self.vc.findViewWithContentDescriptionOrRaise(u'''multiply''').touch()
    #self.vc.sleep(_s)
    #self.vc.dump(window=-1)
    self.vc.findViewByIdOrRaise(u'com.google.android.calculator:id/digit_3').touch()
    #self.vc.sleep(_s)
    #self.vc.dump(window=-1)
    self.vc.findViewWithContentDescriptionOrRaise(u'''equals''').touch()
    self.vc.sleep(_s)
    self.vc.dump(window=-1)
    self.assertEquals(u'7', self.vc.findViewById(u'com.google.android.calculator:id/result').getText())