Appium Automation:获取错误 - org.openqa.selenium.WebDriverException:无法解析远程响应:参数不正确

时间:2017-04-28 16:52:04

标签: java android selenium-webdriver automated-tests appium

我正在尝试使用Java进行appium android自动化。以下是代码:

public class Main {

AppiumDriver driver;

@Before
public void setup() throws Exception{
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setCapability("platformVersion","4.4");
    desiredCapabilities.setCapability("platformName","Android");
    desiredCapabilities.setCapability("app","/PATH_TO_APK");
    driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"),desiredCapabilities);
}

@After
public void tearDown(){
    driver.quit();
}

@Test
public void firstTest(){
    WebElement element = driver.findElementById("ELEMENT_ID");
    element.click();
}
}

以下是错误

org.openqa.selenium.WebDriverException: Unable to parse remote response: Parameters were incorrect. We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities","sessionId","id","sessionId","id","sessionId","id","sessionId","id","sessionId","id","sessionId","id"]} and you sent ["desiredCapabilities","requiredCapabilities","capabilities"]
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'WGB01ML106163.local', ip: 'fe80:0:0:0:3e15:c2ff:febe:8ea0%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_131'
Driver info: driver.version: AndroidDriver

之前有没有人见过这个错误?无法在Google上找到任何内容。请帮忙。

1 个答案:

答案 0 :(得分:0)

我们还需要在功能中传递“deviceName”。

 desiredCapabilities.setCapability("deviceName","Android");

此外,如果您在移动设备上进行混合/本机应用测试,我们还需要传递appPackage和appActivity。因此,结合所有强制性功能,整体所需功能将与此类似。

public void setup() throws Exception
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","ANDROID");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("platformName",Constant.appPlatform);
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", Constant.appPackage);
capabilities.setCapability("appActivity",Constant.appActivity);

driver = new AndroidDriver(new URL("http://127.0.0.1:4727/wd/hub"),capabilities);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}

获取appActivity / appPackage的简便方法是联系您的开发人员。如果不可能,请检查此=> appActivity/appPackage

此处提供了有关各种功能的更多详细信息。

https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md