androidkotlinorientationandroid-espressogui-testing

How to check the orientation of my app in espresso?


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.


Solution

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