Пример #1
0
class UiTestLib(object):
    """Ui Test Lib

    """
    def __init__(self, serial=None):
        """
        """
        logger.info('<p>Device=%s>' % serial, html=True)
        print '<p>Device=%s>' % serial
        self._result = ''
        self.starttime = 0
        self.d = Device(serial)
        self.adb = Adb(serial)
        self.debug = 'True'

    def set_debugable(flag):
        self.debug = flag

    def set_serial(self, serial):
        """Specify given *serial* device to perform test.
        or export ANDROID_SERIAL=CXFS42343 if you have many devices connected but you don't use this
        interface

        When you need to use multiple devices, do not use this keyword to switch between devices in test execution.
        And set the serial to each library.
        Using different library name when importing this library according to
        http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.5.

        Examples:
        | Setting | Value |  Value |  Value |
        | Library | UiTestLib | WITH NAME | Mobile1 |
        | Library | UiTestLib | WITH NAME | Mobile2 |

        And set the serial to each library.
        | Test Case        | Action             | Argument           |
        | Multiple Devices | Mobile1.Set Serial | device_1's serial  |
        |                  | Mobile2.Set Serial | device_2's serial  |
        """
        self.d = Device(serial)
        self.adb = Adb(serial)

    def logmsg(self, msg):
        if self.debug == 'True':
            print msg

    def exe_adb_command(self, cmd):
        """ Execute adb *cmd*
         Examples:
        | Exe Adb Command | shell getprop  |
        """
        return self.adb.cmd(cmd).wait()

    def exe_adb_and_result(self, cmd):
        """Execute adb *cmd* and return lines of the command"""
        lproc = self.adb.cmd(cmd)
        lproc.poll()
        lines = lproc.stdout.readlines()
        return lines

    def get_device_info(self):
        """Get Device information
        return info dictionary
        """
        return self.d.info

    def light_screen(self):
        """Light screen by wakeup.

        Examples:
        | Action     |
        |Light screen|

        Use `Light screen` to light screen.
        """

        self.d.wakeup()
        self._result = self.d.press.home()

    def open_application(self, appname):
        """Open application by it name `appname`.

        Example:
        | Action           | Argument      |
        | Open application | "com.android.settings/com.android.settings.Settings" |
        """
        appname = 'shell am start -n ' + appname
        print 'Open Application:', appname
        self._result = self.exe_adb_command(appname)

    def click_text(self, text, instance=0):
        """Click text label on screen
        instance=0 is default, change when you needed.

        Example:
        | Action     | Argument   |  Argument  |
        | Click Text | text | instance |
        """

        return self.d(text=text, instance=instance).click.wait()

    def long_click_text(self, text, instance=0):
        """
        Long Click text label on screen, *text* and *instance=0*

        Example:
        | Action     | Argument   |  Argument  |
        | Long Click Text | text | instance |
        """

        return self.d(text=text, instance=instance).long_click()

    def long_click_ui(self, **selectors):
        """
        Long Click on **selectors**
        Selector supports below parameters. Refer to UiSelector java doc for detailed information.

            text, textContains, textMatches, textStartsWith
            className, classNameMatches
            description, descriptionContains, descriptionMatches, descriptionStartsWith
            checkable, checked, clickable, longClickable
            scrollable, enabled,focusable, focused, selected
            packageName, packageNameMatches
            resourceId, resourceIdMatches
            index, instance
        Example:
        | Action     | Argument   |  Argument  |  Argument  |
        | Long Click UI | text=XXXX | className=XXX.xxxx | resourceId=xxxxxx |
        """

        return self.d(**selectors).long_click()

    def text_display_on_screen_contains(self, text):
        """Verify text display on screen

        Example:
        | Action     | Argument   |
        |Text display on screen is| text |
        """

        if self.d(text=text).exists:
            self._result = True
            return True
        else:
            self._result = False
            return False

    def object_display_on_screen(self, obj, timeout=5000):
        """ Verify *obj* UiObject display on screen
        return to self._result

        Example:
        | Action     | Argument   |
        |Object display on screen | obj |
        """
        if obj.wait.exists(timeout):
            self._result = True
            return True
        else:
            self._result = False
            return False

    def assert_expectation(self, expect, actual):
        """
        Assert Expectation and actual value
        Example:
        | Action             |   args   |   args      |
        | Assert Expectation |   324324 |  ${actual}  |
        """
        if str(expect) != str(actual):
            raise AssertionError(
                'Actual result is = %s, but expectation is: %s' %
                (str(actual), str(expect)))

    def assert_true(self, condition):
        """
        Assert True of *condition

        Example:
        |Assert True | condition |
        """
        if str(condition) != 'True':  #because only string from robotframework
            raise AssertionError('Result is = %s' % str(condition))

    def assert_result_true(self):
        """
        Assert True of *self._result

        Example:
        |Assert True |
        """
        if self._result != True:
            raise AssertionError('Result is = %s' % str(self._result))

    def wait_for_ui_exists(self, timeout, **selectors):
        """
        Return True if
          Selector is to identify specific ui object in current window.

        # To seleted the object ,text is 'Clock' and its className is 'android.widget.TextView'
        wait_for_ui_exists(text='Clock', className='android.widget.TextView')

        Selector supports below parameters. Refer to UiSelector java doc for detailed information.

            text, textContains, textMatches, textStartsWith
            className, classNameMatches
            description, descriptionContains, descriptionMatches, descriptionStartsWith
            checkable, checked, clickable, longClickable
            scrollable, enabled,focusable, focused, selected
            packageName, packageNameMatches
            resourceId, resourceIdMatches
            index, instance

        Examples:
        | Action     | Argument   |  Argument  |  Argument  |  Argument  |
        |Wait For UI Exists | timeout | text=XXXX | className=XXX.xxxx | resourceId=xxxxxx |
        """
        self._result = self.d(**selectors).wait.exists(timeout=int(timeout))
        return self._result

    def wait_and_click(self, timeout, **selectors):
        """Wait for uiselector and click"""
        if self.d(**selectors).wait.exists(timeout=int(timeout)):
            self.d(**selectors).click()

    def assert_ui_exists(self, **selectors):
        """
        Assert UiObject appear on the screen

        Examples:
        | Action     | Argument   |  Argument  |  Argument  |  Argument  |
        |Assert UI Exists | timeout | text=XXXX | className=XXX.xxxx | resourceId=xxxxxx |
        """
        if not self.d(**selectors).wait.exists():
            raise AssertionError('UiObject does not exists %s' %
                                 selectors.items())

    def result_should_be(self, expected):
        """Verifies that the current result is `expected`.

        Example:
        | Action     | Argument   |
        |  Open application    | com.android.settings/com.android.settings.Settings |
        |  Result Should Be    | 0       |
        """
        print('result is: %s\n', self._result)
        print('ex is: %s\n', expected)
        if str(self._result) != expected:
            raise AssertionError('%s != %s' % (self._result, expected))

    def click_at_coordinates(self, x, y):
        """ Click at (x,y) coordinates.
        Example:
        | Action     | Argument   |  Argument  |
        | Click At Corrdinates | x | y |
        """
        return self.d.click(int(x), int(y))

    def long_click_at_coordinates(self, x, y):
        """
        # long click (x, y) on screen
        """
        return self.d.long_click(int(x), int(y))

    def swipe(self, sx, sy, ex, ey, steps=20):
        """
        Swipe from (sx,sy) to (ex,ey)
        """
        return self.d.swipe(int(sx), int(sy), int(ex), int(ex), int(steps))

    def drag(self, sx, sy, ex, ey, steps=20):
        """
        Drag from (sx,sy) to (ex,ey)
        """
        return self.d.drag(int(sx), int(sy), int(ex), int(ex), int(steps))

    def freeze_rotation(self, rotation=True):
        """
        Freeze rotation,
        *rotation*, True is default,
        """
        return self.d.freeze_rotation(rotation)

    def set_rotation(self, rotation):
        """
        # retrieve orientation,
        # it should be "natural" or "left" or "right" or "upsidedown"

        Example:
        | Action       | Argument   |
        | Set Rotation | nature      |
        | Set Rotation | left        |
        | Set Rotation | right       |
        | Set Rotation | upsidedown  |

        """
        orientation = self.d.orientation
        if rotation == "nature":
            self.d.orientation = "n"  # or "natural"
        elif rotation == "left":
            self.d.orientation = "l"  # or "left"
        elif rotation == "right":
            self.d.orientation = "r"  # or "right"
        elif rotation == "upsidedown":
            self.d.orientation = "upsidedown"  # or "upsidedown"
        else:
            self.d.rotation = "n"

    def take_screenshot(self, scale=None, quality=None):
        """
        Take a screenshot of device and log in the report with timestamp, scale for screenshot size and quality for screenshot quality
        default scale=1.0 quality=100

        Example:
        | Action     | Argument   |  Argument  |
        | Take Screenshot | 0.5 | 80 |
        """
        output_dir = BuiltIn().get_variable_value('${OUTPUTDIR}')
        ts = time.time()
        st = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d%H%M%S')
        screenshot_path = '%s%s%s.png' % (output_dir, os.sep, st)
        screenshot_name = '%s%s.png' % (os.sep, st)
        self.d.screenshot(screenshot_path, scale, quality)
        logger.info('\n<a href="%s">%s</a><br><img src="%s">' %
                    (screenshot_path, st, screenshot_name),
                    html=True)

    def open_notification(self):
        """
        Open notification of the phone
        """
        self.d.open.notification()

    def wait_window_update(self):
        """
        wait for window update
        """
        return self.d.wait.update()

    def wait_window_idle(self):
        """
        wait for window idle
        """
        return self.d.wait.idle()

    def remove_watchers(self):
        """
        Remove UI watchers
        """
        self.d.watchers.remove()

    def get_device(self):
        """
        Get device object, you can do any command using this
        """
        return self.d

    def click_id(self, id, instance=0):
        """
        Click *id* with *instance*=0
        """
        return self.d(resourceId=id, instance=instance).click.wait()

    def long_click_id(self, id, instance=0):
        """
        Long click *id* with *instance*=0
        """
        return self.d(resourceId=id, instance=0).long_click()

    def click_description(self, description, instance=0):
        """
        Click *description* with *instance*=0
        """
        return self.d(description=description, instance=instance).long_click()

    def click_class(self, className, instance=0):
        """
        Click *className* with *instance*=0
        """
        return self.d(className=className, instance=instance).long_click()

    def type_text(self, textStr, **selectors):
        """
        type text on selectors
        like text=EditName
        """
        self.d(**selectors).set_text(textStr)

    def press_key(self, key):
        """ Press Key of following value
            home
            back
            left
            right
            up
            down
            center
            menu
            search
            enter
            delete(or del)
            recent(recent apps)
            volume_up
            volume_down
            volume_mute
            camera
            power

            Examples:
            | Action     | Argument   |
            | Press Key | home |
            | Press Key | back |
            | Press Key | left |
            | Press Key | right |
            | Press Key | recent |
            | Press Key | volume_up |
            | Press Key | camera |
        """
        if key.isdigit():
            return self.d.press(int(key))
        return self.d.press(key)

    def phone_sleep(self, timeout):
        """
        android device sleep with timeout in ms, don't use for executor sleep,
        """
        return self.d.wait(int(timeout))

    def execute_command(self, cmd, block_parent_process=True):
        """
        Execute shell *cmd* command, with block_parent_process = True

        If block_parent_process = False, kill_command is needed to terminal the child process

        Example:
        | Execute Command | ping -c 5 127.0.0.1 |
        """
        if str(block_parent_process) == str(True):
            return subprocess.Popen(cmd,
                                    shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE).communicate()
        else:
            return subprocess.Popen(cmd,
                                    shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)

    def kill_command(self, process, timeout=0):
        """ Kill child *process* in timeout seconds
        Some bugs after process teminated
        """
        time.sleep(float(timeout))
        process.terminate()

    def wait_for_logcat(self, log, timeout=30):
        """ Wait log exists in given timeout, return True if have, otherwise will return False
        log is your want to search, log can be a regular expression
        time in seconds, default value is 30 seconds

        Example:
        | Wait For Logcat | .*ActivityManager.*cmp=com.sonyericsson.album/com.sonyericsson.album.Main.* |
        """
        start = time.time()
        while (time.time() - start) < int(timeout):
            log_proc = self.adb.cmd("logcat -d -v time")
            returncode = log_proc.poll()
            lines = log_proc.stdout.readlines()
            for line in lines:
                rlt = re.search(log, line.rstrip())
                if rlt is not None:
                    print rlt.group(0)
                    self._result = True
                    return True
            time.sleep(2)  #sleep 2s to wait
        self._result = False
        return False

    def clear_logcat(self):
        """
        Clear logcat, it's often used before you want to use *wait_for_logcat()*
        """
        print "Clear logcat before test"
        return self.exe_adb_command("logcat -c")

    def click_object(self, obj):
        """ Click UiObject *obj*

        Exmaple:
        | ${result}    | Get UI Object | text=XXX | className=xxxx |
        | Click Object |   ${result}   |
        """
        obj.click()

    def click_ui(self, **selectors):
        """
        Click selector

        click_selector(text="Home", resourceId = "android:id/title")
        for **selector, please refer *get_ui_object()*
        Selector supports below parameters. Refer to UiSelector java doc for detailed information.

            text, textContains, textMatches, textStartsWith
            className, classNameMatches
            description, descriptionContains, descriptionMatches, descriptionStartsWith
            checkable, checked, clickable, longClickable
            scrollable, enabled,focusable, focused, selected
            packageName, packageNameMatches
            resourceId, resourceIdMatches
            index, instance
        Operation for a UiObjects:
        click, clear_text, drag(obj).to(**selector), gesture, exists, set_text, long_click
        pinch.In(percent=100, steps=10), pinch.Out(percent=100, steps=100),.swipe.right(),
        .swipe.left(steps=10),.swipe("right", steps=20),.wait.gone(),.wait.exists()
        """
        print "selectors:", selectors
        return self.d(**selectors).click()

    def get_ui_object(self, **selectors):
        """
        Get UI object with *selectors*
        you can do anything on UiObject, like click(), long_click(),wait.exists(timeout)
        examples: get_ui_object(text="Home", resourceId = "android:id/title")

        Selector supports below parameters. Refer to UiSelector java doc for detailed information.

            text, textContains, textMatches, textStartsWith
            className, classNameMatches
            description, descriptionContains, descriptionMatches, descriptionStartsWith
            checkable, checked, clickable, longClickable
            scrollable, enabled,focusable, focused, selected
            packageName, packageNameMatches
            resourceId, resourceIdMatches
            index, instance
        Operation for a UiObjects:
        click, clear_text, drag(obj).to(**selector), gesture, exists, set_text, long_click
        pinch.In(percent=100, steps=10), pinch.Out(percent=100, steps=100),.swipe.right(),
        .swipe.left(steps=10),.swipe("right", steps=20),.wait.gone(),.wait.exists()

        Exmaple:
        | ${result}    | Get UI Object | text=XXX | className=xxxx |

        """
        self._result = self.d(**selectors)
        return self._result

    def wait_for_object_exists(self, obj, timeout=0):
        """
        Wait for UiObject *obj* exists in *timeout*= 0

        Example:
        | ${result}    | Get UI Object | text=XXX | className=xxxx |
        | Wait For Object Exists | ${result} | timeout |
        """
        self._result = obj.wait.exists(timeout=int(timeout))
        return self._result

    def wait_for_ui_gone(self, timeout=0, **selectors):
        """
        Wait for UiObject *obj* gone in *timeout*= 0

        Example:
        | ${result}    | Get UI Object | text=XXX | className=xxxx |
        | Wait For Object Gone | ${result} | timeout |

        """
        self._result = self.d(**selectors).wait.gone(timeout=int(timeout))
        return self._result

    def get_key_value(self, key, dictionary):
        """
        Get key value of dictionary
        """
        return dictionary(key)

    def get_tts(self, input_text, delete_file=False, **args):
        """
        Get TTS voice mp3 from Google
        get_tts(input_text='tunnel snakes rule apparently', args = {'language':'en','output':'outputto.mp3'})

        Robot Framework:
        Examples:
        | Action     | Argument   |  Argument  |  Argument  |  Argument  |
        | UiTestLib.Get TTS    |   Hello world    |   False   |    output=ooo.mp3   |   language=en |
        """
        print "Get text to speech: ", input_text
        downloaded = False
        if str(delete_file) == 'True':
            if os.path.exists(args['output']):
                os.remove(args['output'])
        if os.path.exists(args['output']):
            if os.path.getsize(args['output']) <= 0:
                os.remove(args['output'])
        if args['output'] is not None:
            if not os.path.exists(args['output']):
                print 'Generating mp3 file......', args['output']
                downloaded = GoogleTTS.audio_extract(input_text, args)
            else:
                print 'Have same local file'
                downloaded = True
        if not downloaded:
            print "Downloaded TTS from Google failed, trying to download from local FTP..."
            mp3file = open(args['output'], 'w')
            mp3url = 'ftp://cnbjlx9548/atautomation/Test-Content/Croft/' + args[
                'output']
            try:
                resp = urllib2.urlopen(mp3url, timeout=40)
                mp3file.write(resp.read())
                time.sleep(.05)
            except Exception, e:
                print e
                return False
            mp3file.close()
        return True
