Appium 自动化:获取错误 - org.openqa.selenium.WebDriverException:无法解析远程响应:参数不正确
我正在尝试使用 Java 进行 appium android 自动化.代码如下:
I am trying to do appium android automation using Java. Below is the code:
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
有没有人见过这个错误?在谷歌上找不到任何东西.请帮忙.
Has anyone seen this error before? Cant find anything on Google. Please help.
我们还需要在功能中传递deviceName".
We also need to pass the "deviceName" in the capabilities.
desiredCapabilities.setCapability("deviceName","Android");
此外,如果您在移动设备中进行混合/原生应用测试,我们还需要通过 appPackage 和 appActivity.因此,将所有必需的功能结合起来,总体所需的功能将与此类似.
Also, if you doing hybrid/native app testing in the mobile, we need to pass appPackage and appActivity also. So combining all the mandatory capabilities, overall desired capabilities will look similar to this.
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
Easy way to get appActivity/appPackage is contacting your developer. If not possible check this=>appActivity/appPackage
此处提供了有关各种功能的更多详细信息.
More details about various capabilities are available here.
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md