Is it possible with androidviewclient to obtain an

2019-09-12 16:33发布

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()

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-12 17:25

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()
查看更多
登录 后发表回答