How to manage uiAutomator and device Locale (permission dialog)

146 views
Skip to first unread message

Daniele Segato

unread,
Oct 18, 2022, 7:32:04 AM10/18/22
to Android Testing Support Library
Hi,

I'm trying to write androidTests for permissions with uiAutomator.

I've been struggling with the code to automatically allow or deny options from the permission dialog...

  1. the dialog changes between SDK versions (which I can kinda work with provided I put enough when conditions)
  2. cannot find any way to find the buttons in any locale the device has been set.

Ho do I select the correct button from UiDevice?

val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
device.findObject(
    UiSelector()
        .clickable(true)
        .className("android.widget.Button")
        // what do I put here??
)
waitUntil { device.exists() }
// use device

with this function for the waiting

private fun waitUntil(timeoutMillis: Long = 2_000, condition: () -> Boolean): Boolean {
    val startTime = System.nanoTime()
    while (true) {
        if (condition()) return true
        Thread.sleep(10)
        if (System.nanoTime() - startTime > timeoutMillis * 1_000_000) {
            return false
        }
    }
}


I know Firebase TestLab devices are set in English US by default but I also want to be able to run tests on my devices from Android Studio.


and if I look for strings I can find them here:

Isn't there a better way than matching with text in each language I need?

Thanks,
Daniele

Daniele Segato

unread,
Oct 18, 2022, 8:56:01 AM10/18/22
to Android Testing Support Library
I've found the resourceID on my Pixel 2 are

com.android.permissioncontroller:id/permission_allow_foreground_only_button
com.android.permissioncontroller:id/permission_allow_one_time_button
com.android.permissioncontroller:id/permission_deny_button

for a standard permission request..

Is there a place I can find which resource ID to use for each permission by SDK or do I have to switch tag in the platform_packages_apps_packageinstaller and check manually for each SDK?
Reply all
Reply to author
Forward
0 new messages