0

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()
  • I have added a print statement under findviewwithtext( ) function, Now I am able to print the device status. Can we retrieve status like this in findviewbyId() function?.And I need to add a if statement to my code like if switch=on: else. How to call the status in my program?? Please Help!! – parameshwar reddy Jun 08 '16 at 10:00

1 Answers1

0

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()
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • Thanks!! But it showing error like this ERROR: testSomething (__main__.CulebraTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "t6.py", line 49, in testSomething com_csr_csrmeshdemo___id_powerSwitch.getText() AttributeError: 'NoneType' object has no attribute 'getText' – parameshwar reddy Jun 09 '16 at 07:02
  • What you describe is very strange. If `com_csr_csrmeshdemo___id_powerSwitch` is `None` is because no View with such **ID** was found and then the exception `...OrRaise()` should be thrown. Are you sure you have the exact code as the example? – Diego Torres Milano Jun 09 '16 at 15:07
  • My Code is `com_csr_csrmeshdemo___id_powerSwitch = self.vc.findViewWithTextOrRaise(re.compile(u'(OFF)|(ON)')).touch() print"Light ", com_csr_csrmeshdemo___id_powerSwitch.getText()` – parameshwar reddy Jun 10 '16 at 06:31
  • And I have also tried with `com_csr_csrmeshdemo___id_powerSwitch = self.vc.findViewByIdOrRaise("com.csr.csrmeshdemo:id/powerSwitch").touch() print"Light ", com_csr_csrmeshdemo___id_powerSwitch.getText()` still getting same error!! – parameshwar reddy Jun 10 '16 at 06:35
  • `print com_csr_csrmeshdemo___id_powerSwitch` to check its value. Again, `faindViewByIdOrRaise()` returns a View or throws an exception, **there's no way it can return None**. So, show what the error you are getting exactly is. – Diego Torres Milano Jun 10 '16 at 15:23
  • The code is working this way by using using .touch() function separately, without appending it to function. `com_csr_csrmeshdemo___id_powerSwitch = self.vc.findViewWithTextOrRaise(re.compile(u'(OFF)|(ON)')) print"Light ",com_csr_csrmeshdemo___id_powerSwitch.getText() com_csr_csrmeshdemo___id_powerSwitch.touch()` But I am getting output as On when button is Off and ON when button is OFF. I understood why I am getting like that, trying to fix that issue. Thanks – parameshwar reddy Jun 14 '16 at 09:47