我正在尝试运行简单的代码以在模拟器中打开谷歌,输入一些键并提交它。但是每次测试都失败了。我已经使用 SDK 2.3 和 SDK 2.2 进行了尝试。对于这两个 SDK,我在相同的代码中遇到了不同的错误。
SDK 2.3 的错误是:测试运行失败:检测运行因“进程崩溃”而失败。SDK 2.2 的错误是:java.lang.NosuchmethodError(此错误发生在 driver.sendkeys())。
以下是 SDK 2.2 的错误日志:
08-07 17:51:02.767: E/AndroidRuntime(3556): FATAL EXCEPTION: main
08-07 17:51:02.767: E/AndroidRuntime(3556): java.lang.NoSuchMethodError: android.view.MotionEvent.setSource
08-07 17:51:02.767: E/AndroidRuntime(3556): at org.openqa.selenium.android.EventSender$1.run(EventSender.java:55)
08-07 17:51:02.767: E/AndroidRuntime(3556): at android.os.Handler.handleCallback(Handler.java:587)
08-07 17:51:02.767: E/AndroidRuntime(3556): at android.os.Handler.dispatchMessage(Handler.java:92)
08-07 17:51:02.767: E/AndroidRuntime(3556): at android.os.Looper.loop(Looper.java:123)
08-07 17:51:02.767: E/AndroidRuntime(3556): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-07 17:51:02.767: E/AndroidRuntime(3556): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 17:51:02.767: E/AndroidRuntime(3556): at java.lang.reflect.Method.invoke(Method.java:521)
08-07 17:51:02.767: E/AndroidRuntime(3556): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-07 17:51:02.767: E/AndroidRuntime(3556): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-07 17:51:02.767: E/AndroidRuntime(3556): at dalvik.system.NativeStart.main(Native Method)
以下是打开google的示例代码:
public void testGoogleWorks()
{
System.out.println("in test google works");
driver.get("http://www.google.com");
System.out.println("after driver . get");
WebElement searchBox = driver.findElement(By.name("q"));
System.out.println("after search box");
searchBox.sendKeys("Cheese!");
System.out.println("after sendkeys");
searchBox.submit();
System.out.println("after submit");
String title = driver.getTitle();
System.out.println("after driver . gettitle");
assertTrue("Got title: " + title, title.contains("Google"));
assertTrue(driver.findElements(By.name("Testing")).size() > 1);
}
谢谢 。