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

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

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或者是将来更高级版本

<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>2.0.0</version>
<del><version>1.7.0</version></del>
</dependency>
2.问题分析
究其原因,发现Appium2.0.0把AppiumDriver这个类改成了抽象函数,所以到导致了这个问题
public <span style="color:#ff0000;">abstract </span>class AppiumDriver extends RemoteWebDriver implements MobileDriver,
ContextAware, Rotatable, FindsByAccessibilityId, LocationContext,
DeviceActionShortcuts, TouchShortcuts, InteractsWithFiles,
InteractsWithApps, ScrollsTo {

private final static ErrorHandler errorHandler = new ErrorHandler(
new ErrorCodesMobile(), true);
private URL remoteAddress;
private RemoteLocationContext locationContext;
private ExecuteMethod executeMethod;

// frequently used command parameters
protected final String KEY_CODE = "keycode";
protected final String PATH = "path";
private final String SETTINGS = "settings";
根据2.0.0的Changelog的第一点:
Changelog

2.0.0

<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>
</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。
public class NoetPadTest {
/**
* Create the test case
*
* @param testName name of the test case
*/
private <span style="color:#ff0000;">AndroidDriver </span>driver;

@Before
public void setUp() throws Exception {
// set up appium
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "apps");
File app = new File(appDir, "NotePad.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","Android");
//capabilities.setCapability("platformVersion", "4.2");
capabilities.setCapability("platformName", "Android");
//capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.example.android.notepad");
capabilities.setCapability("appActivity", "com.example.android.notepad.NotesList");
//capabilities.setCapability("appActivity", ".NotesList");
driver = new <span style="color:#ff0000;">AndroidDriver</span>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@After
public void tearDown() throws Exception {
driver.quit();
}

---------------------

原文:https://blog.csdn.net/zhubaitian/article/details/39717889

问题一:使用AndroidDriver而非原来的AppiumDriver的原因的更多相关文章

  1. Android 非静态内部类导致内存泄漏原因深入剖析

    背景 上周发现蘑菇街IM-Android代码里面.一些地方代码编写不当.存在内存泄漏的问题.在和疯紫交流的过程中.发现加深了一些理解,所以决定写一下分析思路,相互学习. 内存泄漏 一个不会被使用的对象 ...

  2. Mware vCenter Server 识别固态硬盘为(非SSD)是什么原因?

    人工定义一下: 用root登录进ESXi控制台:esxcli storage nmp device list #列出储存清单esxcli storage nmp satp rule add -s VM ...

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

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

  4. Cannot instantiate the type AppiumDriver,AppiumDriver升级引发的问题

    转自:http://blog.csdn.net/zhubaitian/article/details/39717889 1. 问题描述和起因 在使用Appium1.7.0及其以下版本的时候,我们可以直 ...

  5. MIFARE系列2《非接触卡标准》

    根据信号发送和接收方式的不同,ISO/IEC14443-3定义了TYPEA.TYPEB两种卡型.它们的不同主要在于载波的调制深度及二进制数的编码方式.从读写机具向卡传送信号时,二者是通过13.56Mh ...

  6. JAVA可检测异常和非检测异常

    Java的可检测异常和非检测异常泾渭分明.可检测异常经编译器验证,对于声明抛出异常的任何方法,编译器将强制执行处理或声明规则. 非检测异常不遵循处理或声明规则.在产生此类异常时,不一定非要采取任何适当 ...

  7. C# static 字段初始值设定项无法引用非静态字段、方法或属性

    问题:字段或属性的问题字段初始值设定项无法引用非静态字段.方法 下面代码出错的原因,在类中定义的字段为什么不能用? public string text = test(); //提示 字段或属性的问题 ...

  8. 检索05 --static静态方法 和 非静态方法

    C#静态变量使用static 修饰符进行声明,在类被实例化时创建,通过类进行访问不带有 static 修饰符声明的变量称做非静态变量,在对象被实例化时创建,通过对象进行访问一个类的所有实例的同一C#静 ...

  9. 【Azure 环境】存储在Azure上的文件,使用IE/Edge时自动打开的问题,如何变为下载而非自动打开

    问题描述 存储,作为云服务最重要的一部分.当需要从云存储中下载文件时,时常面临一些格式的文件被浏览器自动打开而非下载,那如何来解决这个问题呢? 在Azure中,存储的服务有以下方式: Azure Bl ...

随机推荐

  1. mybatis框架-查询用户表中的记录数

    之前已经搭建过mybatis框架了,现在我们要用mybatis框架真正的干点事情了. 这是这个简单web项目的整体架构. 我们使用mybatis框架查询用户表中的记录数: 这是用户类: package ...

  2. UVa10828 Back to Kernighan-Ritchie——概率转移&&高斯消元法

    题意 给出一个程序控制流图,从每个结点出发到每个后继接结点的概率均相等.当执行完一个没有后继的结点后,整个程序终止.程序总是从编号为1的结点开始.你的任务是对于若干个查询结点,求出每个结点的期望执行次 ...

  3. LeetCode 818. Race Car

    原题链接在这里:https://leetcode.com/problems/race-car/ 题目: Your car starts at position 0 and speed +1 on an ...

  4. prisma mongodb 试用

    prisma 已经支持mongodb了,我们需要做的就是安装新版本的prisma cli,后然初始化项目使用 环境准备 安装cli 注意使用新版本(prisma/1.32.2) 低版本有坑 npm i ...

  5. async、await总结

    一.async用法 async作为一个关键字放到函数前面,用于表示函数是一个异步函数.异步函数也就意味着该函数的执行不会阻塞后面代码的执行. 异步函数语法很简单,就是在函数前面加上async 关键字, ...

  6. render函数、createElement函数与vm.$slots

    1.render函数.createElement函数 Vue.component('es-header', { render: function (createElement) { return cr ...

  7. mysql 选择所有同学名字

    mysql> select * from test; +----+----------+-------+-----------+ | id | name | score | subject | ...

  8. C语言函数内局部变量释放的坑

    首先把代码贴上来: #include <stdio.h> #include<windows.h> int f(int **iptr){ ; *iptr = &a; ; ...

  9. 新版本Mariadb安装后相关问题的解决

    给新机器Ubuntu安装的Mariadb后无法登录,通过网上各种方法修改root用户密码,仍然无法解决,耗费几个小时! 经过看日志和查手册,发现原因如下: ubuntu确实安装没有启用root用户,所 ...

  10. Kubernetes kubectl 命令概述

    kubectl用于运行Kubernetes集群命令的管理工具. 语法 kubectl [command] [TYPE] [NAME] [flags] command:指定要在一个或多个资源执行的操作 ...