KasperskyLab / Kaspresso

Android UI test framework

Home Page:https://kasperskylab.github.io/Kaspresso/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Permissions.allowViaDialog() only works for PERMISSIONS.Button.ALLOW

TTC1018 opened this issue · comments

In PermissionImpl, allowViaDialog() code is shown below.

override fun allowViaDialog() {
    wait(
        timeoutMs = DIALOG_TIMEOUT_MS,
        logger = logger
    ) {
        handlePermissionRequest(Permissions.Button.ALLOW)
    }
    logger.i("Allow permission via dialog")
}

But since Android 11, the ALLOW_FOREGROUND option was added.
It's OK with Permissions.clickOn(Permissions.Button.ALLOW_FOREGROUND)
but developers may consider allowViaDialog() as a silver bullet for granting runtime permissions.
So I hope this function to be able to handle both situations.

Maybe we could add a conditional to the handlePermissionRequest function?
like this

private fun handlePermissionRequest(button: Permissions.Button) {
    val uiObjectButton = getPermissionDialogButtonAsUiObject(button).let { 
        if (it == null && button == Permissions.Button.ALLOW) {
            getPermissionDialogButtonAsUiObject(Permissions.Button.ALLOW_FOREGROUND)
        } else {
            it
        }
    }
        
    if (uiObjectButton != null && uiObjectButton.exists()) {
        uiObjectButton.click()
    } else {
        logger.e("In method handlePermissionRequest button=$button is not exist or is not found.")
    }
}

It's a simple approach, and I'm sure there's another better way.
Thank you