diff --git a/.circleci/config.yml b/.circleci/config.yml index 44ea6c489..72001ab28 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 @@ -19,23 +20,42 @@ jobs: - android/create-avd: avd-name: avd install: true - system-image: system-images;android-29;default;x86 + system-image: system-images;android-30;google_apis;x86 + + - run: + name: Start ADB server + command: adb start-server + - android/start-emulator: - avd-name: avd - no-window: true - restore-gradle-cache-prefix: v1 - memory: 4096 - post-emulator-launch-assemble-command: ./gradlew installSnapshotDebug + avd-name: avd + no-window: true + restore-gradle-cache-prefix: v1 + 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' # Ensures the emulator is fully booted + + - run: + name: Restart ADB server + command: adb kill-server && adb start-server # Restart ADB server to avoid version mismatch issues + - 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/build.gradle b/services_app/build.gradle index cbd1dff9e..49b5f84d3 100644 --- a/services_app/build.gradle +++ b/services_app/build.gradle @@ -150,6 +150,7 @@ dependencies { androidTestImplementation 'androidx.annotation:annotation:1.7.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation 'androidx.test.espresso:espresso-intents:3.5.1' + androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.5.1' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'org.mockito:mockito-core:2.19.0' androidTestImplementation 'com.google.truth:truth:1.1.3' diff --git a/services_app/src/androidTest/java/org/opendatakit/BaseUITest.java b/services_app/src/androidTest/java/org/opendatakit/BaseUITest.java index 7279013a0..99f869ead 100644 --- a/services_app/src/androidTest/java/org/opendatakit/BaseUITest.java +++ b/services_app/src/androidTest/java/org/opendatakit/BaseUITest.java @@ -7,6 +7,7 @@ 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; @@ -27,12 +28,9 @@ 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; @@ -43,6 +41,8 @@ import androidx.test.espresso.intent.Intents; import androidx.test.espresso.matcher.BoundedMatcher; import androidx.test.espresso.matcher.ViewMatchers; +import androidx.test.espresso.util.HumanReadables; +import androidx.test.espresso.util.TreeIterables; import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Rule; @@ -63,8 +63,10 @@ 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 +80,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)); @@ -113,6 +127,7 @@ public void resetConfiguration() { f.delete(); } ODKFileUtils.clearConfiguredToolFiles(APP_NAME); + } public static ViewAction setChecked(final boolean checked) { @@ -172,23 +187,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 +256,8 @@ 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/IdlingResource.java b/services_app/src/androidTest/java/org/opendatakit/IdlingResource.java new file mode 100644 index 000000000..f50af0d96 --- /dev/null +++ b/services_app/src/androidTest/java/org/opendatakit/IdlingResource.java @@ -0,0 +1,26 @@ +package org.opendatakit; + +import androidx.test.espresso.idling.CountingIdlingResource; + + +public class IdlingResource { + + private static final String RESOURCE = "GLOBAL"; + private static final CountingIdlingResource countingIdlingResource = + new CountingIdlingResource(RESOURCE); + + public static void increment() { + countingIdlingResource.increment(); + } + + public static void decrement() { + if (!countingIdlingResource.isIdleNow()) { + countingIdlingResource.decrement(); + } + } + + public static CountingIdlingResource getIdlingResource() { + return countingIdlingResource; + } +} + 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..d4007e33a 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,36 @@ 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.Espresso; +import androidx.test.espresso.IdlingRegistry; 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.ActivityTestRule; import androidx.test.rule.GrantPermissionRule; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -35,10 +44,15 @@ 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(() -> { + IdlingResource.increment(); + PropertiesSingleton props = activityRule.getActivity().getProps(); assertThat(props).isNotNull(); Map serverProperties = UpdateServerSettingsFragment.getUpdateUrlProperties(TEST_SERVER_URL); @@ -47,49 +61,61 @@ protected void setUpPostLaunch() { props.setProperties(Collections.singletonMap(CommonToolProperties.KEY_FIRST_LAUNCH, "false")); - activity.updateViewModelWithProps(); + activityRule.getActivity().updateViewModelWithProps(); + IdlingResource.decrement(); }); } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void verifyValuesTest() { + IdlingRegistry.getInstance().register(IdlingResource.getIdlingResource()); + 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))); onView(withId(R.id.btnAnonymousSignInLogin)).check(matches(isEnabled())); onView(withId(R.id.btnUserSignInLogin)).check(matches(isEnabled())); + IdlingRegistry.getInstance().unregister(IdlingResource.getIdlingResource()); + } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void verifyVisibilityTest() { - onView(withId(R.id.btnDrawerOpen)).perform(ViewActions.click()); + IdlingRegistry.getInstance().register(IdlingResource.getIdlingResource()); + + 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()); + IdlingRegistry.getInstance().unregister(IdlingResource.getIdlingResource()); + } - @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 @Test public void checkToolbarSettingsButtonClick() { + IdlingRegistry.getInstance().register(IdlingResource.getIdlingResource()); + onView(isRoot()).perform(waitFor(TestConsts.WAIT_TIME)); + onView(withId(R.id.action_settings)).perform(ViewActions.click()); + Intents.intended(IntentMatchers.hasComponent(AppPropertiesActivity.class.getName())); + IdlingRegistry.getInstance().unregister(IdlingResource.getIdlingResource()); + } - @Ignore // OUTREACHY-BROKEN-TEST @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())); } @@ -99,4 +125,4 @@ protected Intent getLaunchIntent() { intent.putExtra(IntentConsts.INTENT_KEY_APP_NAME, APP_NAME); return intent; } -} +} \ No newline at end of file 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..4a1b59490 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 @@ -17,6 +17,7 @@ import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.IdlingResource; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -31,6 +32,7 @@ public class LoggedOutStateTest extends BaseUITest { @Override protected void setUpPostLaunch() { activityScenario.onActivity(activity -> { + IdlingResource.increment(); PropertiesSingleton props = activity.getProps(); assertThat(props).isNotNull(); @@ -41,16 +43,15 @@ protected void setUpPostLaunch() { props.setProperties(Collections.singletonMap(CommonToolProperties.KEY_FIRST_LAUNCH, "false")); activity.updateViewModelWithProps(); + IdlingResource.decrement(); }); } - @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..947a5decf 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,8 @@ import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -59,7 +66,6 @@ protected void setUpPostLaunch() { }); } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void checkFirstStartupTest() { activityScenario.onActivity(activity -> { @@ -70,12 +76,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 +89,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 +122,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 +148,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 +163,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; } -} + +} \ No newline at end of file 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..32dc012ba 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,17 @@ 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.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -188,16 +190,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())); } -} + +} \ No newline at end of file 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..304274e92 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,24 @@ 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.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -61,7 +62,6 @@ protected Intent getLaunchIntent() { return intent; } - @Ignore // OUTREACHY-BROKEN-TEST @Test public void checkFirstStartupTest() { activityScenario.onActivity(activity -> { @@ -89,9 +89,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 +126,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..457f1538f 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,17 @@ 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.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -104,12 +105,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..dc3f43966 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,17 +17,18 @@ 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.IdlingResource; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -46,10 +47,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 +66,9 @@ protected void setUpPostLaunch() { props.setProperties(Collections.singletonMap(CommonToolProperties.KEY_FIRST_LAUNCH, "false")); - activity.updateViewModelWithProps(); + activityRule.getActivity().updateViewModelWithProps(); }); + Espresso.onIdle(); } @Override @@ -113,7 +118,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..85edbe305 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,17 +17,18 @@ 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.IdlingResource; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -47,10 +48,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 +67,9 @@ protected void setUpPostLaunch() { props.setProperties(Collections.singletonMap(CommonToolProperties.KEY_FIRST_LAUNCH, "false")); - activity.updateViewModelWithProps(); + activityRule.getActivity().updateViewModelWithProps(); }); + Espresso.onIdle(); } @Override @@ -102,7 +107,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..6d6539d87 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,16 +11,14 @@ 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.IdlingResource; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; 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..0f8ac10ca 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,16 +11,14 @@ 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.IdlingResource; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; 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..bfe41e97b 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,18 @@ 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.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -36,10 +38,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 +57,9 @@ protected void setUpPostLaunch() { props.setProperties(Collections.singletonMap(CommonToolProperties.KEY_FIRST_LAUNCH, "false")); - activity.updateViewModelWithProps(); + activityRule.getActivity().updateViewModelWithProps(); }); - + Espresso.onIdle(); } @Override @@ -89,10 +94,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..58584fbc5 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,18 @@ 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.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -40,10 +42,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 +62,9 @@ protected void setUpPostLaunch() { props.setProperties(Collections.singletonMap(CommonToolProperties.KEY_FIRST_LAUNCH, "false")); - activity.updateViewModelWithProps(); + activityRule.getActivity().updateViewModelWithProps(); }); + Espresso.onIdle(); } @Override @@ -108,7 +115,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..9901cb858 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,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.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; @@ -69,9 +70,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..1f1b993c0 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,16 +10,14 @@ 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.IdlingResource; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.CommonToolProperties; import org.opendatakit.properties.PropertiesSingleton; 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..4b53fe2e0 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 @@ -4,27 +4,30 @@ 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.contrib.RecyclerViewActions.scrollToPosition; import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; 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 static org.opendatakit.utilities.ViewMatchers.childAtPosition; import android.content.Intent; import androidx.test.espresso.Espresso; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.After; import org.junit.Ignore; import org.junit.Test; +import org.junit.runner.RunWith; import org.opendatakit.BaseUITest; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; +@RunWith(AndroidJUnit4.class) public class AdminAppPropertiesActivityTest extends BaseUITest { @Override @@ -40,36 +43,46 @@ protected void setUpPostLaunch() { @Test public void checkIfChangeAdminPasswordScreen_isVisible() { - onView(withId(androidx.preference.R.id.recycler_view)).perform(actionOnItemAtPosition(3, scrollTo())) - .check(matches(atPosition(3, hasDescendant(withText(R.string.change_admin_password))))); + onView(withId(androidx.preference.R.id.recycler_view)) + .perform(scrollToPosition(3)) + .perform(actionOnItemAtPosition(3, scrollTo())) + .check(matches(hasDescendant(withText(R.string.change_admin_password)))); onView(allOf(withId(android.R.id.summary), 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())) - .check(matches(atPosition(8, hasDescendant(withText(R.string.restrict_server))))); + onView(withId(androidx.preference.R.id.recycler_view)) + .perform(scrollToPosition(8)) + .perform(actionOnItemAtPosition(8, scrollTo())) + .check(matches(hasDescendant(withText(R.string.restrict_server)))); onView(allOf(withId(android.R.id.summary), childAtPosition(withId(androidx.preference.R.id.recycler_view), 8), 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())) - .check(matches(atPosition(9, hasDescendant(withText(R.string.restrict_device))))); + onView(withId(androidx.preference.R.id.recycler_view)) + .perform(scrollToPosition(9)) + .perform(actionOnItemAtPosition(9, scrollTo())) + .check(matches(hasDescendant(withText(R.string.restrict_device)))); onView(allOf(withId(android.R.id.summary), 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())) - .check(matches(atPosition(10, hasDescendant(withText(R.string.admin_tool_tables_settings))))); + onView(withId(androidx.preference.R.id.recycler_view)) + .perform(scrollToPosition(10)) + .perform(actionOnItemAtPosition(10, scrollTo())) + .check(matches(hasDescendant(withText(R.string.admin_tool_tables_settings)))); onView(allOf(withId(android.R.id.summary), childAtPosition(withId(androidx.preference.R.id.recycler_view), 10), isDisplayed())).check(matches(withText(R.string.admin_tool_tables_settings_summary))); @@ -77,8 +90,10 @@ public void checkIfManageAbilityToChangeTableSpecificSettingScreen_isVisible() { @Test public void checkIfResetConfigurationScreen_isVisible() { - onView(withId(androidx.preference.R.id.recycler_view)).perform(actionOnItemAtPosition(6, scrollTo())) - .check(matches(atPosition(6, hasDescendant(withText(R.string.clear_settings))))); + onView(withId(androidx.preference.R.id.recycler_view)) + .perform(scrollToPosition(6)) + .perform(actionOnItemAtPosition(6, scrollTo())) + .check(matches(hasDescendant(withText(R.string.clear_settings)))); onView(allOf(withId(android.R.id.summary), childAtPosition(withId(androidx.preference.R.id.recycler_view), 6), isDisplayed())).check(matches(withText(R.string.clear_configuration_settings))); @@ -86,21 +101,25 @@ public void checkIfResetConfigurationScreen_isVisible() { @Test public void checkIfExitAdminModeScreen_isVisible() { - onView(withId(androidx.preference.R.id.recycler_view)).perform(actionOnItemAtPosition(11, scrollTo())) - .check(matches(atPosition(11, hasDescendant(withText(R.string.exit_admin_mode))))); + onView(withId(androidx.preference.R.id.recycler_view)) + .perform(scrollToPosition(11)) + .perform(actionOnItemAtPosition(11, scrollTo())) + .check(matches(hasDescendant(withText(R.string.exit_admin_mode)))); } @Test public void checkIfVerifyUserPermissionScreen_isVisible() { - onView(withId(androidx.preference.R.id.recycler_view)).perform(actionOnItemAtPosition(2, scrollTo())) - .check(matches(atPosition(2, hasDescendant(withText(R.string.verify_server_settings_header))))); + onView(withId(androidx.preference.R.id.recycler_view)) + .perform(scrollToPosition(2)) + .perform(actionOnItemAtPosition(2, scrollTo())) + .check(matches(hasDescendant(withText(R.string.verify_server_settings_header)))); onView(allOf(withId(android.R.id.summary), childAtPosition(withId(androidx.preference.R.id.recycler_view), 2), isDisplayed())).check(matches(withText(R.string.click_to_verify_server_settings))); } @After - public void after() { + public void tearDown() { resetConfiguration(); } @@ -111,5 +130,4 @@ protected Intent getLaunchIntent() { intent.putExtra(IntentConsts.INTENT_KEY_SETTINGS_IN_ADMIN_MODE, true); return intent; } - -} \ No newline at end of file +} 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..afaa70d6f 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,21 +18,22 @@ import androidx.test.espresso.contrib.RecyclerViewActions; -import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.IdlingResource; 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 { @Override protected void setUpPostLaunch() { activityScenario.onActivity(activity -> { + IdlingResource.increment(); PropertiesSingleton props = activity.getProps(); assertThat(props).isNotNull(); + IdlingResource.decrement(); }); onView(withId(R.id.app_properties_content)).check(matches(isDisplayed())); 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..c7e6e8bbc 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,10 @@ 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.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; @@ -36,6 +37,7 @@ protected void setUpPostLaunch() { activityScenario.onActivity(activity -> { PropertiesSingleton props = activity.getProps(); assertThat(props).isNotNull(); + IdlingResource.decrement(); }); enableAdminMode(); Espresso.pressBack(); @@ -102,7 +104,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..3155952fe 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,13 @@ 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.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; @@ -39,6 +37,7 @@ protected void setUpPostLaunch() { activityScenario.onActivity(activity -> { PropertiesSingleton props = activity.getProps(); assertThat(props).isNotNull(); + IdlingResource.decrement(); }); enableAdminMode(); Espresso.pressBack(); @@ -117,7 +116,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..14e123203 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,10 @@ 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.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; @@ -37,6 +38,7 @@ protected void setUpPostLaunch() { activityScenario.onActivity(activity -> { PropertiesSingleton props = activity.getProps(); assertThat(props).isNotNull(); + IdlingResource.decrement(); }); enableAdminMode(); Espresso.pressBack(); @@ -94,7 +96,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..17e9c5055 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,15 @@ 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.IdlingResource; 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 { @@ -41,6 +33,7 @@ protected void setUpPostLaunch() { activityScenario.onActivity(activity -> { PropertiesSingleton props = activity.getProps(); assertThat(props).isNotNull(); + IdlingResource.decrement(); }); onView(withId(R.id.app_properties_content)).check(matches(isDisplayed())); 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..1f571e1fb 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,9 +17,9 @@ import androidx.test.espresso.contrib.RecyclerViewActions; -import org.junit.Ignore; import org.junit.Test; import org.opendatakit.BaseUITest; +import org.opendatakit.IdlingResource; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; @@ -32,6 +32,7 @@ protected void setUpPostLaunch() { activityScenario.onActivity(activity -> { PropertiesSingleton props = activity.getProps(); assertThat(props).isNotNull(); + IdlingResource.decrement(); }); onView(withId(R.id.app_properties_content)).check(matches(isDisplayed())); @@ -41,6 +42,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..212fc75b2 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,11 +18,10 @@ 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; +import org.opendatakit.IdlingResource; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; @@ -36,6 +34,7 @@ protected void setUpPostLaunch() { activityScenario.onActivity(activity -> { PropertiesSingleton props = activity.getProps(); assertThat(props).isNotNull(); + IdlingResource.decrement(); }); onView(withId(R.id.app_properties_content)).check(matches(isDisplayed())); 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..1f1050a2a 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,22 +6,18 @@ 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.IdlingResource; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; @@ -34,6 +30,7 @@ protected void setUpPostLaunch() { activityScenario.onActivity(activity -> { PropertiesSingleton props = activity.getProps(); assertThat(props).isNotNull(); + IdlingResource.decrement(); }); onView(withId(R.id.app_properties_content)).check(matches(isDisplayed())); 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..4ac0f0df8 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,20 @@ 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.IdlingResource; +import org.opendatakit.TestConsts; import org.opendatakit.consts.IntentConsts; import org.opendatakit.properties.PropertiesSingleton; import org.opendatakit.services.R; @@ -34,6 +35,7 @@ protected void setUpPostLaunch() { activityScenario.onActivity(activity -> { PropertiesSingleton props = activity.getProps(); assertThat(props).isNotNull(); + IdlingResource.decrement(); }); onView(withId(R.id.app_properties_content)).check(matches(isDisplayed())); @@ -47,19 +49,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..4573a0d9c 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 @@ -24,6 +24,7 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.opendatakit.IdlingResource; import org.opendatakit.consts.IntentConsts; import org.opendatakit.services.MainActivity; import org.opendatakit.services.R; diff --git a/services_app/src/main/java/org/opendatakit/services/MainActivity.java b/services_app/src/main/java/org/opendatakit/services/MainActivity.java index 247c638a5..a1e1c309e 100644 --- a/services_app/src/main/java/org/opendatakit/services/MainActivity.java +++ b/services_app/src/main/java/org/opendatakit/services/MainActivity.java @@ -16,6 +16,7 @@ import android.Manifest; import android.app.Activity; +import android.content.ComponentName; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; 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" /> diff --git a/services_app/src/main/res/values/strings.xml b/services_app/src/main/res/values/strings.xml index 458002761..34c5687e7 100644 --- a/services_app/src/main/res/values/strings.xml +++ b/services_app/src/main/res/values/strings.xml @@ -450,5 +450,6 @@ Sign in using Credentials Set Credentials Sign in as Anonymous User + SIGN IN OR OUT