androidviewclient是否可以获取并打印按钮状态? [英] Is it possible with androidviewclient to obtain and print button status?

查看:157
本文介绍了androidviewclient是否可以获取并打印按钮状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用androidviewclient 11.5.6并尝试自动执行具有powerSwitch按钮的BLE应用程序。我想获取按钮的状态并打印状态。 androidviewclient是否可能,或者我应该尝试使用其他工具?请帮忙!!
这是我的代码

I am using androidviewclient 11.5.6 and trying to automate BLE application having powerSwitch button. I want to obtain the status of button and print the status. Is it possible with androidviewclient or I should try with some other tool?? Please help!! Here Is my code

#! /usr/bin/env python
# -*- coding: utf-8 -*-

import re
import sys
import os
import time


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': 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': False, 'verbose-comments': False, 'gui': False, 'find-views-with-text': True, 'prepend-to-sys-path': False, 'install-apk': None, 'drop-shadow': False, 'output': 'mytest.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')
    #com_csr_csrmeshdemo___id_powerSwitch = self.vc.findViewByIdOrRaise("com.csr.csrmeshdemo:id/powerSwitch").touch()
        com_csr_csrmeshdemo___id_powerSwitch = self.vc.findViewWithTextOrRaise(u'OFF').touch()
    print"Light ON"
    self.vc.dump(window='-1')
    time.sleep(5)
    #com_csr_csrmeshdemo___id_powerSwitch = self.vc.findViewByIdOrRaise("com.csr.csrmeshdemo:id/powerSwitch").touch()
    com_csr_csrmeshdemo___id_powerSwitch = self.vc.findViewWithTextOrRaise(u'ON').touch()
    print"Light OFF"



if __name__ == '__main__':
    CulebraTests.main()


推荐答案

如果我正确理解您要查找的内容,则是

If I understand correctly what you are looking for is

com_csr_csrmeshdemo___id_powerSwitch = self.vc.findViewByIdOrRaise("com.csr.csrmeshdemo:id/powerSwitch")
print "Light", com_csr_csrmeshdemo___id_powerSwitch.getText()

这篇关于androidviewclient是否可以获取并打印按钮状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