[英]How to find out the state of a checkbox using AndroidViewClient
I'm using androidviewclient for automated black-box level testing of an android GUI, I have two checkboxes (YES and NO) with YES checked by default, I use vc.touch() to select NO and I need to know whether NO has been selected.The way I do it now is by taking screenshot before and after a touch and compare them. 我正在使用androidviewclient进行Android GUI的自动黑盒级别测试,我有两个复选框(YES和NO),默认情况下选中YES,我使用vc.touch()选择NO,我需要知道NO是否有我现在选择的方法是在触摸前后截取屏幕截图并进行比较。 Is there any easier way to find the state of the button/check-box.
有没有更简单的方法来找到按钮/复选框的状态。 It seems touch() is a void function outputting nothing.
似乎touch()是一个无效输出的void函数。
As an example, I'm using Clock and the Vibrate checkbox in Alarms 举个例子,我在Alarms中使用Clock和Vibrate复选框
Then, I generated the script using culebra and manually added the assert
at the end (it could be done in one line but I added 2 for clarity) 然后,我使用culebra生成脚本并在末尾手动添加
assert
(可以在一行中完成,但为了清晰起见我添加了2)
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2016 Diego Torres Milano
Created on 2016-06-03 by Culebra v11.5.6
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
|/ \_/ \_/ \_/ \ o \
\_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''
import re
import sys
import os
import unittest
from com.dtmilano.android.viewclient import ViewClient, CulebraTestCase
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': 0.5, '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': True, 'find-views-with-text': True, 'prepend-to-sys-path': False, 'install-apk': None, 'drop-shadow': False, 'output': '/home/diego/tmp/culebra/checbox.py', '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
self.vc.dump(window=-1)
checkbox = self.vc.findViewWithTextOrRaise(u'Vibrate')
self.assertTrue(checkbox.isChecked())
if __name__ == '__main__':
CulebraTests.main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.