Configure emulation / orientation of the device programmatically in the control test

In my instrumental tests, I want to test something in landscape and portrait modes, so I would like to set the orientation before starting the tests. Is there a way to programmatically adjust the orientation of a device or emulator?

I know the setRequestedOrientation() method, but it works for a certain activity, if another action is triggered, I must remember that I need to call it again. Iโ€™m looking for a way to set the orientation โ€œgloballyโ€ so that every new action starts automatically with that orientation.

UPDATE:

The solution must meet two requirements: 1) it does not force me to change my production code, 2) it must be run in the CI environment.

+6
source share
3 answers

Here is the ViewAction I created for simplification: https://gist.github.com/nbarraille/03e8910dc1d415ed9740

Use is described in the comments. Hope this helps.

+5
source

You can do this for all your activities by creating your own AbtractActivity class.

 public abstract class AbstractActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } 

Now you need to inherit all your actions from this class.

+1
source

You can run two emulators simultaneously, one in potrait mode and one in landscape mode. To change the emulator orientation, use ctrl + f12.

0
source

All Articles