当前位置: 首页>>代码示例>>Python>>正文


Python Device.drag方法代码示例

本文整理汇总了Python中uiautomator.Device.drag方法的典型用法代码示例。如果您正苦于以下问题:Python Device.drag方法的具体用法?Python Device.drag怎么用?Python Device.drag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在uiautomator.Device的用法示例。


在下文中一共展示了Device.drag方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Mobile

# 需要导入模块: from uiautomator import Device [as 别名]
# 或者: from uiautomator.Device import drag [as 别名]

#.........这里部分代码省略.........

    def swipe(self, sx, sy, ex, ey, steps=10):
        """
        swipe from (sx, sy) to (ex, ey) with steps
        """
        self.device.swipe(sx, sy, ex, ey, steps)

# Swipe from the center of the ui object to its edge

    def swipe_left(self, obj, steps=10):
        """
        swipe the *obj* from center to left
        """
        obj.swipe.left(steps=steps)

    def swipe_right(self, obj, steps=10):
        """
        swipe the *obj* from center to right
        """
        obj.swipe.right(steps=steps)

    def swipe_top(self, obj, steps=10):
        """
        swipe the *obj* from center to top
        """
        obj.swipe.top(steps=steps)

    def swipe_bottom(self, obj, steps=10):
        """
        swipe the *obj* from center to bottom
        """
        obj.swipe.bottom(steps=steps)

    def drag(self,sx, sy, ex, ey, steps=10):
        """
        drag from (sx, sy) to (ex, ey) with steps
        """
        self.device.drag(sx, sy, ex, ey, steps)

    #Wait until the specific ui object appears or gone

    # wait until the ui object appears
    def wait_for_exists(self, timeout=0, *args, **attribute):
        """
        true means the object which has *attribute* exist
        false means the object does not exist
        in the given timeout
        """
        return self.device(**attribute).wait.exists(timeout=timeout)

    # wait until the ui object gone
    def wait_until_gone(self, timeout=0, *args, **attribute):
        """
        true means the object which has *attribute* disappear
        false means the object exist
        in the given timeout
        """
        return self.device(**attribute).wait.gone(timeout=timeout)

    def wait_for_object_exists(self, obj, timeout=0):
        """
        true means the object exist
        false means the object does not exist
        in the given timeout
        """
        return obj.wait.exists(timeout=timeout)
开发者ID:am01230123,项目名称:parallelization,代码行数:70,代码来源:Mobile.py

示例2: ModelInfo

# 需要导入模块: from uiautomator import Device [as 别名]
# 或者: from uiautomator.Device import drag [as 别名]

#.........这里部分代码省略.........
        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)
    
    
开发者ID:sqler21c,项目名称:Python,代码行数:68,代码来源:ModelInfo.py

示例3: AndroidDevice

# 需要导入模块: from uiautomator import Device [as 别名]
# 或者: from uiautomator.Device import drag [as 别名]

