Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outreachy2024/testing system images #289

Open
wants to merge 35 commits into
base: upgrade-jdk11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
83b69f0
Fix for UI Tests
Stryker101 Jun 1, 2024
1ccb754
Update config.yml
Stryker101 Jun 1, 2024
93138fc
Fix for UI Tests
Stryker101 Jun 1, 2024
bb5ba6c
Update config.yml
Stryker101 Jun 1, 2024
882ac4c
Update config.yml
Stryker101 Jun 1, 2024
bd8faad
Update config.yml
Stryker101 Jun 1, 2024
e9ee2f9
Merge branch 'odk-x:upgrade-jdk11' into upgrade-jdk11
Stryker101 Jun 4, 2024
d56de98
Merge branch 'upgrade-jdk11' of https://github.com/Stryker101/ODK_ser…
Stryker101 Jun 4, 2024
c42011b
fix for ui tests
Stryker101 Jun 4, 2024
8eeed74
attempt to stabilize 1
Stryker101 Jun 6, 2024
b1917fd
rebase with clean history
Stryker101 Jun 8, 2024
1cc4f6d
testing with default system image
Stryker101 Jun 8, 2024
38bd44e
testing with default system image
Stryker101 Jun 8, 2024
853b8b3
testing with default system image
Stryker101 Jun 8, 2024
a012c79
testing with idling resource
Stryker101 Jun 8, 2024
5c95778
testing with idling resource
Stryker101 Jun 8, 2024
f831d69
testing with idling resource corrected
Stryker101 Jun 8, 2024
1921d63
testing with idling resource corrected
Stryker101 Jun 8, 2024
92abddc
testing with idling resource corrected
Stryker101 Jun 8, 2024
591ab6e
testing with idling resource corrected
Stryker101 Jun 8, 2024
d624807
testing with idling resource corrected
Stryker101 Jun 8, 2024
d9c9cbe
testing with idling resource corrected
Stryker101 Jun 8, 2024
cc876c6
testing with idling resource corrected
Stryker101 Jun 8, 2024
38f0cd0
testing with idling resource corrected
Stryker101 Jun 8, 2024
5e26217
testing with idling resource corrected
Stryker101 Jun 8, 2024
4978562
restructure Idling resource
Stryker101 Jun 17, 2024
4b95164
restructure Idling resource
Stryker101 Jun 17, 2024
3be16ad
restructure Idling resource
Stryker101 Jun 17, 2024
f899922
restructure Idling resource
Stryker101 Jun 17, 2024
984f427
using recyclerview idling resource
Stryker101 Jun 17, 2024
c17a6ad
using recyclerview idling resource
Stryker101 Jun 17, 2024
706e85b
using recyclerview idling resource
Stryker101 Jun 17, 2024
47d1672
removed recyclerview idling resource
Stryker101 Jun 17, 2024
ec462fa
added ignore to some tests
Stryker101 Jun 17, 2024
5df9412
added ignore to some tests
Stryker101 Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: 2.1

orbs:
android: circleci/[email protected]

jobs:
test:
description: Runs unit tests and instrumented tests on the Android Common
Expand All @@ -19,48 +20,75 @@ 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

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:
Expand Down
1 change: 1 addition & 0 deletions services_app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
99 changes: 76 additions & 23 deletions services_app/src/androidTest/java/org/opendatakit/BaseUITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -63,8 +63,10 @@
import org.opendatakit.utilities.ODKFileUtils;

import java.io.File;
import java.util.concurrent.TimeoutException;

public abstract class BaseUITest<T extends Activity> {
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";
Expand All @@ -78,41 +80,54 @@ public abstract class BaseUITest<T extends Activity> {
protected ActivityScenario<T> 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));
if (f.exists()) {
f.delete();
}
ODKFileUtils.clearConfiguredToolFiles(APP_NAME);

}

public static ViewAction setChecked(final boolean checked) {
Expand Down Expand Up @@ -172,23 +187,62 @@ protected boolean matchesSafely(final RecyclerView view) {
}
};
}

public static ViewAction waitFor(long delay) {
return new ViewAction() {
@Override public Matcher<View> getConstraints() {
return ViewMatchers.isRoot();
@Override
public Matcher<View> 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<View> viewMatcher, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}

@Override
public String getDescription() {
return "Wait for a specific view with id <" + 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()));
Expand All @@ -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];
}

}
}

Original file line number Diff line number Diff line change
@@ -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;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
*/
public class TestConsts {
public static final String APPNAME = "unittestTMP";

public static final long WAIT_TIME = 2000;

}
Loading