Пример #2
0
class ModelInfo():
    '''
    classdocs
    '''
    
    def __init__(self, deviceserial):
        '''
        Constructor
        '''
    
    #sndLog = CLS("test", "test")
        self.osType = sys.platform
        
        self.mstrInfo = {}
        
        #self.devSerials = self.instAdb.device_serial()
        self.mstrDevice = Device(deviceserial)
        self.mstrInfo = self.mstrDevice.info
    
    '''
        DEVICE Infoamtions
        { u'displayRotation': 0,
          u'displaySizeDpY': 640,
          u'displaySizeDpX': 360,
          u'currentPackageName': u'com.android.launcher',
          u'productName': u'takju',
          u'displayWidth': 720,
          u'sdkInt': 18,
          u'displayHeight': 1184,
          u'naturalOrientation': True
        }
    '''        
    def getCurrntProductInfo(self):
        return self.mstrInfo
        
    def getProductNmae(self):
        return self.mstrInfo['productName']
        
    def getCurrntPkg(self):
        return self.mstrInfo['currentPackageName']
    
    def getSDKInt(self):
            return self.mstrInfo['sdkInt']
        
    def getRotation(self):
        return self.mstrInfo['displayRotation']
    
    
    def getNaturalOri(self):
        return self.mstrInfo['naturalOrientation']
    
    def getDisplayState(self):
        return self.mstrDevice.screen
                
    def setReflash(self):
        pass
    
    #define Key activity
    def setDevScrnOn(self):
        self.mstrDevice.screen.on()
    
    
    def setMstDevScrnOff(self):
        self.mstrDevice.screen.off()

            
    def setWakeup(self):
        self.mstrDevice.wakeup()
            
    def setSleep(self):
        self.mstrDevice.sleep()
            
     #Hard key Soft key       
    def pressHome(self):
        return self.mstrDevice.press.home()
    
    def pressBack(self):
        return self.mstrDevice.press.back()
        
    
    ######################################################################
    
    def pressLeft(self):
        return self.mstrDevice.press.left()
        
    def pressRight(self):
        return self.mstrDevice.press.right()
    
    def pressUp(self):
        return self.mstrDevice.press.up()
        
    def pressDown(self):
        return self.mstrDevice.press.down()
        
    def pressCenter(self):
        return self.mstrDevice.press.center()
    
    ######################################################################    
        
    def pressMenu(self):
        return self.mstrDevice.press.menu()
        
    def pressSearch(self):
        return self.mstrDevice.press.search()
           
    def pressEnter(self):
        return self.mstrDevice.press.enter()
            
    def pressDelete(self):
        return self.mstrDevice.press.delete() # or del
        
    def pressRecent(self):
        return self.mstrDevice.press.recent()
            
    def pressVol_Up(self):
        return self.mstrDevice.press.volume_up()
            
    def pressVol_Down(self):
        return self.mstrDevice.press.volume_down()
            
    def pressVol_Mute(self):
        return self.mstrDevice.press.volume_mute()
            
    def pressPower(self):
        return self.mstrDevice.press.power()
            
    def clik(self, x, y):
        return self.mstrDevice.click(x, y)
            
    def longClik(self,x, y):
        '''
            Description:
                
            param:
                x, y : start first point x, y
                
            return : Boolean
        '''
        return self.mstrDevice.long_click(x, y)
            
    def swipe(self, sx, sy, ex, ey, steps=10):
        '''
            Description:
                
            param:
                sx, xy : start first x, y
                ex, ey : move to x, y
            return : Boolean
        '''
        return self.mstrDevice.swipe(sx, sy, ex, ey, steps)
           
    def drage(self,sx, sy, ex, ey, steps=10):
        '''
            Description:
                
            param:
                sx, xy : start first x, y
                ex, ey : move to x, y
            return : Boolean
        '''
        return self.mstrDevice.drag(sx, sy, ex, ey, steps)
       
    #screen action of the device   
    def setOrientation(self,scrAct='natural', choiceDevice='mstr'):
        '''
            Description
                
            param
                d.orientation = 'l' or 'left'
                d.orientation = 'r' or 'right'
                d.orientation = 'n' or 'natural'
            return : None
        '''
        self.mstrDevice.orientation = scrAct
    
    def setFreezeRotation(self,condition=False,choiceDevice='mstr'):
        '''
            param:
                condition : False un-freeze rotation
            return : None
        '''
        self.mstrDevice.freeze_rotation(condition)
    
    
            
    def takeScreenShot(self, choiceDevice = 'mstr'):
        '''
            Description:
                take screenshot and save to local file 'home.png' can work until android 4.2
            param
                image name
        '''
        
    def dumpWindowHeirarchy(self,filename='./log/hierachy.xml'):
        return self.mstrDevice.dump(filename)
        
    def dumpWindowHeirarchyStream(self):
        return self.mstrDevice.dump()
        
    def notification(self):
        '''
            Open notification, can not work until android 4.3
            return : Boolean
        '''
        return self.mstrDevice.open.Notification()
    
    def quickSettings(self):
        '''
            open quick settins, can not work until android 4.3
            return : Boolean 
        '''
        return self.mstrDevice.open.quick_settings()
    def waitidle(self):
        '''
            wait for current window to idle
            return : None
        '''
        self.mstrDevice.wait.idle()
        
    def waitWindowUpdate(self):
        '''
            wait until window upate event occurs
            return : Boolean
        '''
        self.mstrDevice.wait.update()
        
    def getCurrentActivityInfo(self, text):
        '''
          INFOMATION:
              { u'contentDescription': u'',
              u'checked': False,
              u'scrollable': False,
              u'text': u'Settings',
              u'packageName': u'com.android.launcher',
              u'selected': False,
              u'enabled': True,
              u'bounds': {u'top': 385,
                          u'right': 360,
                          u'bottom': 585,
                          u'left': 200},
              u'className': u'android.widget.TextView',
              u'focused': False,
              u'focusable': True,
              u'clickable': True,
              u'chileCount': 0,
              u'longClickable': True,
              u'visibleBounds': {u'top': 385,
                                 u'right': 360,
                                 u'bottom': 585,
                                 u'left': 200},
              u'checkable': False
            }
        '''  
        return self.mstrDevice(text).info
    
    def uiObjExist(self,text):
        '''
            ture if exists, else False
        '''
        return self.mstrDevice.exists(text)
    
    def watcher(self):
        pass
    def handler(self):
        pass
    def selector(self):
        pass
        
    def __del__(self):
        pass    
