ImmersiveModeConfirmation with Espresso 2.2.2

Viewed 1290

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);
3 Answers

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.

Related