Android Robotium: how to go back to my Activity under test after clicking/launching another Activity

二次信任 提交于 2019-12-04 04:16:47

问题


I have an issue with my Robotium tests. On one of my Activity A, I am clicking on a button. Clicking on this button launches another activity B. So in my robotium test I have something like this :

Button myBtn = (Button) solo.getView(R.id.myBtn);

so after this action, the emulator is automatically launching activity B. Now, the problem is that I do not have any possibility of going back to the activity under test (A) in the code.

Can you please tell me how to avoid getting jailed in the activity B when clicking on the button that trigger its launch ? In other words, is it possible to go back to the activity under test ?

FYI : I need to go back to the activity under test because there are other test methods waiting to be fired.

thanks in advance,


回答1:


Please try methods like

solo.clickOnView(R.id.myBtn)

to click on your button You can also try

solo.clickOnButton()

To go back to activity you can use

solo.goBack();

or

solo.goBackToActivity("ActivityName");



回答2:


Once you call any activity outside your application, it’s not possible to come back to your application using solo.<any API>, because solo is tight to UID of your application and doesn't work on other app's activity (with different UID).

Basically solo can only work on activities which belong to the application for which it’s created.



来源:https://stackoverflow.com/questions/10653576/android-robotium-how-to-go-back-to-my-activity-under-test-after-clicking-launch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!