六、Appium触屏操作自动化

TouchAction 用法

action0 = TouchAction().tap(el)
action1 = TouchAction().tap(el)
MultiAction().add(action0).add(action1).perform()
    def test_touchaction(self):
        action=TouchAction(self.driver)
        # 获取当前屏幕的大小
        width = self.driver.get_window_rect()['width']
        height = self.driver.get_window_rect()['height']
        x1 = int(width/2)
        y_start = int(height * 4/5)
        y_end = int(height * 1/5)
        action.press(x=x1, y=y_start).wait(200).move_to(x=x1, y= y_end).release().perform()

手势操作

TouchAction(driver).press(x=244,y=374).wait(100).move_to(x=711,y=374).wait(100).move_to(x=1198,y=374).wait(100).move_to(x=1198,y=865).wait(100) .move_to(x=1198,y=1323).wait(100).release().perform()
  • 例子
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction


class TesetTouchAction:
    def setup(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        # desired_caps['platformVersion'] = '6.0'
        desired_caps['deviceName'] = '127.0.0.1:7555'
        desired_caps['appPackage'] = 'cn.kmob.screenfingermovelock'
        desired_caps['appActivity'] = 'com.samsung.ui.MainActivity'
        desired_caps['noReset'] = 'true'
        # desired_caps['dontStopAppOnReset'] = "true"
        desired_caps['skipDeviceInitialization'] = "true"
        """当要输入中文时需要以下两个参数"""
        desired_caps['unicodeKeyBoard']='true'
        desired_caps['resetKeyBoard']='true'
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
        # 隐式等待
        self.driver.implicitly_wait(5)

    def teardown(self):
        self.driver.quit()

    def test_touchaction_unlock(self):
        action = TouchAction(self.driver)
        action.press(x=244, y=374).wait(100).move_to(x=711, y=374).wait(100).move_to(x=1198, y=374).\
            wait(100).move_to(x=1198, y=865).wait(100).move_to(x=1198, y=1323).wait(100).release().perform()

下一节:高级定位技巧,XPath、UIAutomator定位表达式以及滑动定位应用。

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容