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();     }


 

作者

自主博客

微信

CSDN

天地会珠海分舵

http://techgogogo.com


服务号:TechGoGoGo

扫描码:

var kevent = 'onabort|onblur|onchange|onclick|ondblclick|onerror|onfocus|onkeydown|onkeypress|onkeyup|onload|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onreset|onresize|onselect|onsubmit|onunload'; var aevent = kevent.split('|'); jQuery('.showContent img').each(function(){ var nimg = this; jQuery.each(aevent, function(i, n){ if (n!='onload') { jQuery(nimg).attr(n, ''); } else { if (jQuery(nimg).attr(n) != 'if(this.width>650) this.width=650;') { jQuery(nimg).attr(n, ''); } } }); });

分享至
一键收藏,随时查看,分享好友!
0人
了这篇文章
类别:未分类┆阅读( 0)┆评论( 0) ┆ 返回博主首页┆ 返回博客首页
上一篇 为网上流行论点“UIAutomator不能通过中文文本.. 下一篇 MonkeyRunner创建一个Note的实例

相关文章

  • mysql5.1.37升级到5.5.3遇到的问题
  • 金蝶k3使用中经常出现的问题
  • [content-description] find_element_by_acc..
  • adt升级后出错

职位推荐

  • 安卓工程师
  • ios工程师
  • android高级开发
  • Android架构师
  • IOS工程师

文章评论

 
 

发表评论            

昵  称:
登录  快速注册
验证码:

点击图片可刷新验证码请点击后输入验证码博客过2级,无需填写验证码

内  容:

同时赞一个

每日博报 精彩不止一点关闭

你可能感兴趣的:(问题,升级,appium)