Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

False positives: junit.framework.AssertionFailedError: EditText is not found

I have a problem setting up Robotium tests to run on Travis without random false posivities.

Every couple of builds I get

pl.mg6.agrtt.TestActivityTests > testCanEnterTextAndPressButton[test(AVD) - 4.4.2] FAILED
    junit.framework.AssertionFailedError: EditText is not found!
    at com.robotium.solo.Waiter.waitForAndGetView(Waiter.java:540)

on all my tests.

I have created a simple project on GitHub to show the issue.
You may see how it builds on Travis. Note build #7 failed after modyfing unrelated file.

I'm suspecting this to be caused by emulator being locked or its sceeen dimmed. I could reproduce this issue on local machine by turning connected device's screen off and then running

./gradlew connectedAndroidTest

After modyfing tests I got a different error message, which is somewhat more informative, so I'm adding it just in case someone tries to find a solution:

pl.mg6.agrtt.TestActivityTests > testCanFindViewsEnterTextAndPressButton[test(AVD) - 4.4.2] FAILED
    junit.framework.AssertionFailedError: Click at (160.0, 264.0) can not be completed! (java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission)
    at com.robotium.solo.Clicker.clickOnScreen(Clicker.java:106)
like image 938
MaciejGórski Avatar asked Dec 03 '25 10:12

MaciejGórski


2 Answers

While the root cause of this problem is still unknown to me, after some investigation and with a help from Robotium's author Renas Reda I could confirm what I initially suspected that emulator indeed locks itself.

A workaround I'm using now is this code put in setUp method:

getInstrumentation().runOnMainSync(new Runnable() {
    @Override
    public void run() {
        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    }
});
like image 104
MaciejGórski Avatar answered Dec 06 '25 00:12

MaciejGórski


Robotium discards invisible views when using enterText(int, String). Instead use getView(int) of Solo to use resulting view in enterText(View, String).

Like this:

public void testCanEnterTextAndPressButton() {
    solo.enterText(((EditText) solo.getView(R.id.editText1)), "my login");
    solo.enterText(((EditText) solo.getView(R.id.editText2)), "my password");
    solo.clickOnView(solo.getView(R.id.button));
}

And if the device screen is locked Robotium fails to run those instructions you gave. You might want to disable screen locking.

By code above my tests pass.

like image 28
interlude Avatar answered Dec 05 '25 23:12

interlude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!