From dfdbc1be359ada83dd9c3399c9d1cf579ca0796c Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 10 Apr 2024 18:59:06 +0530 Subject: [PATCH] Fixed: Sometimes all the test cases crash on first time and some fail due to the navigation drawer being visible on the window. (Android 13). * We are clearing the data of application on 2nd and 3rd run, and the test cases are running normally so now we are clearing the application data on first run as well. * Additionally, we've implemented drawer closure in `LanguageFragmentTest`, `LocalFileTransferTest`, and `NoteFragmentTest`. These tests sometimes encountered an open navigation drawer due to test failures or process crashes. * Enhancements have been made to the `testShowCaseFeatureShowOnce` test case. It's now independent of other test cases, ensuring it remains unaffected in the event of a test process crash or failure. --- .../language/LanguageFragmentTest.kt | 2 ++ .../localFileTransfer/LocalFileTransferTest.kt | 10 ++++++++++ .../kiwix/kiwixmobile/note/NoteFragmentTest.kt | 3 ++- .../kiwix/kiwixmobile/utils/StandardActions.kt | 6 ++++++ contrib/instrumentation.sh | 18 +++++++++++------- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt index 4a954558b..31f609f20 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageFragmentTest.kt @@ -38,6 +38,7 @@ import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.testutils.RetryRule import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible +import org.kiwix.kiwixmobile.utils.StandardActions @LargeTest @RunWith(AndroidJUnit4::class) @@ -82,6 +83,7 @@ class LanguageFragmentTest { @Test fun testLanguageFragment() { + StandardActions.closeDrawer() // close the drawer if open before running the test cases. language { clickDownloadOnBottomNav() waitForDataToLoad() diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt index 4384c30f4..2ef5f4760 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/localFileTransfer/LocalFileTransferTest.kt @@ -40,6 +40,7 @@ import org.kiwix.kiwixmobile.main.KiwixMainActivity import org.kiwix.kiwixmobile.nav.destination.library.library import org.kiwix.kiwixmobile.testutils.RetryRule import org.kiwix.kiwixmobile.testutils.TestUtils +import org.kiwix.kiwixmobile.utils.StandardActions class LocalFileTransferTest { @Rule @@ -87,6 +88,7 @@ class LocalFileTransferTest { activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply { moveToState(Lifecycle.State.RESUMED) } + StandardActions.closeDrawer() if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) { activityScenario.onActivity { it.navigate(R.id.libraryFragment) @@ -115,6 +117,7 @@ class LocalFileTransferTest { it.navigate(R.id.libraryFragment) } } + StandardActions.closeDrawer() library { assertGetZimNearbyDeviceDisplayed() clickFileTransferIcon { @@ -142,6 +145,7 @@ class LocalFileTransferTest { it.navigate(R.id.libraryFragment) } } + StandardActions.closeDrawer() library { // test show case view show once. clickFileTransferIcon(LocalFileTransferRobot::assertClickNearbyDeviceMessageNotVisible) @@ -170,6 +174,12 @@ class LocalFileTransferTest { if (isResetShowCaseId) { // To clear showCaseID to ensure the showcase view will show. uk.co.deanwild.materialshowcaseview.PrefsManager.resetAll(context) + } else { + // set that Show Case is showed, because sometimes its change the + // order of test case on API level 33 and our test case fails. + val internal = + context.getSharedPreferences("material_showcaseview_prefs", Context.MODE_PRIVATE) + internal.edit().putInt("status_$SHOWCASE_ID", -1).apply() } } } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt index 1c22c5f8b..21d0beb19 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt @@ -41,6 +41,7 @@ import org.kiwix.kiwixmobile.nav.destination.library.library import org.kiwix.kiwixmobile.testutils.RetryRule import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible +import org.kiwix.kiwixmobile.utils.StandardActions import java.io.File import java.io.FileOutputStream import java.io.OutputStream @@ -116,7 +117,7 @@ class NoteFragmentTest : BaseActivityTest() { .apply { zimFileUri = zimFile.toUri().toString() } ) } - + StandardActions.closeDrawer() // close the drawer if open before running the test cases. note { clickOnNoteMenuItem(context) assertBackwardNavigationHistoryDialogDisplayed() diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt index 7192f6c34..78e72d94b 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt @@ -24,6 +24,7 @@ import androidx.test.espresso.action.ViewActions import androidx.test.espresso.matcher.ViewMatchers import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn import com.adevinta.android.barista.interaction.BaristaDialogInteractions +import com.adevinta.android.barista.interaction.BaristaDrawerInteractions.closeDrawerWithGravity import com.adevinta.android.barista.interaction.BaristaDrawerInteractions.openDrawerWithGravity import com.adevinta.android.barista.interaction.BaristaSleepInteractions import org.kiwix.kiwixmobile.R @@ -43,6 +44,11 @@ object StandardActions { openDrawerWithGravity(R.id.navigation_container, GravityCompat.START) } + fun closeDrawer() { + BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong()) + closeDrawerWithGravity(R.id.navigation_container, GravityCompat.START) + } + @JvmStatic fun deleteZimIfExists(zimName: String, adapterId: Int) { try { diff --git a/contrib/instrumentation.sh b/contrib/instrumentation.sh index 318fc0262..7a488a5d6 100644 --- a/contrib/instrumentation.sh +++ b/contrib/instrumentation.sh @@ -5,6 +5,17 @@ adb shell svc wifi enable adb logcat -c # shellcheck disable=SC2035 adb logcat *:E -v color & + +PACKAGE_NAME="org.kiwix.kiwixmobile" +# Function to check if the application is installed +is_app_installed() { + adb shell pm list packages | grep -q "${PACKAGE_NAME}" +} + +if is_app_installed; then + # Clear application data to properly run the test cases. + adb shell pm clear "${PACKAGE_NAME}" +fi retry=0 while [ $retry -le 3 ]; do if ./gradlew jacocoInstrumentationTestReport; then @@ -19,13 +30,6 @@ while [ $retry -le 3 ]; do # shellcheck disable=SC2035 adb logcat *:E -v color & - PACKAGE_NAME="org.kiwix.kiwixmobile" - - # Function to check if the application is installed - is_app_installed() { - adb shell pm list packages | grep -q "${PACKAGE_NAME}" - } - if is_app_installed; then # Clear application data to properly run the test cases. adb shell pm clear "${PACKAGE_NAME}"