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

前端 未结 6 1332
萌比男神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:49

    After my own troubles with testing of the orientation I want to add that while lelloman's advice to use UiDevice is correct from the documentation standpoint - unfortunately it doesn't work as expected in some cases.

    I found that at least on the API 23 emulator rotation could stuck after the test's crash:

    1. Do uiDevice.setOrientationLeft()
    2. Application crashes;
    3. Rotation is stuck;
      3.1 Forcing rotation through UiDevice works but when test ends rotation is back the wrong one until you manually change rotation to "Auto-rotate";
      3.2 uiDevice.unfreezeRotation() helps while test is running but after the test's end rotation is back to the wrong one.

    I don't have this issue on API 28.

    So I found that using setRequestedOrientation is the only solution for me.

提交回复
热议问题