Пример #3
0
class ModelInfo():
    '''
    classdocs
    '''
    def __init__(self, deviceserial):
        '''
        Constructor
        '''

        #sndLog = CLS("test", "test")
        self.osType = sys.platform

        self.mstrInfo = {}

        #self.devSerials = self.instAdb.device_serial()
        self.mstrDevice = Device(deviceserial)
        self.mstrInfo = self.mstrDevice.info

    '''
        DEVICE Infoamtions
        { u'displayRotation': 0,
          u'displaySizeDpY': 640,
          u'displaySizeDpX': 360,
          u'currentPackageName': u'com.android.launcher',
          u'productName': u'takju',
          u'displayWidth': 720,
          u'sdkInt': 18,
          u'displayHeight': 1184,
          u'naturalOrientation': True
        }
    '''

    def getCurrntProductInfo(self):
        return self.mstrInfo

    def getProductNmae(self):
        return self.mstrInfo['productName']

    def getCurrntPkg(self):
        return self.mstrInfo['currentPackageName']

    def getSDKInt(self):
        return self.mstrInfo['sdkInt']

    def getRotation(self):
        return self.mstrInfo['displayRotation']

    def getNaturalOri(self):
        return self.mstrInfo['naturalOrientation']

    def getDisplayState(self):
        return self.mstrDevice.screen

    def setReflash(self):
        pass

    #define Key activity
    def setDevScrnOn(self):
        self.mstrDevice.screen.on()

    def setMstDevScrnOff(self):
        self.mstrDevice.screen.off()

    def setWakeup(self):
        self.mstrDevice.wakeup()

    def setSleep(self):
        self.mstrDevice.sleep()

    #Hard key Soft key
    def pressHome(self):
        return self.mstrDevice.press.home()

    def pressBack(self):
        return self.mstrDevice.press.back()

    ######################################################################

    def pressLeft(self):
        return self.mstrDevice.press.left()

    def pressRight(self):
        return self.mstrDevice.press.right()

    def pressUp(self):
        return self.mstrDevice.press.up()

    def pressDown(self):
        return self.mstrDevice.press.down()

    def pressCenter(self):
        return self.mstrDevice.press.center()

    ######################################################################

    def pressMenu(self):
        return self.mstrDevice.press.menu()

    def pressSearch(self):
        return self.mstrDevice.press.search()

    def pressEnter(self):
        return self.mstrDevice.press.enter()

    def pressDelete(self):
        return self.mstrDevice.press.delete()  # or del

    def pressRecent(self):
        return self.mstrDevice.press.recent()

    def pressVol_Up(self):
        return self.mstrDevice.press.volume_up()

    def pressVol_Down(self):
        return self.mstrDevice.press.volume_down()

    def pressVol_Mute(self):
        return self.mstrDevice.press.volume_mute()

    def pressPower(self):
        return self.mstrDevice.press.power()

    def clik(self, x, y):
        return self.mstrDevice.click(x, y)

    def longClik(self, x, y):
        '''
            Description:
                
            param:
                x, y : start first point x, y
                
            return : Boolean
        '''
        return self.mstrDevice.long_click(x, y)

    def swipe(self, sx, sy, ex, ey, steps=10):
        '''
            Description:
                
            param:
                sx, xy : start first x, y
                ex, ey : move to x, y
            return : Boolean
        '''
        return self.mstrDevice.swipe(sx, sy, ex, ey, steps)

    def drage(self, sx, sy, ex, ey, steps=10):
        '''
            Description:
                
            param:
                sx, xy : start first x, y
                ex, ey : move to x, y
            return : Boolean
        '''
        return self.mstrDevice.drag(sx, sy, ex, ey, steps)

    #screen action of the device
    def setOrientation(self, scrAct='natural', choiceDevice='mstr'):
        '''
            Description
                
            param
                d.orientation = 'l' or 'left'
                d.orientation = 'r' or 'right'
                d.orientation = 'n' or 'natural'
            return : None
        '''
        self.mstrDevice.orientation = scrAct

    def setFreezeRotation(self, condition=False, choiceDevice='mstr'):
        '''
            param:
                condition : False un-freeze rotation
            return : None
        '''
        self.mstrDevice.freeze_rotation(condition)

    def takeScreenShot(self, choiceDevice='mstr'):
        '''
            Description:
                take screenshot and save to local file 'home.png' can work until android 4.2
            param
                image name
        '''

    def dumpWindowHeirarchy(self, filename='./log/hierachy.xml'):
        return self.mstrDevice.dump(filename)

    def dumpWindowHeirarchyStream(self):
        return self.mstrDevice.dump()

    def notification(self):
        '''
            Open notification, can not work until android 4.3
            return : Boolean
        '''
        return self.mstrDevice.open.Notification()

    def quickSettings(self):
        '''
            open quick settins, can not work until android 4.3
            return : Boolean 
        '''
        return self.mstrDevice.open.quick_settings()

    def waitidle(self):
        '''
            wait for current window to idle
            return : None
        '''
        self.mstrDevice.wait.idle()

    def waitWindowUpdate(self):
        '''
            wait until window upate event occurs
            return : Boolean
        '''
        self.mstrDevice.wait.update()

    def getCurrentActivityInfo(self, text):
        '''
          INFOMATION:
              { u'contentDescription': u'',
              u'checked': False,
              u'scrollable': False,
              u'text': u'Settings',
              u'packageName': u'com.android.launcher',
              u'selected': False,
              u'enabled': True,
              u'bounds': {u'top': 385,
                          u'right': 360,
                          u'bottom': 585,
                          u'left': 200},
              u'className': u'android.widget.TextView',
              u'focused': False,
              u'focusable': True,
              u'clickable': True,
              u'chileCount': 0,
              u'longClickable': True,
              u'visibleBounds': {u'top': 385,
                                 u'right': 360,
                                 u'bottom': 585,
                                 u'left': 200},
              u'checkable': False
            }
        '''
        return self.mstrDevice(text).info

    def uiObjExist(self, text):
        '''
            ture if exists, else False
        '''
        return self.mstrDevice.exists(text)

    def watcher(self):
        pass

    def handler(self):
        pass

    def selector(self):
        pass

    def __del__(self):
        pass