#.........这里部分代码省略.........
            if k and v:
                shellcmd.append('-e')
                shellcmd.append(k)
                shellcmd.append(str(v))
        shellcmd.append(pkgname)
        result = self.d.server.adb.cmd(*shellcmd).communicate()
        return result

    def TODOinstallPackage(self, **kwargs):
        pass

    def TODOremovePackage(self, **kwargs):
        pass

    def press(self, keyname, waittime=1):
        #hard, soft key: home,back,up,down,right,left,center,menu,power or ANDROID_KEYEVENT
        self.d.press(keyname)
        time.sleep(waittime)
        return self

    def click(self, x, y, waittime=1):
        self.d.click(x, y)
        time.sleep(waittime)
        return self

    def click_image(self, imagename, waittime=1, threshold=0.01):
        '''
        if the wanted image found on current screen click it.
        if the wanted image not found raise exception and set test to be failure.
        '''
        expect_image_path = os.path.join(configer['right_dir_path'], imagename)
        assert os.path.exists(expect_image_path), 'the local expected image %s not found!' % imagename
        current_image_path = os.path.join(configer['report_dir_path'], imagename)
        self.d.screenshot(current_image_path)
        assert os.path.exists(current_image_path), 'fetch current screen shot image %s failed!' % imagename
        pos = getMatchedCenterOffset(expect_image_path, current_image_path, threshold)
        assert pos, 'Fail Reason: The wanted image \'%s\' not found on screen!' % imagename
        self.d.click(pos[0], pos[1])
        time.sleep(waittime)
        return self

    def swipe(self, sx, sy, ex, ey, steps=100, waittime=1):
        self.d.swipe(sx, sy, ex, ey, steps)
        time.sleep(waittime)
        return self

    def drag(self, sx, sy, ex, ey, steps=100, waittime=1):
        self.d.drag(sx, sy, ex, ey, steps)
        time.sleep(waittime)
        return self

    #inspect
    def exists(self, **kwargs):
        '''
        if the expected component exists on current screen layout return true else return false.
        '''
        return self.d.exists(**kwargs)

    #device snapshot
    def screenshot(self, filename, waittime=1):
        path = os.path.join(configer['report_dir_path'], filename)
        self.d.screenshot(path)
        return self

    def expect(self, imagename, interval=2, timeout=4, threshold=0.01, msg=''):
        '''
        if the expected image found on current screen return self 
        else raise exception. set test to be failure.
        '''
        expect_image_path = os.path.join(configer['right_dir_path'], imagename)
        assert os.path.exists(expect_image_path)
        current_image_path = os.path.join(configer['report_dir_path'], imagename)
        begin = time.time()
        while (time.time() - begin < timeout):
            self.d.screenshot(current_image_path)
            if isMatch(expect_image_path , current_image_path , threshold):
                return self
            time.sleep(interval)
        name, ext = os.path.splitext(os.path.basename(imagename))
        shutil.copyfile(expect_image_path, os.path.join(configer['report_dir_path'], '%s%s%s' % (name, '_expect', ext)))
        reason = msg if not msg else 'Fail Reason: Image \'%s\' not found on screen!' % imagename
        assert False, reason

    def find(self, imagename, interval=2, timeout=4, threshold=0.01):
        '''
        if the expected image found on current screen return true else return false
        '''
        expect_image_path = os.path.join(configer['right_dir_path'], imagename)
        assert os.path.exists(expect_image_path)
        current_image_path = os.path.join(configer['report_dir_path'], imagename)
        begin = time.time()
        isExists = False
        while (time.time() - begin < timeout):
            time.sleep(interval)
            self.d.screenshot(current_image_path)
            isExists = isMatch(expect_image_path , current_image_path , threshold)
            if not isExists:
                time.sleep(interval)
                continue
        return isExists
开发者ID:lucker6666,项目名称:devicewrapper,代码行数:104,代码来源:android.py

示例4: AdbDevice

# 需要导入模块: from uiautomator import Device [as 别名]
# 或者: from uiautomator.Device import drag [as 别名]

