gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 21:05:34 24 4
gpt4 key购买 nike

我这样做是为了退出使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com