1

In my application, I want to change the screen orientation and perform a click action on the button using Espresso.

I have tried all the solution mentioned over the internet, but nothing works. It's not changing the screen orientation. Can someone help me?

This is what I have tried:

ComposePageObject.clickComposeButton();
mActivityRule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Thread.sleep(5000); 

Do I need to create any custom class for this?

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
  • You should give more details and code templates, like which things you have tried – Hardik Chauhan Aug 05 '19 at 10:49
  • @HardikChauhan - This is what I tried. ComposePageObject.clickComposeButton(); mActivityRule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Thread.sleep(5000); Do I need to create any custom class for this? – Keshav Kumar Aug 05 '19 at 11:24
  • check this solutions, https://stackoverflow.com/questions/37362200/how-to-rotate-activity-i-mean-screen-orientation-change-using-espresso – Hardik Chauhan Aug 05 '19 at 11:26
  • @HardikChauhan - I tried some of the solutions from this blog too, but didn't work. – Keshav Kumar Aug 05 '19 at 11:30
  • You can use the [edit] button to make improvements to your question. This is better than trying to add code as a comment. – Martin Evans Aug 05 '19 at 13:40

1 Answers1

5

You can use

androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'

and with this library, write some code in your test

UiDevice device = UiDevice.getInstance(getInstrumentation());
device.setOrientationLeft();

Check lib more, there is some other options for changing orientation

Olena Y
  • 233
  • 2
  • 8