I want to create a test for my Android app. Everytime it loses focus, it should do something.
Therefore, I want to test this out by pressing the overview button 2 times (the button next to the home button). But how can I do this with Espresso? I tried out some Keycodes to press, but none of them worked (Unfortunately, there is no KEY_OVERVIEW
in the table).
So how can I test this?
Thanks,
Niklas
This is not possible with espresso, espresso is for UI testing within your app but can not interact with UI elements outside.
If you want to press the Overview (or Back- or any other system) button you can use ui-automator:
UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.pressRecentApps();
mDevice.pressRecentApps();
this code above presses the recent Apps button twice.
ui-automator is exactly for interacting with UI outside your app (home or recent app button, permission dialogs, ....) and is perfectly combineable with espresso to enhance your tests. To use it include this in your gradle:
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With