I'm developing my first android application and I was setting up the CI server. My espresso tests run fine on my machine but travis errors out with the following
java.lang.RuntimeException: Waited for the root of the view hierarchy to have window focus and not be requesting layout for over 10 seconds.
It seems that I need to unlock the emulator screen before I run the tests. To do so I have to add a manifest to src/debug
with the required permissions and then unlock the screen with:
KeyguardManager mKeyGuardManager = (KeyguardManager) ctx.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock mLock = mKeyGuardManager.newKeyguardLock(name);
mLock.disableKeyguard();
The thing is I don't want to litter my activities with the above code wrapped in if blocks. Is there a way to unlock the screen from the espresso test itself?
My espresso test:
@RunWith(AndroidJUnit4.class)
public class EspressoSetupTest {
@Rule
public final ActivityTestRule<WelcomeActivity> activity =
new ActivityTestRule<>(WelcomeActivity.class, true, true);
@Test
public void launchTest() {
onView(withId(R.id.welcome_textView_hello))
.perform(click())
.check(matches(withText("RetroLambda is working")));
}
}
You can use the
setUp()
method in your Espresso Test like:src/debug/AndroidManifest.xml