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

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

    This more complete solution creates a custom Espresso ViewActionand works well. It shows how to get the Activity (even when it is an AppCompatActivity) before calling its setRequestedOrientation() method. It also has a clean caller interface:

    onView(isRoot()).perform(orientationLandscape()); 
    onView(isRoot()).perform(orientationPortrait());
    

    I follow each orientation change with a 100 ms delay, though you may not need it.

提交回复
热议问题