Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Issue:116, Issue:173 Verify the nav toolbar buttons[UI Tests] #10822

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* 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

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 verifyTheNavToolBarButtonsTest() {
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val defaultWebPageTitle = "Test_Page_1"

// Visit a URL, wait until it's loaded
homeScreen {
navigationToolbar {
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
verifyPageContent(defaultWebPage.content)

// Verify the items of Nav URL Bar
verifyNavURLBarItems()

// Verify 'x' button actions
// verifyXButtonActions()
// TestAssetHelper.waitingTime

// Verify various items after returning back to the initial WebPage
// verifyNavURLBar()
verifyPageContent(defaultWebPage.content)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TejaswiKarasani I think the error you are seeing comes from this line...can you try to wait longer just to check that? if it still fails, try commenting out this line...thinking about more options here in the meantime...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other option may be to check the content in the url bar...and see if that works...

Copy link
Contributor Author

@TejaswiKarasani TejaswiKarasani May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other option may be to check the content in the url bar...and see if that works...

When I saw in UI Automator, I couldn't find any specific id for the content in the url bar, I just found the whole url under one id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is text (although I'm not sure you can say starts with...the port number will change each time)
Screenshot 2020-05-25 at 17 56 50

Copy link
Contributor Author

@TejaswiKarasani TejaswiKarasani May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought it was the whole red highlight box and didn't struck my mind that it is for text inside the red box and by the way there is some particular function for testhelper.longWaitingTime or testhelper.longWaitingTime...and set time for minutes and seconds? or should I create a separate function for the long waiting time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may be able to use one off those

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah cool.!

}.openHomeScreen {

// Verify items on HomeScreen
verifyHomeScreen()
verifyExistingTabList()

// Go to the same page again and check for main menu
}.openTab(defaultWebPageTitle) {
clickMenuButton()
verifyMainMenu()
}
}
}
}
103 changes: 102 additions & 1 deletion app/src/androidTest/java/org/mozilla/fenix/ui/robots/BrowserRobot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ 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
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
Expand Down Expand Up @@ -134,6 +136,48 @@ class BrowserRobot {
)
}

fun verifyNavURLBar() = assertNavURLBar()

fun verifyNavURLBarEditMode() = assertNavURLBarEditMode()

fun verifyNavURLBarEditModeEmpty() = assertNavURLBarEditModeEmpty()

fun verifySecureConnectionLockIcon() = assertSecureConnectionLockIcon()

fun verifyEnhancedTrackingProtectionSwitch() = assertEnhancedTrackingProtectionSwitch()

fun verifyProtectionSettingsButton() = assertProtectionSettingsButton()

fun verifyEnhancedTrackingOptions() {
clickEnhancedTrackingProtectionIcon()
verifyEnhancedTrackingProtectionSwitch()
verifyProtectionSettingsButton()
}

fun verifyMenuButton() = assertMenuButton()

fun verifyNavURLBarItems() {
verifyEnhancedTrackingOptions()
pressBack()
waitingTime
verifySecureConnectionLockIcon()
verifyTabCounter("1")
verifyNavURLBar()
verifyMenuButton()
}

fun verifyXButton() = assertXButton()

fun verifyXButtonActions() {
clickNavURLBar()
verifyXButton()
clickXButton()
verifyNavURLBarEditMode()
verifyNavURLBarEditModeEmpty()
}

fun verifyMainMenu() = assertMainMenu()

fun verifyNoLinkImageContextMenuItems(containsTitle: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.textContains(containsTitle)))
Expand All @@ -147,6 +191,14 @@ class BrowserRobot {
)
}

fun clickEnhancedTrackingProtectionIcon() = enhancedTrackingProtectionIcon().click()

fun clickNavURLBar() = navURLBar().click()

fun clickXButton() = xButton().click()

fun clickMenuButton() = menuButton().click()

fun clickContextOpenLinkInNewTab() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(
Expand Down Expand Up @@ -370,7 +422,56 @@ fun dismissTrackingOnboarding() {
dismissOnboardingButton().click()
}

fun navURLBar() = onView(withId(R.id.mozac_browser_toolbar_url_view))
private fun navURLBar() = onView(withId(R.id.mozac_browser_toolbar_url_view))

private fun assertNavURLBar() = navURLBar()
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun navURLBarEditMode() = onView(withId(R.id.mozac_browser_toolbar_edit_url_view))

private fun assertNavURLBarEditMode() {
navURLBarEditMode()
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

private fun assertNavURLBarEditModeEmpty() {
navURLBarEditMode()
.check((matches(withText(containsString("")))))
}

fun enhancedTrackingProtectionIcon() = 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 xButton() = onView(withId(R.id.mozac_browser_toolbar_clear_view))

private fun assertXButton() = xButton()
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun menuButton() = onView(withId(R.id.icon))

private fun assertMenuButton() {
menuButton()
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

private fun assertMainMenu() {
onView(withId(R.id.mozac_browser_menu_recyclerView))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

private fun tabsCounter() = onView(withId(R.id.mozac_browser_toolbar_browser_actions))

Expand Down