Methods for changing orientation of the UI Automator Framework do not work

Asked

Viewed 218 times

2

The methods setOrientationLeft() and setOrientationRight() below simply do not work, both on emulated devices and on physical devices. I would like to know if there are any rules for using sponges or specific scenarios.

Exampleinstrumentedtestkotlin.kt

    @RunWith(AndroidJUnit4::class)
    @SdkSuppress(minSdkVersion = 16)
    @FixMethodOrder(MethodSorters.NAME_ASCENDING)

    class ExampleInstrumentedTestKotlin {

        private var mDevice: UiDevice? = null

        private val launcherPackageName: String
            get() {
                val intent = Intent(Intent.ACTION_MAIN)
                intent.addCategory(Intent.CATEGORY_HOME)
                val pm = getApplicationContext<Context>().packageManager
                val resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)
                return resolveInfo!!.activityInfo.packageName
            }

        companion object {
            private val BASIC_SAMPLE_PACKAGE = "xxx.xxxx.xxxx"
            private val LAUNCH_TIMEOUT = 5000
            private val STRING_TO_BE_TYPED = "UiAutomator"
        }

        @Before
        fun openApp() {

            mDevice = UiDevice.getInstance(getInstrumentation())
            mDevice!!.pressHome()

            val launcherPackage = launcherPackageName
            assertThat(launcherPackage, notNullValue())
                    mDevice!!.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT.toLong())

            val context = getApplicationContext<Context>()
            val intent = context.packageManager
            .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE)
            intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
            context.startActivity(intent)
            mDevice!!.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT.toLong())

        }

        @Test
        fun teste(){
            load(10)  //função para aguardar 10 segundos
            mDevice!!.setOrientationLeft()
            load(10)  //função para aguardar 10 segundos
            mDevice!!.setOrientationRight()
        }
    }
  • What is not going?? which error appears? Uidevice is null always same?

  • The code does not present any error, it passes as if it has everything ok, however the orientation of the device does not change as expressed in the documentation, the part of the code that was missing I added, was the function openApp.

  • Have you tried some method wait of UiDevice? For example, waitForIdle()

  • yes, but it doesn’t work.

1 answer

0


The "problem" was fixed, in the previous version of the application it only worked in the mode Portrait, to keep the look of the application interesting, so had the rule in activitys in the manifest:

android:screenOrientation="portrait"

In the current version this rule has been removed from my Activity and so the methods now work normal, both on emulated devices and on physical devices.

In short, the methods do work, as long as the orientation of the acitivtys is not configured to work in a specific mode.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.