Appium - Unable to instantiate AndroidDriver

10,568

Solution 1

Try replacing:

driver = new AndroidDriver(new URL("127.0.0.1:4723"), cap);

With:

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

Solution 2

It is giving an error: AndroidDriver is Raw type. You can initialize driver as below:

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
...
public class Testing()
{
  public  AppiumDriver driver;
  ...
  @BeforeTest
  public void testMethod()
   {
     driver = new AndroidDriver(new URL(Node), capabilities);
     ...
   }
}

Solution 3

I also met this problem before, but I now have solved, and the reasons for this problem is because Java - client-(version number). jar is not compatible,So I will Java - client-(version number). jar replacement into Java - the client - 3.1.0. Jar.Hope to be able to help you!

Share:
10,568
Santosh Kumar
Author by

Santosh Kumar

Updated on June 07, 2022

Comments

  • Santosh Kumar
    Santosh Kumar almost 2 years

    When I am trying to instantiate AndroidDriver class it is giving an error. Please help.

    Code

    import io.appium.java_client.android.AndroidDriver;
    
    public class Testing {
        @Test
        public void testMethod() {
            AndroidDriver driver;
            DesiredCapabilities cap = new DesiredCapabilities();
            cap.setCapability("deviceName", "samsung-sm_g530h-5554c610");
            cap.setCapability("platformVersion", "4.4.4");
            cap.setCapability("platformName", "Android");
            cap.setCapability(CapabilityType.BROWSER_NAME, "");
            cap.setCapability("appPackage", "com.whatsapp");
            cap.setCapability("appActivity", "com.whatsapp.HomeActivity");
            driver = new AndroidDriver(new URL("127.0.0.1:4723"), cap);
        }
    }
    

    // Here is the error enter image description here