0

I am using espresso for android ui testing. I want to test whether my screen is in portrait mode. I am using Kotlin programming language.

What did I try: I tried to search how to perform this. But all I could get was change the orientation of the app using espresso.

So I tried this:

@Test
    fun isOrientationVertical() {
        assertEquals(resources.configuration.orientation, Configuration.ORIENTATION_LANDSCAPE.toString())
    }

However, 'resources' (to be precise, getResources()) is not getting detected.

What am I expecting: Something like this:

  1. x = get the orientation
  2. assert equals(if x is equal to portrait)

Thanks a lot in advance. Please do let me know if I am not clear.

Manika Sharma
  • 113
  • 1
  • 12
  • what is `resources` here? a test class generally does not have any parent class, so there won't be a `getResources` method. you will need to run code in the context of your app, for example if you are using `ActivityScenario` you can run it inside a `scenario.onActivity` block (similarly for `FragmentScenario`) – Adam Burley Aug 03 '23 at 13:30

1 Answers1

0

Have a look at this answer: https://stackoverflow.com/a/42591933/20356055
Instead of setRequestedOrientation() you can use getRequestedOrientation

Fah
  • 199
  • 9