2016-06-08 79 views
0

我有以下代碼。無法在appium自動化期間切換android應用程序

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」在執行driver.startActivity行時發生錯誤。我在這裏犯了什麼錯誤?

回答

0

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 in InvocationTargetException

您可以通過使用getCause()方法對InvocationTargetException找出原/實際exception

+0

原因:null target:java.lang.NoClassDefFoundError:org/apache/commons/lang3/StringUtils – user1700354

+0

所以現在您遇到了錯誤,您可以繼續解決此問題。 JVM無法找到您的類定義。 – Paras

+0

我將commons-lang-2.6保留在構建路徑中。仍然存在錯誤。但是如何從driver.startActivity()拋出這個異常呢? – user1700354

相關問題