From 4f1a442854e2291f9565d28a1be5a80186f4ec26 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 6 Aug 2025 23:03:44 +0530 Subject: [PATCH] Improved the `NavigationHistoryTest`, `DeepLinksTest`, `NoteFragmentTest`, and `ZimFileReaderWithSplittedZimFileTest` test cases. --- .../kiwixmobile/deeplinks/DeepLinksTest.kt | 8 +++---- .../kiwixmobile/note/NoteFragmentTest.kt | 1 - .../page/history/NavigationHistoryRobot.kt | 23 ++++++++++--------- .../page/history/NavigationHistoryTest.kt | 3 +-- .../ZimFileReaderWithSplittedZimFileTest.kt | 4 ++-- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/deeplinks/DeepLinksTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/deeplinks/DeepLinksTest.kt index 1a0c469a7..617d42601 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/deeplinks/DeepLinksTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/deeplinks/DeepLinksTest.kt @@ -112,8 +112,8 @@ class DeepLinksTest : BaseActivityTest() { clickOnCopy(composeTestRule) navigationHistory { checkZimFileLoadedSuccessful(composeTestRule) - assertZimFileLoaded() // check if the zim file successfully loaded - clickOnAndroidArticle() + assertZimFileLoaded(composeTestRule) // check if the zim file successfully loaded + clickOnAndroidArticle(composeTestRule) } } ?: kotlin.run { // error in getting the zim file Uri @@ -142,8 +142,8 @@ class DeepLinksTest : BaseActivityTest() { clickOnCopy(composeTestRule) navigationHistory { checkZimFileLoadedSuccessful(composeTestRule) - assertZimFileLoaded() // check if the zim file successfully loaded - clickOnAndroidArticle() + assertZimFileLoaded(composeTestRule) // check if the zim file successfully loaded + clickOnAndroidArticle(composeTestRule) } } ?: kotlin.run { // error in getting the zim file Uri 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 1a2cff45e..efcabb17d 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/note/NoteFragmentTest.kt @@ -168,7 +168,6 @@ class NoteFragmentTest : BaseActivityTest() { clickOnSavedNote(composeTestRule) clickOnOpenNote(composeTestRule) assertNoteSaved(composeTestRule) - pressBack() } if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) { // temporary disabled on Android 25 diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryRobot.kt index c665a642e..06079a459 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryRobot.kt @@ -29,7 +29,6 @@ import androidx.test.espresso.web.webdriver.DriverAtoms.findElement import androidx.test.espresso.web.webdriver.DriverAtoms.webClick import androidx.test.espresso.web.webdriver.Locator import applyWithViewHierarchyPrinting -import com.adevinta.android.barista.interaction.BaristaSleepInteractions import junit.framework.AssertionFailedError import org.kiwix.kiwixmobile.BaseRobot import org.kiwix.kiwixmobile.core.R @@ -76,8 +75,9 @@ class NavigationHistoryRobot : BaseRobot() { } } - fun clickOnAndroidArticle() { - pauseForBetterTestPerformance() + fun clickOnAndroidArticle(composeTestRule: ComposeContentTestRule) { + composeTestRule.waitForIdle() + pauseForBetterTestPerformance(composeTestRule) onWebView() .withElement( findElement( @@ -88,8 +88,9 @@ class NavigationHistoryRobot : BaseRobot() { .perform(webClick()) } - fun assertZimFileLoaded() { - pauseForBetterTestPerformance() + fun assertZimFileLoaded(composeTestRule: ComposeContentTestRule) { + composeTestRule.waitForIdle() + pauseForBetterTestPerformance(composeTestRule) onWebView() .withElement( findElement( @@ -127,7 +128,7 @@ class NavigationHistoryRobot : BaseRobot() { .assertTextEquals(context.getString(R.string.backward_history)) } } catch (_: AssertionError) { - pauseForBetterTestPerformance() + pauseForBetterTestPerformance(composeTestRule) if (retryCountForBackwardNavigationHistory > 0) { retryCountForBackwardNavigationHistory-- assertBackwardNavigationHistoryDialogDisplayed(composeTestRule) @@ -151,7 +152,7 @@ class NavigationHistoryRobot : BaseRobot() { .assertTextEquals(context.getString(R.string.forward_history)) } } catch (_: AssertionError) { - pauseForBetterTestPerformance() + pauseForBetterTestPerformance(composeTestRule) if (retryCountForForwardNavigationHistory > 0) { retryCountForForwardNavigationHistory-- assertForwardNavigationHistoryDialogDisplayed(composeTestRule) @@ -160,7 +161,7 @@ class NavigationHistoryRobot : BaseRobot() { } fun clickOnDeleteHistory(composeTestRule: ComposeContentTestRule) { - pauseForBetterTestPerformance() + pauseForBetterTestPerformance(composeTestRule) testFlakyView({ composeTestRule.apply { waitForIdle() @@ -177,7 +178,7 @@ class NavigationHistoryRobot : BaseRobot() { .assertTextEquals(context.getString(R.string.clear_all_history_dialog_title)) } } catch (ignore: AssertionFailedError) { - pauseForBetterTestPerformance() + pauseForBetterTestPerformance(composeTestRule) if (retryCountForClearNavigationHistory > 0) { retryCountForClearNavigationHistory-- assertDeleteDialogDisplayed(composeTestRule) @@ -187,8 +188,8 @@ class NavigationHistoryRobot : BaseRobot() { } } - private fun pauseForBetterTestPerformance() { - BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong()) + private fun pauseForBetterTestPerformance(composeTestRule: ComposeContentTestRule) { + composeTestRule.waitUntilTimeout(TestUtils.TEST_PAUSE_MS_FOR_SEARCH_TEST.toLong()) } fun clickOnReaderFragment(composeTestRule: ComposeContentTestRule) { diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt index 2cbbfbf6d..75364b5ab 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/page/history/NavigationHistoryTest.kt @@ -153,7 +153,7 @@ class NavigationHistoryTest : BaseActivityTest() { navigationHistory { closeTabSwitcherIfVisible(composeTestRule) checkZimFileLoadedSuccessful(composeTestRule) - clickOnAndroidArticle() + clickOnAndroidArticle(composeTestRule) longClickOnBackwardButton(composeTestRule) assertBackwardNavigationHistoryDialogDisplayed(composeTestRule) pressBack() @@ -163,7 +163,6 @@ class NavigationHistoryTest : BaseActivityTest() { clickOnDeleteHistory(composeTestRule) assertDeleteDialogDisplayed(composeTestRule) clickOnCancelButton(composeTestRule) - pressBack() } if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt index 2e91b53a9..fdbb8c528 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/reader/ZimFileReaderWithSplittedZimFileTest.kt @@ -134,8 +134,8 @@ class ZimFileReaderWithSplittedZimFileTest : BaseActivityTest() { navigationHistory { checkZimFileLoadedSuccessful(composeTestRule) clickOnReaderFragment(composeTestRule) // activate the accessibility check to check the issues. - assertZimFileLoaded() // check if the zim file successfully loaded - clickOnAndroidArticle() + assertZimFileLoaded(composeTestRule) // check if the zim file successfully loaded + clickOnAndroidArticle(composeTestRule) } } ?: kotlin.run { // error in creating the zim file chunk