[英]Failed to switch between android apps during appium automation
I have the below code. 我有下面的代码。
DesiredCapabilities capabilities =DesiredCapabilities.android();
capabilities.setCapability("device","Android");
capabilities.setCapability("deviceName","hammerhead");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage","com.android.calculator2");
capabilities.setCapability("appActivity","com.android.calculator2.Calculator");
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@resource-id='com.android.calculator2:id/digit_7']")).click();
driver.findElement(By.xpath("//*[@resource-id='com.android.calculator2:id/op_add']")).click();
driver.startActivity("com.android.browser","com.android.browser.BrowserActivity");
"java.lang.reflect.InvocationTargetException" error is thrown on executing driver.startActivity line. 执行driver.startActivity行时引发“ java.lang.reflect.InvocationTargetException”错误。 What mistake I'm making here? 我在这里犯什么错误?
Invocation Target Exception:- This exception occurs when an underlying method throws an exception. 调用目标异常:-当基础方法引发异常时,将发生此异常。 So if there is any method that is invoked using
Reflection API
throws any runtime exception, the Reflection API will wrap that exception inInvocationTargetException
因此,如果有任何使用Reflection API
调用的方法抛出任何运行时异常,则反射API会将异常包装在InvocationTargetException
You can figure out the original/actual exception
by using getCause()
method on the InvocationTargetException
. 您可以使用InvocationTargetException
上的getCause()
方法找出原始/实际exception
。
I had the same problem too. 我也有同样的问题。 This is due to the problem of StringUtils. 这是由于StringUtils的问题。 I downloaded Apache Commons Lang plugin and problem was solved. 我下载了Apache Commons Lang插件,问题已解决。
The download can be found here: http://commons.apache.org/proper/commons-lang/download_lang.cgi 可在以下位置找到下载内容: http : //commons.apache.org/proper/commons-lang/download_lang.cgi
After downloading, add commons-lang3-3.4.jar to your external libraries in your IDE. 下载后,将commons-lang3-3.4.jar添加到IDE中的外部库中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.