From bc452b6adca374ec2038be6e730c9c7aa9005612 Mon Sep 17 00:00:00 2001 From: Oana Horvath Date: Wed, 22 Sep 2021 17:42:00 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/17847: adding back editCustomSearchEngineTest UI test --- .../java/org/mozilla/fenix/ui/SmokeTest.kt | 31 +++++++ .../ui/robots/SettingsSubMenuSearchRobot.kt | 80 ++++++++++++++----- 2 files changed, 93 insertions(+), 18 deletions(-) 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 44d7dbc72..45aad8c36 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt @@ -544,6 +544,37 @@ class SmokeTest { } } + @Test + // Verifies setting as default a customized search engine name and URL + fun editCustomSearchEngineTest() { + val searchEngine = object { + var title = "Elefant" + var url = "https://www.elefant.ro/search?SearchTerm=%s" + var newTitle = "Test" + } + + homeScreen { + }.openThreeDotMenu { + }.openSettings { + }.openSearchSubMenu { + openAddSearchEngineMenu() + selectAddCustomSearchEngine() + typeCustomEngineDetails(searchEngine.title, searchEngine.url) + saveNewSearchEngine() + openEngineOverflowMenu(searchEngine.title) + clickEdit() + typeCustomEngineDetails(searchEngine.newTitle, searchEngine.url) + saveEditSearchEngine() + changeDefaultSearchEngine(searchEngine.newTitle) + }.goBack { + }.goBack { + }.openSearch { + verifyDefaultSearchEngine(searchEngine.newTitle) + clickSearchEngineShortcutButton() + verifyEnginesListShortcutContains(activityTestRule, searchEngine.newTitle) + } + } + @Ignore("Disabled for failing with new Compose Awesomebar") @Test // Test running on beta/release builds in CI: diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSearchRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSearchRobot.kt index 435ce4a8f..731aa75df 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSearchRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuSearchRobot.kt @@ -8,23 +8,28 @@ package org.mozilla.fenix.ui.robots import androidx.recyclerview.widget.RecyclerView import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.clearText import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.action.ViewActions.typeText import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.contrib.RecyclerViewActions -import androidx.test.espresso.matcher.ViewMatchers.Visibility +import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.hasDescendant import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withChild import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withParent import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.UiSelector import org.hamcrest.CoreMatchers +import org.hamcrest.Matchers.allOf +import org.junit.Assert.assertTrue import org.mozilla.fenix.R import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime -import org.mozilla.fenix.helpers.TestHelper.packageName import org.mozilla.fenix.helpers.click /** @@ -53,9 +58,11 @@ class SettingsSubMenuSearchRobot { fun saveNewSearchEngine() { addSearchEngineSaveButton().click() - mDevice.findObject( - UiSelector().resourceId("$packageName:id/recycler_view") - ).waitForExists(waitingTime) + assertTrue( + mDevice.findObject( + UiSelector().textContains("Default search engine") + ).waitForExists(waitingTime) + ) } fun addNewSearchEngine(searchEngineName: String) { @@ -63,6 +70,35 @@ class SettingsSubMenuSearchRobot { saveNewSearchEngine() } + fun selectAddCustomSearchEngine() = onView(withText("Other")).click() + + fun typeCustomEngineDetails(engineName: String, engineURL: String) { + onView(withId(R.id.edit_engine_name)) + .perform(clearText()) + .perform(typeText(engineName)) + onView(withId(R.id.edit_search_string)) + .perform(clearText()) + .perform(typeText(engineURL)) + } + + fun openEngineOverflowMenu(searchEngineName: String) { + mDevice.findObject( + UiSelector().resourceId("org.mozilla.fenix.debug:id/overflow_menu") + ).waitForExists(waitingTime) + threeDotMenu(searchEngineName).click() + } + + fun clickEdit() = onView(withText("Edit")).click() + + fun saveEditSearchEngine() { + onView(withId(R.id.save_button)).click() + assertTrue( + mDevice.findObject( + UiSelector().textContains("Saved") + ).waitForExists(waitingTime) + ) + } + class Transition { val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) @@ -78,21 +114,21 @@ class SettingsSubMenuSearchRobot { private fun assertDefaultSearchEngineHeader() = onView(withText("Default search engine")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) private fun assertSearchEngineList() { onView(withText("Google")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) onView(withText("Amazon.com")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) onView(withText("Bing")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) onView(withText("DuckDuckGo")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) onView(withText("Wikipedia")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) onView(withText("Add search engine")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) } private fun assertShowSearchSuggestions() { @@ -102,7 +138,7 @@ private fun assertShowSearchSuggestions() { ) ) onView(withText("Show search suggestions")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) } private fun assertShowSearchShortcuts() { @@ -112,7 +148,7 @@ private fun assertShowSearchShortcuts() { ) ) onView(withText("Show search engines")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) } private fun assertShowClipboardSuggestions() { @@ -122,7 +158,7 @@ private fun assertShowClipboardSuggestions() { ) ) onView(withText("Show clipboard suggestions")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) } private fun assertSearchBrowsingHistory() { @@ -132,7 +168,7 @@ private fun assertSearchBrowsingHistory() { ) ) onView(withText("Search browsing history")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) } private fun assertSearchBookmarks() { @@ -142,12 +178,12 @@ private fun assertSearchBookmarks() { ) ) onView(withText("Search bookmarks")) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) } private fun selectSearchEngine(searchEngine: String) { onView(withText(searchEngine)) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) .perform(click()) } @@ -189,3 +225,11 @@ private fun addSearchEngineSaveButton() = onView(withId(R.id.add_search_engine)) private fun assertEngineListContains(searchEngineName: String) { onView(withId(R.id.search_engine_group)).check(matches(hasDescendant(withText(searchEngineName)))) } + +private fun threeDotMenu(searchEngineName: String) = + onView( + allOf( + withId(R.id.overflow_menu), + withParent(withChild(withText(searchEngineName))) + ) + )