当我使用 remotewebdriver 实例化时,我完美地得到了返回的对象。
但是,如果我使用 AndroidDriver 而不是 remotewebdriver,那么我会收到以下错误。请帮忙。
2018-09-27 12:17:09.712:WARN:osjs.HttpChannel:qtp817406040-14: /wd/hub/session java.io.IOException: org.openqa.grid.common.exception.GridException: Cannot extract a capabilities from the request: {
"desiredCapabilities": {
"appPackage": "com.xxxxxxx.ymca",
"clearSystemFiles": "true",
"noReset": "true",
"noSign": true,
"deviceName": "Altitude",
"fullReset": "false",
"version": "",
"platform": "ANDROID",
"appWaitDuration": 60,
"appActivity": "com.ytlcomms.ymca.activities.LoginActivity",
"newCommandTimeout": 60,
"automationName": "UiAutomator2",
"autoGrantPermissions": true,
"browserName": "android",
"platformName": "Android"
},
"capabilities": {
"alwaysMatch": {
"appium:appActivity": "com.ytlcomms.ymca.activities.LoginActivity",
"appium:appPackage": "com.xxxxxxxx.ymca",
"appium:appWaitDuration": 60,
"appium:autoGrantPermissions": true,
"appium:automationName": "UiAutomator2",
"browserName": "android",
"appium:clearSystemFiles": "true",
"appium:deviceName": "Altitude",
"appium:fullReset": "false",
"appium:newCommandTimeout": 60,
"appium:noReset": "true",
"appium:noSign": true,
"platform": "ANDROID",
"platformName": "android",
"version": ""
},
"firstMatch": [
{
}
]
}
}
这就是堆栈跟踪所告诉的内容:
Caused by: java.lang.IllegalArgumentException: Illegal key values seen in w3c capabilities: [platform, version]
我正在使用下面的代码实例化。
RemoteWebDriver getDriver(String appName, String appPackage, String appActivity) {
DesiredCapabilities androidDcap = DesiredCapabilities.android();
if (appName.equalsIgnoreCase("YMCA"))
androidDcap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
androidDcap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
androidDcap.setCapability(MobileCapabilityType.BROWSER_NAME, "");
androidDcap.setCapability(MobileCapabilityType.DEVICE_NAME, "Altitude");
androidDcap.setCapability(MobileCapabilityType.CLEAR_SYSTEM_FILES, true);
androidDcap.setCapability("autoGrantPermissions", "true");
androidDcap.setCapability(MobileCapabilityType.NO_RESET, true);
androidDcap.setCapability(MobileCapabilityType.FULL_RESET, false);
androidDcap.setCapability(AndroidMobileCapabilityType.NO_SIGN, true);
androidDcap.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
androidDcap.setCapability(AndroidMobileCapabilityType.APP_WAIT_DURATION, 60);
androidDcap.setCapability("newCommandTimeout", 60);
androidDcap.setCapability("appPackage", appPackage);
androidDcap.setCapability("appActivity", appActivity);
try {
if (System.getProperty("location").equalsIgnoreCase("local")) {
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4651/wd/hub"), androidDcap);
} else {
driver = new RemoteWebDriver(new URL(PropertyHelper.getProperties("REMOTE_HUB_URL")), androidDcap);
}
} catch (Exception e) {
logger.error("Driver instantiating failed", e);
}
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
return driver;
}
Appium Java 客户端版本:6.1.0 Selenium 独立版本:3.14.0