From 576558818ee566d7cea2a1184582b244f8f071e9 Mon Sep 17 00:00:00 2001 From: TejaswiKarasani Date: Sat, 13 Jun 2020 19:21:40 +0530 Subject: [PATCH] For #116 #173: UI test for verifying the nav toolbar buttons (#10976) --- .../java/org/mozilla/fenix/ui/SmokeTest.kt | 64 +++++++++++++++++++ .../mozilla/fenix/ui/robots/BrowserRobot.kt | 62 +++++++++++++++++- .../fenix/ui/robots/NavigationToolbarRobot.kt | 19 ++++++ 3 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt new file mode 100644 index 000000000..22d8f3110 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt @@ -0,0 +1,64 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.ui + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.uiautomator.UiDevice +import okhttp3.mockwebserver.MockWebServer +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.mozilla.fenix.helpers.AndroidAssetDispatcher +import org.mozilla.fenix.helpers.HomeActivityTestRule +import org.mozilla.fenix.helpers.TestAssetHelper +import org.mozilla.fenix.ui.robots.homeScreen +import org.mozilla.fenix.ui.robots.navigationToolbar + +/** + * Test Suite that contains tests defined as part of the Smoke and Sanity check defined in Test rail. + * These tests will verify different functionalities of the app as a way to quickly detect regressions in main areas + */ +class SmokeTest { + private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + private lateinit var mockWebServer: MockWebServer + + @get:Rule + val activityTestRule = HomeActivityTestRule() + + @Before + fun setUp() { + mockWebServer = MockWebServer().apply { + setDispatcher(AndroidAssetDispatcher()) + start() + } + } + + @After + fun tearDown() { + mockWebServer.shutdown() + } + + @Test + fun verifyBasicNavigationToolbarFunctionality() { + val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) + + homeScreen { + navigationToolbar { + }.enterURLAndEnterToBrowser(defaultWebPage.url) { + verifyPageContent(defaultWebPage.content) + verifyNavURLBarItems() + }.openNavigationToolbar { + }.goBackToWebsite { + // Check disabled due to intermittent failures + // verifyPageContent(defaultWebPage.content) + }.openTabDrawer { + verifyExistingTabList() + }.openHomeScreen { + verifyHomeScreen() + } + } + } +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt index 2650d73d9..f8d1a00be 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt @@ -10,6 +10,7 @@ import android.content.Context import android.content.Intent import android.net.Uri import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.Espresso.pressBack import androidx.test.espresso.action.ViewActions import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.intent.Intents @@ -17,6 +18,7 @@ import androidx.test.espresso.intent.matcher.BundleMatchers import androidx.test.espresso.intent.matcher.IntentMatchers import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed +import androidx.test.espresso.matcher.ViewMatchers.Visibility import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText @@ -134,6 +136,32 @@ class BrowserRobot { ) } + fun verifyNavURLBar() = assertNavURLBar() + + fun verifySecureConnectionLockIcon() = assertSecureConnectionLockIcon() + + fun verifyEnhancedTrackingProtectionSwitch() = assertEnhancedTrackingProtectionSwitch() + + fun verifyProtectionSettingsButton() = assertProtectionSettingsButton() + + fun verifyEnhancedTrackingOptions() { + clickEnhancedTrackingProtectionPanel() + verifyEnhancedTrackingProtectionSwitch() + verifyProtectionSettingsButton() + } + + fun verifyMenuButton() = assertMenuButton() + + fun verifyNavURLBarItems() { + verifyEnhancedTrackingOptions() + pressBack() + waitingTime + verifySecureConnectionLockIcon() + verifyTabCounter("1") + verifyNavURLBar() + verifyMenuButton() + } + fun verifyNoLinkImageContextMenuItems(containsTitle: String) { val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) mDevice.waitNotNull(Until.findObject(By.textContains(containsTitle))) @@ -147,6 +175,8 @@ class BrowserRobot { ) } + fun clickEnhancedTrackingProtectionPanel() = enhancedTrackingProtectionPanel().click() + fun clickContextOpenLinkInNewTab() { val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) mDevice.waitNotNull( @@ -336,8 +366,7 @@ class BrowserRobot { } fun openTabDrawer(interact: TabDrawerRobot.() -> Unit): TabDrawerRobot.Transition { - mDevice.waitForIdle() - + mDevice.waitForIdle(waitingTime) tabsCounter().click() mDevice.waitNotNull( @@ -372,7 +401,34 @@ fun dismissTrackingOnboarding() { fun navURLBar() = onView(withId(R.id.mozac_browser_toolbar_url_view)) -private fun tabsCounter() = onView(withId(R.id.mozac_browser_toolbar_browser_actions)) +private fun assertNavURLBar() = navURLBar() + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + +fun enhancedTrackingProtectionPanel() = onView(withId(R.id.mozac_browser_toolbar_tracking_protection_indicator)) + +private fun assertEnhancedTrackingProtectionSwitch() { + withText(R.id.trackingProtectionSwitch) + .matches(withEffectiveVisibility(Visibility.VISIBLE)) +} + +private fun assertProtectionSettingsButton() { + onView(withId(R.id.protection_settings)) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +} + +private fun assertSecureConnectionLockIcon() { + onView(withId(R.id.mozac_browser_toolbar_security_indicator)) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +} + +private fun menuButton() = onView(withId(R.id.icon)) + +private fun assertMenuButton() { + menuButton() + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) +} + +private fun tabsCounter() = onView(withId(R.id.counter_box)) private fun mediaPlayerPlayButton() = mDevice.findObject( 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 b752b0fa2..057cc6cf2 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 @@ -24,6 +24,7 @@ import androidx.test.uiautomator.By import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.Until import org.hamcrest.CoreMatchers.anyOf +import org.hamcrest.CoreMatchers.containsString import org.hamcrest.CoreMatchers.not import org.mozilla.fenix.R import org.mozilla.fenix.helpers.SessionLoadedIdlingResource @@ -51,6 +52,24 @@ class NavigationToolbarRobot { private lateinit var sessionLoadedIdlingResource: SessionLoadedIdlingResource val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + fun goBackToWebsite(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition { + mDevice.waitNotNull( + Until.findObject(By.res("org.mozilla.fenix.debug:id/toolbar")), + waitingTime + ) + urlBar().click() + mDevice.waitNotNull( + Until.findObject(By.res("org.mozilla.fenix.debug:id/mozac_browser_toolbar_edit_url_view")), + waitingTime + ) + clearAddressBar().click() + awesomeBar().check((matches(withText(containsString(""))))) + goBackButton() + + BrowserRobot().interact() + return BrowserRobot.Transition() + } + fun enterURLAndEnterToBrowser( url: Uri, interact: BrowserRobot.() -> Unit