Skip to content

Commit

Permalink
Sometimes CI stuck on DownloadTest when the test case waits for data …
Browse files Browse the repository at this point in the history
…to load, but the "Swipe Down for Library" error text shows on the screen because of that CI takes a long time to fail, so to improve this scenario we have refactored our test case if this text is shown on the screen then it tries to refresh the online content and test case will pass.
  • Loading branch information
MohitMaliDeveloper authored and MohitMaliFtechiz committed Sep 9, 2024
1 parent 94d3683 commit 8893968
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ fun downloadRobot(func: DownloadRobot.() -> Unit) =

class DownloadRobot : BaseRobot() {

private var retryCountForDataToLoad = 10
private var retryCountForCheckDownloadStart = 10

fun clickLibraryOnBottomNav() {
Expand All @@ -57,20 +56,30 @@ class DownloadRobot : BaseRobot() {
clickOn(ViewId(R.id.downloadsFragment))
}

fun waitForDataToLoad() {
fun waitForDataToLoad(retryCountForDataToLoad: Int = 10) {
try {
isVisible(TextId(string.your_languages))
} catch (e: RuntimeException) {
if (retryCountForDataToLoad > 0) {
retryCountForDataToLoad--
waitForDataToLoad()
// refresh the data if there is "Swipe Down for Library" visible on the screen.
refreshOnlineListIfSwipeDownForLibraryTextVisible()
waitForDataToLoad(retryCountForDataToLoad - 1)
return
}
// throw the exception when there is no more retry left.
throw RuntimeException("Couldn't load the online library list.\n Original exception = $e")
}
}

private fun refreshOnlineListIfSwipeDownForLibraryTextVisible() {
try {
onView(withText(string.swipe_down_for_library)).check(matches(isDisplayed()))
refreshOnlineList()
} catch (e: RuntimeException) {
// do nothing as the view is not visible
}
}

fun checkIfZimFileDownloaded() {
pauseForBetterTestPerformance()
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class InitialDownloadRobot : BaseRobot() {
isVisible(TextId(string.your_languages))
} catch (e: RuntimeException) {
if (retryCountForDataToLoad > 0) {
// refresh the data if there is "Swipe Down for Library" visible on the screen.
refreshOnlineListIfSwipeDownForLibraryTextVisible()
waitForDataToLoad(retryCountForDataToLoad - 1)
return
}
Expand All @@ -79,6 +81,15 @@ class InitialDownloadRobot : BaseRobot() {
}
}

private fun refreshOnlineListIfSwipeDownForLibraryTextVisible() {
try {
onView(withText(string.swipe_down_for_library)).check(matches(isDisplayed()))
refreshOnlineList()
} catch (e: RuntimeException) {
// do nothing as the view is not visible
}
}

fun downloadZimFile() {
pauseForBetterTestPerformance()
testFlakyView({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ package org.kiwix.kiwixmobile.language
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
import androidx.test.espresso.matcher.ViewMatchers.withId
import applyWithViewHierarchyPrinting
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
import com.adevinta.android.barista.interaction.BaristaSwipeRefreshInteractions.refresh
import junit.framework.AssertionFailedError
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.Findable.Text
import org.kiwix.kiwixmobile.Findable.ViewId
import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.R.string
import org.kiwix.kiwixmobile.testutils.TestUtils
Expand All @@ -50,6 +53,8 @@ class LanguageRobot : BaseRobot() {
isVisible(TextId(string.your_languages))
} catch (e: RuntimeException) {
if (retryCountForDataToLoad > 0) {
// refresh the data if there is "Swipe Down for Library" visible on the screen.
refreshOnlineListIfSwipeDownForLibraryTextVisible()
waitForDataToLoad(retryCountForDataToLoad - 1)
return
}
Expand All @@ -58,6 +63,19 @@ class LanguageRobot : BaseRobot() {
}
}

private fun refreshOnlineListIfSwipeDownForLibraryTextVisible() {
try {
onView(ViewMatchers.withText(string.swipe_down_for_library)).check(matches(isDisplayed()))
refreshOnlineList()
} catch (e: RuntimeException) {
// do nothing as the view is not visible
}
}

private fun refreshOnlineList() {
refresh(R.id.librarySwipeRefresh)
}

fun clickOnLanguageIcon() {
// Wait for a few seconds to properly saved selected language.
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import androidx.test.espresso.accessibility.AccessibilityChecks
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import leakcanary.LeakAssertions
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -96,7 +95,6 @@ class DarkModeViewPainterTest : BaseActivityTest() {
toggleDarkMode(false)
openZimFileInReader()
verifyDarkMode(false)
LeakAssertions.assertNoLeaks()
}

private fun openZimFileInReader() {
Expand Down

0 comments on commit 8893968

Please sign in to comment.