#.........这里部分代码省略.........
        if point1[0] <= point[0] <= point2[0] and point1[1] <= point[1] <= point2[1]:
            area = (point2[0] - point1[0]) * (point2[1] - point1[1])
            return True, area
        else:
            return False, None

    def viewFilter(self, view):
        if view.getClass() == self.viewClass:
            return True
        else:
            return False

    def screenOn(self, status):
        if status == True:
            self.d.screen.on()
        else:
            self.d.screen.off()

    def clearLog(self):
        self.cmd.shell(['logcat', '-c'])

    def longClick(self, x, y, duration):
        if y <= self.d.info['displayHeight']:
            self.d.swipe(x, y, x, y, steps=duration / 10)
        else:
            self.cmd.shell(['input', 'tap', str(x), str(y)])

    def click(self, x, y):
        if y <= self.d.info['displayHeight']:
            self.d.click(x, y)
        else:
            self.cmd.shell(['input', 'tap', str(x), str(y)])

    def drag(self, x, y, duration):
        self.d.drag(x[0], x[1], y[0], y[1], steps=duration / 10)

    def swipe(self, x, y, duration):
        self.cmd.shell(['input', 'swipe', str(x[0]), str(x[1]), str(y[0]), str(y[1]), str(duration)])

    def type(self, text):
        translate = re.sub(r'([#\(\)\&\*\'\\\"\~\`\|\<\>?\;])', r'\\\1', text)
        self.cmd.shell(['input', 'text', translate])
        # self.d(className="android.widget.EditText").set_text(text)

    def hideKeyboard(self):
        if self.isKeyboardShown():
            self.backBtn()

    def unlock(self):
        if self.isLocked():
            self.menuBtn()

    def isLocked(self):
        lockScreenRE = re.compile('mShowingLockscreen=(true|false)')
        m = lockScreenRE.search(self.cmd.dumpsys(['window', 'policy']))
        if m is not None:
            return m.group(1) == 'true'

    def isScreenOn(self):
        screenOnRE = re.compile('mScreenOnFully=(true|false)')
        m = screenOnRE.search(self.cmd.dumpsys(['window', 'policy']))
        if m is not None:
            return m.group(1) == 'true'

    def powerBtn(self):
        self.cmd.inputKeyevnt('POWER')
开发者ID:ChenYuTingJerry,项目名称:AutoSense_2,代码行数:70,代码来源:Adb.py

示例5: Mobile

# 需要导入模块: from uiautomator import Device [as 别名]
# 或者: from uiautomator.Device import drag [as 别名]

#.........这里部分代码省略.........
        | ${object} | Get Object | description=Home screen 3 | # Get the UI object |
        | Object Swipe Left | ${object} | | # Swipe the UI object left |
        | Object Swipe Left | ${object} | 5 | # Swipe the UI object left with steps=5 |
        | Object Swipe Left | ${object} | steps=5 | # Swipe the UI object left with steps=5 |

        See `introduction` for details about identified UI object.
        """
        obj.swipe.left(steps=steps)

    def object_swipe_right(self, obj, steps=10):
        """
        Swipe the *obj* from center to right

        See `Object Swipe Left` for more details.
        """
        obj.swipe.right(steps=steps)

    def object_swipe_top(self, obj, steps=10):
        """
        Swipe the *obj* from center to top

        See `Object Swipe Left` for more details.
        """
        obj.swipe.up(steps=steps)

    def object_swipe_bottom(self, obj, steps=10):
        """
        Swipe the *obj* from center to bottom

        See `Object Swipe Left` for more details.
        """
        obj.swipe.down(steps=steps)

    def drag_by_coordinates(self,sx, sy, ex, ey, steps=10):
        """
        Drag from (sx, sy) to (ex, ey) with steps

        See `Swipe By Coordinates` also.
        """
        self.device.drag(sx, sy, ex, ey, steps)

    #Wait until the specific ui object appears or gone

    # wait until the ui object appears
    def wait_for_exists(self, timeout=0, *args, **selectors):
        """
        true means the object which has *selectors* exist
        false means the object does not exist
        in the given timeout
        """
        return self.device(**selectors).wait.exists(timeout=timeout)

    # wait until the ui object gone
    def wait_until_gone(self, timeout=0, *args, **selectors):
        """
        true means the object which has *selectors* disappear
        false means the object exist
        in the given timeout
        """
        return self.device(**selectors).wait.gone(timeout=timeout)

    def wait_for_object_exists(self, obj, timeout=0):
        """
        true means the object exist
        false means the object does not exist
        in the given timeout
开发者ID:am01230123,项目名称:furry-ironman,代码行数:70,代码来源:Mobile.py

示例6: UiTestLib

# 需要导入模块: from uiautomator import Device [as 别名]
# 或者: from uiautomator.Device import drag [as 别名]

#.........这里部分代码省略.........
    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"
开发者ID:huaping,项目名称:StabilityKPI,代码行数:70,代码来源:UiTestLib.py


注:本文中的uiautomator.Device.drag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。