From 72ed403be37d79bf6683634435c638623032dd57 Mon Sep 17 00:00:00 2001 From: simosathan9 Date: Wed, 22 May 2024 21:56:00 +0300 Subject: [PATCH 01/10] Add dependencies for espresso tests --- app/build.gradle.kts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8599d5c08b..1eee724ac3 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -28,6 +28,7 @@ android { multiDexEnabled = true resourceConfigurations += listOf("ar", "bg", "bn", "bn-rIN", "bs", "cs", "da", "de", "el-rGR", "en", "eo", "es", "es-rAR", "fi", "fr", "he-rIL", "hi", "hr", "hu", "in-rID", "is", "it", "ja", "ko", "lt", "lv", "nb-rNO", "nl", "oc", "pl", "pt-rPT", "ro-rRO", "ru", "sk", "sl", "sv", "tr", "uk", "vi", "zh-rCN", "zh-rTW") + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -94,6 +95,10 @@ dependencies { implementation("androidx.preference:preference:1.2.1") implementation("com.google.android.material:material:1.12.0") implementation("com.github.yalantis:ucrop:2.2.9") + implementation("androidx.tracing:tracing:1.2.0") + androidTestImplementation("androidx.test.ext:junit:1.2.0-beta01") + androidTestImplementation("androidx.test:rules:1.6.0-beta01") + androidTestImplementation("androidx.test.espresso:espresso-contrib:3.6.0-beta01") coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4") // Splash Screen @@ -113,6 +118,14 @@ dependencies { testImplementation("androidx.test:core:1.5.0") testImplementation("junit:junit:4.13.2") testImplementation("org.robolectric:robolectric:4.12.2") + + // Espresso + androidTestImplementation("androidx.test.espresso:espresso-core:3.6.0-beta01") + androidTestImplementation("androidx.test:core:1.5.0") + androidTestImplementation("androidx.test:rules:1.6.0-beta01") + androidTestImplementation("androidx.test.ext:junit:1.2.0-beta01") + androidTestImplementation("androidx.test:runner:1.5.2") + androidTestImplementation("androidx.test.espresso:espresso-contrib:3.6.0-beta01") } tasks.withType().configureEach { From ed1b5baeba05776d8a64da1ed9f8804d005da51c Mon Sep 17 00:00:00 2001 From: simosathan9 Date: Wed, 22 May 2024 21:56:48 +0300 Subject: [PATCH 02/10] Language Change UI Test --- .../card_locker/LanguageChangeUITest.java | 158 ++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java diff --git a/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java b/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java new file mode 100644 index 0000000000..1303065c4c --- /dev/null +++ b/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java @@ -0,0 +1,158 @@ +package protect.card_locker; + + +import static androidx.test.espresso.Espresso.onData; +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.contrib.RecyclerViewActions.actionOnItemAtPosition; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withClassName; +import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withParent; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anything; +import static org.hamcrest.Matchers.is; + +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; + +import androidx.test.espresso.DataInteraction; +import androidx.test.espresso.ViewInteraction; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; +import org.hamcrest.core.IsInstanceOf; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class LanguageChangeUITest { + + @Rule + public ActivityScenarioRule mActivityScenarioRule = + new ActivityScenarioRule<>(MainActivity.class); + + @Test + public void languageChangeUITest() { + ViewInteraction overflowMenuButton = onView( + allOf(withContentDescription(R.string.action_more_options), + isDisplayed())); + overflowMenuButton.perform(click()); + + ViewInteraction materialTextView = onView( + allOf(withId(androidx.recyclerview.R.id.title), withText("Settings"), + childAtPosition( + childAtPosition( + withId(androidx.appcompat.R.id.content), + 0), + 0), + isDisplayed())); + materialTextView.perform(click()); + + ViewInteraction recyclerView = onView( + allOf(withId(com.jaredrummler.android.colorpicker.R.id.recycler_view), + childAtPosition( + withId(android.R.id.list_container), + 0))); + recyclerView.perform(actionOnItemAtPosition(4, click())); + + DataInteraction appCompatCheckedTextView = onData(anything()) + .inAdapterView(allOf(withId(androidx.appcompat.R.id.select_dialog_listview), + childAtPosition( + withId(androidx.appcompat.R.id.contentPanel), + 0))) + .atPosition(8); + appCompatCheckedTextView.perform(click()); + + ViewInteraction textView = onView( + allOf(withText("Einstellungen"), + withParent(allOf(withId(R.id.toolbar), + withParent(IsInstanceOf.instanceOf(android.widget.LinearLayout.class)))), + isDisplayed())); + textView.check(matches(withText("Einstellungen"))); + + ViewInteraction recyclerView2 = onView( + allOf(withId(com.jaredrummler.android.colorpicker.R.id.recycler_view), + childAtPosition( + withId(android.R.id.list_container), + 0))); + recyclerView2.perform(actionOnItemAtPosition(4, click())); + + DataInteraction appCompatCheckedTextView2 = onData(anything()) + .inAdapterView(allOf(withId(androidx.appcompat.R.id.select_dialog_listview), + childAtPosition( + withId(androidx.appcompat.R.id.contentPanel), + 0))) + .atPosition(9); + appCompatCheckedTextView2.perform(click()); + + ViewInteraction textView2 = onView( + allOf(withText("Ρυθμίσεις"), + withParent(allOf(withId(R.id.toolbar), + withParent(IsInstanceOf.instanceOf(android.widget.LinearLayout.class)))), + isDisplayed())); + textView2.check(matches(withText("Ρυθμίσεις"))); + + ViewInteraction recyclerView3 = onView( + allOf(withId(com.jaredrummler.android.colorpicker.R.id.recycler_view), + childAtPosition( + withId(android.R.id.list_container), + 0))); + recyclerView3.perform(actionOnItemAtPosition(4, click())); + + DataInteraction appCompatCheckedTextView3 = onData(anything()) + .inAdapterView(allOf(withId(androidx.appcompat.R.id.select_dialog_listview), + childAtPosition( + withId(androidx.appcompat.R.id.contentPanel), + 0))) + .atPosition(0); + appCompatCheckedTextView3.perform(click()); + + ViewInteraction appCompatImageButton = onView( + allOf(withContentDescription("Navigate up"), + childAtPosition( + allOf(withId(R.id.toolbar), + childAtPosition( + withClassName(is("com.google.android.material.appbar.AppBarLayout")), + 0)), + 1), + isDisplayed())); + appCompatImageButton.perform(click()); + + ViewInteraction textView3 = onView( + allOf(withId(R.id.welcome_text), withText("Welcome to Catima"), + withParent(allOf(withId(R.id.helpSection), + withParent(withId(R.id.include)))), + isDisplayed())); + textView3.check(matches(withText("Welcome to Catima"))); + } + + private static Matcher childAtPosition( + final Matcher parentMatcher, final int position) { + + return new TypeSafeMatcher() { + @Override + public void describeTo(Description description) { + description.appendText("Child at position " + position + " in parent "); + parentMatcher.describeTo(description); + } + + @Override + public boolean matchesSafely(View view) { + ViewParent parent = view.getParent(); + return parent instanceof ViewGroup && parentMatcher.matches(parent) + && view.equals(((ViewGroup) parent).getChildAt(position)); + } + }; + } +} From 65f98a6125ded5d75a0b4f2e7fdfbaa9546dbbb9 Mon Sep 17 00:00:00 2001 From: simosathan9 Date: Wed, 22 May 2024 21:57:06 +0300 Subject: [PATCH 03/10] Card Creation UI Test --- .../card_locker/LoyaltyCardCreationTest.java | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 app/src/androidTest/java/protect/card_locker/LoyaltyCardCreationTest.java diff --git a/app/src/androidTest/java/protect/card_locker/LoyaltyCardCreationTest.java b/app/src/androidTest/java/protect/card_locker/LoyaltyCardCreationTest.java new file mode 100644 index 0000000000..b60fbcd266 --- /dev/null +++ b/app/src/androidTest/java/protect/card_locker/LoyaltyCardCreationTest.java @@ -0,0 +1,190 @@ +package protect.card_locker; + +import static androidx.test.espresso.Espresso.onData; +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; +import static androidx.test.espresso.action.ViewActions.replaceText; +import static androidx.test.espresso.action.ViewActions.scrollTo; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withClassName; +import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withParent; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anything; +import static org.hamcrest.Matchers.is; + +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; + +import androidx.test.espresso.DataInteraction; +import androidx.test.espresso.ViewInteraction; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; +import androidx.test.rule.GrantPermissionRule; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + + +@LargeTest +@RunWith(AndroidJUnit4.class) +public class LoyaltyCardCreationTest { + @Rule + public ActivityScenarioRule mActivityScenarioRule = + new ActivityScenarioRule<>(MainActivity.class); + + @Rule + public GrantPermissionRule mGrantPermissionRule = + GrantPermissionRule.grant( + "android.permission.CAMERA", + "android.permission.WRITE_EXTERNAL_STORAGE", + "android.permission.READ_EXTERNAL_STORAGE"); + + @Test + public void loyaltyCardCreationTest() { + ViewInteraction textView = onView( + allOf(withId(R.id.add_card_instruction), withText("Click the + plus button to add a card, or import from the ⋮ menu."), + withParent(allOf(withId(R.id.helpSection), + withParent(withId(R.id.include)))), + isDisplayed())); + textView.check(matches(withText("Click the + plus button to add a card, or import from the ⋮ menu."))); + + ViewInteraction floatingActionButton = onView( + allOf(withId(R.id.fabAdd), withContentDescription("Add"), + childAtPosition( + childAtPosition( + withId(android.R.id.content), + 0), + 2), + isDisplayed())); + floatingActionButton.perform(click()); + + ViewInteraction extendedFloatingActionButton = onView( + allOf(withId(R.id.fabOtherOptions), withText("More options"), + childAtPosition( + allOf(withId(R.id.zxing_barcode_scanner), + childAtPosition( + withClassName(is("android.widget.RelativeLayout")), + 1)), + 0), + isDisplayed())); + extendedFloatingActionButton.perform(click()); + + DataInteraction materialTextView = onData(anything()) + .inAdapterView(allOf(withId(androidx.appcompat.R.id.select_dialog_listview), + childAtPosition( + withId(androidx.appcompat.R.id.contentPanel), + 0))) + .atPosition(0); + materialTextView.perform(click()); + + ViewInteraction editText = onView( + allOf(childAtPosition( + childAtPosition( + withId(androidx.appcompat.R.id.custom), + 0), + 1), + isDisplayed())); + editText.perform(replaceText("123456789"), closeSoftKeyboard()); + + ViewInteraction materialButton = onView( + allOf(withId(android.R.id.button1), withText("OK"), + childAtPosition( + childAtPosition( + withId(androidx.appcompat.R.id.buttonPanel), + 0), + 3))); + materialButton.perform(scrollTo(), click()); + + ViewInteraction editText2 = onView( + allOf(withId(R.id.cardIdView), withText("123456789"), + withParent(withParent(withId(R.id.cardIdField))), + isDisplayed())); + editText2.check(matches(withText("123456789"))); + + ViewInteraction textInputEditText = onView( + allOf(withId(R.id.storeNameEdit), + childAtPosition( + childAtPosition( + withId(R.id.storeNameField), + 0), + 0), + isDisplayed())); + textInputEditText.perform(replaceText("CatimaUITestCard"), closeSoftKeyboard()); + + ViewInteraction tabView = onView( + allOf(withContentDescription("Options"), + childAtPosition( + childAtPosition( + withId(R.id.tabs), + 0), + 1), + isDisplayed())); + tabView.perform(click()); + + ViewInteraction textInputEditText2 = onView( + allOf(withId(R.id.balanceField), withText("0"), + childAtPosition( + childAtPosition( + withId(R.id.balanceView), + 0), + 0), + isDisplayed())); + textInputEditText2.perform(replaceText("10000")); + + ViewInteraction textInputEditText3 = onView( + allOf(withId(R.id.balanceField), withText("10000"), + childAtPosition( + childAtPosition( + withId(R.id.balanceView), + 0), + 0), + isDisplayed())); + textInputEditText3.perform(closeSoftKeyboard()); + + ViewInteraction floatingActionButton2 = onView( + allOf(withId(R.id.fabSave), withContentDescription("Save"), + childAtPosition( + childAtPosition( + withId(android.R.id.content), + 0), + 2), + isDisplayed())); + floatingActionButton2.perform(click()); + + ViewInteraction textView2 = onView( + allOf(withId(R.id.balance), withText("10000 points"), + withParent(withParent(withId(R.id.row))), + isDisplayed())); + textView2.check(matches(withText("10000 points"))); + } + + private static Matcher childAtPosition( + final Matcher parentMatcher, final int position) { + + return new TypeSafeMatcher() { + @Override + public void describeTo(Description description) { + description.appendText("Child at position " + position + " in parent "); + parentMatcher.describeTo(description); + } + + @Override + public boolean matchesSafely(View view) { + ViewParent parent = view.getParent(); + return parent instanceof ViewGroup && parentMatcher.matches(parent) + && view.equals(((ViewGroup) parent).getChildAt(position)); + } + }; + } +} \ No newline at end of file From 150332fb0cc686f26b9e423a3019d9d35773c417 Mon Sep 17 00:00:00 2001 From: simosathan9 Date: Thu, 30 May 2024 14:25:07 +0300 Subject: [PATCH 04/10] Apply changes suggested in PR review --- app/build.gradle.kts | 4 +-- .../card_locker/LanguageChangeUITest.java | 4 ++- .../card_locker/LoyaltyCardCreationTest.java | 30 +++++++++++-------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1eee724ac3..fc8e1c1cfc 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -29,6 +29,7 @@ android { resourceConfigurations += listOf("ar", "bg", "bn", "bn-rIN", "bs", "cs", "da", "de", "el-rGR", "en", "eo", "es", "es-rAR", "fi", "fr", "he-rIL", "hi", "hr", "hu", "in-rID", "is", "it", "ja", "ko", "lt", "lv", "nb-rNO", "nl", "oc", "pl", "pt-rPT", "ro-rRO", "ru", "sk", "sl", "sv", "tr", "uk", "vi", "zh-rCN", "zh-rTW") testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunnerArguments(mapOf("clearPackageData" to "true")) } buildTypes { @@ -96,9 +97,6 @@ dependencies { implementation("com.google.android.material:material:1.12.0") implementation("com.github.yalantis:ucrop:2.2.9") implementation("androidx.tracing:tracing:1.2.0") - androidTestImplementation("androidx.test.ext:junit:1.2.0-beta01") - androidTestImplementation("androidx.test:rules:1.6.0-beta01") - androidTestImplementation("androidx.test.espresso:espresso-contrib:3.6.0-beta01") coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4") // Splash Screen diff --git a/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java b/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java index 1303065c4c..2c13a0cf29 100644 --- a/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java +++ b/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java @@ -12,6 +12,7 @@ import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withParent; import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.anything; import static org.hamcrest.Matchers.is; @@ -49,8 +50,9 @@ public void languageChangeUITest() { isDisplayed())); overflowMenuButton.perform(click()); + String expectedText = getInstrumentation().getTargetContext().getString(R.string.settings); ViewInteraction materialTextView = onView( - allOf(withId(androidx.recyclerview.R.id.title), withText("Settings"), + allOf(withId(androidx.recyclerview.R.id.title), withText(expectedText), childAtPosition( childAtPosition( withId(androidx.appcompat.R.id.content), diff --git a/app/src/androidTest/java/protect/card_locker/LoyaltyCardCreationTest.java b/app/src/androidTest/java/protect/card_locker/LoyaltyCardCreationTest.java index b60fbcd266..a8f1174c30 100644 --- a/app/src/androidTest/java/protect/card_locker/LoyaltyCardCreationTest.java +++ b/app/src/androidTest/java/protect/card_locker/LoyaltyCardCreationTest.java @@ -13,6 +13,7 @@ import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withParent; import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.anything; import static org.hamcrest.Matchers.is; @@ -46,21 +47,21 @@ public class LoyaltyCardCreationTest { @Rule public GrantPermissionRule mGrantPermissionRule = GrantPermissionRule.grant( - "android.permission.CAMERA", - "android.permission.WRITE_EXTERNAL_STORAGE", - "android.permission.READ_EXTERNAL_STORAGE"); + "android.permission.CAMERA"); @Test public void loyaltyCardCreationTest() { + String expectedText = getInstrumentation().getTargetContext().getString(R.string.noGiftCards); ViewInteraction textView = onView( - allOf(withId(R.id.add_card_instruction), withText("Click the + plus button to add a card, or import from the ⋮ menu."), + allOf(withId(R.id.add_card_instruction), withText(expectedText), withParent(allOf(withId(R.id.helpSection), withParent(withId(R.id.include)))), isDisplayed())); - textView.check(matches(withText("Click the + plus button to add a card, or import from the ⋮ menu."))); + textView.check(matches(withText(expectedText))); + expectedText = getInstrumentation().getTargetContext().getString(R.string.action_add); ViewInteraction floatingActionButton = onView( - allOf(withId(R.id.fabAdd), withContentDescription("Add"), + allOf(withId(R.id.fabAdd), withContentDescription(expectedText), childAtPosition( childAtPosition( withId(android.R.id.content), @@ -69,8 +70,9 @@ public void loyaltyCardCreationTest() { isDisplayed())); floatingActionButton.perform(click()); + expectedText = getInstrumentation().getTargetContext().getString(R.string.action_more_options); ViewInteraction extendedFloatingActionButton = onView( - allOf(withId(R.id.fabOtherOptions), withText("More options"), + allOf(withId(R.id.fabOtherOptions), withText(expectedText), childAtPosition( allOf(withId(R.id.zxing_barcode_scanner), childAtPosition( @@ -97,8 +99,9 @@ public void loyaltyCardCreationTest() { isDisplayed())); editText.perform(replaceText("123456789"), closeSoftKeyboard()); + expectedText = getInstrumentation().getTargetContext().getString(R.string.ok); ViewInteraction materialButton = onView( - allOf(withId(android.R.id.button1), withText("OK"), + allOf(withId(android.R.id.button1), withText(expectedText), childAtPosition( childAtPosition( withId(androidx.appcompat.R.id.buttonPanel), @@ -122,8 +125,9 @@ public void loyaltyCardCreationTest() { isDisplayed())); textInputEditText.perform(replaceText("CatimaUITestCard"), closeSoftKeyboard()); + expectedText = getInstrumentation().getTargetContext().getString(R.string.options); ViewInteraction tabView = onView( - allOf(withContentDescription("Options"), + allOf(withContentDescription(expectedText), childAtPosition( childAtPosition( withId(R.id.tabs), @@ -152,8 +156,9 @@ public void loyaltyCardCreationTest() { isDisplayed())); textInputEditText3.perform(closeSoftKeyboard()); + expectedText = getInstrumentation().getTargetContext().getString(R.string.save); ViewInteraction floatingActionButton2 = onView( - allOf(withId(R.id.fabSave), withContentDescription("Save"), + allOf(withId(R.id.fabSave), withContentDescription(expectedText), childAtPosition( childAtPosition( withId(android.R.id.content), @@ -162,11 +167,12 @@ public void loyaltyCardCreationTest() { isDisplayed())); floatingActionButton2.perform(click()); + expectedText = getInstrumentation().getTargetContext().getResources().getQuantityString(R.plurals.balancePoints, 5, 10000); ViewInteraction textView2 = onView( - allOf(withId(R.id.balance), withText("10000 points"), + allOf(withId(R.id.balance), withText(expectedText), withParent(withParent(withId(R.id.row))), isDisplayed())); - textView2.check(matches(withText("10000 points"))); + textView2.check(matches(withText(expectedText))); } private static Matcher childAtPosition( From d329c027e8da91c8972e40dcefb78f4c28c99851 Mon Sep 17 00:00:00 2001 From: simosathan9 Date: Tue, 4 Jun 2024 21:45:47 +0300 Subject: [PATCH 05/10] Update testInstrumentationRunnerArguments in build.gradle.kts --- app/build.gradle.kts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index fc8e1c1cfc..c9ab15b77c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -29,7 +29,7 @@ android { resourceConfigurations += listOf("ar", "bg", "bn", "bn-rIN", "bs", "cs", "da", "de", "el-rGR", "en", "eo", "es", "es-rAR", "fi", "fr", "he-rIL", "hi", "hr", "hu", "in-rID", "is", "it", "ja", "ko", "lt", "lv", "nb-rNO", "nl", "oc", "pl", "pt-rPT", "ro-rRO", "ru", "sk", "sl", "sv", "tr", "uk", "vi", "zh-rCN", "zh-rTW") testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - testInstrumentationRunnerArguments(mapOf("clearPackageData" to "true")) + testInstrumentationRunnerArguments["clearPackageData"] = "true" } buildTypes { @@ -124,6 +124,8 @@ dependencies { androidTestImplementation("androidx.test.ext:junit:1.2.0-beta01") androidTestImplementation("androidx.test:runner:1.5.2") androidTestImplementation("androidx.test.espresso:espresso-contrib:3.6.0-beta01") + + androidTestUtil("androidx.test:orchestrator:1.1.0") } tasks.withType().configureEach { From 34a588c36b494cbd08b1f3fb67402e78e13e9c5c Mon Sep 17 00:00:00 2001 From: simosathan9 Date: Tue, 4 Jun 2024 21:58:04 +0300 Subject: [PATCH 06/10] Change language selection process on LanguageChangeUITest. Changed the way LanguageChangeUITest chooses a new language in order to check that the system has indeed change the language to the specified one. --- .../card_locker/LanguageChangeUITest.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java b/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java index 2c13a0cf29..4298d99296 100644 --- a/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java +++ b/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java @@ -68,12 +68,15 @@ public void languageChangeUITest() { 0))); recyclerView.perform(actionOnItemAtPosition(4, click())); + String selectedLanguage = "de"; + int position = getPositionOfItem(selectedLanguage); + DataInteraction appCompatCheckedTextView = onData(anything()) .inAdapterView(allOf(withId(androidx.appcompat.R.id.select_dialog_listview), childAtPosition( withId(androidx.appcompat.R.id.contentPanel), 0))) - .atPosition(8); + .atPosition(position); appCompatCheckedTextView.perform(click()); ViewInteraction textView = onView( @@ -90,12 +93,15 @@ public void languageChangeUITest() { 0))); recyclerView2.perform(actionOnItemAtPosition(4, click())); + selectedLanguage = "el-rGR"; + position = getPositionOfItem(selectedLanguage); + DataInteraction appCompatCheckedTextView2 = onData(anything()) .inAdapterView(allOf(withId(androidx.appcompat.R.id.select_dialog_listview), childAtPosition( withId(androidx.appcompat.R.id.contentPanel), 0))) - .atPosition(9); + .atPosition(position); appCompatCheckedTextView2.perform(click()); ViewInteraction textView2 = onView( @@ -157,4 +163,16 @@ public boolean matchesSafely(View view) { } }; } + + private static int getPositionOfItem(String selectedLanguage) { + String[] availableLocales = getInstrumentation().getTargetContext().getResources().getStringArray(R.array.locale_values); + int position = 0; + for (String locale : availableLocales) { + if (locale.equals(selectedLanguage)) { + break; + } + position++; + } + return position; + } } From 99cbaceb708a145f32b1fff776c432267b2983fe Mon Sep 17 00:00:00 2001 From: simosathan9 Date: Wed, 5 Jun 2024 14:45:05 +0300 Subject: [PATCH 07/10] Change android.yml to run Espresso tests during CI --- .github/workflows/android.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 4c6a6befd5..4a4611db1c 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -46,6 +46,8 @@ jobs: run: timeout 5m ./gradlew testReleaseUnitTest || { ./gradlew --stop && timeout 5m ./gradlew testReleaseUnitTest; } - name: SpotBugs run: ./gradlew spotbugsRelease + - name: Espresso + run: ./gradlew connectedAndroidTest - name: Archive test results if: always() uses: actions/upload-artifact@v4.3.3 From f3e6bcc664e5c543f01ada8266014955f1ebcf5b Mon Sep 17 00:00:00 2001 From: simosathan9 Date: Thu, 6 Jun 2024 23:03:51 +0300 Subject: [PATCH 08/10] Refactor locale position lookup to use `Arrays.asList().indexOf()` Co-authored-by: FC (Fay) Stegerman --- .../java/protect/card_locker/LanguageChangeUITest.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java b/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java index 4298d99296..08649e8eb1 100644 --- a/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java +++ b/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java @@ -166,13 +166,6 @@ public boolean matchesSafely(View view) { private static int getPositionOfItem(String selectedLanguage) { String[] availableLocales = getInstrumentation().getTargetContext().getResources().getStringArray(R.array.locale_values); - int position = 0; - for (String locale : availableLocales) { - if (locale.equals(selectedLanguage)) { - break; - } - position++; - } - return position; + return Arrays.asList(availableLocales).indexOf(selectedLanguage); } } From 38313922b5a9b5c4cc12b5e83c034af2430073c3 Mon Sep 17 00:00:00 2001 From: simosathan9 Date: Thu, 6 Jun 2024 23:07:14 +0300 Subject: [PATCH 09/10] Add import needed for the proposed refactoring --- .../java/protect/card_locker/LanguageChangeUITest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java b/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java index 08649e8eb1..fe4f3562fb 100644 --- a/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java +++ b/app/src/androidTest/java/protect/card_locker/LanguageChangeUITest.java @@ -35,6 +35,8 @@ import org.junit.Test; import org.junit.runner.RunWith; +import java.util.Arrays; + @LargeTest @RunWith(AndroidJUnit4.class) public class LanguageChangeUITest { From 4bc5a720ca66ae0502c5873fbb34dca30fc2990e Mon Sep 17 00:00:00 2001 From: simosathan9 Date: Thu, 6 Jun 2024 23:15:19 +0300 Subject: [PATCH 10/10] Remove Espresso from android.yml --- .github/workflows/android.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 4a4611db1c..4c6a6befd5 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -46,8 +46,6 @@ jobs: run: timeout 5m ./gradlew testReleaseUnitTest || { ./gradlew --stop && timeout 5m ./gradlew testReleaseUnitTest; } - name: SpotBugs run: ./gradlew spotbugsRelease - - name: Espresso - run: ./gradlew connectedAndroidTest - name: Archive test results if: always() uses: actions/upload-artifact@v4.3.3