概述
在最初使用Appium1.0.0.3版本的时候,中间在写测试代码的时候,需要用到swipe方法来处理屏幕的滑动效果,代码如下:
try {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> swipeObject = new HashMap<String, Double>();
swipeObject.put("startX", 0.95);
swipeObject.put("startY", 0.5);
swipeObject.put("endX", 0.05);
swipeObject.put("endY", 0.5);
swipeObject.put("duration", 2000);
for(int i=1;i<=touchCount;i++)
{ System.out.println("开始第"+i+"次滑动!");
driver.executeScript("mobile:swipe", swipeObject);
waitPage(5);
}
} catch (WebDriverException ex) {
System.out.println("执行滑动操作异常...");
ex.printStackTrace();
}
好了,问题来了,问题如下:
info: [debug] Appium session started with sessionId 766660cc-2416-4f93-8a34-98c92b6fac6b
info: <-- POST /wd/hub/session 303 31669.348 ms - 9
info: --> GET /wd/hub/session/766660cc-2416-4f93-8a34-98c92b6fac6b {}
info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"","platformVersion":"4.4","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"D:workspaceappdemoappsMobileTest.apk","platformVersion":"4.4","deviceName":"Android Emulator","platformName":"Android","browserName":""},"app":"D:workspaceappdemoappsMobileTest.apk","deviceName":"Android Emulator","platformName":"Android"},"sessionId":"766660cc-2416-4f93-8a34-98c92b6fac6b"}
info: <-- GET /wd/hub/session/766660cc-2416-4f93-8a34-98c92b6fac6b 200 1.297 ms - 585 {"status":0,"value":{"platform":"LINUX","browserName":"","platformVersion":"4.4","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"D:workspaceappdemoappsMobileTest.apk","platformVersion":"4.4","deviceName":"Android Emulator","platformName":"Android","browserName":""},"app":"D:workspaceappdemoappsMobileTest.apk","deviceName":"Android Emulator","platformName":"Android"},"sessionId":"766660cc-2416-4f93-8a34-98c92b6fac6b"}
info: --> POST /wd/hub/session/766660cc-2416-4f93-8a34-98c92b6fac6b/execute {"script":"mobile: swipe","args":[{"startX":10,"duration":1,"startY":5,"endX":3,"endY":5}]}
info: [debug] Tried to execute non-existent mobile command 'swipe'. Most mobile commands have been ported to official client library methods. Please check your Appium library for more information and documentation。
以下记录的是分析解决的办法和步骤:
1、首先是百度搜索,结果无果;
2、既然是有异常抛出,肯定是代码中抛出来的啊,于是转向去Appium官网去查看(https://github.com/appium/appium),该地方有源码
此时便可以查找到错误信息。错误信息所在的位置,如图:
此时去看我的源码(位置:C:Appiumnode_modulesappiumlibservercontroller.js)
错误代码在964行:
此时可以继续分析了,我传入的cmd明显就是"swipe",此时在代码中搜索“mobileCmdMap”,搜索到的结果如下:
此时便发现了问题,原因是在“mobileCmdMap”中没有swipe。
但是到Appium1.2.4.1中发现却是有此方法的(但是到了Appium的1.3.4.1的版本又没有swipe方法):
所以最终总结在写测试代码中,对于滑动的操作还是建议使用“mobile: flick”,而不建议使用“mobile: swipe”.
版权声明:本文为博主原创文章,未经博主允许不得转载。
最后
以上就是曾经胡萝卜为你收集整理的记录一下Appium中使用swipe方法时候出现的问题(Appium1.0.0.3版本)的全部内容,希望文章能够帮你解决记录一下Appium中使用swipe方法时候出现的问题(Appium1.0.0.3版本)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复