7

I'm just trying to test a submit button at the end of a form.

FormAndroidTest.java:

@Test
public void testSubmitButton() throws Exception {

    // Execute
    onView(withId(R.id.btnSaveFeedback))
            .perform(click());

}

The click() is called, I can see it performed the click in the app, but the call never comes back (until it times out).

I've narrowed it down to being caused by the startActivity call in the click handler:

FormActivity.java:

public void onSubmitClicked(View view) {

    ...

    startActivity(new Intent(this, NextActivity.class)
            .addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
            .addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME));

    ...
}

I've traced it down to the call sendUp() call in Espresso's Tap.java failing:

private static Tapper.Status sendSingleTap(...) {

    ...

    DownResultHolder res = MotionEvents.sendDown(uiController, coordinates, precision);
    try {
        if (!MotionEvents.sendUp(uiController, res.down)) { <-- THIS TIMES OUT
            Log.d(TAG, "Injection of up event as part of the click failed. Send cancel event.");
            MotionEvents.sendCancel(uiController, res.down);
            return Tapper.Status.FAILURE;

    ...
}

Within that it's the uiController.injectMotionEvent(motionEvent); which loops until the injection has completed, which in this case it never does and times out.

I'm assuming it must have something to do with my threads not settling, but I don't see why or how to resolve it. I've seen a few related threads, but the given answers don't seem to solve my exact problem.

Thanks

ScottyC
  • 1,467
  • 1
  • 15
  • 22
  • I know it's a long time but any solutions for that? I have the same problem but no solution nor any ideas on how to fix this! – Tobias Reich Jul 24 '19 at 12:25
  • Sorry, at this point I don't even remember what happened with the code, but as far as I remember, no, I ended up having to test it another way. – ScottyC Jul 25 '19 at 17:03
  • It is 2021 now and this error is still not fixed. Had to use the `perform(swipeUp())` hack to get it working. – anshajkhare Jan 20 '21 at 15:30
  • If you're using idling resources somewhere make sure you've "unlocked" all of them. I sometimes run into issues where I have e.g. a ```CountingIdlingResource``` and it doesn't get decremented properly because of errors in the main code itself. Also make sure to actually use idling resources properly to "lock" network calls, coroutines etc. – Oliver Metz Feb 10 '21 at 23:41

0 Answers0