java - junit.framework.AssertionFailedError : Back button can't be pressed

标签 java android ui-automation android-uiautomator

我这样做是为了退出使用 Android UIAutomator 的应用程序。

assertTrue("Back button can't be pressed", getUiDevice().pressBack());

assertTrue("Back button can't be pressed", getUiDevice().pressBack());   // This line will giving exception.

当我们按两次后退按钮时,我的应用程序将退出,这就是我调用它两次的原因。

但是

然后它会给我异常。

但是当我手动返回两次时它会完美地工作。

异常(exception)是:

junit.framework.AssertionFailedError: Back button can't be pressed
        at com.android.jdsu.automation.youtube.YoutubeUiTest.exitApplicaion(Yout
ubeUiTest.java:487)
        at com.android.jdsu.automation.youtube.YoutubeUiTest.testYouTube(Youtube
UiTest.java:208)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAuto
matorTestRunner.java:160)
        at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutoma
torTestRunner.java:96)
        at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.ja
va:91)
        at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)
        at dalvik.system.NativeStart.main(Native Method)

INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: test=testYouTube
INSTRUMENTATION_STATUS: class=com.android.jdsu.automation.youtube.YoutubeUiTest
INSTRUMENTATION_STATUS: stack=junit.framework.AssertionFailedError: Back button
can't be pressed
        at com.android.jdsu.automation.youtube.YoutubeUiTest.exitApplicaion(Yout
ubeUiTest.java:487)
        at com.android.jdsu.automation.youtube.YoutubeUiTest.testYouTube(Youtube
UiTest.java:208)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAuto
matorTestRunner.java:160)
        at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutoma
torTestRunner.java:96)
        at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.ja
va:91)
        at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)
        at dalvik.system.NativeStart.main(Native Method)

最佳答案

是的,我也遇到过同样的问题,但不明白为什么会这样。 我通过使用如下方法让它工作:

UiDevice device = UiDevice.getInstance();
device.pressMenu();

这对我来说很好用。 否则你也可以使用 keyevent 如下:

Runtime.getRuntime().exec("/system/bin/input keyevent 82");

关于java - junit.framework.AssertionFailedError : Back button can't be pressed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24697114/

相关文章:

java - 是否有适用于 Apache Beam 的 Https IO 连接器?

java - Spring消息未出现在jsp页面上

Android:内核信息和硬件要求?

c# - 如何访问 UI Spy 看不到的元素以使用 C# 自动化 win32 应用程序

wpf - 如何在对项目进行分组的 WPF ItemsControl 上使用 UI 自动化?

android - TestNG结果的testng-results.xml中的 "duration in ms"代表什么?

java - 静态映射的空指针异常

java - 反向打印给定数组

android - 如何阻止电子邮件 Intent 导致强制关闭错误?

java - android:listSelector 在notifyDataSetChanged()之后,颜色消失