From d7c63a63c699199323197d00d19ed0599766bdab Mon Sep 17 00:00:00 2001 From: mcarare Date: Wed, 14 Oct 2020 17:26:35 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/15688: Update UI tests. --- .../mozilla/fenix/ui/TabbedBrowsingTest.kt | 12 +++++++---- .../fenix/ui/robots/HomeScreenRobot.kt | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt index 7ff893c418..bebecaba52 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt @@ -311,8 +311,10 @@ class TabbedBrowsingTest { }.enterURLAndEnterToBrowser(defaultWebPage.url) { }.openTabButtonShortcutsMenu { }.openNewPrivateTabFromShortcutsMenu { - verifyHomeScreen() - verifyNavigationToolbar() + verifyKeyboardVisible() + verifyFocusedNavigationToolbar() + // dismiss search dialog + homeScreen { }.pressBack() verifyHomePrivateBrowsingButton() verifyHomeMenu() verifyHomeWordmark() @@ -326,8 +328,10 @@ class TabbedBrowsingTest { }.openTabButtonShortcutsMenu { }.openTabFromShortcutsMenu { - verifyHomeScreen() - verifyNavigationToolbar() + verifyKeyboardVisible() + verifyFocusedNavigationToolbar() + // dismiss search dialog + homeScreen { }.pressBack() verifyHomeMenu() verifyHomeWordmark() verifyTabButton() diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt index 8540e2a0a3..b9edac4a23 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt @@ -25,6 +25,7 @@ import androidx.test.espresso.matcher.ViewMatchers.hasSibling import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility +import androidx.test.espresso.matcher.ViewMatchers.withHint import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.platform.app.InstrumentationRegistry @@ -38,6 +39,7 @@ import androidx.test.uiautomator.Until.findObject import org.hamcrest.CoreMatchers.allOf import org.hamcrest.CoreMatchers.containsString import org.hamcrest.CoreMatchers.not +import org.junit.Assert import org.mozilla.fenix.R import org.mozilla.fenix.components.Search import org.mozilla.fenix.helpers.TestAssetHelper @@ -52,6 +54,7 @@ import org.mozilla.fenix.helpers.withBitmapDrawable */ class HomeScreenRobot { fun verifyNavigationToolbar() = assertNavigationToolbar() + fun verifyFocusedNavigationToolbar() = assertFocusedNavigationToolbar() fun verifyHomeScreen() = assertHomeScreen() fun verifyHomePrivateBrowsingButton() = assertHomePrivateBrowsingButton() fun verifyHomeMenu() = assertHomeMenu() @@ -64,6 +67,7 @@ class HomeScreenRobot { fun verifyHomeComponent() = assertHomeComponent() fun verifyDefaultSearchEngine(searchEngine: String) = verifySearchEngineIcon(searchEngine) fun verifyNoTabsOpened() = assertNoTabsOpened() + fun verifyKeyboardVisible() = assertKeyboardVisibility(isExpectedToBeVisible = true) // First Run elements fun verifyWelcomeHeader() = assertWelcomeHeader() @@ -387,6 +391,10 @@ class HomeScreenRobot { .perform(click()) } + fun pressBack() { + onView(ViewMatchers.isRoot()).perform(ViewActions.pressBack()) + } + fun openTabsListThreeDotMenu(interact: ThreeDotMenuMainRobot.() -> Unit): ThreeDotMenuMainRobot.Transition { // tabsListThreeDotButton().perform(click()) @@ -481,6 +489,14 @@ fun homeScreen(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val appContext = InstrumentationRegistry.getInstrumentation().targetContext +private fun assertKeyboardVisibility(isExpectedToBeVisible: Boolean) = + Assert.assertEquals( + isExpectedToBeVisible, + UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + .executeShellCommand("dumpsys input_method | grep mInputShown") + .contains("mInputShown=true") + ) + private fun navigationToolbar() = onView(allOf(withText("Search or enter address"))) @@ -490,6 +506,10 @@ private fun assertNavigationToolbar() = onView(allOf(withText("Search or enter address"))) .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +private fun assertFocusedNavigationToolbar() = + onView(allOf(withHint("Search or enter address"))) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + private fun assertHomeScreen() = onView(ViewMatchers.withResourceName("homeLayout")) .check(matches(withEffectiveVisibility(Visibility.VISIBLE)))