I'm quite new to Espresso on Android and I am running into the following problem: I want Espresso to perform a longclick(or something..) on a button, and while the button is kept pressed down, I want to check the state of a different View.
In (more or less) pseudocode:
onView(withId(button_id)).perform(pressButtonDown());
onView(withId(textBox_id)).check(matches(withText("Button is pressed")));
onView(withId(button_id)).perform(releaseButton());
I tried writing 2 custom Taps, PRESS and RELEASE, with MotionEvents.sendDown() and .sendUp(), but did not get it to work. If this is the right path, I can post the code I've got so far.
Edit:
public class PressViewActions
{
public static ViewAction pressDown(){
return new GeneralClickAction(HoldTap.DOWN, GeneralLocation.CENTER, Press.THUMB);
}
public static ViewAction release() {
return new GeneralClickAction(HoldTap.UP, GeneralLocation.CENTER, Press.THUMB);
}
}
And the code for the Tappers:
public enum HoldTap implements Tapper {
DOWN {
@Override
public Tapper.Status sendTap(UiController uiController, float[] coordinates, float[] precision)
{
checkNotNull(uiController);
checkNotNull(coordinates);
checkNotNull(precision);
DownResultHolder res = MotionEvents.sendDown(uiController, coordinates, precision);
ResultHolder.setController(uiController);
ResultHolder.setResult(res);
return Status.SUCCESS;
}
},
UP{
@Override
public Tapper.Status sendTap(UiController uiController, float[] coordinates, float[] precision)
{
DownResultHolder res = ResultHolder.getResult();
UiController controller = ResultHolder.getController();
try {
if(!MotionEvents.sendUp(controller, res.down))
{
MotionEvents.sendCancel(controller, res.down);
return Status.FAILURE;
}
}
finally {
//res.down.recycle();
}
return Status.SUCCESS;
}
}
}
The error I get is the following:
android.support.test.espresso.PerformException: Error performing 'up click' on view 'with id: de.test.app:id/key_ptt'.
...
...
Caused by: java.lang.RuntimeException: Couldn't click at: 281.5,1117.5 precision: 25.0, 25.0 . Tapper: UP coordinate provider: CENTER precision describer: THUMB. Tried 3 times. With Rollback? false
I hope, this helps.
Any help and ideas will be appreciated!
Tanks a lot in advance!