Пример #4
0
class UiTestLib(object):
    """Ui Test Lib

    """

    def __init__(self, serial=None):
        """
        """
        logger.info("<p>Device=%s>" % serial, html=True)
        print "<p>Device=%s>" % serial
        self._result = ""
        self.starttime = 0
        self.d = Device(serial)
        self.adb = Adb(serial)
        self.debug = "True"

    def set_debugable(flag):
        self.debug = flag

    def set_serial(self, serial):
        """Specify given *serial* device to perform test.
        or export ANDROID_SERIAL=CXFS42343 if you have many devices connected but you don't use this
        interface

        When you need to use multiple devices, do not use this keyword to switch between devices in test execution.
        And set the serial to each library.
        Using different library name when importing this library according to
        http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.5.

        Examples:
        | Setting | Value |  Value |  Value |
        | Library | UiTestLib | WITH NAME | Mobile1 |
        | Library | UiTestLib | WITH NAME | Mobile2 |

        And set the serial to each library.
        | Test Case        | Action             | Argument           |
        | Multiple Devices | Mobile1.Set Serial | device_1's serial  |
        |                  | Mobile2.Set Serial | device_2's serial  |
        """
        self.d = Device(serial)
        self.adb = Adb(serial)

    def logmsg(self, msg):
        if self.debug == "True":
            print msg

    def exe_adb_command(self, cmd):
        """ Execute adb *cmd*
         Examples:
        | Exe Adb Command | shell getprop  |
        """
        return self.adb.cmd(cmd).wait()

    def exe_adb_and_result(self, cmd):
        """Execute adb *cmd* and return lines of the command"""
        lproc = self.adb.cmd(cmd)
        lproc.poll()
        lines = lproc.stdout.readlines()
        return lines

    def get_device_info(self):
        """Get Device information
        return info dictionary
        """
        return self.d.info

    def light_screen(self):
        """Light screen by wakeup.

        Examples:
        | Action     |
        |Light screen|

        Use `Light screen` to light screen.
        """

        self.d.wakeup()
        self._result = self.d.press.home()

    def open_application(self, appname):
        """Open application by it name `appname`.

        Example:
        | Action           | Argument      |
        | Open application | "com.android.settings/com.android.settings.Settings" |
        """
        appname = "shell am start -n " + appname
        print "Open Application:", appname
        self._result = self.exe_adb_command(appname)

    def click_text(self, text, instance=0):
        """Click text label on screen
        instance=0 is default, change when you needed.

        Example:
        | Action     | Argument   |  Argument  |
        | Click Text | text | instance |
        """

        return self.d(text=text, instance=instance).click.wait()

    def long_click_text(self, text, instance=0):
        """
        Long Click text label on screen, *text* and *instance=0*

        Example:
        | Action     | Argument   |  Argument  |
        | Long Click Text | text | instance |
        """

        return self.d(text=text, instance=instance).long_click()

    def long_click_ui(self, **selectors):
        """
        Long Click on **selectors**
        Selector supports below parameters. Refer to UiSelector java doc for detailed information.

            text, textContains, textMatches, textStartsWith
            className, classNameMatches
            description, descriptionContains, descriptionMatches, descriptionStartsWith
            checkable, checked, clickable, longClickable
            scrollable, enabled,focusable, focused, selected
            packageName, packageNameMatches
            resourceId, resourceIdMatches
            index, instance
        Example:
        | Action     | Argument   |  Argument  |  Argument  |
        | Long Click UI | text=XXXX | className=XXX.xxxx | resourceId=xxxxxx |
        """

        return self.d(**selectors).long_click()

    def text_display_on_screen_contains(self, text):
        """Verify text display on screen

        Example:
        | Action     | Argument   |
        |Text display on screen is| text |
        """

        if self.d(text=text).exists:
            self._result = True
            return True
        else:
            self._result = False
            return False

    def object_display_on_screen(self, obj, timeout=5000):
        """ Verify *obj* UiObject display on screen
        return to self._result

        Example:
        | Action     | Argument   |
        |Object display on screen | obj |
        """
        if obj.wait.exists(timeout):
            self._result = True
            return True
        else:
            self._result = False
            return False

    def assert_expectation(self, expect, actual):
        """
        Assert Expectation and actual value
        Example:
        | Action             |   args   |   args      |
        | Assert Expectation |   324324 |  ${actual}  |
        """
        if str(expect) != str(actual):
            raise AssertionError("Actual result is = %s, but expectation is: %s" % (str(actual), str(expect)))

    def assert_true(self, condition):
        """
        Assert True of *condition

        Example:
        |Assert True | condition |
        """
        if str(condition) != "True":  # because only string from robotframework
            raise AssertionError("Result is = %s" % str(condition))

    def assert_result_true(self):
        """
        Assert True of *self._result

        Example:
        |Assert True |
        """
        if self._result != True:
            raise AssertionError("Result is = %s" % str(self._result))

    def wait_for_ui_exists(self, timeout, **selectors):
        """
        Return True if
          Selector is to identify specific ui object in current window.

        # To seleted the object ,text is 'Clock' and its className is 'android.widget.TextView'
        wait_for_ui_exists(text='Clock', className='android.widget.TextView')

        Selector supports below parameters. Refer to UiSelector java doc for detailed information.

            text, textContains, textMatches, textStartsWith
            className, classNameMatches
            description, descriptionContains, descriptionMatches, descriptionStartsWith
            checkable, checked, clickable, longClickable
            scrollable, enabled,focusable, focused, selected
            packageName, packageNameMatches
            resourceId, resourceIdMatches
            index, instance

        Examples:
        | Action     | Argument   |  Argument  |  Argument  |  Argument  |
        |Wait For UI Exists | timeout | text=XXXX | className=XXX.xxxx | resourceId=xxxxxx |
        """
        self._result = self.d(**selectors).wait.exists(timeout=int(timeout))
        return self._result

    def wait_and_click(self, timeout, **selectors):
        """Wait for uiselector and click"""
        if self.d(**selectors).wait.exists(timeout=int(timeout)):
            self.d(**selectors).click()

    def assert_ui_exists(self, **selectors):
        """
        Assert UiObject appear on the screen

        Examples:
        | Action     | Argument   |  Argument  |  Argument  |  Argument  |
        |Assert UI Exists | timeout | text=XXXX | className=XXX.xxxx | resourceId=xxxxxx |
        """
        if not self.d(**selectors).wait.exists():
            raise AssertionError("UiObject does not exists %s" % selectors.items())

    def result_should_be(self, expected):
        """Verifies that the current result is `expected`.

        Example:
        | Action     | Argument   |
        |  Open application    | com.android.settings/com.android.settings.Settings |
        |  Result Should Be    | 0       |
        """
        print ("result is: %s\n", self._result)
        print ("ex is: %s\n", expected)
        if str(self._result) != expected:
            raise AssertionError("%s != %s" % (self._result, expected))

    def click_at_coordinates(self, x, y):
        """ Click at (x,y) coordinates.
        Example:
        | Action     | Argument   |  Argument  |
        | Click At Corrdinates | x | y |
        """
        return self.d.click(int(x), int(y))

    def long_click_at_coordinates(self, x, y):
        """
        # long click (x, y) on screen
        """
        return self.d.long_click(int(x), int(y))

    def swipe(self, sx, sy, ex, ey, steps=20):
        """
        Swipe from (sx,sy) to (ex,ey)
        """
        return self.d.swipe(int(sx), int(sy), int(ex), int(ex), int(steps))

    def drag(self, sx, sy, ex, ey, steps=20):
        """
        Drag from (sx,sy) to (ex,ey)
        """
        return self.d.drag(int(sx), int(sy), int(ex), int(ex), int(steps))

    def freeze_rotation(self, rotation=True):
        """
        Freeze rotation,
        *rotation*, True is default,
        """
        return self.d.freeze_rotation(rotation)

    def set_rotation(self, rotation):
        """
        # retrieve orientation,
        # it should be "natural" or "left" or "right" or "upsidedown"

        Example:
        | Action       | Argument   |
        | Set Rotation | nature      |
        | Set Rotation | left        |
        | Set Rotation | right       |
        | Set Rotation | upsidedown  |

        """
        orientation = self.d.orientation
        if rotation == "nature":
            self.d.orientation = "n"  # or "natural"
        elif rotation == "left":
            self.d.orientation = "l"  # or "left"
        elif rotation == "right":
            self.d.orientation = "r"  # or "right"
        elif rotation == "upsidedown":
            self.d.orientation = "upsidedown"  # or "upsidedown"
        else:
            self.d.rotation = "n"

    def take_screenshot(self, scale=None, quality=None):
        """
        Take a screenshot of device and log in the report with timestamp, scale for screenshot size and quality for screenshot quality
        default scale=1.0 quality=100

        Example:
        | Action     | Argument   |  Argument  |
        | Take Screenshot | 0.5 | 80 |
        """
        output_dir = BuiltIn().get_variable_value("${OUTPUTDIR}")
        ts = time.time()
        st = datetime.datetime.fromtimestamp(ts).strftime("%Y%m%d%H%M%S")
        screenshot_path = "%s%s%s.png" % (output_dir, os.sep, st)
        screenshot_name = "%s%s.png" % (os.sep, st)
        self.d.screenshot(screenshot_path, scale, quality)
        logger.info('\n<a href="%s">%s</a><br><img src="%s">' % (screenshot_path, st, screenshot_name), html=True)

    def open_notification(self):
        """
        Open notification of the phone
        """
        self.d.open.notification()

    def wait_window_update(self):
        """
        wait for window update
        """
        return self.d.wait.update()

    def wait_window_idle(self):
        """
        wait for window idle
        """
        return self.d.wait.idle()

    def remove_watchers(self):
        """
        Remove UI watchers
        """
        self.d.watchers.remove()

    def get_device(self):
        """
        Get device object, you can do any command using this
        """
        return self.d

    def click_id(self, id, instance=0):
        """
        Click *id* with *instance*=0
        """
        return self.d(resourceId=id, instance=instance).click.wait()

    def long_click_id(self, id, instance=0):
        """
        Long click *id* with *instance*=0
        """
        return self.d(resourceId=id, instance=0).long_click()

    def click_description(self, description, instance=0):
        """
        Click *description* with *instance*=0
        """
        return self.d(description=description, instance=instance).long_click()

    def click_class(self, className, instance=0):
        """
        Click *className* with *instance*=0
        """
        return self.d(className=className, instance=instance).long_click()

    def type_text(self, textStr, **selectors):
        """
        type text on selectors
        like text=EditName
        """
        self.d(**selectors).set_text(textStr)

    def press_key(self, key):
        """ Press Key of following value
            home
            back
            left
            right
            up
            down
            center
            menu
            search
            enter
            delete(or del)
            recent(recent apps)
            volume_up
            volume_down
            volume_mute
            camera
            power

            Examples:
            | Action     | Argument   |
            | Press Key | home |
            | Press Key | back |
            | Press Key | left |
            | Press Key | right |
            | Press Key | recent |
            | Press Key | volume_up |
            | Press Key | camera |
        """
        if key.isdigit():
            return self.d.press(int(key))
        return self.d.press(key)

    def phone_sleep(self, timeout):
        """
        android device sleep with timeout in ms, don't use for executor sleep,
        """
        return self.d.wait(int(timeout))

    def execute_command(self, cmd, block_parent_process=True):
        """
        Execute shell *cmd* command, with block_parent_process = True

        If block_parent_process = False, kill_command is needed to terminal the child process

        Example:
        | Execute Command | ping -c 5 127.0.0.1 |
        """
        if str(block_parent_process) == str(True):
            return subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
        else:
            return subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    def kill_command(self, process, timeout=0):
        """ Kill child *process* in timeout seconds
        Some bugs after process teminated
        """
        time.sleep(float(timeout))
        process.terminate()

    def wait_for_logcat(self, log, timeout=30):
        """ Wait log exists in given timeout, return True if have, otherwise will return False
        log is your want to search, log can be a regular expression
        time in seconds, default value is 30 seconds

        Example:
        | Wait For Logcat | .*ActivityManager.*cmp=com.sonyericsson.album/com.sonyericsson.album.Main.* |
        """
        start = time.time()
        while (time.time() - start) < int(timeout):
            log_proc = self.adb.cmd("logcat -d -v time")
            returncode = log_proc.poll()
            lines = log_proc.stdout.readlines()
            for line in lines:
                rlt = re.search(log, line.rstrip())
                if rlt is not None:
                    print rlt.group(0)
                    self._result = True
                    return True
            time.sleep(2)  # sleep 2s to wait
        self._result = False
        return False

    def clear_logcat(self):
        """
        Clear logcat, it's often used before you want to use *wait_for_logcat()*
        """
        print "Clear logcat before test"
        return self.exe_adb_command("logcat -c")

    def click_object(self, obj):
        """ Click UiObject *obj*

        Exmaple:
        | ${result}    | Get UI Object | text=XXX | className=xxxx |
        | Click Object |   ${result}   |
        """
        obj.click()

    def click_ui(self, **selectors):
        """
        Click selector

        click_selector(text="Home", resourceId = "android:id/title")
        for **selector, please refer *get_ui_object()*
        Selector supports below parameters. Refer to UiSelector java doc for detailed information.

            text, textContains, textMatches, textStartsWith
            className, classNameMatches
            description, descriptionContains, descriptionMatches, descriptionStartsWith
            checkable, checked, clickable, longClickable
            scrollable, enabled,focusable, focused, selected
            packageName, packageNameMatches
            resourceId, resourceIdMatches
            index, instance
        Operation for a UiObjects:
        click, clear_text, drag(obj).to(**selector), gesture, exists, set_text, long_click
        pinch.In(percent=100, steps=10), pinch.Out(percent=100, steps=100),.swipe.right(),
        .swipe.left(steps=10),.swipe("right", steps=20),.wait.gone(),.wait.exists()
        """
        print "selectors:", selectors
        return self.d(**selectors).click()

    def get_ui_object(self, **selectors):
        """
        Get UI object with *selectors*
        you can do anything on UiObject, like click(), long_click(),wait.exists(timeout)
        examples: get_ui_object(text="Home", resourceId = "android:id/title")

        Selector supports below parameters. Refer to UiSelector java doc for detailed information.

            text, textContains, textMatches, textStartsWith
            className, classNameMatches
            description, descriptionContains, descriptionMatches, descriptionStartsWith
            checkable, checked, clickable, longClickable
            scrollable, enabled,focusable, focused, selected
            packageName, packageNameMatches
            resourceId, resourceIdMatches
            index, instance
        Operation for a UiObjects:
        click, clear_text, drag(obj).to(**selector), gesture, exists, set_text, long_click
        pinch.In(percent=100, steps=10), pinch.Out(percent=100, steps=100),.swipe.right(),
        .swipe.left(steps=10),.swipe("right", steps=20),.wait.gone(),.wait.exists()

        Exmaple:
        | ${result}    | Get UI Object | text=XXX | className=xxxx |

        """
        self._result = self.d(**selectors)
        return self._result

    def wait_for_object_exists(self, obj, timeout=0):
        """
        Wait for UiObject *obj* exists in *timeout*= 0

        Example:
        | ${result}    | Get UI Object | text=XXX | className=xxxx |
        | Wait For Object Exists | ${result} | timeout |
        """
        self._result = obj.wait.exists(timeout=int(timeout))
        return self._result

    def wait_for_ui_gone(self, timeout=0, **selectors):
        """
        Wait for UiObject *obj* gone in *timeout*= 0

        Example:
        | ${result}    | Get UI Object | text=XXX | className=xxxx |
        | Wait For Object Gone | ${result} | timeout |

        """
        self._result = self.d(**selectors).wait.gone(timeout=int(timeout))
        return self._result

    def get_key_value(self, key, dictionary):
        """
        Get key value of dictionary
        """
        return dictionary(key)

    def get_tts(self, input_text, delete_file=False, **args):
        """
        Get TTS voice mp3 from Google
        get_tts(input_text='tunnel snakes rule apparently', args = {'language':'en','output':'outputto.mp3'})

        Robot Framework:
        Examples:
        | Action     | Argument   |  Argument  |  Argument  |  Argument  |
        | UiTestLib.Get TTS    |   Hello world    |   False   |    output=ooo.mp3   |   language=en |
        """
        print "Get text to speech: ", input_text
        downloaded = False
        if str(delete_file) == "True":
            if os.path.exists(args["output"]):
                os.remove(args["output"])
        if os.path.exists(args["output"]):
            if os.path.getsize(args["output"]) <= 0:
                os.remove(args["output"])
        if args["output"] is not None:
            if not os.path.exists(args["output"]):
                print "Generating mp3 file......", args["output"]
                downloaded = GoogleTTS.audio_extract(input_text, args)
            else:
                print "Have same local file"
                downloaded = True
        if not downloaded:
            print "Downloaded TTS from Google failed, trying to download from local FTP..."
            mp3file = open(args["output"], "w")
            mp3url = "ftp://cnbjlx9548/atautomation/Test-Content/Croft/" + args["output"]
            try:
                resp = urllib2.urlopen(mp3url, timeout=40)
                mp3file.write(resp.read())
                time.sleep(0.05)
            except Exception, e:
                print e
                return False
            mp3file.close()
        return True
