获取[debug] [MJSONWP]错误的参数:更新selenium版本的BadParametersError

时间:2018-02-28 09:53:42

标签: java selenium selenium-webdriver appium

在将selenium升级到3.9.1之前,自动化套装工作正常。一旦更新了selenium,我就会在初始化Android驱动程序时遇到以下错误。

[HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"app":"/Users/abhinav.tiwari/Documents/Office Stuff/Automation/ui-automation-testing/TestData/mobile/testAutomation.apk","deviceName":"emulator-5554","fullReset":"false","noReset":"true","platformName":"Android","platformVersion":"6.0"},"capabilities":{"desiredCapabilities":{"app":"/Users/abhinav.tiwari/Documents/Office Stuff/Automation/ui-automation-testing/TestData/mobile/testAutomation.apk","deviceName":"emulator-5554","fullReset":"false","noReset":"true","platformName":"Android","platformVersion":"6.0"},"firstMatch":[{"platformName":"android"}]}}
[debug] [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities","sessionId","id"]} and you sent ["desiredCapabilities","capabilities"]
[HTTP] <-- POST /wd/hub/session 400 5 ms - 178 
exception is .......org.openqa.selenium.WebDriverException: Unable to parse remote response: Parameters were incorrect. We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities","sessionId","id"]} and you sent ["desiredCapabilities","capabilities"]
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:25:02.294Z'

我使用的是5.0.4版本的java客户端和1.7.2版本的appium。 我在互联网上做了很多研究,但找不到任何解决方案。

以下是我的代码:

final File apkPath= new File(System.getProperty("user.dir")+File.separator+"TestData"+File.separator+"mobile"+File.separator+"testAutomation.apk");
//Adding DesiredCapabilities
DesiredCapabilities androidCapability = new DesiredCapabilities();
androidCapability.setCapability("platform", testConfig.getRunTimeProperty("platform"));
androidCapability.setCapability("platformVersion", testConfig.getRunTimeProperty("platformVersion"));
androidCapability.setCapability("deviceName", testConfig.getRunTimeProperty("deviceName"));
androidCapability.setCapability("app",apkPath.getAbsolutePath());
androidCapability.setCapability("appPackage", testConfig.getRunTimeProperty("appPackageName"));
androidCapability.setCapability("appActivity",testConfig.getRunTimeProperty("appActivity"));
try
{
    AppiumDriver<WebElement> driver = new AndroidDriver<>(new URL("http://"+testConfig.getRunTimeProperty("serverIP")+":"+testConfig.getRunTimeProperty("serverPort")+"/wd/hub"),androidCapability);

}
catch(Exception e)

1 个答案:

答案 0 :(得分:0)

在您的问题中,您尚未提及已升级到 Selenium v​​3.9.1 Selenium客户端版本。

在最近的发布中, Selenium 已经发展了很多。几点:

  • Selenium v3.7.0

    Migrated from using `DesiredCapabilities` to either `MutableCapabilities` or (preferably) `ImmutableCapabilities`.
    

您使用setCapability()DesiredCapabilities类的方法是从MutableCapabilities类继承的。 setCapability()的当前实现定义如下:

  • setCapability()

    public void setCapability(java.lang.String capabilityName, boolean value)
    
  • setCapability()

    public void setCapability(java.lang.String capabilityName, java.lang.String value)
    
  • setCapability()

    public void setCapability(java.lang.String capabilityName, Platform value)
    
  • setCapability()

    public void setCapability(java.lang.String key, java.lang.Object value)
    

执行时,您的程序只需要"required":["desiredCapabilities"],因为您已经通过了["desiredCapabilities","capabilities"]。因此你的程序错误了。

解决方案

此问题的解决方案仅发送受支持的"required":["desiredCapabilities"]。您还可以使用merge(Capabilities extraCapabilities)类中的MutableCapabilities函数,并将参数作为选项

传递