转自:http://blog.csdn.net/zhubaitian/article/details/39717889

1. 问题描述和起因

在使用Appium1.7.0及其以下版本的时候,我们可以直接使用如下代码来创建一个AppiumDriver实例进行对安卓设备的操作。

  1. driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

但在把Appium包升级到当前最新的2.0.0版本的时候,这段代码会引发如下的一问题


当前的pom.xml相关设置如下:记得把1.7.0改成2.0.0或者是将来更高级版本

  1. <dependency>
  2. <groupId>io.appium</groupId>
  3. <artifactId>java-client</artifactId>
  4. <version>2.0.0</version>
  5. <del><version>1.7.0</version></del>
  6. </dependency>

2.问题分析

究其原因,发现Appium2.0.0把AppiumDriver这个类改成了抽象函数,所以到导致了这个问题

  1. public <span style="color:#ff0000;">abstract </span>class AppiumDriver extends RemoteWebDriver implements MobileDriver,
  2. ContextAware, Rotatable, FindsByAccessibilityId, LocationContext,
  3. DeviceActionShortcuts, TouchShortcuts, InteractsWithFiles,
  4. InteractsWithApps, ScrollsTo {
  5. private final static ErrorHandler errorHandler = new ErrorHandler(
  6. new ErrorCodesMobile(), true);
  7. private URL remoteAddress;
  8. private RemoteLocationContext locationContext;
  9. private ExecuteMethod executeMethod;
  10. // frequently used command parameters
  11. protected final String KEY_CODE = "keycode";
  12. protected final String PATH = "path";
  13. private final String SETTINGS = "settings";

根据2.0.0的Changelog的第一点:

  1. Changelog
  2. 2.0.0
  3. <ul><li><span style="font-family: Arial, Helvetica, sans-serif;">AppiumDriver is now an abstract class, use IOSDriver and AndroidDriver which both extend it. You no longer need to include the PLATFORM_NAME desired capability since it's automatic for each class. Thanks to @TikhomirovSergey for all their work</span></li></ul><span style="font-family:Arial, Helvetica, sans-serif;"><span style="white-space:pre">     </span><span style="color:#3366ff;">AppiumDriver现在变成了一个抽象类,请使用从它继承下来的IOSDriver和AndroidDriver。你不再需要加上PLATFORM_NAME这个capability,因为代码会根据你使用的是IOSDriver或者AndroidDriver来确定究竟是哪个平台。</span>
  4. </span><ul><li><span style="font-family: Arial, Helvetica, sans-serif;">ScrollTo() and ScrollToExact() methods reimplemented</span></li><li><span style="font-family: Arial, Helvetica, sans-serif;">Zoom() and Pinch() are now a little smarter and less likely to fail if you element is near the edge of the screen. Congratulate @BJap on their first PR!</span></li></ul>

3.问题解决

根据问题分析,把代码修改如下,使用AndroidDriver而非原来的AppiumDriver。
  1. public class NoetPadTest {
  2. /**
  3. * Create the test case
  4. *
  5. * @param testName name of the test case
  6. */
  7. private <span style="color:#ff0000;">AndroidDriver </span>driver;
  8. @Before
  9. public void setUp() throws Exception {
  10. // set up appium
  11. File classpathRoot = new File(System.getProperty("user.dir"));
  12. File appDir = new File(classpathRoot, "apps");
  13. File app = new File(appDir, "NotePad.apk");
  14. DesiredCapabilities capabilities = new DesiredCapabilities();
  15. capabilities.setCapability("deviceName","Android");
  16. //capabilities.setCapability("platformVersion", "4.2");
  17. capabilities.setCapability("platformName", "Android");
  18. //capabilities.setCapability("app", app.getAbsolutePath());
  19. capabilities.setCapability("appPackage", "com.example.android.notepad");
  20. capabilities.setCapability("appActivity", "com.example.android.notepad.NotesList");
  21. //capabilities.setCapability("appActivity", ".NotesList");
  22. driver = new <span style="color:#ff0000;">AndroidDriver</span>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
  23. }
  24. @After
  25. public void tearDown() throws Exception {
  26. driver.quit();
  27. }

Cannot instantiate the type AppiumDriver,AppiumDriver升级引发的问题的更多相关文章

  1. Cannot instantiate the type HttpClient问题

    看自己动手写爬虫,没想到一上来就跪了. 里面提到用的jar包是apache的http客户端开源项目---HttpClient 就去官网下载了一个版本4.3 当按书上代码敲时 HttpClient ht ...

  2. Cannot instantiate the type List&lt;Integer&gt;

    在使用java.util.List; 的时候,把语句写成了: List<Integer> arr = new List<Integer>(); 导致错误: Cannot ins ...

  3. Cannot instantiate the type Map

    今天在使用Map中犯了个低级错误,记录一下: 打算使用map为一个视频List观看记录的统计标识,key为vid,value默认为false,当该key已经统计,标识value为true,初始实例化M ...

  4. AppiumDriver升级到2.0.0版本引发的问题--Cannot instantiate the type AppiumDriver

    1. 问题描述和起因 在使用Appium1.7.0及其以下版本的时候,我们可以直接使用如下代码来创建一个AppiumDriver实例进行对安卓设备的操作. driver = new AndroidDr ...

  5. Cannot instantiate the type AppiumDriver

    I have added following jars in my projects build path: java-client-2.0.0 from http://appium.io/downl ...

  6. SQLSERVER 2012之AlwaysOn -- 一次硬件升级引发的问题

    这是上周遇到的一个案例:对已有的硬件进行升级而引发的问题,期间还触发了一个比较严重的BUG,可谓多灾多难:不过值得庆幸的是,在一连串连锁问题出现的时候,并没有出现人工操作失误(这往往是在处理故障中风险 ...

  7. input的type等于mage标签引发的页面提交!

    主要原因是使用了<input type="image",而且放在了<form中. <input type="image"标签类似<inp ...

  8. 工作学习2-gcc升级引发的崩溃

    分享一下调查gcc 8.0下,函数漏写返回值崩溃问题,调查记录. 现在新的硬件,基本操作系统都是redhat 8.0,升级后测试时,发现了一个崩溃问题,记录一下. ================== ...

  9. 定制化JDK升级引发的离奇事件

    1.背景 由于Oracle对外宣称Oracle JDK停止免费用于商用.公司法务部门评估之后担心后续会惹上光司,于是就开始了JDK升级-将所有服务Oracle修改为OpenJDK.上周开始微服务JDK ...

随机推荐

  1. Matplotlib基本图形之直方图

    Matplotlib基本图形之直方图 直方图特点 由一系列高度不等的纵向条形组成,表示数据分布情况例如年级同学身高分布注意与条形图的区别 示例代码: import osimport numpy as ...

  2. 学习笔记6——插件 API,“过滤器”(Filters)和“动作”(Actions)

    WordPress 中有一种叫执行挂勾的机制,允许插件把一些功能“挂载”到 WordPress 当中.也就是说,在系统运行至某一个环节时,去调用插件内的一些函数.执行挂勾分为两种: 动作 (Actio ...

  3. 论文《Piexel Recurrent Nerual Network》总结

    论文<Piexel Recurrent Nerual Network>总结 论文:<Pixel Recurrent Nerual Network> 时间:2016 作者:Aar ...

  4. [uiautomator篇] 基类

      package com.softwinner.performance.benchmark; /** * UiAssistant public class * @author liuzhipeng ...

  5. POJ 2092 Grandpa is Famous

    Grandpa is Famous Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 7153   Accepted: 3624 ...

  6. 算法复习——2—sat(bzoj2199)

    题目: Description 由于对Farmer John的领导感到极其不悦,奶牛们退出了农场,组建了奶牛议会.议会以“每头牛 都可以获得自己想要的”为原则,建立了下面的投票系统: M只到场的奶牛 ...

  7. bzoj2144 跳跳棋 二分

    [bzoj2144]跳跳棋 Description 跳跳棋是在一条数轴上进行的.棋子只能摆在整点上.每个点不能摆超过一个棋子.我们用跳跳棋来做一个简单的游戏:棋盘上有3颗棋子,分别在a,b,c这三个位 ...

  8. spring aop在mvc的controller中加入切面无效

    spring aop在mvc的controller中加入切面无效 因为MVC的controller,aop默认使用jdk代理.要使用cglib代理. 在spring-mybatis.xml配置文件中加 ...

  9. ObjectDataSource配合存储过程(采用数据集)的使用(删除可以解决,但是编辑出错好像它的方法也无法解决

    原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] ObjectDataSource是比较有意思的一个东西 通过在网络上遍访各位高手,终于自己有了一些心得体会。现总结 ...

  10. WAMP本地环境升级php版本

    !!!本次测试未完全成功,仅供提供经验. (1)下载php最新版本 http://windows.php.net/download/ (2)解压放到wamp/bin/php目录下 (3) 从已存在的p ...