0
votes

I am using below code to launch android driver. But I am getting error at the time of launching the driver. On line:

driver = new AndroidDriver<WebElement>(new URL(appiumServiceUrl), capabilities);

Complete Code:

public class Test {

protected static AppiumDriver<WebElement> driver;
private AppiumDriverLocalService appiumService;
private String appiumServiceUrl;
Properties prop = new Properties();

@org.testng.annotations.Test
public void testappiumdriver() throws FileNotFoundException, IOException
{
    appiumService = AppiumDriverLocalService.buildDefaultService();
    appiumService.start();
    appiumServiceUrl = appiumService.getUrl().toString();
    prop.load(new FileInputStream("device_capabilities.properties"));
    Map<String, String> prop_map = new HashMap<String, String>();
    for (String key : prop.stringPropertyNames()) {
        prop_map.put(key, prop.getProperty(key));
    }           
    DesiredCapabilities capabilities = new DesiredCapabilities(prop_map);
    driver = new AndroidDriver<WebElement>(new URL(appiumServiceUrl), capabilities);
}

}

Error:

FAILED: testappiumdriver org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z' System info: host: 'PSL-GGN-597', ip: '192.168.2.137', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91' Driver info: driver.version: AndroidDriver at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:195) at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:209) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession at org.openqa.selenium.remote.RemoteWebDriver. (RemoteWebDriver.java:130) at io.appium.java_client.DefaultGenericMobileDriver. (DefaultGenericMobileDriver.java:38) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:84) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:94) at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:93) at test.Test.testappiumdriver(Test.java:37)

I am using below jars in my project:

selenium-java 3.13 selenium-server 3.13 java-client 6.1.0

I have also tried with different version of selenium and java-client but again getting same error.

2
please post the log few lines before the error occur.Suban Dhyako

2 Answers

1
votes

****Solution 1st****

 DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("deviceName", "xyz");
    capabilities.setCapability("platformVersion", "6.0");
    capabilities.setCapability("platformName", Platform.ANDROID);
    capabilities.setCapability("appPackage", "com.hp.HPSupportAssistant");
    capabilities.setCapability("appActivity", "com.hp.HPSupportAssistant.MainActivity");
     capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 6000);    capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS,true);
    //desiredCap.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);

Here comment below line and then run it will work

desiredCap.setCapability(MobileCapabilityType.AUTOMATION_NAME,AutomationName.ANDROID_UIAUTOMATOR2);

solution 2nd Or keep above line in desired capabilities but before that do run 3 cmd on cmd promt

adb shell pm list packages -f > D://t.txt
adb uninstall io.appium.uiautomator2.server
adb uninstall io.appium.uiautomator2.server.test

desiredCap.setCapability(MobileCapabilityType.AUTOMATION_NAME,AutomationName.ANDROID_UIAUTOMATOR2);
0
votes

This error message...

org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible 
 Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z' 
 System info: host: 'PSL-GGN-597', ip: '192.168.2.137', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91' 
 Driver info: driver.version: AndroidDriver

...implies that the AndroidDriver was unable to initiate/spawn a new session.

Your main issue is the incompatibility between the version of the binaries you are using as follows:

  • Your JDK version is 1.8.0_91 which is pretty ancient.

Solution

  • Upgrade JDK to recent levels JDK 8u191.
  • Take a System Reboot.
  • Execute your @Test.