Appium [已解决][求助] 关于 IOS 的 swipe 操作无效及一些疑问

陈永达 · 2015年09月14日 · 最后由 fengcanfly 回复于 2016年07月01日 · 1814 次阅读

最近在做 IOS 的 appium 脚本的时候遇到了一些问题:
在操作 swipe 时,发现在 ios 上并没有移动。
看了一下 log:

info: [debug] Socket data received (93 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":17,"value":"duration value must be greater than or equal to 0.5 or less than 60"}
info: [debug] Responding to client with error: {"status":17,"value":{"message":"An error occurred while executing user supplied JavaScript.","origValue":"duration value must be greater than or equal to 0.5 or less than 60"},"sessionId":"6c99f732-dbd1-45f7-ac43-a567202c2d64"}
info: <-- POST /wd/hub/session/6c99f732-dbd1-45f7-ac43-a567202c2d64/touch/perform 500 262.950 ms 

意思是说 duration 参数单位应该是秒。
但是在代码里,看到的源码是:

/**
 * @see TouchShortcuts#swipe(int, int, int, int, int)
 */
@Override
public void swipe(int startx, int starty, int endx, int endy, int duration) {
    TouchAction touchAction = new TouchAction(this);

    // appium converts press-wait-moveto-release to a swipe action
    touchAction.press(startx, starty).waitAction(duration)
            .moveTo(endx, endy).release();

    touchAction.perform();
}

单位是毫秒。
我 server 版本是 1.4.8,client 版本是 3.1.0,ios 模拟的是 8.4 版本,为什么会有这样的差异,是我版本用的不匹配么?
ios 端 swipe 该如何处理?

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 10 条回复 时间 点赞

Try:

#python
diretion = up | down | left | right
1. driver.execute_script("mobile: scroll", [{"direction":direction}])
2. driver.execute_script("mobile: scroll", [{"direction":direction, element: element.id}])

Appium 在 iOS 端貌似已经弃用 swipe、flick

#1 楼 @anikikun
非常感谢,尝试了一下:

// java
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "DOWN");
js.executeScript("mobile: scroll", scrollObject);

果然可行,非常感谢

#2 楼 @cydtest 这个 swipe 无效是模拟器的问题。真机没有这个问题的。 mobile: scroll 就是针对这个问题的 work around。
详看:https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/touch-actions.md#bugs-and-workarounds

#3 楼 @chenhengjie123 原来是这样!!!

#3 楼 @chenhengjie123 为啥我的真机运行 wd.swipe() 还是会提示: An error occurred while executing user supplied JavaScript

ios 真机 9.2

#6 楼 @ubunhu 给 server log 才能分析。

另外,给下 appium 版本

#8 楼 @chenhengjie123 我查过资料了说当前界面或者 swipe 的坐标元素 visible 值 false 导致 swipe 或者 scroll 都无效,appium 版本 1.4.16

#8 楼 @chenhengjie123 iOS 真机上也是滑动无效,appium 版本 1.5.2

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册