退回到直接的W3C远程终端连接和SessionNotCreatedException:无法创建新的远程会话

时间:2019-01-11 13:23:01

标签: appium appium-android

运行appium脚本时,它将引发异常:

Unable to create new remote session

即使我在appium设置中覆盖其会话。 我通过具有configuration.properties为脚本提供URL和其他参数。

Android Studio日志:

file path: 
C:\Users\ab.chauhan\AndroidStudioProjects\AppiumHJ\app\configs\Configuration.properties
Inside application handling constructor
C:\Users\ab.chauhan\AndroidStudioProjects\AppiumHJ\app\FrameworkReports\11_Jan_2019
file path: C:\Users\ab.chauhan\AndroidStudioProjects\AppiumHJ\app\configs\Configuration.properties
Inside application handling constructor
C:\Users\ab.chauhan\AndroidStudioProjects\AppiumHJ\app\FrameworkReports\11_Jan_2019Before Suite Execution started
Driver:null
URL:http://0.0.0.0:4723/wd/hub
cap: Capabilities [{appPackage=cfg.getAppPackage(), appActivity=cfg.getAppActivity(), noReset=true, newCommandTimeout=4000, platformVersion=7.0 NRD90M, automationName=uiautomator2, platformName=Android, deviceName=Xiaomi Redmi Note 4 Android 7.0, API 23}]
Jan 11, 2019 6:40:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Jan 11, 2019 6:40:35 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to original OSS JSON Wire Protocol.
Jan 11, 2019 6:40:36 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Falling back to straight W3C remote end connection
.
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{appPackage=cfg.getAppPackage(), appActivity=cfg.getAppActivity(), noReset=true, newCommandTimeout=4000, platformVersion=7.0 NRD90M, automationName=uiautomator2, platformName=Android, deviceName=Xiaomi Redmi Note 4 Android 7.0, API 23}], required capabilities = Capabilities [{}]
Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700'
System info: host: 'GSG1PM-FT0384', ip: '10.10.23.99', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_152-release'
Driver info: driver.version: AndroidDriver

Appium脚本:

DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Xiaomi Redmi Note 4 Android 7.0, API 23");
cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "4000");
cap.setCapability("noReset", true);
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.0 NRD90M");
cap.setCapability("automationName", cfg.getAutomationName());
cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,"cfg.getAppPackage()");
cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "cfg.getAppActivity()");
System.out.println("Before Suite Execution started");
System.out.println("Driver:"+driver);
System.out.println("URL:"+cfg.getApplicationUrl());
System.out.println("cap: "+cap);
try{
driver = new AndroidDriver<MobileElement>(new URL(cfg.getApplicationUrl()), cap);
System.out.println(driver);}
catch(MalformedURLException e){
    e.printStackTrace();}
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

2 个答案:

答案 0 :(得分:1)

问题的答案在于您设置的功能。

您需要根据自己的能力修改这些行,

cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,"cfg.getAppPackage()");
cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "cfg.getAppActivity()");

收件人

cap.setCapability (AndroidMobileCapabilityType.APP_PACKAGE, cfg.getAppPackage());
cap.setCapability (AndroidMobileCapabilityType.APP_ACTIVITY, cfg.getAppActivity());

实际上,您在引号内调用了方法,不应这样做。像在URLAutomationName中一样直接调用它。

答案 1 :(得分:0)

此错误消息...

Jan 11, 2019 6:40:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession 
 INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end 
Jan 11, 2019 6:40:35 PM org.openqa.selenium.remote.ProtocolHandshake createSession 
 INFO: Falling back to original OSS JSON Wire Protocol. 
Jan 11, 2019 6:40:36 PM org.openqa.selenium.remote.ProtocolHandshake createSession 
 INFO: Falling back to straight W3C remote end connection
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session.

org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。

...表示 AndroidDriver 无法启动/产生新的 Remote Session

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

  • 您使用的是很古老的 java.version 1.8.0_152-release

解决方案

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