appium1.8版本在android应用上实现滑屏swipe

appium1.8版本在android应用上实现滑屏swipe

step1

  1. 上网找使用方法。
    网上提供的方法大多如下:

获得机器屏幕大小x,y

def getSize(self):
    x = self.driver.get_window_size()['width']
    y = self.driver.get_window_size()['height']
    return (x, y)

# 屏幕向上滑动
def swipeUp(self, t = 5000):
    l = self.getSize()
    x1 = int(l[0] * 0.5)  # x坐标
    y1 = int(l[1] * 0.75)  # 起始y坐标
    y2 = int(l[1] * 0.25)  # 终点y坐标
    self.driver.swipe(x1, y1, x1, y2, t)
    #self.driver.swipe(x1, y1, x1, y2)

does not work!!!

  1. 看报错日志。
    python 调用端报错为:
    File “/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py”, line 242, in check_response
    raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: The swipe did not complete successfully

appium server端报错为:
[debug] [AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“swipe”,“params”:{“startX”:720,“startY”:1920,“endX”:720,“endY”:640,“steps”:11}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“swipe”,“params”:{“startX”:720,“startY”:1920,“endX”:720,“endY”:640,“steps”:11}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: swipe
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1440,2560]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Display bounds: [0,0][1440,2560]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Swiping from [x=720.0, y=1920.0] to [x=720.0, y=640.0] with steps: 11
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:13,“value”:“The swipe did not complete successfully”}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Matched JSONWP error code 13 to UnknownError

  1. 网上找到新的使用方法。
    https://testerhome.com/topics/1550
    native mobile command的使用方法
    self.driver.swipe(75,500,75,0,500)

python端报错不允许使用mobile方法
最后通过appium重启添加参数–relaxed-security

==> 再报错

找到appium的文档里关于native mobile command的文档
http://appium.io/docs/en/commands/mobile-command/#android-uiautomator2-only
发现里面对于android并没有使用modile:swipe,这个是ios使用的。android的只有modile:shell。

=> 尝试使用adb 命令来实现滑屏
self.driver.execute_script(“mobile:shell”, int(self.x / 2), int(self.y / 2), int(self.x / 2), int(self.y / 4), duration)

==> 再报错 Error: The ‘command’ argument is mandatory’
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/android-shell.md
官方使用文档。
最后修改成
def swipe_up_half(self, count=1, duration=500):
for i in range(count):
self.driver.execute_script(self.cmdMobileShell, {
‘command’: ‘input’,
‘args’: [‘swipe’, int(self.x / 2), int(self.y * 3/ 4), int(self.x / 2), int(self.y / 4), duration],
‘includeStderr’: True,
‘timeout’: 5000
})

It work!!!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值