mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 21:59:54 +01:00
Fix PromoVideoTest for CI
This commit is contained in:
@@ -68,19 +68,38 @@ public class ViewActions {
|
|||||||
|
|
||||||
public static ViewAction waitForActivity(Class<? extends Activity> clazz,
|
public static ViewAction waitForActivity(Class<? extends Activity> clazz,
|
||||||
Stage stage, long timeout) {
|
Stage stage, long timeout) {
|
||||||
return new CustomViewAction() {
|
return new CustomViewAction(timeout) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean exitConditionTrue(View view) {
|
protected boolean exitConditionTrue(View view) {
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
ActivityLifecycleMonitor lifecycleMonitor =
|
ActivityLifecycleMonitor lifecycleMonitor =
|
||||||
ActivityLifecycleMonitorRegistry.getInstance();
|
ActivityLifecycleMonitorRegistry.getInstance();
|
||||||
|
log(lifecycleMonitor);
|
||||||
|
for (Activity a : lifecycleMonitor
|
||||||
|
.getActivitiesInStage(stage)) {
|
||||||
|
if (a.getClass().equals(clazz)) found = true;
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void log(ActivityLifecycleMonitor lifecycleMonitor) {
|
||||||
|
log(lifecycleMonitor, Stage.PRE_ON_CREATE);
|
||||||
|
log(lifecycleMonitor, Stage.CREATED);
|
||||||
|
log(lifecycleMonitor, Stage.STARTED);
|
||||||
|
log(lifecycleMonitor, Stage.RESUMED);
|
||||||
|
log(lifecycleMonitor, Stage.PAUSED);
|
||||||
|
log(lifecycleMonitor, Stage.STOPPED);
|
||||||
|
log(lifecycleMonitor, Stage.RESTARTED);
|
||||||
|
log(lifecycleMonitor, Stage.DESTROYED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void log(ActivityLifecycleMonitor lifecycleMonitor,
|
||||||
|
Stage stage) {
|
||||||
for (Activity a : lifecycleMonitor
|
for (Activity a : lifecycleMonitor
|
||||||
.getActivitiesInStage(stage)) {
|
.getActivitiesInStage(stage)) {
|
||||||
Log.e("TEST", a.getClass().getSimpleName() +
|
Log.e("TEST", a.getClass().getSimpleName() +
|
||||||
" is in state " + stage);
|
" is in state " + stage);
|
||||||
if (a.getClass().equals(clazz)) found = true;
|
|
||||||
}
|
}
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
|||||||
import static androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread;
|
import static androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A full-screen overlay used to make taps visible in instrumentation tests.
|
||||||
|
*/
|
||||||
public class OverlayView extends View {
|
public class OverlayView extends View {
|
||||||
|
|
||||||
public static OverlayView attach(Context ctx) throws Throwable {
|
public static OverlayView attach(Context ctx) throws Throwable {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ 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.closeSoftKeyboard;
|
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
|
||||||
import static androidx.test.espresso.action.ViewActions.replaceText;
|
import static androidx.test.espresso.action.ViewActions.replaceText;
|
||||||
|
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.contrib.RecyclerViewActions.actionOnItemAtPosition;
|
import static androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||||
@@ -49,13 +50,13 @@ import static org.junit.Assert.assertTrue;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class PromoVideoTest extends ScreenshotTest {
|
public class PromoVideoTest extends ScreenshotTest {
|
||||||
|
|
||||||
// we can leave debug to true (to speed up CI)
|
// we can leave isFilming to false (to speed up CI)
|
||||||
// and only set it to false when doing recordings
|
// and only set it to true when doing recordings
|
||||||
private static final boolean debug = true;
|
private static final boolean isFilming = false;
|
||||||
|
|
||||||
private static final int DELAY_SMALL = debug ? 0 : 4_000;
|
private static final int DELAY_SMALL = isFilming ? 4_000 : 0;
|
||||||
private static final int DELAY_MEDIUM = debug ? 0 : 7_500;
|
private static final int DELAY_MEDIUM = isFilming ? 7_500 : 0;
|
||||||
private static final int DELAY_LONG = debug ? 0 : 10_000;
|
private static final int DELAY_LONG = isFilming ? 10_000 : 0;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ActivityScenarioRule<SplashScreenActivity> testRule =
|
public ActivityScenarioRule<SplashScreenActivity> testRule =
|
||||||
@@ -74,7 +75,7 @@ public class PromoVideoTest extends ScreenshotTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createAccountAddContact() throws Throwable {
|
public void createAccountAddContact() throws Throwable {
|
||||||
if (!debug) {
|
if (isFilming) {
|
||||||
// Using this breaks emulator CI tests for some reason.
|
// Using this breaks emulator CI tests for some reason.
|
||||||
// Only use it for filming for now until we have time to debug this.
|
// Only use it for filming for now until we have time to debug this.
|
||||||
overlayView = OverlayView.attach(getApplicationContext());
|
overlayView = OverlayView.attach(getApplicationContext());
|
||||||
@@ -84,7 +85,14 @@ public class PromoVideoTest extends ScreenshotTest {
|
|||||||
onView(withId(R.id.logoView))
|
onView(withId(R.id.logoView))
|
||||||
.perform(waitUntilMatches(isDisplayed()));
|
.perform(waitUntilMatches(isDisplayed()));
|
||||||
|
|
||||||
if (debug) waitFor(SetupActivity.class, 25_000);
|
// It takes a long time for SetupActivity to start after the splash,
|
||||||
|
// (because it is shown longer for videos), so increase timeout.
|
||||||
|
if (!isFilming) waitFor(SetupActivity.class, 20_000);
|
||||||
|
|
||||||
|
// Note: We use waiting code only when not filming,
|
||||||
|
// to make the test reliable for CI. Otherwise, we used fixed
|
||||||
|
// delays to deterministically align with subtitles.
|
||||||
|
|
||||||
sleep(DELAY_LONG);
|
sleep(DELAY_LONG);
|
||||||
|
|
||||||
// Enter username
|
// Enter username
|
||||||
@@ -136,7 +144,7 @@ public class PromoVideoTest extends ScreenshotTest {
|
|||||||
sleep(DELAY_SMALL);
|
sleep(DELAY_SMALL);
|
||||||
|
|
||||||
// wait for contact list to be shown
|
// wait for contact list to be shown
|
||||||
if (debug) waitFor(NavDrawerActivity.class);
|
if (!isFilming) waitFor(NavDrawerActivity.class);
|
||||||
|
|
||||||
// clicking the FAB doesn't work, so we click its inner FAB as well
|
// clicking the FAB doesn't work, so we click its inner FAB as well
|
||||||
onView(withId(R.id.speedDial))
|
onView(withId(R.id.speedDial))
|
||||||
@@ -173,11 +181,12 @@ public class PromoVideoTest extends ScreenshotTest {
|
|||||||
sleep(DELAY_SMALL);
|
sleep(DELAY_SMALL);
|
||||||
|
|
||||||
// add pending contact
|
// add pending contact
|
||||||
|
onView(withId(R.id.addButton)).perform(scrollTo());
|
||||||
doClick(withId(R.id.addButton));
|
doClick(withId(R.id.addButton));
|
||||||
sleep(DELAY_LONG);
|
sleep(DELAY_LONG);
|
||||||
|
|
||||||
// wait for pending contact list activity to be shown
|
// wait for pending contact list activity to be shown
|
||||||
if (debug) {
|
if (!isFilming) {
|
||||||
waitFor(PendingContactListActivity.class);
|
waitFor(PendingContactListActivity.class);
|
||||||
waitFor(allOf(withText(R.string.pending_contact_requests),
|
waitFor(allOf(withText(R.string.pending_contact_requests),
|
||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
@@ -197,10 +206,11 @@ public class PromoVideoTest extends ScreenshotTest {
|
|||||||
sleep(DELAY_LONG);
|
sleep(DELAY_LONG);
|
||||||
|
|
||||||
// wait for contact list to be shown
|
// wait for contact list to be shown
|
||||||
if (debug) {
|
if (!isFilming) {
|
||||||
waitFor(NavDrawerActivity.class);
|
waitFor(NavDrawerActivity.class);
|
||||||
waitFor(allOf(withText(R.string.contact_list_button),
|
waitFor(allOf(withText(R.string.contact_list_button),
|
||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
|
waitFor(allOf(withId(R.id.recyclerView), isDisplayed()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// click on new contact
|
// click on new contact
|
||||||
@@ -239,12 +249,12 @@ public class PromoVideoTest extends ScreenshotTest {
|
|||||||
private void doClick(final Matcher<View> viewMatcher, long sleepMs)
|
private void doClick(final Matcher<View> viewMatcher, long sleepMs)
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
doClick(viewMatcher);
|
doClick(viewMatcher);
|
||||||
if (!debug) sleep(sleepMs);
|
if (isFilming) sleep(sleepMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doClick(final Matcher<View> viewMatcher)
|
private void doClick(final Matcher<View> viewMatcher)
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
if (!debug) {
|
if (isFilming) {
|
||||||
onView(viewMatcher)
|
onView(viewMatcher)
|
||||||
.perform(waitUntilMatches(isDisplayed()))
|
.perform(waitUntilMatches(isDisplayed()))
|
||||||
.perform(visualClick(overlayView));
|
.perform(visualClick(overlayView));
|
||||||
@@ -257,7 +267,7 @@ public class PromoVideoTest extends ScreenshotTest {
|
|||||||
|
|
||||||
private void doItemClick(final Matcher<View> viewMatcher, int pos)
|
private void doItemClick(final Matcher<View> viewMatcher, int pos)
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
if (!debug) {
|
if (isFilming) {
|
||||||
onView(viewMatcher).perform(
|
onView(viewMatcher).perform(
|
||||||
actionOnItemAtPosition(pos, visualClick(overlayView)));
|
actionOnItemAtPosition(pos, visualClick(overlayView)));
|
||||||
sleep(500);
|
sleep(500);
|
||||||
@@ -268,7 +278,7 @@ public class PromoVideoTest extends ScreenshotTest {
|
|||||||
|
|
||||||
private void closeKeyboard(final Matcher<View> viewMatcher)
|
private void closeKeyboard(final Matcher<View> viewMatcher)
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
if (!debug) sleep(750);
|
if (isFilming) sleep(750);
|
||||||
onView(viewMatcher).perform(closeSoftKeyboard());
|
onView(viewMatcher).perform(closeSoftKeyboard());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user