0

I am using AVC 11.5.6 and using function FindviewwithtextorRaise() and trying to automate a test case. I need the script to search for application in the app list after opening menu. If the App not available in opened list the script should scroll and search again instead of raising exception.

Thanks!

1 Answers1

1

First of all, if you don't want exceptions to be thrown if Views are not found don't use the ...OrRaise() methods, use the plain ones.

Second, you can start from a culebra generated script where you can use the Drag Dialog to scroll the scrollables up, down, left or right according to the case and then manually edit the file and add the while loop.

As an example, here is a script that looks for Speech Recorder in Apps and touch when found.

#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2016  Diego Torres Milano
Created on 2016-06-09 by Culebra v11.5.7
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    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': 'scroll.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)
        speechRecorder = self.vc.findViewWithContentDescription(u'''Speech Recorder''')
        while not speechRecorder:
            self.device.dragDip((297.33, 368.67), (83.33, 383.33), 1000, 20, 0)
            self.vc.sleep(1)
            self.vc.dump(window=-1)
            speechRecorder = self.vc.findViewWithContentDescription(u'''Speech Recorder''')

        speechRecorder.touch()


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

You should add some condition to exit if it's never found. This one will loop forever.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134