ligi
ligi

Reputation: 39519

run espresso androidTest s in Portrait and Landscape

what is a good way to run my test-suite in portrait and landscape mode? Is there already a way to do so or do I have to implement a solution?

Upvotes: 3

Views: 2047

Answers (2)

Alex Klymentiev
Alex Klymentiev

Reputation: 46

When you create @Rule ActivityTestRule<MainActivity> myActivity; you can perform something like this:

     myActivity.getActivity()
    .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Upvotes: 3

somebody
somebody

Reputation: 1

By default Espresso doesn't support it, however you can add you're own ViewAction.

Add the class OrientationChangeAction to you're project and use it like below https://gist.github.com/nbarraille/03e8910dc1d415ed9740

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

Found this solution within this comment; https://stackoverflow.com/a/28949976

Upvotes: 0

Related Questions