dragandroidviewclient

What are the parameters in device.drag method in AndroidViewClient?


what does the orientation parameter in the drag method do? Also when I change the duration and/or steps, it does not make that much difference

vc.device.drag(start, end, duration, steps, orientation):


Solution

  • Take a look at the source code (the greatest of Open Source):

    def drag(self, (x0, y0), (x1, y1), duration, steps=1, orientation=-1):
        '''
        Sends drag event in PX (actually it's using C{input swipe} command).
    
        @param (x0, y0): starting point in PX
        @param (x1, y1): ending point in PX
        @param duration: duration of the event in ms
        @param steps: number of steps (currently ignored by @{input swipe})
        @param orientation: the orientation (-1: undefined)
        '''
    
        self.__checkTransport()
        if orientation == -1:
            orientation = self.display['orientation']
        (x0, y0) = self.__transformPointByOrientation((x0, y0), orientation, self.display['orientation'])
        (x1, y1) = self.__transformPointByOrientation((x1, y1), orientation, self.display['orientation'])
    
        version = self.getSdkVersion()
        if version <= 15:
            raise RuntimeError('drag: API <= 15 not supported (version=%d)' % version)
        elif version <= 17:
            self.shell('input swipe %d %d %d %d' % (x0, y0, x1, y1))
        else:
            self.shell('input touchscreen swipe %d %d %d %d %d' % (x0, y0, x1, y1, duration))
    

    also, keep in mind that one of the main objectives of AndroidViewClient and culebra is to generate tests that can run under a wide range of conditions, not just the one present when they were generated. You can run the same test on a different device, screen or resolution. Also, you can run the same test under a different orientation and you don't want the test to be affected by that fact, then when the test is generated the orientation is saved and eventually the coordinates translated if when run the device was rotated.

    duration usage depends on the android version, as you can see in the source.

    steps, as stated, are currently ignored.