From 82d79934d58bcbb38d95123d323b7a9d01546ea5 Mon Sep 17 00:00:00 2001 From: MohitMali Date: Mon, 31 Oct 2022 20:34:17 +0530 Subject: [PATCH] Fix nightly workflow is almost always red --- .../kiwixmobile/language/LanguageRobot.kt | 5 +---- .../main/TopLevelDestinationTest.kt | 19 +++++++++++-------- .../destination/library/OnlineLibraryRobot.kt | 5 +---- .../kiwixmobile/utils/StandardActions.kt | 12 ++++++------ 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageRobot.kt index 8aa8ed1bc..b31bc6ea3 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/language/LanguageRobot.kt @@ -18,13 +18,10 @@ package org.kiwix.kiwixmobile.language -import android.widget.AutoCompleteTextView import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.action.ViewActions.typeText import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText -import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom import applyWithViewHierarchyPrinting import org.kiwix.kiwixmobile.BaseRobot import org.kiwix.kiwixmobile.Findable @@ -54,7 +51,7 @@ class LanguageRobot : BaseRobot() { fun searchAndSaveLanguage(searchLanguage: String, matchLanguage: String) { onView(withId(R.id.menu_language_search)).perform(click()) - onView(isAssignableFrom(AutoCompleteTextView::class.java)).perform(typeText(searchLanguage)) + isVisible(ViewId(androidx.appcompat.R.id.search_src_text)).text = searchLanguage onView(withText(matchLanguage)).perform(click()) onView(withId(R.id.menu_language_save)).perform(click()) } diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt index 200416785..72cf85493 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/main/TopLevelDestinationTest.kt @@ -19,18 +19,24 @@ package org.kiwix.kiwixmobile.main import androidx.core.content.edit import androidx.preference.PreferenceManager -import androidx.test.rule.ActivityTestRule +import androidx.test.core.app.ActivityScenario +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Before import org.junit.Test import org.kiwix.kiwixmobile.BaseActivityTest import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.help.HelpRobot +import org.kiwix.kiwixmobile.nav.destination.library.OnlineLibraryRobot import org.kiwix.kiwixmobile.settings.SettingsRobot import org.kiwix.kiwixmobile.webserver.ZimHostRobot class TopLevelDestinationTest : BaseActivityTest() { - override var activityRule: ActivityTestRule = activityTestRule { - PreferenceManager.getDefaultSharedPreferences(context).edit { + @Before + fun setUp() { + PreferenceManager.getDefaultSharedPreferences( + InstrumentationRegistry.getInstrumentation().targetContext.applicationContext + ).edit { putBoolean(SharedPreferenceUtil.PREF_SHOW_INTRO, false) putBoolean(SharedPreferenceUtil.PREF_WIFI_ONLY, false) } @@ -38,6 +44,7 @@ class TopLevelDestinationTest : BaseActivityTest() { @Test fun testTopLevelDestination() { + ActivityScenario.launch(KiwixMainActivity::class.java) topLevel { clickReaderOnBottomNav { } @@ -46,11 +53,7 @@ class TopLevelDestinationTest : BaseActivityTest() { clickFileTransferIcon { } } - clickDownloadOnBottomNav { - assertLibraryListDisplayed() - clickOnGlobeIcon { - } - } + clickDownloadOnBottomNav(OnlineLibraryRobot::assertLibraryListDisplayed) clickBookmarksOnNavDrawer { assertBookMarksDisplayed() clickOnTrashIcon() diff --git a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryRobot.kt b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryRobot.kt index d16f5a297..7e04a40e9 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryRobot.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/nav/destination/library/OnlineLibraryRobot.kt @@ -22,8 +22,6 @@ import applyWithViewHierarchyPrinting import org.kiwix.kiwixmobile.BaseRobot import org.kiwix.kiwixmobile.Findable.ViewId import org.kiwix.kiwixmobile.R -import org.kiwix.kiwixmobile.language.LanguageRobot -import org.kiwix.kiwixmobile.language.language fun onlineLibrary(func: OnlineLibraryRobot.() -> Unit) = OnlineLibraryRobot().applyWithViewHierarchyPrinting(func) @@ -34,8 +32,7 @@ class OnlineLibraryRobot : BaseRobot() { isVisible(ViewId(R.id.libraryList)) } - fun clickOnGlobeIcon(func: LanguageRobot.() -> Unit) { + fun clickOnGlobeIcon() { clickOn(ViewId(R.id.select_language)) - language(func) } } 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 cb437cded..369fe1950 100644 --- a/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt +++ b/app/src/androidTest/java/org/kiwix/kiwixmobile/utils/StandardActions.kt @@ -18,16 +18,16 @@ package org.kiwix.kiwixmobile.utils import android.util.Log -import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn -import com.adevinta.android.barista.interaction.BaristaSleepInteractions -import org.kiwix.kiwixmobile.R +import androidx.core.view.GravityCompat import androidx.test.espresso.Espresso 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 +import com.adevinta.android.barista.interaction.BaristaDrawerInteractions.openDrawerWithGravity +import com.adevinta.android.barista.interaction.BaristaSleepInteractions +import org.kiwix.kiwixmobile.R import org.kiwix.kiwixmobile.testutils.TestUtils -import java.lang.RuntimeException /** * Created by mhutti1 on 27/04/17. @@ -39,7 +39,7 @@ object StandardActions { } fun openDrawer() { - BaristaDrawerInteractions.openDrawer() + openDrawerWithGravity(R.id.navigation_container, GravityCompat.START) } @JvmStatic