是否可以使用androidviewclient获取并打印按钮状态?

时间:2016-06-08 05:05:17

标签: android python-2.7 androidviewclient

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

#! /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()

1 个答案:

答案 0 :(得分:0)

如果我理解你正在寻找的是

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