stef
stef

Reputation: 161

ImmersiveModeConfirmation with Espresso 2.2.2

Looks like some virtual devices on Google cloud test servers can't execute tests properly because of the Immersive mode confirmation popup (shown here: https://developer.android.com/training/system-ui/immersive.html) - is there a way to automatically close that popup with Espresso? Basically my code works in a local emulator, but not on Google cloud servers. This is what's failing:

View v = activity.getWindow().getDecorView();
v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

Upvotes: 2

Views: 2260

Answers (4)

fillobotto
fillobotto

Reputation: 3785

Based on jmartinalonso's answer. I solved by adding the following code to @BeforeClass function:

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice

try  {
    UiDevice
        .getInstance(InstrumentationRegistry.getInstrumentation())
        .executeShellCommand("settings put secure immersive_mode_confirmations confirmed")
}catch (_: IOException) {

}

Upvotes: 0

jmartinalonso
jmartinalonso

Reputation: 2482

I have solved the problem using a similar version of @paul-t. Once the emulator has been started run the next command:

adb shell settings put secure immersive_mode_confirmations confirmed

After that you can execute your Espresso tests.

Inspiration: http://sviatoslavdev.blogspot.com/2018/02/adb-setings-secure.html

Upvotes: 2

Benny
Benny

Reputation: 1738

I found a working solution. It's similar to Paul's answer but is by setting the permission programmatically before your tests run instead of using the ADB. There is a LinkedIn Open Source library that does everything for you, from getting WRITE_SECURE_SETTINGS permissions to changing the need for immersive confirmation dialog dynamically. After setting up the library, use the following line before your test starts:

TestButler.setImmersiveModeConfirmation(false);

For more details and setup instructions go here.

Upvotes: 0

Paul T
Paul T

Reputation: 9

You can run these ADB commands right after the emulator has started:

adb shell settings put secure immersive_mode_confirmations your.package.com
adb reboot (required)

immersive_mode_confirmations is a comma separated list of packages that no longer need confirmation for immersive mode

Upvotes: 0

Related Questions