1. Problem description and cause
When using Appium1.7.0 and the following versions, we can create an Appiumdriver instance for the operation of an Android device directly using the following code.
Driver = new Androiddriver (New URL ("Http://127.0.0.1:4723/wd/hub"), capabilities);
However, when upgrading the Appium package to the current 2.0.0 version, this code will cause the following problem
The current pom.xml settings are as follows: Remember to change the 1.7.0 to 2.0.0 or the future. Advanced version
<dependency> <groupId>io.appium</groupId> <artifactid>java-client</ artifactid> <version>2.0.0</version> <del><version>1.7.0</version> </del></dependency>
2. Problem analysis The reason, found that Appium2.0.0 appiumdriver this class into an abstract function, so to cause the problem
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 (), t Rue);p rivate URL remoteaddress;private remotelocationcontext locationcontext;private executemethod executeMethod;// Frequently used command parametersprotected final string key_code = "KeyCode";p rotected final string path = "path";p rivate Final String SETTINGS = "SETTINGS";
According to the 1th of 2.0.0 's changelog:
Changelog2.0.0<ul><li><span style= "font-family:arial, Helvetica, Sans-serif;" >appiumdriver is now a abstract class, use Iosdriver and androiddriver which both extend it. You are 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 now becomes an abstract class, using the Iosdriver and Androiddriver inherited from it. You no longer need to add platform_name to this capability, because the code will determine which platform is based on what you are using Iosdriver or 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 () is 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. Problem solving based on the analysis of the problem, modify the code as follows, using Androiddriver instead of the original appiumdriver.
public class Noetpadtest {/** * Create the test case * * @param testname name of the the test case */priva Te <span style= "color: #ff0000;" >androiddriver </span>driver; @Before public void SetUp () throws Exception {//Set up Appium file Classpathroot = new file (system.getp Roperty ("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 (); }
Appiumdriver upgrade to 2.0. version 0 issues raised--cannot instantiate the type Appiumdriver