Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot instantiate the type AppiumDriver

I have added following jars in my projects build path:

  1. java-client-2.0.0 from http://appium.io/downloads.html >> Appium Client libraries >> Java
  2. selenium-java-2.43.1
  3. selenium-java-2.43.1-srcs
  4. selenium-server-standalone-2.43.1
    and here's my code:

    public class SampleApp{
    
    WebDriver dr;
    
    @Test
    public void testApp() throws MalformedURLException, InterruptedException {
        String apkpath = "D:\\apkdump\\sampleapp.apk";
        File app = new File (apkpath);
        DesiredCapabilities capabilities= new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
        capabilities.setCapability("deviceName","TestADB18");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("app",app.getAbsolutePath());
        capabilities.setCapability("appPackage", "com.test");
        capabilities.setCapability("appActivity", "com.sampleapp.Main");
        dr = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
        dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    
    }
    
    
    }
    

    I am getting red line below new AppiumDriver which says that Cannot instantiate the type AppiumDriver. Now if remove all selenium jars the error disappears but then I can't resolve errors with webdriver.

    What is the conflict between jars?

    I saw similar question here but that could run the code and was getting Null pointer exception but in my case I cant even run it, it is giving run on saving the code. Secondly the answer has been posted without using AppiumDriver

like image 549
paul Avatar asked Nov 03 '14 13:11

paul


3 Answers

You don't need to downgrade or anything. There is a design change in the Java Client version 2.0.0 as they mention on their site:

AppiumDriver is now an abstract class, use IOSDriver and AndroidDriver which both extend it.

So, just change your driver line to be:

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

Hope that helps...

like image 58
Hassan Radi Avatar answered Nov 08 '22 18:11

Hassan Radi


This error can be fixed by downgrading the Appium Client(see step 1 in my question) from latest to java-client-1.5.0. You can keep rest of the jars to latest.

Downgraded version of Appium Client can be downloaded from here http://mvnrepository.com/artifact/io.appium/java-client/1.5.0

like image 21
paul Avatar answered Nov 08 '22 20:11

paul


WebDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),getDesiredCapabilities("192.21.168.56:5555"));

use this. and import:

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
like image 1
Satya Ram hari krishna swamy Avatar answered Nov 08 '22 20:11

Satya Ram hari krishna swamy