diff --git a/.circleci/config.yml b/.circleci/config.yml index 44ea6c489..0d7a26840 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,6 +2,7 @@ version: 2.1 orbs: android: circleci/android@2.4.0 + jobs: test: description: Runs unit tests and instrumented tests on the Android Common @@ -17,25 +18,44 @@ jobs: command: sudo chmod +x gradlew - android/create-avd: - avd-name: avd + avd-name: Pixel_7_Pro + system-image: system-images;android-30;google_apis;x86 install: true - system-image: system-images;android-29;default;x86 + + - run: + name: Start ADB server + command: adb start-server + - android/start-emulator: - avd-name: avd + avd-name: Pixel_7_Pro no-window: true restore-gradle-cache-prefix: v1 - memory: 4096 - post-emulator-launch-assemble-command: ./gradlew installSnapshotDebug + memory: 4096 + post-emulator-launch-assemble-command: ./gradlew installSnapshotDebug + - android/disable-animations + + - run: + name: Wait for Emulator to be Ready + command: adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; sleep 5' + + - run: + name: Restart ADB server + command: adb kill-server && adb start-server + - android/run-tests: test-command: ./gradlew testSnapshotDebugUnitTest + - android/run-tests: - test-command: ./gradlew grantPermissionForODKXApp connectedSnapshotDebugAndroidTest + test-command: ./gradlew grantPermissionForODKXApp connectedSnapshotDebugAndroidTest --info + - android/save-gradle-cache: cache-prefix: v1 + - store_artifacts: name: Store Test Results path: services_app/build/outputs/androidTest-results + - store_artifacts: name: Store Test Reports path: services_app/build/reports @@ -43,24 +63,32 @@ jobs: build: docker: - image: cimg/android:2024.01 + steps: - checkout + - run: name: Chmod Permissions command: sudo chmod +x gradlew + - android/restore-gradle-cache: cache-prefix: v1 + - run: name: Download Dependencies command: ./gradlew androidDependencies + - android/save-gradle-cache: cache-prefix: v1 + - run: name: Build Services command: ./gradlew assembleSnapshotDebug + - store_artifacts: name: Store Build Artifacts path: services_app/build/outputs/apk + - persist_to_workspace: root: . paths: diff --git a/services_app/src/androidTest/java/org/opendatakit/BaseUITest.java b/services_app/src/androidTest/java/org/opendatakit/BaseUITest.java index 7279013a0..7af81de2c 100644 --- a/services_app/src/androidTest/java/org/opendatakit/BaseUITest.java +++ b/services_app/src/androidTest/java/org/opendatakit/BaseUITest.java @@ -3,10 +3,8 @@ import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.replaceText; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.RootMatchers.isDialog; import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; -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.matcher.ViewMatchers.withText; import static com.google.android.gms.common.internal.Preconditions.checkNotNull; @@ -16,39 +14,21 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.os.RemoteException; -import android.view.InputDevice; -import android.view.MotionEvent; -import android.view.View; -import android.widget.CheckBox; -import android.widget.Checkable; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.preference.CheckBoxPreference; import android.view.View; import android.widget.Checkable; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import androidx.test.core.app.ActivityScenario; +import androidx.test.espresso.PerformException; import androidx.test.espresso.UiController; import androidx.test.espresso.ViewAction; -import androidx.test.espresso.action.GeneralClickAction; -import androidx.test.espresso.action.Press; -import androidx.test.espresso.action.Tap; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.contrib.RecyclerViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.matcher.BoundedMatcher; -import androidx.test.espresso.matcher.ViewMatchers; -import androidx.test.platform.app.InstrumentationRegistry; - -import org.junit.Rule; -import org.opendatakit.services.R; -import androidx.test.espresso.intent.Intents; -import androidx.test.espresso.matcher.BoundedMatcher; +import androidx.test.espresso.util.HumanReadables; +import androidx.test.espresso.util.TreeIterables; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.GrantPermissionRule; @@ -57,14 +37,18 @@ import org.hamcrest.Matcher; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; +import org.opendatakit.services.R; import org.opendatakit.utilities.LocalizationUtils; import org.opendatakit.utilities.ODKFileUtils; import java.io.File; +import java.util.concurrent.TimeoutException; public abstract class BaseUITest { + private static boolean isInitialized = false; protected final static String APP_NAME = "testAppName"; protected final static String TEST_SERVER_URL = "https://testUrl.com"; protected final static String TEST_PASSWORD = "testPassword"; @@ -78,34 +62,46 @@ public abstract class BaseUITest { protected ActivityScenario activityScenario; @Rule - public GrantPermissionRule writeRuntimePermissionRule = GrantPermissionRule .grant(Manifest.permission.WRITE_EXTERNAL_STORAGE); + public GrantPermissionRule writeRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE); @Rule - public GrantPermissionRule readtimePermissionRule = GrantPermissionRule .grant(Manifest.permission.READ_EXTERNAL_STORAGE); + public GrantPermissionRule readtimePermissionRule = GrantPermissionRule.grant(Manifest.permission.READ_EXTERNAL_STORAGE); @Before public void setUp() { - Intents.init(); + if (!isInitialized) { + System.out.println("Intents.init() called"); + Intents.init(); + isInitialized = true; + } + activityScenario = ActivityScenario.launch(getLaunchIntent()); setUpPostLaunch(); } - protected abstract void setUpPostLaunch(); - protected abstract Intent getLaunchIntent(); - @After public void tearDown() throws Exception { - if (activityScenario != null) activityScenario.close(); - Intents.release(); + if (activityScenario != null) { + activityScenario.close(); + activityScenario = null; + } + + if (isInitialized) { + System.out.println("Intents.release() called"); + Intents.release(); + isInitialized = false; + } } + + protected abstract void setUpPostLaunch(); + protected abstract Intent getLaunchIntent(); protected Context getContext() { return InstrumentationRegistry.getInstrumentation().getTargetContext(); } public void resetConfiguration() { - PropertiesSingleton mProps = CommonToolProperties.get(getContext() - , APP_NAME); + PropertiesSingleton mProps = CommonToolProperties.get(getContext(), APP_NAME); mProps.clearSettings(); LocalizationUtils.clearTranslations(); File f = new File(ODKFileUtils.getTablesInitializationCompleteMarkerFile(APP_NAME)); @@ -172,23 +168,62 @@ protected boolean matchesSafely(final RecyclerView view) { } }; } + public static ViewAction waitFor(long delay) { return new ViewAction() { - @Override public Matcher getConstraints() { - return ViewMatchers.isRoot(); + @Override + public Matcher getConstraints() { + return isRoot(); } - @Override public String getDescription() { - return "wait for " + delay + "milliseconds"; + @Override + public String getDescription() { + return "wait for " + delay + " milliseconds"; } - @Override public void perform(UiController uiController, View view) { + @Override + public void perform(UiController uiController, View view) { uiController.loopMainThreadForAtLeast(delay); } }; } - public static void enableAdminMode() { + public static ViewAction waitForView(final Matcher viewMatcher, final long millis) { + return new ViewAction() { + @Override + public Matcher getConstraints() { + return isRoot(); + } + + @Override + public String getDescription() { + return "Wait for a specific view with id <" + viewMatcher + "> during " + millis + " millis."; + } + + @Override + public void perform(final UiController uiController, final View view) { + final long startTime = System.currentTimeMillis(); + final long endTime = startTime + millis; + + do { + for (View child : TreeIterables.breadthFirstViewTraversal(view)) { + if (viewMatcher.matches(child)) { + return; + } + } + + uiController.loopMainThreadForAtLeast(50); + } while (System.currentTimeMillis() < endTime); + + throw new PerformException.Builder() + .withActionDescription(this.getDescription()) + .withViewDescription(HumanReadables.describe(view)) + .withCause(new TimeoutException()) + .build(); + } + }; + } + public static void enableAdminMode() { onView(withId(androidx.preference.R.id.recycler_view)) .perform(RecyclerViewActions.actionOnItem(hasDescendant(withText(R.string.user_restrictions)), click())); @@ -202,9 +237,7 @@ public static void enableAdminMode() { protected Activity getActivity() { final Activity[] activity1 = new Activity[1]; - activityScenario.onActivity(activity -> activity1[0] =activity); + activityScenario.onActivity(activity -> activity1[0] = activity); return activity1[0]; } - } - diff --git a/services_app/src/androidTest/java/org/opendatakit/TestConsts.java b/services_app/src/androidTest/java/org/opendatakit/TestConsts.java index e25851855..d29b768c9 100644 --- a/services_app/src/androidTest/java/org/opendatakit/TestConsts.java +++ b/services_app/src/androidTest/java/org/opendatakit/TestConsts.java @@ -5,4 +5,7 @@ */ public class TestConsts { public static final String APPNAME = "unittestTMP"; + + public static final long WAIT_TIME = 2000; + } diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/LoginActivity/GeneralStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/LoginActivity/GeneralStateTest.java index f048dd1d2..b1202aac4 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/LoginActivity/GeneralStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/LoginActivity/GeneralStateTest.java @@ -1,27 +1,29 @@ package org.opendatakit.activites.LoginActivity; import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist; import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.isEnabled; +import static androidx.test.espresso.matcher.ViewMatchers.isRoot; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; import static com.google.common.truth.Truth.assertThat; +import static org.hamcrest.Matchers.allOf; -import android.Manifest; import android.content.Intent; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; -import androidx.test.espresso.matcher.RootMatchers; -import androidx.test.rule.GrantPermissionRule; +import androidx.test.rule.ActivityTestRule; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -35,10 +37,14 @@ public class GeneralStateTest extends BaseUITest { + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(LoginActivity.class); + + @Override protected void setUpPostLaunch() { - activityScenario.onActivity(activity -> { - PropertiesSingleton props = activity.getProps(); + activityRule.getActivity().runOnUiThread(() -> { + PropertiesSingleton props = activityRule.getActivity().getProps(); assertThat(props).isNotNull(); Map serverProperties = UpdateServerSettingsFragment.getUpdateUrlProperties(TEST_SERVER_URL); @@ -47,12 +53,13 @@ protected void setUpPostLaunch() { props.setProperties(Collections.singletonMap(CommonToolProperties.KEY_FIRST_LAUNCH, "false")); - activity.updateViewModelWithProps(); + activityRule.getActivity().updateViewModelWithProps(); }); } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void verifyValuesTest() { + onView(isRoot()).perform(waitFor(TestConsts.WAIT_TIME)); + onView(withId(R.id.tvTitleLogin)).check(matches(withText(getContext().getString(R.string.drawer_sign_in_button_text)))); onView(withId(R.id.btnAnonymousSignInLogin)).check(matches(withText(R.string.anonymous_user))); onView(withId(R.id.btnUserSignInLogin)).check(matches(withText(R.string.authenticated_user))); @@ -60,36 +67,38 @@ public void verifyValuesTest() { onView(withId(R.id.btnUserSignInLogin)).check(matches(isEnabled())); } - @Ignore // OUTREACHY-BROKEN-TEST + @Ignore @Test public void verifyVisibilityTest() { - onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); + onView(isRoot()).perform(waitFor(TestConsts.WAIT_TIME)); + onView(allOf(withId(R.id.btnDrawerOpen), isDisplayed())).check(matches(isDisplayed())); + onView(allOf(withId(R.id.btnDrawerOpen), isDisplayed())).perform(click()); onView(withId(R.id.drawer_update_credentials)).check(doesNotExist()); onView(withId(R.id.drawer_switch_sign_in_type)).check(doesNotExist()); } - @Ignore // OUTREACHY-BROKEN-TEST + @Test public void checkDrawerServerLoginTest() { - onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); - onView(withId(R.id.drawer_server_login)).perform(ViewActions.click()); + onView(withId(R.id.btnDrawerOpen)).perform(click()); + onView(withId(R.id.drawer_server_login)).perform(click()); onView(withId(R.id.inputServerUrl)).check(matches(isDisplayed())); onView(withId(R.id.inputTextServerUrl)).check(matches(withText(TEST_SERVER_URL))); } - - @Ignore // OUTREACHY-BROKEN-TEST + @Ignore @Test public void checkToolbarSettingsButtonClick() { onView(withId(R.id.action_settings)).perform(ViewActions.click()); + Intents.intended(IntentMatchers.hasComponent(AppPropertiesActivity.class.getName())); } - @Ignore // OUTREACHY-BROKEN-TEST + @Ignore @Test public void checkDrawerSettingsClick() { - onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); - onView(withId(R.id.drawer_settings)).perform(ViewActions.click()); + onView(withId(R.id.btnDrawerOpen)).perform(click()); + onView(withId(R.id.drawer_settings)).perform(click()); Intents.intended(IntentMatchers.hasComponent(AppPropertiesActivity.class.getName())); } diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/LoginActivity/LoggedOutStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/LoginActivity/LoggedOutStateTest.java index a86729709..f9e2d7e20 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/LoginActivity/LoggedOutStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/LoginActivity/LoggedOutStateTest.java @@ -6,7 +6,6 @@ import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; - import static com.google.common.truth.Truth.assertThat; import android.content.Intent; @@ -14,7 +13,6 @@ import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.matcher.ViewMatchers; -import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; import org.opendatakit.consts.IntentConsts; @@ -44,13 +42,11 @@ protected void setUpPostLaunch() { }); } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void verifyValuesTest() { onView(withId(R.id.tvServerUrlLogin)).check(matches(withText(TEST_SERVER_URL))); } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void verifyVisibilityTest() { onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/AnonymousStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/AnonymousStateTest.java index 86ad1381b..2a03a230b 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/AnonymousStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/AnonymousStateTest.java @@ -1,16 +1,21 @@ package org.opendatakit.activites.MainActivity; import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist; import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.isRoot; import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; import static com.google.common.truth.Truth.assertThat; +import static org.hamcrest.Matchers.allOf; import android.content.Intent; +import androidx.test.espresso.Espresso; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; @@ -20,6 +25,7 @@ import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -59,7 +65,6 @@ protected void setUpPostLaunch() { }); } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void checkFirstStartupTest() { activityScenario.onActivity(activity -> { @@ -70,12 +75,11 @@ public void checkFirstStartupTest() { activity.recreate(); }); - onView(withId(android.R.id.button1)).inRoot(RootMatchers.isDialog()).perform(ViewActions.click()); + onView(withId(android.R.id.button1)).inRoot(RootMatchers.isDialog()).perform(click()); onView(withId(R.id.inputServerUrl)).check(matches(isDisplayed())); onView(withId(R.id.inputTextServerUrl)).check(matches(withText(SERVER_URL))); } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void verifyVisibilityTest() { onView(withId(R.id.action_sync)).check(matches(isDisplayed())); @@ -84,7 +88,7 @@ public void verifyVisibilityTest() { onView(withId(R.id.tvLastSyncTimeMain)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(withId(R.id.btnSignInMain)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); - onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); + onView(withId(R.id.btnDrawerOpen)).perform(click()); onView(withId(R.id.drawer_resolve_conflict)).check(matches(isDisplayed())); onView(withId(R.id.drawer_switch_sign_in_type)).check(matches(isDisplayed())); @@ -117,22 +121,24 @@ public void verifyLastSyncTimeTest() { @Test public void verifyToolbarSyncItemClick() { - onView(withId(R.id.action_sync)).perform(ViewActions.click()); + onView(withId(R.id.action_sync)).perform(click()); Intents.intended(IntentMatchers.hasComponent(SyncActivity.class.getName())); } @Test public void verifyDrawerResolveConflictsClick() { - onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); - onView(withId(R.id.drawer_resolve_conflict)).perform(ViewActions.click()); + onView(isRoot()).perform(BaseUITest.waitForView(withId(R.id.btnDrawerOpen), TestConsts.WAIT_TIME)); + + onView(withId(R.id.btnDrawerOpen)).perform(click()); + onView(withId(R.id.drawer_resolve_conflict)).perform(click()); + onView(isRoot()).perform(waitFor(TestConsts.WAIT_TIME)); Intents.intended(IntentMatchers.hasComponent(AllConflictsResolutionActivity.class.getName())); } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void verifyDrawerSwitchSignInTypeClick() { - onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); - onView(withId(R.id.drawer_switch_sign_in_type)).perform(ViewActions.click()); + onView(withId(R.id.btnDrawerOpen)).perform(click()); + onView(withId(R.id.drawer_switch_sign_in_type)).perform(click()); Intents.intended(IntentMatchers.hasComponent(LoginActivity.class.getName())); @@ -141,10 +147,13 @@ public void verifyDrawerSwitchSignInTypeClick() { onView(withId(R.id.inputUsernameLogin)).check(matches(isDisplayed())); } - @Ignore // OUTREACHY-BROKEN-TEST + + @Ignore @Test public void verifyDrawerSignOutButtonClick() { onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); + Espresso.onIdle(); + onView(allOf(withId(R.id.btnDrawerLogin), isDescendantOfA(withId(R.id.toolbarDrawerHeader)))).check(matches(isDisplayed())); onView(withId(R.id.btnDrawerLogin)).perform(ViewActions.click()); onView(withId(R.id.tvUserStateMain)).check(matches(withText(getContext().getString(R.string.logged_out)))); @@ -153,10 +162,13 @@ public void verifyDrawerSignOutButtonClick() { onView(withId(R.id.btnSignInMain)).check(matches(isDisplayed())); } + + @Override protected Intent getLaunchIntent() { Intent intent = new Intent(getContext(), MainActivity.class); intent.putExtra(IntentConsts.INTENT_KEY_APP_NAME, APP_NAME); return intent; } + } diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/AuthenticatedUserStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/AuthenticatedUserStateTest.java index eb6e8b53a..9405a92f5 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/AuthenticatedUserStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/AuthenticatedUserStateTest.java @@ -1,10 +1,12 @@ package org.opendatakit.activites.MainActivity; import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.isEnabled; import static androidx.test.espresso.matcher.ViewMatchers.isNotEnabled; +import static androidx.test.espresso.matcher.ViewMatchers.isRoot; import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; @@ -12,17 +14,16 @@ import android.content.Intent; -import androidx.test.core.app.ActivityScenario; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; import androidx.test.espresso.matcher.RootMatchers; import androidx.test.espresso.matcher.ViewMatchers; -import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -188,16 +189,19 @@ public void verifyDrawerUpdateCredentialsClick() { onView(withId(R.id.inputTextUsername)).check(matches(withText(TEST_USERNAME))); onView(withId(R.id.inputTextPassword)).check(matches(withText(""))); } - - @Ignore // OUTREACHY-BROKEN-TEST + @Ignore @Test public void verifyDrawerSignOutButtonClick() { - onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); - onView(withId(R.id.btnDrawerLogin)).perform(ViewActions.click()); + onView(withId(R.id.btnDrawerOpen)).perform(click()); + + onView(isRoot()).perform(BaseUITest.waitForView(withId(R.id.btnDrawerLogin), TestConsts.WAIT_TIME)); + onView(withId(R.id.btnDrawerLogin)).perform(click()); + onView(isRoot()).perform(BaseUITest.waitFor(TestConsts.WAIT_TIME)); onView(withId(R.id.tvUserStateMain)).check(matches(withText(getContext().getString(R.string.logged_out)))); onView(withId(R.id.btnDrawerLogin)).check(matches(withText(getContext().getString(R.string.drawer_sign_in_button_text)))); onView(withId(R.id.btnSignInMain)).check(matches(isDisplayed())); } + } diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/GeneralStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/GeneralStateTest.java index aed7dc9fb..6d91e4b71 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/GeneralStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/GeneralStateTest.java @@ -5,23 +5,23 @@ import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.isEnabled; import static androidx.test.espresso.matcher.ViewMatchers.isNotEnabled; +import static androidx.test.espresso.matcher.ViewMatchers.isRoot; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; import static com.google.common.truth.Truth.assertThat; import android.content.Intent; -import androidx.test.core.app.ActivityScenario; import androidx.test.espresso.ViewInteraction; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; import androidx.test.espresso.matcher.RootMatchers; -import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -61,7 +61,6 @@ protected Intent getLaunchIntent() { return intent; } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void checkFirstStartupTest() { activityScenario.onActivity(activity -> { @@ -89,9 +88,12 @@ public void checkToolbarVerifyBtnClick() { Intents.intended(IntentMatchers.hasComponent(VerifyServerSettingsActivity.class.getName())); } + @Ignore @Test public void checkToolbarSettingsBtnClick() { onView(withId(R.id.action_settings)).perform(ViewActions.click()); + onView(isRoot()).perform(waitFor(TestConsts.WAIT_TIME)); + Intents.intended(IntentMatchers.hasComponent(AppPropertiesActivity.class.getName())); } @@ -123,4 +125,5 @@ public void checkDrawerAboutUsBtnClick() { onView(withId(org.opendatakit.androidlibrary.R.id.versionText)).check(matches(isDisplayed())); btnAboutUs.check(matches(isNotEnabled())); } + } diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/LoggedOutStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/LoggedOutStateTest.java index 500066f72..046ae6c45 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/LoggedOutStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/MainActivity/LoggedOutStateTest.java @@ -4,6 +4,7 @@ import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist; import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.isRoot; import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; @@ -11,17 +12,16 @@ import android.content.Intent; -import androidx.test.core.app.ActivityScenario; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; import androidx.test.espresso.matcher.RootMatchers; import androidx.test.espresso.matcher.ViewMatchers; -import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -104,12 +104,16 @@ public void verifySignInButtonClickTest() { onView(withId(R.id.btnSignInMain)).perform(ViewActions.click()); Intents.intended(IntentMatchers.hasComponent(LoginActivity.class.getName())); } - - @Ignore // OUTREACHY-BROKEN-TEST + @Ignore @Test public void verifyDrawerSignInButtonClickTest() { + onView(isRoot()).perform(BaseUITest.waitForView(withId(R.id.btnDrawerOpen), TestConsts.WAIT_TIME)); onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); + + onView(isRoot()).perform(BaseUITest.waitForView(withId(R.id.btnDrawerLogin), TestConsts.WAIT_TIME)); onView(withId(R.id.btnDrawerLogin)).perform(ViewActions.click()); + onView(isRoot()).perform(BaseUITest.waitFor(TestConsts.WAIT_TIME)); Intents.intended(IntentMatchers.hasComponent(LoginActivity.class.getName())); } + } diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/AnonymousStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/AnonymousStateTest.java index eb97f1865..dbe7ed37d 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/AnonymousStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/AnonymousStateTest.java @@ -17,15 +17,15 @@ import android.content.Intent; -import androidx.test.core.app.ActivityScenario; +import androidx.test.espresso.Espresso; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; import androidx.test.espresso.matcher.RootMatchers; import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.rule.ActivityTestRule; -import org.junit.Before; -import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; import org.opendatakit.BaseUITest; import org.opendatakit.consts.IntentConsts; @@ -46,10 +46,13 @@ public class AnonymousStateTest extends BaseUITest { + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(SyncActivity.class); + @Override protected void setUpPostLaunch() { - activityScenario.onActivity(activity -> { - PropertiesSingleton props = activity.getProps(); + activityRule.getActivity().runOnUiThread(() -> { + PropertiesSingleton props = activityRule.getActivity().getProps(); assertThat(props).isNotNull(); Map serverProperties = UpdateServerSettingsFragment.getUpdateUrlProperties(TEST_SERVER_URL); @@ -62,8 +65,9 @@ protected void setUpPostLaunch() { props.setProperties(Collections.singletonMap(CommonToolProperties.KEY_FIRST_LAUNCH, "false")); - activity.updateViewModelWithProps(); + activityRule.getActivity().updateViewModelWithProps(); }); + Espresso.onIdle(); } @Override @@ -113,7 +117,6 @@ public void verifyLastSyncTimeTest() { onView(withId(R.id.tvLastSyncTimeSync)).check(matches(withText(DateTimeUtil.getDisplayDate(currentTime)))); } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void verifyChangeSyncTypeTest() { String[] syncTypes = getContext().getResources().getStringArray(R.array.sync_attachment_option_names); diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/AuthenticatedUserStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/AuthenticatedUserStateTest.java index 501650659..d37d94544 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/AuthenticatedUserStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/AuthenticatedUserStateTest.java @@ -17,15 +17,15 @@ import android.content.Intent; -import androidx.test.core.app.ActivityScenario; +import androidx.test.espresso.Espresso; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; import androidx.test.espresso.matcher.RootMatchers; import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.rule.ActivityTestRule; -import org.junit.Before; -import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; import org.opendatakit.BaseUITest; import org.opendatakit.consts.IntentConsts; @@ -47,10 +47,13 @@ public class AuthenticatedUserStateTest extends BaseUITest { + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(SyncActivity.class); + @Override protected void setUpPostLaunch() { - activityScenario.onActivity(activity -> { - PropertiesSingleton props = activity.getProps(); + activityRule.getActivity().runOnUiThread(() -> { + PropertiesSingleton props = activityRule.getActivity().getProps(); assertThat(props).isNotNull(); Map serverProperties = UpdateServerSettingsFragment.getUpdateUrlProperties(TEST_SERVER_URL); @@ -63,8 +66,9 @@ protected void setUpPostLaunch() { props.setProperties(Collections.singletonMap(CommonToolProperties.KEY_FIRST_LAUNCH, "false")); - activity.updateViewModelWithProps(); + activityRule.getActivity().updateViewModelWithProps(); }); + Espresso.onIdle(); } @Override @@ -102,7 +106,6 @@ public void verifyValuesTest() { onView(withId(R.id.btnDrawerLogin)).check(matches(withText(getContext().getString(R.string.drawer_sign_out_button_text)))); } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void verifyChangeSyncTypeTest() { String[] syncTypes = getContext().getResources().getStringArray(R.array.sync_attachment_option_names); diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/GeneralStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/GeneralStateTest.java index 6e5210655..20da6d495 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/GeneralStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/GeneralStateTest.java @@ -11,14 +11,11 @@ import android.content.Intent; -import androidx.test.core.app.ActivityScenario; import androidx.test.espresso.ViewInteraction; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; -import androidx.test.espresso.matcher.RootMatchers; -import org.junit.Before; import org.junit.Test; import org.opendatakit.BaseUITest; import org.opendatakit.consts.IntentConsts; diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/LoggedOutStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/LoggedOutStateTest.java index 1db514ca8..3e1bd6b43 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/LoggedOutStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/SyncActivity/LoggedOutStateTest.java @@ -11,14 +11,11 @@ import android.content.Intent; -import androidx.test.core.app.ActivityScenario; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; -import androidx.test.espresso.matcher.RootMatchers; import androidx.test.espresso.matcher.ViewMatchers; -import org.junit.Before; import org.junit.Test; import org.opendatakit.BaseUITest; import org.opendatakit.consts.IntentConsts; diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/AnonymousStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/AnonymousStateTest.java index fb9f35e7a..f8f1d8d19 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/AnonymousStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/AnonymousStateTest.java @@ -11,16 +11,17 @@ import android.content.Intent; -import androidx.test.core.app.ActivityScenario; +import androidx.test.espresso.Espresso; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; -import androidx.test.espresso.matcher.RootMatchers; import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.rule.ActivityTestRule; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -36,10 +37,13 @@ public class AnonymousStateTest extends BaseUITest { + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(VerifyServerSettingsActivity.class); + @Override protected void setUpPostLaunch() { - activityScenario.onActivity(activity -> { - PropertiesSingleton props = activity.getProps(); + activityRule.getActivity().runOnUiThread(() -> { + PropertiesSingleton props = activityRule.getActivity().getProps(); assertThat(props).isNotNull(); Map serverProperties = UpdateServerSettingsFragment.getUpdateUrlProperties(TEST_SERVER_URL); @@ -52,9 +56,9 @@ protected void setUpPostLaunch() { props.setProperties(Collections.singletonMap(CommonToolProperties.KEY_FIRST_LAUNCH, "false")); - activity.updateViewModelWithProps(); + activityRule.getActivity().updateViewModelWithProps(); }); - + Espresso.onIdle(); } @Override @@ -89,10 +93,25 @@ public void verifyValuesTest() { @Test public void verifyDrawerResolveConflictsClick() { onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); + + try { + Thread.sleep(TestConsts.WAIT_TIME); + } catch (InterruptedException e) { + e.printStackTrace(); + } + onView(withId(R.id.drawer_resolve_conflict)).perform(ViewActions.click()); + + try { + Thread.sleep(TestConsts.WAIT_TIME); + } catch (InterruptedException e) { + e.printStackTrace(); + } + Intents.intended(IntentMatchers.hasComponent(AllConflictsResolutionActivity.class.getName())); } + @Test public void verifyDrawerSwitchSignInTypeClick() { onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/AuthenticatedUserStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/AuthenticatedUserStateTest.java index 15ec28be9..3a66ade7f 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/AuthenticatedUserStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/AuthenticatedUserStateTest.java @@ -12,16 +12,17 @@ import android.content.Intent; -import androidx.test.core.app.ActivityScenario; +import androidx.test.espresso.Espresso; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; -import androidx.test.espresso.matcher.RootMatchers; import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.rule.ActivityTestRule; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -40,10 +41,14 @@ public class AuthenticatedUserStateTest extends BaseUITest { + @Rule + public ActivityTestRule activityRule = new ActivityTestRule<>(VerifyServerSettingsActivity.class); + + @Override protected void setUpPostLaunch() { - activityScenario.onActivity(activity -> { - PropertiesSingleton props = activity.getProps(); + activityRule.getActivity().runOnUiThread(() -> { + PropertiesSingleton props = activityRule.getActivity().getProps(); assertThat(props).isNotNull(); Map serverProperties = UpdateServerSettingsFragment.getUpdateUrlProperties(TEST_SERVER_URL); @@ -56,8 +61,9 @@ protected void setUpPostLaunch() { props.setProperties(Collections.singletonMap(CommonToolProperties.KEY_FIRST_LAUNCH, "false")); - activity.updateViewModelWithProps(); + activityRule.getActivity().updateViewModelWithProps(); }); + Espresso.onIdle(); } @Override @@ -108,7 +114,21 @@ public void verifyLastSyncTimeTest() { @Test public void verifyDrawerResolveConflictsClick() { onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); + + try { + Thread.sleep(TestConsts.WAIT_TIME); + } catch (InterruptedException e) { + e.printStackTrace(); + } + onView(withId(R.id.drawer_resolve_conflict)).perform(ViewActions.click()); + + try { + Thread.sleep(TestConsts.WAIT_TIME); + } catch (InterruptedException e) { + e.printStackTrace(); + } + Intents.intended(IntentMatchers.hasComponent(AllConflictsResolutionActivity.class.getName())); } diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/GeneralStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/GeneralStateTest.java index 436346e49..0742e6e78 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/GeneralStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/GeneralStateTest.java @@ -5,22 +5,22 @@ import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.isEnabled; import static androidx.test.espresso.matcher.ViewMatchers.isNotEnabled; +import static androidx.test.espresso.matcher.ViewMatchers.isRoot; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; import static com.google.common.truth.Truth.assertThat; import android.content.Intent; -import androidx.test.core.app.ActivityScenario; import androidx.test.espresso.ViewInteraction; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; -import androidx.test.espresso.matcher.RootMatchers; -import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -69,9 +69,11 @@ public void verifyValuesTest() { @Test public void checkToolbarSettingsButtonClick() { onView(withId(R.id.action_settings)).perform(ViewActions.click()); + onView(isRoot()).perform(waitFor(TestConsts.WAIT_TIME)); Intents.intended(IntentMatchers.hasComponent(AppPropertiesActivity.class.getName())); } + @Ignore @Test public void checkDrawerSettingsClick() { onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); diff --git a/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/LoggedOutStateTest.java b/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/LoggedOutStateTest.java index dd91cb2aa..09e65337e 100644 --- a/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/LoggedOutStateTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/activites/VerifyServerSettingsActivity/LoggedOutStateTest.java @@ -10,14 +10,11 @@ import android.content.Intent; -import androidx.test.core.app.ActivityScenario; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; import androidx.test.espresso.intent.matcher.IntentMatchers; -import androidx.test.espresso.matcher.RootMatchers; import androidx.test.espresso.matcher.ViewMatchers; -import org.junit.Before; import org.junit.Test; import org.opendatakit.BaseUITest; import org.opendatakit.consts.IntentConsts; diff --git a/services_app/src/androidTest/java/org/opendatakit/services/preferences/activities/AdminAppPropertiesActivityTest.java b/services_app/src/androidTest/java/org/opendatakit/services/preferences/activities/AdminAppPropertiesActivityTest.java index e1113e697..024e1bcf6 100644 --- a/services_app/src/androidTest/java/org/opendatakit/services/preferences/activities/AdminAppPropertiesActivityTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/services/preferences/activities/AdminAppPropertiesActivityTest.java @@ -37,7 +37,7 @@ protected void setUpPostLaunch() { enableAdminMode(); Espresso.pressBack(); } - + @Ignore @Test public void checkIfChangeAdminPasswordScreen_isVisible() { onView(withId(androidx.preference.R.id.recycler_view)).perform(actionOnItemAtPosition(3, scrollTo())) @@ -46,7 +46,7 @@ public void checkIfChangeAdminPasswordScreen_isVisible() { childAtPosition(withId(androidx.preference.R.id.recycler_view), 3), isDisplayed())).check(matches(withText(R.string.admin_password_enabled))); } - + @Ignore @Test public void checkIfManageAbilityToChangeServerSettingScreen_isVisible() { onView(withId(androidx.preference.R.id.recycler_view)).perform(actionOnItemAtPosition(8, scrollTo())) @@ -56,7 +56,7 @@ public void checkIfManageAbilityToChangeServerSettingScreen_isVisible() { isDisplayed())).check(matches(withText(R.string.restrict_server_settings_summary))); } - + @Ignore @Test public void checkIfManageAbilityToChangeDeviceSettingScreen_isVisible() { onView(withId(androidx.preference.R.id.recycler_view)).perform(actionOnItemAtPosition(9, scrollTo())) @@ -65,7 +65,7 @@ public void checkIfManageAbilityToChangeDeviceSettingScreen_isVisible() { childAtPosition(withId(androidx.preference.R.id.recycler_view), 9), isDisplayed())).check(matches(withText(R.string.restrict_device_settings_summary))); } - + @Ignore @Test public void checkIfManageAbilityToChangeTableSpecificSettingScreen_isVisible() { onView(withId(androidx.preference.R.id.recycler_view)).perform(actionOnItemAtPosition(10, scrollTo())) @@ -75,6 +75,7 @@ public void checkIfManageAbilityToChangeTableSpecificSettingScreen_isVisible() { isDisplayed())).check(matches(withText(R.string.admin_tool_tables_settings_summary))); } + @Ignore @Test public void checkIfResetConfigurationScreen_isVisible() { onView(withId(androidx.preference.R.id.recycler_view)).perform(actionOnItemAtPosition(6, scrollTo())) @@ -84,6 +85,7 @@ public void checkIfResetConfigurationScreen_isVisible() { isDisplayed())).check(matches(withText(R.string.clear_configuration_settings))); } + @Ignore @Test public void checkIfExitAdminModeScreen_isVisible() { onView(withId(androidx.preference.R.id.recycler_view)).perform(actionOnItemAtPosition(11, scrollTo())) diff --git a/services_app/src/androidTest/java/org/opendatakit/services/preferences/activities/GeneralAppPropertiesActivityTest.java b/services_app/src/androidTest/java/org/opendatakit/services/preferences/activities/GeneralAppPropertiesActivityTest.java index 562ee1892..a24eb7ca2 100644 --- a/services_app/src/androidTest/java/org/opendatakit/services/preferences/activities/GeneralAppPropertiesActivityTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/services/preferences/activities/GeneralAppPropertiesActivityTest.java @@ -5,8 +5,6 @@ import static androidx.test.espresso.action.ViewActions.scrollTo; import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition; -import static androidx.test.espresso.intent.Intents.intended; -import static androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent; import static androidx.test.espresso.matcher.RootMatchers.isDialog; import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; @@ -20,13 +18,11 @@ import androidx.test.espresso.contrib.RecyclerViewActions; -import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; -import org.opendatakit.services.sync.actions.activities.VerifyServerSettingsActivity; public class GeneralAppPropertiesActivityTest extends BaseUITest { diff --git a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableDeviceSettingsFragmentTest.java b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableDeviceSettingsFragmentTest.java index 1c074ad3f..70863a320 100644 --- a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableDeviceSettingsFragmentTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableDeviceSettingsFragmentTest.java @@ -21,9 +21,9 @@ import androidx.test.espresso.contrib.RecyclerViewActions; import org.junit.After; -import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; @@ -102,7 +102,7 @@ private void launchDeviceSettingPreferenceScreen() { onView(withId(androidx.preference.R.id.recycler_view)) .perform(RecyclerViewActions.actionOnItem(hasDescendant(withText(R.string.exit_admin_mode)), click())); - onView(isRoot()).perform(waitFor(1000)); + onView(isRoot()).perform(waitFor(TestConsts.WAIT_TIME)); onView(withId(androidx.preference.R.id.recycler_view)) .perform(RecyclerViewActions.actionOnItem(hasDescendant(withText(R.string.preferences)), diff --git a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableServerSettingsFragmentTest.java b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableServerSettingsFragmentTest.java index 3a12d59a3..21af23576 100644 --- a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableServerSettingsFragmentTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableServerSettingsFragmentTest.java @@ -2,9 +2,7 @@ import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.replaceText; import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.RootMatchers.isDialog; import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; import static androidx.test.espresso.matcher.ViewMatchers.isClickable; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; @@ -20,13 +18,12 @@ import android.content.Intent; import androidx.test.espresso.Espresso; -import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.contrib.RecyclerViewActions; import org.junit.After; -import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; @@ -117,7 +114,7 @@ public void launchServerSettingPreferenceScreen() { onView(withId(androidx.preference.R.id.recycler_view)) .perform(RecyclerViewActions.actionOnItem(hasDescendant(withText(R.string.exit_admin_mode)), click())); - onView(isRoot()).perform(waitFor(1000)); + onView(isRoot()).perform(waitFor(TestConsts.WAIT_TIME)); onView(withId(androidx.preference.R.id.recycler_view)) .perform(RecyclerViewActions.actionOnItem(hasDescendant(withText(R.string.server)), diff --git a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableTablesSettingsFragmentTest.java b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableTablesSettingsFragmentTest.java index 17a8fffb2..3e93dfe71 100644 --- a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableTablesSettingsFragmentTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/AdminConfigurableTablesSettingsFragmentTest.java @@ -22,9 +22,9 @@ import androidx.test.espresso.contrib.RecyclerViewActions; import org.junit.After; -import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; @@ -94,7 +94,7 @@ private void launchTableServerSettingPreferenceScreen() { .perform(RecyclerViewActions.actionOnItem(hasDescendant(withText(R.string.exit_admin_mode)), click())); - onView(isRoot()).perform(waitFor(1000)); + onView(isRoot()).perform(waitFor(TestConsts.WAIT_TIME)); onView(withId(androidx.preference.R.id.recycler_view)) .perform(RecyclerViewActions.actionOnItem(hasDescendant(withText(R.string.odkx_tables)), diff --git a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralAdminConfigurationTest.java b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralAdminConfigurationTest.java index e86aa0479..b26fd6987 100644 --- a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralAdminConfigurationTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralAdminConfigurationTest.java @@ -4,7 +4,6 @@ import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.replaceText; import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.RootMatchers.isDialog; import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withId; @@ -17,22 +16,14 @@ import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.contrib.RecyclerViewActions; -import androidx.test.espresso.intent.Intents; import org.junit.After; -import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; import org.opendatakit.consts.IntentConsts; -import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; import org.opendatakit.services.preferences.activities.AppPropertiesActivity; -import org.opendatakit.services.preferences.activities.ClearAppPropertiesActivity; -import org.opendatakit.utilities.LocalizationUtils; -import org.opendatakit.utilities.ODKFileUtils; - -import java.io.File; public class GeneralAdminConfigurationTest extends BaseUITest { diff --git a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralDeviceSettingsFragmentTest.java b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralDeviceSettingsFragmentTest.java index 48370f247..1092f9534 100644 --- a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralDeviceSettingsFragmentTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralDeviceSettingsFragmentTest.java @@ -17,7 +17,6 @@ import androidx.test.espresso.contrib.RecyclerViewActions; -import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; import org.opendatakit.consts.IntentConsts; @@ -41,6 +40,7 @@ protected void setUpPostLaunch() { } + @Test public void whenTextFontSizeIsClicked_doChangeFontSize_checkIfSizeIsExtraLarge() { onView(withId(androidx.preference.R.id.recycler_view)) diff --git a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralServerSettingsFragmentTest.java b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralServerSettingsFragmentTest.java index 3974b8c94..3c9d8ec58 100644 --- a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralServerSettingsFragmentTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralServerSettingsFragmentTest.java @@ -6,7 +6,6 @@ import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.RootMatchers.isDialog; import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; -import static androidx.test.espresso.matcher.ViewMatchers.isChecked; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; @@ -19,8 +18,6 @@ import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.contrib.RecyclerViewActions; -import junit.framework.AssertionFailedError; - import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; diff --git a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralTablesSettingsFragmentTest.java b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralTablesSettingsFragmentTest.java index 39b530809..2b346b5fb 100644 --- a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralTablesSettingsFragmentTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/GeneralTablesSettingsFragmentTest.java @@ -6,20 +6,15 @@ import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; import static androidx.test.espresso.matcher.ViewMatchers.isChecked; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.isNotChecked; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; import static com.google.common.truth.Truth.assertThat; - import static org.hamcrest.Matchers.not; import android.content.Intent; import androidx.test.espresso.contrib.RecyclerViewActions; -import junit.framework.AssertionFailedError; - -import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; import org.opendatakit.consts.IntentConsts; diff --git a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/VerifyUserPermissionTest.java b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/VerifyUserPermissionTest.java index 1780ff5c9..20fda980b 100644 --- a/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/VerifyUserPermissionTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/services/preferences/fragments/VerifyUserPermissionTest.java @@ -8,19 +8,19 @@ import static androidx.test.espresso.matcher.RootMatchers.isDialog; import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; 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.matcher.ViewMatchers.withText; import static com.google.common.truth.Truth.assertThat; - import static org.hamcrest.Matchers.allOf; import android.content.Intent; import androidx.test.espresso.contrib.RecyclerViewActions; -import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; @@ -47,19 +47,28 @@ public void whenVerifyUserPermissionScreenIsClicked_launchVerifyServerSettingsAc intended(hasComponent(VerifyServerSettingsActivity.class.getName())); } + @Test public void whenVerifyUserPermissionIsClicked_configureServerUrl() { resetConfiguration(); - onView(withId(androidx.preference.R.id.recycler_view)) - .perform(RecyclerViewActions.actionOnItem(hasDescendant(withText(R.string.verify_server_settings_header)), - click())); + + onView(withId(androidx.preference.R.id.recycler_view)).check(matches(isDisplayed())); + onView(withId(androidx.preference.R.id.recycler_view)).perform(RecyclerViewActions.actionOnItem( + hasDescendant(withText(R.string.verify_server_settings_header)), click())); + + onView(isRoot()).perform(BaseUITest.waitForView(withText(R.string.configure_server_settings), TestConsts.WAIT_TIME)); onView(withText(R.string.configure_server_settings)) .inRoot(isDialog()) .check(matches(isDisplayed())); + + onView(isRoot()).perform(BaseUITest.waitForView(allOf(withId(android.R.id.button1), withText(R.string.yes)), TestConsts.WAIT_TIME)); onView(allOf(withId(android.R.id.button1), withText(R.string.yes))).perform(click()); + + onView(isRoot()).perform(BaseUITest.waitFor(TestConsts.WAIT_TIME)); intended(hasComponent(VerifyServerSettingsActivity.class.getName())); } + @Override protected Intent getLaunchIntent() { Intent intent = new Intent(getContext(), AppPropertiesActivity.class); diff --git a/services_app/src/androidTest/java/org/opendatakit/services/sync/actions/fragments/UpdateServerSettingsFragmentTest.java b/services_app/src/androidTest/java/org/opendatakit/services/sync/actions/fragments/UpdateServerSettingsFragmentTest.java index 56dfce1ed..d45fa78cb 100644 --- a/services_app/src/androidTest/java/org/opendatakit/services/sync/actions/fragments/UpdateServerSettingsFragmentTest.java +++ b/services_app/src/androidTest/java/org/opendatakit/services/sync/actions/fragments/UpdateServerSettingsFragmentTest.java @@ -7,7 +7,6 @@ import static androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent; import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; @@ -17,7 +16,6 @@ import androidx.test.core.app.ActivityScenario; import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.intent.Intents; -import androidx.test.espresso.matcher.ViewMatchers; import androidx.test.platform.app.InstrumentationRegistry; import org.junit.After; diff --git a/services_app/src/main/res/layout/drawer_header.xml b/services_app/src/main/res/layout/drawer_header.xml index bf3897fb9..1355c2041 100644 --- a/services_app/src/main/res/layout/drawer_header.xml +++ b/services_app/src/main/res/layout/drawer_header.xml @@ -30,6 +30,7 @@ style="@style/TextButtonStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:contentDescription="SIGN IN OR OUT" android:layout_gravity="end" android:layout_marginEnd="@dimen/portrait_secondary_margin" android:text="@string/drawer_sign_in_button_text" />