How to rotate activity, I mean: screen orientation change using Espresso?

前端 未结 6 1338
萌比男神i
萌比男神i 2020-12-30 00:11

I have decided that one of the testing criteria for my application tests with Google\'s Espresso is:

Test should maintain Activity state after s

6条回答
  •  青春惊慌失措
    2020-12-30 00:50

    You can't mix Robotium and Espresso tests. The best way sometimes to solve any issue is to check source code of desired but not comaptible method.

    I'm pretty sure that you have already setUp() method, which has code like:

    myActivity = this.getActivity();

    Use this to change your screen orientation change:

    myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    or

    myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    You may also need to use myActivity.getInstrumentation().waitForIdleSync(); or Thread.sleep(milliseconds); in order to wait for the rotation end because it is performed in Async manner. The second methods depends on emulator/device so choose it wisely.

    Hope it help.

提交回复
热议问题