UI自动化测试经验分享之TouchActions类、TouchAction类的联系、方法

其实很早之前就做了部分分享,关于这两个类,但是一直搞不清楚有啥区别和联系。
之前分享的TouchActions类 flick_element()

个人博客:https://blog.csdn.net/zyooooxie

(一)TouchActions类、TouchAction类的联系

在查看Appium的TouchAction类的源码时候,看到一些注释:

# The Selenium team implemented a version of the Touch Action API in their code
# (https://code.google.com/p/selenium/source/browse/py/selenium/webdriver/common/touch_actions.py)
# but it is deficient in many ways, and does not work in such a way as to be
# amenable to Appium's use of iOS UIAutomation and Android UIAutomator
# So it is reimplemented here.
#
# Theirs is `TouchActions`. Appium's is `TouchAction`.

翻译下,就是说 :
Selenium团队在其代码中实现了Touch Action API的一个版本,但它在很多方面都存在缺陷,并不能以这样的方式适合Appium的iOS UIAutomation和Android UIAutomator使用,所以这里重新实现了。
故Selenium的是TouchActions,而Appium的是TouchAction。

(二)TouchAction类的方法

实际App自动化测试常用的

方法:tap(element=None, x=None, y=None, count=1) 对一个元素或控件执行点击操作
Perform a tap action on the element

count=1 实际修改未起作用

    def test_2(self):
        self.driver.implicitly_wait(5)

        time.sleep(2)
        e1 = self.driver.find_element_by_accessibility_id('抽屉菜单')
        TouchAction(self.driver).tap(x=920, y=950).release().perform()  # 坐标
        TouchAction(self.driver).tap(element=e1).release().perform()       # 查找de元素
        # TouchAction(self.driver).tap(element=e1, x=600, y=550).release().perform()    # 查找到元素,预想失败

        time.sleep(2)

方法:press(el=None, x=None, y=None) 按压某元素或坐标点
Begin a chain with a press down action at a particular element or point

方法:long_press(el=None, x=None, y=None, duration=1000) 长按某元素或坐标点1000毫秒
Begin a chain with a press down that lasts duration milliseconds

方法:move_to(el=None, x=None, y=None) 将指针从上一个点移动到指定的元素或点
Move the pointer from the previous point to the element or point specified 将指针(光标)从过去 指向指定的元素或点

方法:wait(ms=0) 等待0毫秒
Pause for ms milliseconds

release() perform()

(三)TouchActions类的方法

可以作为补充

方法:tap(on_element) 点击给定元素
Taps on a given element 单击

方法:double_tap(on_element) 双击特定元素
Double taps on a given element 双击

方法:tap_and_hold(xcoord, ycoord)
Touch down at given coordinates 在给定坐标处按住

方法:move(xcoord, ycoord) 在屏幕上执行手势“移动”
Move held tap to specified location 将保持点击移动到指定位置

方法:scroll(xoffset, yoffset) 滚动到某个位置(按x和y偏移滚动)
Touch and scroll, moving by xoffset and yoffset
触摸并滚动,按xoffset和yoffset移动

方法:scroll_from_element(on_element, xoffset, yoffset) 从某元素开始滚动到某个位置
Touch and scroll starting at on_element, moving by xoffset and yoffset
从on_element开始触摸并滚动,按xoffset和yoffset移动

方法:long_press(on_element)
Long press on an element 长按一个元素

方法:flick(xspeed, yspeed)
Flicks, starting anywhere on the screen 轻弹,从屏幕上的任何位置开始

方法:flick_element(on_element, xoffset, yoffset, speed) 从某元素开始以指定的速度移动(执行轻弹手势)
Flick starting at on_element, and moving by the xoffset and yoffset with specified speed
从on_element开始轻弹,然后按xoffset和yoffset移动以指定的速度

release() perform()

交流技术 欢迎+QQ 153132336 zy
个人博客 https://blog.csdn.net/zyooooxie

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值