Unverified Commit 57655881 authored by TejaswiKarasani's avatar TejaswiKarasani Committed by GitHub
Browse files

For #116 #173: UI test for verifying the nav toolbar buttons (#10976)

parent 704fc6f9
/* 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()
}
}
}
}
......@@ -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(
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment