mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
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:
parent
db10e1e7ba
commit
dfdbc1be35
@ -38,6 +38,7 @@ import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
|||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
|
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
|
||||||
|
import org.kiwix.kiwixmobile.utils.StandardActions
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@ -82,6 +83,7 @@ class LanguageFragmentTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testLanguageFragment() {
|
fun testLanguageFragment() {
|
||||||
|
StandardActions.closeDrawer() // close the drawer if open before running the test cases.
|
||||||
language {
|
language {
|
||||||
clickDownloadOnBottomNav()
|
clickDownloadOnBottomNav()
|
||||||
waitForDataToLoad()
|
waitForDataToLoad()
|
||||||
|
@ -40,6 +40,7 @@ import org.kiwix.kiwixmobile.main.KiwixMainActivity
|
|||||||
import org.kiwix.kiwixmobile.nav.destination.library.library
|
import org.kiwix.kiwixmobile.nav.destination.library.library
|
||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils
|
import org.kiwix.kiwixmobile.testutils.TestUtils
|
||||||
|
import org.kiwix.kiwixmobile.utils.StandardActions
|
||||||
|
|
||||||
class LocalFileTransferTest {
|
class LocalFileTransferTest {
|
||||||
@Rule
|
@Rule
|
||||||
@ -87,6 +88,7 @@ class LocalFileTransferTest {
|
|||||||
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
|
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
|
||||||
moveToState(Lifecycle.State.RESUMED)
|
moveToState(Lifecycle.State.RESUMED)
|
||||||
}
|
}
|
||||||
|
StandardActions.closeDrawer()
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
|
||||||
activityScenario.onActivity {
|
activityScenario.onActivity {
|
||||||
it.navigate(R.id.libraryFragment)
|
it.navigate(R.id.libraryFragment)
|
||||||
@ -115,6 +117,7 @@ class LocalFileTransferTest {
|
|||||||
it.navigate(R.id.libraryFragment)
|
it.navigate(R.id.libraryFragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
StandardActions.closeDrawer()
|
||||||
library {
|
library {
|
||||||
assertGetZimNearbyDeviceDisplayed()
|
assertGetZimNearbyDeviceDisplayed()
|
||||||
clickFileTransferIcon {
|
clickFileTransferIcon {
|
||||||
@ -142,6 +145,7 @@ class LocalFileTransferTest {
|
|||||||
it.navigate(R.id.libraryFragment)
|
it.navigate(R.id.libraryFragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
StandardActions.closeDrawer()
|
||||||
library {
|
library {
|
||||||
// test show case view show once.
|
// test show case view show once.
|
||||||
clickFileTransferIcon(LocalFileTransferRobot::assertClickNearbyDeviceMessageNotVisible)
|
clickFileTransferIcon(LocalFileTransferRobot::assertClickNearbyDeviceMessageNotVisible)
|
||||||
@ -170,6 +174,12 @@ class LocalFileTransferTest {
|
|||||||
if (isResetShowCaseId) {
|
if (isResetShowCaseId) {
|
||||||
// To clear showCaseID to ensure the showcase view will show.
|
// To clear showCaseID to ensure the showcase view will show.
|
||||||
uk.co.deanwild.materialshowcaseview.PrefsManager.resetAll(context)
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ import org.kiwix.kiwixmobile.nav.destination.library.library
|
|||||||
import org.kiwix.kiwixmobile.testutils.RetryRule
|
import org.kiwix.kiwixmobile.testutils.RetryRule
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
import org.kiwix.kiwixmobile.testutils.TestUtils.closeSystemDialogs
|
||||||
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
|
import org.kiwix.kiwixmobile.testutils.TestUtils.isSystemUINotRespondingDialogVisible
|
||||||
|
import org.kiwix.kiwixmobile.utils.StandardActions
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
@ -116,7 +117,7 @@ class NoteFragmentTest : BaseActivityTest() {
|
|||||||
.apply { zimFileUri = zimFile.toUri().toString() }
|
.apply { zimFileUri = zimFile.toUri().toString() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
StandardActions.closeDrawer() // close the drawer if open before running the test cases.
|
||||||
note {
|
note {
|
||||||
clickOnNoteMenuItem(context)
|
clickOnNoteMenuItem(context)
|
||||||
assertBackwardNavigationHistoryDialogDisplayed()
|
assertBackwardNavigationHistoryDialogDisplayed()
|
||||||
|
@ -24,6 +24,7 @@ import androidx.test.espresso.action.ViewActions
|
|||||||
import androidx.test.espresso.matcher.ViewMatchers
|
import androidx.test.espresso.matcher.ViewMatchers
|
||||||
import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
|
import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn
|
||||||
import com.adevinta.android.barista.interaction.BaristaDialogInteractions
|
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.BaristaDrawerInteractions.openDrawerWithGravity
|
||||||
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
import com.adevinta.android.barista.interaction.BaristaSleepInteractions
|
||||||
import org.kiwix.kiwixmobile.R
|
import org.kiwix.kiwixmobile.R
|
||||||
@ -43,6 +44,11 @@ object StandardActions {
|
|||||||
openDrawerWithGravity(R.id.navigation_container, GravityCompat.START)
|
openDrawerWithGravity(R.id.navigation_container, GravityCompat.START)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun closeDrawer() {
|
||||||
|
BaristaSleepInteractions.sleep(TestUtils.TEST_PAUSE_MS.toLong())
|
||||||
|
closeDrawerWithGravity(R.id.navigation_container, GravityCompat.START)
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun deleteZimIfExists(zimName: String, adapterId: Int) {
|
fun deleteZimIfExists(zimName: String, adapterId: Int) {
|
||||||
try {
|
try {
|
||||||
|
@ -5,6 +5,17 @@ adb shell svc wifi enable
|
|||||||
adb logcat -c
|
adb logcat -c
|
||||||
# shellcheck disable=SC2035
|
# shellcheck disable=SC2035
|
||||||
adb logcat *:E -v color &
|
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
|
retry=0
|
||||||
while [ $retry -le 3 ]; do
|
while [ $retry -le 3 ]; do
|
||||||
if ./gradlew jacocoInstrumentationTestReport; then
|
if ./gradlew jacocoInstrumentationTestReport; then
|
||||||
@ -19,13 +30,6 @@ while [ $retry -le 3 ]; do
|
|||||||
# shellcheck disable=SC2035
|
# shellcheck disable=SC2035
|
||||||
adb logcat *:E -v color &
|
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
|
if is_app_installed; then
|
||||||
# Clear application data to properly run the test cases.
|
# Clear application data to properly run the test cases.
|
||||||
adb shell pm clear "${PACKAGE_NAME}"
|
adb shell pm clear "${PACKAGE_NAME}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user