From fdda2e300111fdc91d6c44590528b3d8d1e11f23 Mon Sep 17 00:00:00 2001 From: Oana Horvath Date: Thu, 26 Nov 2020 11:10:21 +0200 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/16615: UI smoke test toggleSearchSuggestions --- .../helpers/RecyclerViewIdlingResource.kt | 2 +- .../mozilla/fenix/ui/SettingsBasicsTest.kt | 19 ------- .../java/org/mozilla/fenix/ui/SmokeTest.kt | 50 +++++++++++++++++++ .../fenix/ui/robots/NavigationToolbarRobot.kt | 20 +++----- 4 files changed, 59 insertions(+), 32 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/helpers/RecyclerViewIdlingResource.kt b/app/src/androidTest/java/org/mozilla/fenix/helpers/RecyclerViewIdlingResource.kt index 61de022cfe..68b671b559 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/helpers/RecyclerViewIdlingResource.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/helpers/RecyclerViewIdlingResource.kt @@ -9,7 +9,7 @@ class RecyclerViewIdlingResource constructor(private val recycler: androidx.recy private var callback: ResourceCallback? = null override fun isIdleNow(): Boolean { - if (recycler.adapter != null && recycler.adapter!!.itemCount > minItemCount) { + if (recycler.adapter != null && recycler.adapter!!.itemCount >= minItemCount) { if (callback != null) { callback!!.onTransitionToIdle() } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt index ebafc68ac1..b21e7044e7 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt @@ -105,25 +105,6 @@ class SettingsBasicsTest { } } - @Ignore("This test works locally, fails on firebase. https://github.com/mozilla-mobile/fenix/issues/8174") - @Test - fun toggleSearchSuggestions() { - // Goes through the settings and changes the search suggestion toggle, then verifies it changes. - homeScreen { - }.openNavigationToolbar { - verifySearchSuggestionsAreMoreThan(1, "mozilla") - }.goBack { - }.openThreeDotMenu { - }.openSettings { - }.openSearchSubMenu { - disableShowSearchSuggestions() - }.goBack { - }.goBack { - }.openNavigationToolbar { - verifySearchSuggestionsAreEqualTo(0, "mozilla") - } - } - @Test fun toggleShowVisitedSitesAndBookmarks() { // Bookmarks a few websites, toggles the history and bookmarks setting to off, then verifies if the visited and bookmarked websites do not show in the suggestions. diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt index 15e2f414af..772e7765f3 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt @@ -4,7 +4,10 @@ package org.mozilla.fenix.ui +import android.view.View import androidx.core.net.toUri +import androidx.recyclerview.widget.RecyclerView +import androidx.test.espresso.IdlingRegistry import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import okhttp3.mockwebserver.MockWebServer @@ -12,9 +15,12 @@ import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test +import org.mozilla.fenix.R import org.mozilla.fenix.helpers.AndroidAssetDispatcher import org.mozilla.fenix.helpers.HomeActivityTestRule +import org.mozilla.fenix.helpers.RecyclerViewIdlingResource import org.mozilla.fenix.helpers.TestAssetHelper +import org.mozilla.fenix.helpers.ViewVisibilityIdlingResource import org.mozilla.fenix.ui.robots.clickUrlbar import org.mozilla.fenix.ui.robots.homeScreen import org.mozilla.fenix.ui.robots.navigationToolbar @@ -27,6 +33,8 @@ import org.mozilla.fenix.ui.robots.navigationToolbar class SmokeTest { private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) private lateinit var mockWebServer: MockWebServer + private var awesomeBar: ViewVisibilityIdlingResource? = null + private var searchSuggestionsIdlingResource: RecyclerViewIdlingResource? = null @get:Rule val activityTestRule = HomeActivityTestRule() @@ -273,4 +281,46 @@ class SmokeTest { verifyEnginesListShortcutContains("YouTube") } } + + @Test + fun toggleSearchSuggestions() { + // Goes through the settings and changes the search suggestion toggle, then verifies it changes. + homeScreen { + }.openNavigationToolbar { + typeSearchTerm("mozilla") + val awesomeBarView = getAwesomebarView() + awesomeBarView?.let { + awesomeBar = ViewVisibilityIdlingResource(it, View.VISIBLE) + } + IdlingRegistry.getInstance().register(awesomeBar!!) + searchSuggestionsIdlingResource = + RecyclerViewIdlingResource(awesomeBarView as RecyclerView, 1) + IdlingRegistry.getInstance().register(searchSuggestionsIdlingResource!!) + verifySearchSuggestionsAreMoreThan(1) + IdlingRegistry.getInstance().unregister(searchSuggestionsIdlingResource!!) + }.goBack { + }.openThreeDotMenu { + }.openSettings { + }.openSearchSubMenu { + disableShowSearchSuggestions() + }.goBack { + }.goBack { + }.openNavigationToolbar { + typeSearchTerm("mozilla") + searchSuggestionsIdlingResource = + RecyclerViewIdlingResource(getAwesomebarView() as RecyclerView) + IdlingRegistry.getInstance().register(searchSuggestionsIdlingResource!!) + verifySearchSuggestionsAreEqualTo(0) + IdlingRegistry.getInstance().unregister(searchSuggestionsIdlingResource!!) + } + } + + // This finds the dialog fragment child of the homeFragment, otherwise the awesomeBar would return null + private fun getAwesomebarView(): View? { + val homeFragment = activityTestRule.activity.supportFragmentManager.primaryNavigationFragment + val searchDialogFragment = homeFragment?.childFragmentManager?.fragments?.first { + it.javaClass.simpleName == "SearchDialogFragment" + } + return searchDialogFragment?.view?.findViewById(R.id.awesome_bar) + } } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt index 184bf7eafe..250aa25462 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.kt @@ -43,16 +43,18 @@ import org.mozilla.fenix.helpers.ext.waitNotNull */ class NavigationToolbarRobot { - fun verifySearchSuggestionsAreMoreThan(suggestionSize: Int, searchTerm: String) = - assertSuggestionsAreMoreThan(suggestionSize, searchTerm) + fun verifySearchSuggestionsAreMoreThan(suggestionSize: Int) = + assertSuggestionsAreMoreThan(suggestionSize) - fun verifySearchSuggestionsAreEqualTo(suggestionSize: Int, searchTerm: String) = - assertSuggestionsAreEqualTo(suggestionSize, searchTerm) + fun verifySearchSuggestionsAreEqualTo(suggestionSize: Int) = + assertSuggestionsAreEqualTo(suggestionSize) fun verifyNoHistoryBookmarks() = assertNoHistoryBookmarks() fun verifyTabButtonShortcutMenuItems() = assertTabButtonShortcutMenuItems() + fun typeSearchTerm(searchTerm: String) = awesomeBar().perform(typeText(searchTerm)) + class Transition { private lateinit var sessionLoadedIdlingResource: SessionLoadedIdlingResource @@ -246,18 +248,12 @@ fun clickUrlbar(interact: SearchRobot.() -> Unit): SearchRobot.Transition { return SearchRobot.Transition() } -private fun assertSuggestionsAreEqualTo(suggestionSize: Int, searchTerm: String) { - mDevice.waitForIdle() - awesomeBar().perform(typeText(searchTerm)) - +private fun assertSuggestionsAreEqualTo(suggestionSize: Int) { mDevice.waitForIdle() onView(withId(R.id.awesome_bar)).check(suggestionsAreEqualTo(suggestionSize)) } -private fun assertSuggestionsAreMoreThan(suggestionSize: Int, searchTerm: String) { - mDevice.waitForIdle() - awesomeBar().perform(typeText(searchTerm)) - +private fun assertSuggestionsAreMoreThan(suggestionSize: Int) { mDevice.waitForIdle() onView(withId(R.id.awesome_bar)).check(suggestionsAreGreaterThan(suggestionSize)) }