0

当我使用 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

4

2 回答 2

0

我遇到过同样的问题。通过降级 selenium-standalone-server-3.13.0 解决

这里的问题是您应该使用 java-client 中给出的 selenium-standalone-server 版本。就我而言,我使用的是 java-client-6.1.0。为此,我们需要使用 selenium-standalone-server-3.13.0

请看这里

您可以在此处获取旧版本的 jar 文件

于 2019-03-01T05:31:59.423 回答
0

我在 chrome 浏览器上设置 web 执行时遇到了同样的问题,最后找到了解决方案。

我正在传递我的能力,如下所示(抛出与此处提到的相同的错误)

DesiredCapabilities capability = DesiredCapabilities.chrome();

改为下面,它工作

DesiredCapabilities capability = new DesiredCapabilities();
    capability.setBrowserName("chrome");
于 2022-02-03T06:31:55.350 回答