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.
This commit is contained in:
MohitMaliFtechiz 2024-04-10 18:59:06 +05:30
parent db10e1e7ba
commit dfdbc1be35
5 changed files with 31 additions and 8 deletions

View File

@ -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()

View File

@ -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()
}
}
}

View File

@ -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()

View File

@ -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 {

View File

@ -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}"