WebDriverException:无法创建新会话,因为未找到需要HttpClient,InputStream和long的'createSession'

时间:2018-11-20 12:10:28

标签: java android selenium selenium-webdriver appium

我正在使用以下代码启动android驱动程序。但是启动驱动程序时出现错误。 在线:

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

完整代码:

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

}

错误:

  

失败:testappiumdriver       org.openqa.selenium.WebDriverException:无法创建新会话,因为使用HttpClient的“ createSession”   找不到InputStream和long或无法访问它       内部版本信息:版本:'3.13.0',版本:'2f0d292',时间:'2018-06-25T15:24:21.231Z'       系统信息:主机:'PSL-GGN-597',ip:'192.168.2.137',操作系统名称:'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version:   '1.8.0_91'       驱动程序信息:driver.version:AndroidDriver         在io.appium.java_client.remote.AppiumCommandExecutor $ 1.createSession(AppiumCommandExecutor.java:195)         在io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:209)         在io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)         在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)         在         io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)         在io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)         在io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)         在           org.openqa.selenium.remote.RemoteWebDriver.startSession         在org.openqa.selenium.remote.RemoteWebDriver中。          (RemoteWebDriver.java:130)         在io.appium.java_client.DefaultGenericMobileDriver处。          (DefaultGenericMobileDriver.java:38)         在io.appium.java_client.AppiumDriver。(AppiumDriver.java:84)         在io.appium.java_client.AppiumDriver。(AppiumDriver.java:94)         在io.appium.java_client.android.AndroidDriver。(AndroidDriver.java:93)         在test.Test.testappiumdriver(Test.java:37)

我在我的项目中使用了以下jars:

Selenium-java 3.13 硒服务器3.13 Java客户端6.1.0

我也尝试过使用不同版本的selenium和java-client,但是再次遇到相同的错误。

2 个答案:

答案 0 :(得分:0)

此错误消息...

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

...表示 AndroidDriver 无法启动/产生新会话。

您的主要问题是所使用的二进制版本之间的不兼容性

  • 您的 JDK版本 1.8.0_91 ,这是古老的

解决方案

  • JDK 升级到最新级别JDK 8u191
  • 进行系统重启
  • 执行您的@Test

答案 1 :(得分:0)

****解决方案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);

在下面的行中添加注释,然后运行即可

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

解决方案第二 或保持所需能力以上,但在此之前 在cmd promt上运行3 cmd

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