我這樣做是爲了退出應用程序,使用Android UIAutomator。當我們按下兩次後退按鈕這就是爲什麼我打電話了兩次junit.framework.AssertionFailedError:後退按鈕無法按下
assertTrue("Back button can't be pressed", getUiDevice().pressBack());
assertTrue("Back button can't be pressed", getUiDevice().pressBack()); // This line will giving 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)
返回false是我還在兩次調用之間使用了'Thread.sleep(3000)',但它仍會給出相同的異常。 –