forked from upstream-mirrors/OpenTracks
UI tests: use longClick() instead of veryLongClick().
This commit is contained in:
@@ -5,6 +5,7 @@ import static androidx.test.espresso.Espresso.onData;
|
|||||||
import static androidx.test.espresso.Espresso.onView;
|
import static androidx.test.espresso.Espresso.onView;
|
||||||
import static androidx.test.espresso.Espresso.pressBack;
|
import static androidx.test.espresso.Espresso.pressBack;
|
||||||
import static androidx.test.espresso.action.ViewActions.click;
|
import static androidx.test.espresso.action.ViewActions.click;
|
||||||
|
import static androidx.test.espresso.action.ViewActions.longClick;
|
||||||
import static androidx.test.espresso.action.ViewActions.scrollTo;
|
import static androidx.test.espresso.action.ViewActions.scrollTo;
|
||||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||||
@@ -14,7 +15,6 @@ import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
|||||||
import static org.hamcrest.Matchers.allOf;
|
import static org.hamcrest.Matchers.allOf;
|
||||||
import static org.hamcrest.Matchers.anything;
|
import static org.hamcrest.Matchers.anything;
|
||||||
import static de.dennisguse.opentracks.util.EspressoUtils.childAtPosition;
|
import static de.dennisguse.opentracks.util.EspressoUtils.childAtPosition;
|
||||||
import static de.dennisguse.opentracks.util.EspressoUtils.veryLongTouch;
|
|
||||||
import static de.dennisguse.opentracks.util.EspressoUtils.waitFor;
|
import static de.dennisguse.opentracks.util.EspressoUtils.waitFor;
|
||||||
import static de.dennisguse.opentracks.util.EspressoUtils.withListSize;
|
import static de.dennisguse.opentracks.util.EspressoUtils.withListSize;
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ public class EspressoDeleteTrackTest {
|
|||||||
trackControllerStopButton.perform(waitFor(5000));
|
trackControllerStopButton.perform(waitFor(5000));
|
||||||
|
|
||||||
// stop;
|
// stop;
|
||||||
trackControllerStopButton.perform(veryLongTouch(1600));
|
trackControllerStopButton.perform(longClick());
|
||||||
}
|
}
|
||||||
|
|
||||||
// back
|
// back
|
||||||
@@ -100,7 +100,7 @@ public class EspressoDeleteTrackTest {
|
|||||||
countBefore = numberOfItemsListView();
|
countBefore = numberOfItemsListView();
|
||||||
|
|
||||||
// select track
|
// select track
|
||||||
onData(anything()).inAdapterView(withId(R.id.track_list)).atPosition(0).perform(veryLongTouch(5000));
|
onData(anything()).inAdapterView(withId(R.id.track_list)).atPosition(0).perform(longClick());
|
||||||
|
|
||||||
// open menu and delete selected track
|
// open menu and delete selected track
|
||||||
ViewInteraction overflowMenuButton = onView(
|
ViewInteraction overflowMenuButton = onView(
|
||||||
|
|||||||
@@ -11,19 +11,12 @@ import static org.hamcrest.Matchers.anything;
|
|||||||
import static de.dennisguse.opentracks.util.EspressoUtils.selectTabAtIndex;
|
import static de.dennisguse.opentracks.util.EspressoUtils.selectTabAtIndex;
|
||||||
import static de.dennisguse.opentracks.util.EspressoUtils.waitFor;
|
import static de.dennisguse.opentracks.util.EspressoUtils.waitFor;
|
||||||
|
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import androidx.test.espresso.UiController;
|
|
||||||
import androidx.test.espresso.ViewAction;
|
|
||||||
import androidx.test.espresso.ViewInteraction;
|
import androidx.test.espresso.ViewInteraction;
|
||||||
import androidx.test.espresso.action.MotionEvents;
|
|
||||||
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.filters.LargeTest;
|
import androidx.test.filters.LargeTest;
|
||||||
import androidx.test.rule.GrantPermissionRule;
|
import androidx.test.rule.GrantPermissionRule;
|
||||||
|
|
||||||
import org.hamcrest.Matcher;
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -93,7 +86,7 @@ public class EspressoUITest {
|
|||||||
tabLayout.perform(waitFor(1000));
|
tabLayout.perform(waitFor(1000));
|
||||||
|
|
||||||
// stop
|
// stop
|
||||||
trackControllerStopButton.perform(veryLongTouch(1600));
|
trackControllerStopButton.perform(longClick());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,36 +94,6 @@ public class EspressoUITest {
|
|||||||
@Test
|
@Test
|
||||||
public void selectAndDeleteTrack() {
|
public void selectAndDeleteTrack() {
|
||||||
onView(withId(R.id.track_list)).check(matches(isDisplayed()));
|
onView(withId(R.id.track_list)).check(matches(isDisplayed()));
|
||||||
onData(anything()).inAdapterView(withId(R.id.track_list)).atPosition(0).perform(veryLongTouch(2000));
|
onData(anything()).inAdapterView(withId(R.id.track_list)).atPosition(0).perform(longClick());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ViewAction veryLongTouch(final int duration_ms) {
|
|
||||||
return new ViewAction() {
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return "Perform long touch.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Matcher<View> getConstraints() {
|
|
||||||
return isDisplayed();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void perform(UiController uiController, final View view) {
|
|
||||||
// Get view absolute position
|
|
||||||
int[] location = new int[2];
|
|
||||||
view.getLocationOnScreen(location);
|
|
||||||
|
|
||||||
// Offset coordinates by view position
|
|
||||||
float[] coordinates = new float[]{location[0] + 1, location[1] + 1};
|
|
||||||
|
|
||||||
// Send down event, pause, and send up
|
|
||||||
MotionEvent down = MotionEvents.sendDown(uiController, coordinates, new float[]{1f, 1f}).down;
|
|
||||||
uiController.loopMainThreadForAtLeast(duration_ms);
|
|
||||||
MotionEvents.sendUp(uiController, down, coordinates);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -3,10 +3,10 @@ package de.dennisguse.opentracks.ui.customRecordingLayout;
|
|||||||
|
|
||||||
import static androidx.test.espresso.Espresso.onView;
|
import static androidx.test.espresso.Espresso.onView;
|
||||||
import static androidx.test.espresso.action.ViewActions.click;
|
import static androidx.test.espresso.action.ViewActions.click;
|
||||||
|
import static androidx.test.espresso.action.ViewActions.longClick;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.assertThat;
|
import static androidx.test.espresso.matcher.ViewMatchers.assertThat;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static de.dennisguse.opentracks.util.EspressoUtils.veryLongTouch;
|
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public class EspressoCustomLayoutTest {
|
|||||||
|
|
||||||
// stop recording
|
// stop recording
|
||||||
ViewInteraction trackControllerStopButton = onView(withId(R.id.track_recording_fab_action));
|
ViewInteraction trackControllerStopButton = onView(withId(R.id.track_recording_fab_action));
|
||||||
trackControllerStopButton.perform(veryLongTouch(1600));
|
trackControllerStopButton.perform(longClick());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class RecyclerViewItemCountAssertion implements ViewAssertion {
|
private static class RecyclerViewItemCountAssertion implements ViewAssertion {
|
||||||
|
|||||||
@@ -1,21 +1,14 @@
|
|||||||
package de.dennisguse.opentracks.util;
|
package de.dennisguse.opentracks.util;
|
||||||
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
|
||||||
import static androidx.test.espresso.util.TreeIterables.breadthFirstViewTraversal;
|
|
||||||
|
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewParent;
|
import android.view.ViewParent;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import androidx.test.espresso.PerformException;
|
|
||||||
import androidx.test.espresso.UiController;
|
import androidx.test.espresso.UiController;
|
||||||
import androidx.test.espresso.ViewAction;
|
import androidx.test.espresso.ViewAction;
|
||||||
import androidx.test.espresso.action.MotionEvents;
|
|
||||||
import androidx.test.espresso.util.HumanReadables;
|
|
||||||
|
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
|
||||||
@@ -23,8 +16,6 @@ import org.hamcrest.Description;
|
|||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
import org.hamcrest.TypeSafeMatcher;
|
import org.hamcrest.TypeSafeMatcher;
|
||||||
|
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
|
|
||||||
public class EspressoUtils {
|
public class EspressoUtils {
|
||||||
|
|
||||||
public static Matcher<View> childAtPosition(
|
public static Matcher<View> childAtPosition(
|
||||||
@@ -80,76 +71,6 @@ public class EspressoUtils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ViewAction veryLongTouch(final int duration_ms) {
|
|
||||||
return new ViewAction() {
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return "Perform long touch.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Matcher<View> getConstraints() {
|
|
||||||
return isDisplayed();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void perform(UiController uiController, final View view) {
|
|
||||||
// Get view absolute position
|
|
||||||
int[] location = new int[2];
|
|
||||||
view.getLocationOnScreen(location);
|
|
||||||
|
|
||||||
// Offset coordinates by view position
|
|
||||||
float[] coordinates = new float[]{location[0] + 1, location[1] + 1};
|
|
||||||
|
|
||||||
// Send down event, pause, and send up
|
|
||||||
MotionEvent down = MotionEvents.sendDown(uiController, coordinates, new float[]{1f, 1f}).down;
|
|
||||||
uiController.loopMainThreadForAtLeast(duration_ms);
|
|
||||||
MotionEvents.sendUp(uiController, down, coordinates);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ViewAction waitId(final int viewId, final long millis) {
|
|
||||||
return new ViewAction() {
|
|
||||||
@Override
|
|
||||||
public Matcher<View> getConstraints() {
|
|
||||||
return isRoot();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void perform(final UiController uiController, final View view) {
|
|
||||||
uiController.loopMainThreadUntilIdle();
|
|
||||||
final long startTime = System.currentTimeMillis();
|
|
||||||
final long endTime = startTime + millis;
|
|
||||||
final Matcher<View> viewMatcher = withId(viewId);
|
|
||||||
|
|
||||||
do {
|
|
||||||
for (View child : breadthFirstViewTraversal(view)) {
|
|
||||||
// found view with required ID
|
|
||||||
if (viewMatcher.matches(child)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uiController.loopMainThreadForAtLeast(50);
|
|
||||||
}
|
|
||||||
while (System.currentTimeMillis() < endTime);
|
|
||||||
|
|
||||||
// timeout happens
|
|
||||||
throw new PerformException.Builder()
|
|
||||||
.withActionDescription(this.getDescription())
|
|
||||||
.withViewDescription(HumanReadables.describe(view))
|
|
||||||
.withCause(new TimeoutException())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ViewAction selectTabAtIndex(final int index) {
|
public static ViewAction selectTabAtIndex(final int index) {
|
||||||
return new ViewAction() {
|
return new ViewAction() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user