Пример #5
0
 time.sleep(7)
 # d(resourceId="com.twitter.android:id/password_entry")
 os.system("adb -s 0123456789ABCDEF shell input text {}".format(password))
 time.sleep(4)
 d(text="下一步").click()
 time.sleep(2)
 d(text="暂时不用").click()
 time.sleep(2)
 d(text="我确定").click()
 # d(text="跳过").click()
 # d(resourceId="android:确定").click()
 # d.long_press(300, 350)
 randomName = str(int(random.random() * 10)) + enname[:9] + str(
     int(random.random() * 10))
 print(randomName)
 d.long_click(200, 350)
 os.system('adb -s 0123456789ABCDEF shell input keyevent 67')
 os.system(
     'adb -s 0123456789ABCDEF shell input text "{}"'.format(randomName))
 time.sleep(3)
 d(text="下一步").click()
 time.sleep(2)
 d(textContains="现在开始").click()
 tw.insert({
     "userName": username,
     "passwords": password,
     "name": randomName
 })
 # here maybe quit account.
 #
 #
Пример #6
0
def main():

    port = '5554'

    d = Device('emulator-' + port)

    #d.dump("/home/yu/repeatbugreport/middleResults/result.xml")

    #this is for flash
    d(resourceId="com.example.terin.asu_flashcardapp:id/email").set_text(
        "*****@*****.**")
    d(resourceId="com.example.terin.asu_flashcardapp:id/password").set_text(
        "12331986")
    d(resourceId="com.example.terin.asu_flashcardapp:id/email_sign_in_button"
      ).click()

    time.sleep(4)
    '''
    #this is for yastore
    d(resourceId="android:id/text1").click();
    
    d(resourceId="com.github.yeriomin.yalpstore:id/email").set_text("*****@*****.**")
    d(resourceId="com.github.yeriomin.yalpstore:id/password").set_text("lunar1986")
    d(resourceId="com.github.yeriomin.yalpstore:id/button_ok").click();
    time.sleep(4)
    '''
    '''this is for mifos
    d(resourceId="com.mifos.mifosxdroid:id/et_username").set_text("mifos")    
    d(resourceId="com.mifos.mifosxdroid:id/et_password").set_text("password") 
    
    d(text="LOGIN").click();
    
    
    time.sleep(2)
    '''

    #d(text="ALLOW").click();

    #d.press.back()
    #d.press.home()
    d.orientation = "n"

    d.screen.on()

    #address='/home/yu/repeatbugreport'
    address = '.'

    doc = minidom.parse(address + '/middleResults/run.xml')
    root = doc.documentElement

    for step in root.childNodes:
        if step.nodeType == minidom.Node.ELEMENT_NODE:  ##minidom is a little bit ugly

            textid = ""
            textX = ""
            textY = ""
            textStr = ""

            actionTypes = step.getElementsByTagName("Actiontype")
            if actionTypes[0].firstChild.nodeValue == "Noaction":
                continue
            if actionTypes[0].firstChild.nodeValue == "back":
                d.press.back()
                continue

            if actionTypes[0].firstChild.nodeValue == "enter":
                d.press("enter")
                time.sleep(2)
                continue

            ##########get the source id
            ownText = step.getElementsByTagName("ownText")

            if ownText.length != 0:
                textid = ownText[0].firstChild.nodeValue

            #########get the x-position and y-position
            xPositions = step.getElementsByTagName("xposition")
            yPositions = step.getElementsByTagName("yposition")

            if xPositions.length != 0:
                textX = xPositions[0].firstChild.nodeValue
                textY = yPositions[0].firstChild.nodeValue

            #########get the click text
            clickText = step.getElementsByTagName("clickText")

            if clickText.length != 0:
                if clickText[0].childNodes.length != 0:
                    textStr = clickText[0].firstChild.nodeValue

            #print(actionTypes[0].firstChild.nodeValue)
            if actionTypes[0].firstChild.nodeValue == "EditText":

                typewhat = step.getElementsByTagName("typeWhat")
                textTypeWhat = typewhat[0].firstChild.nodeValue

                if textTypeWhat == "default":
                    continue

                #write text
                d(resourceId=textid).set_text(textTypeWhat)
                #d.press("enter")

                #print(textid)
                #print(textTypeWhat)

                #d(resourceId="com.newsblur:id/login_password").set_text("asd")
                #d.wait.idle()
                time.sleep(0.5)

            else:
                #elif actionTypes[0].firstChild.nodeValue=="ClickList":
                #########get the x-position and y-position

                clicktype = step.getElementsByTagName("clicktype")
                textclicktype = clicktype[0].firstChild.nodeValue

                try:
                    if textclicktype == "short":
                        if not textid == "":
                            d(resourceId=textid).click()

                        if not textStr == "":
                            d(text=textStr).click()
                        else:
                            d.click(int(textX), int(textY))

                    elif textclicktype == "long":
                        if not textid == "":
                            d(resourceId=textid).long_click()

                        elif not textStr == "":
                            d(text=textStr).long_click()
                        else:
                            d.long_click(int(textX), int(textY))
                #d.wait.update()
                except Exception as err:
                    break

            time.sleep(2)

            #d.dump("/home/yu/repeatbugreport/middleResults/result.xml")

    d.dump(address + "/middleResults/result.xml")

    cmd = "adb -s emulator-" + port + " shell dumpsys window windows | grep -E 'mFocusedApp'"
    packInfo = commands.getstatusoutput(cmd)

    fo = open(address + "/middleResults/packInfo", "w")
    fo.write(str(packInfo))
    fo.close()

    if root.getAttribute("Rotate") == "True":

        d.orientation = "l"
        time.sleep(0.5)
        d.orientation = "n"
        time.sleep(0.5)