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

Commit

Permalink
Added UI tests for the Submenu About settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
KMaragh committed Oct 25, 2019
1 parent 6290c0c commit 019943e
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.mozilla.fenix.helpers
import android.view.View
import org.hamcrest.CoreMatchers.not
import org.hamcrest.Matcher
import org.mozilla.fenix.helpers.matchers.TextViewRegexMatcher
import androidx.test.espresso.matcher.ViewMatchers.isChecked as espressoIsChecked
import androidx.test.espresso.matcher.ViewMatchers.isEnabled as espressoIsEnabled
import androidx.test.espresso.matcher.ViewMatchers.isSelected as espressoIsSelected
Expand All @@ -30,3 +31,8 @@ private fun maybeInvertMatcher(matcher: Matcher<View>, useUnmodifiedMatcher: Boo
useUnmodifiedMatcher -> matcher
else -> not(matcher)
}

/**
* The [matchDatePattern] function will match a date pattern following this format: "Wednesday 10/16 @ 12:09 PM".
*/
fun withPattern(regex: String): Matcher<View>? = TextViewRegexMatcher(regex)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.mozilla.fenix.helpers.matchers

import android.view.View
import android.widget.TextView
import androidx.test.espresso.matcher.BoundedMatcher
import org.hamcrest.Description
import java.util.regex.Pattern

class TextViewRegexMatcher(private val regex: String) : BoundedMatcher<View, TextView>(TextView::class.java) {
private val pattern = Pattern.compile(regex)

override fun describeTo(description: Description?) {
description?.appendText("Checking the matcher on received view: with pattern=$regex")
}

override fun matchesSafely(item: TextView?): Boolean {
return item?.text?.let {
pattern.matcher(it).matches()
} ?: false
}
}
22 changes: 18 additions & 4 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SettingsAboutTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import okhttp3.mockwebserver.MockWebServer
import org.junit.Rule
import org.junit.Before
import org.junit.After
import org.junit.Ignore
import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
Expand Down Expand Up @@ -59,25 +58,34 @@ class SettingsAboutTest {
}

// ABOUT
@Ignore("This is a stub test, ignore for now")
@Test
fun verifyHelpRedirect() {
// Open 3dot (main) menu
// Select settings
// Click on "Help"
// Verify redirect to: https://support.mozilla.org/
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.clickOnHelpButton {
verifyHelpUrl()
}
}

@Ignore("This is a stub test, ignore for now")
@Test
fun verifyRateOnGooglePlayRedirect() {
// Open 3dot (main) menu
// Select settings
// Click on "Rate on Google Play"
// Verify Android "Open with Google Play Store" sub menu
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.clickOnRateButton {
verifyRateOnGooglePlayURL()
}
}

@Ignore("This is a stub test, ignore for now")
@Test
fun verifyAboutFirefoxPreview() {
// Open 3dot (main) menu
Expand All @@ -89,5 +97,11 @@ class SettingsAboutTest {
// "Firefox Preview is produced by Mozilla"
// Day, Date, timestamp
// "Open source libraries we use"
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.clickOnAboutFirefoxPreview {
verifyFirefoxPreviewPage()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@ import org.mozilla.fenix.helpers.ext.waitNotNull

class BrowserRobot {

fun verifyHelpUrl() {
fun verifyUrl(redirectUrl: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
val redirectUrl = "https://support.mozilla.org/"
mDevice.waitNotNull(Until.findObject(By.res("org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view")), TestAssetHelper.waitingTime)
onView(withId(R.id.mozac_browser_toolbar_url_view))
.check(matches(withText(containsString(redirectUrl))))
}

fun verifyHelpUrl() {
verifyUrl("https://support.mozilla.org/")
}

fun verifyWhatsNewURL() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
val redirectUrl = "https://support.mozilla.org/"
mDevice.waitNotNull(Until.findObject(By.res("org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view")), TestAssetHelper.waitingTime)
onView(withId(R.id.mozac_browser_toolbar_url_view))
.check(matches(withText(containsString(redirectUrl))))
verifyUrl("https://support.mozilla.org/")
}

fun verifyRateOnGooglePlayURL() {
verifyUrl("https://play.google.com/store/")
}

/* Asserts that the text within DOM element with ID="testContent" has the given text, i.e.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package org.mozilla.fenix.ui.robots

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
Expand Down Expand Up @@ -63,13 +63,42 @@ class SettingsRobot {

fun goBack(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
mDevice.waitForIdle()
goBackButton().perform(ViewActions.click())
goBackButton().click()

HomeScreenRobot().interact()
return HomeScreenRobot.Transition()
}

fun openSearchSubMenu(interact: SettingsSubMenuSearchRobot.() -> Unit): SettingsSubMenuSearchRobot.Transition {
fun clickOnHelpButton(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {

mDevice.waitForIdle()
assertHelp().click()

BrowserRobot().interact()
return BrowserRobot.Transition()
}

fun clickOnRateButton(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {

mDevice.waitForIdle()
assertRateOnGooglePlay().click()

BrowserRobot().interact()
return BrowserRobot.Transition()
}

fun clickOnAboutFirefoxPreview(interact: SettingsSubMenuAboutRobot.() -> Unit):
SettingsSubMenuAboutRobot.Transition {

mDevice.waitForIdle()
assertAboutFirefoxPreview().click()

SettingsSubMenuAboutRobot().interact()
return SettingsSubMenuAboutRobot.Transition()
}

fun openSearchSubMenu(interact: SettingsSubMenuSearchRobot.() -> Unit):
SettingsSubMenuSearchRobot.Transition {
mDevice.waitForIdle()
fun searchEngineButton() = onView(ViewMatchers.withText("Search"))
searchEngineButton().click()
Expand Down Expand Up @@ -172,24 +201,24 @@ private fun assertRemoteDebug() = onView(ViewMatchers.withText("Remote debugging
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

// ABOUT SECTION
private fun assertAboutHeading() {
private fun assertAboutHeading(): ViewInteraction {
TestHelper.scrollToElementByText("About")
onView(ViewMatchers.withText("About"))
return onView(ViewMatchers.withText("About"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
private fun assertHelp() {
private fun assertHelp(): ViewInteraction {
TestHelper.scrollToElementByText("About Firefox Preview")
onView(ViewMatchers.withText("Help"))
return onView(ViewMatchers.withText("Help"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
private fun assertRateOnGooglePlay() {
private fun assertRateOnGooglePlay(): ViewInteraction {
TestHelper.scrollToElementByText("About Firefox Preview")
onView(ViewMatchers.withText("Rate on Google Play"))
return onView(ViewMatchers.withText("Rate on Google Play"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
private fun assertAboutFirefoxPreview() {
private fun assertAboutFirefoxPreview(): ViewInteraction {
TestHelper.scrollToElementByText("About Firefox Preview")
onView(ViewMatchers.withText("About Firefox Preview"))
return onView(ViewMatchers.withText("About Firefox Preview"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,82 @@

package org.mozilla.fenix.ui.robots

import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.Espresso.onView
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.hamcrest.CoreMatchers
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import org.hamcrest.CoreMatchers.containsString
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.withPattern
import org.mozilla.fenix.ui.robots.SettingsSubMenuAboutRobot.Companion.buildAndVersionPattern
import org.mozilla.fenix.ui.robots.SettingsSubMenuAboutRobot.Companion.datePattern

/**
* Implementation of Robot Pattern for the settings search sub menu.
*/
class SettingsSubMenuAboutRobot {

fun verifyFirefoxPreviewPage() = assertFirefoxPreviewPage()

class Transition {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
mDevice.waitForIdle()
goBackButton().perform(ViewActions.click())
goBackButton().perform(click())

SettingsRobot().interact()
return SettingsRobot.Transition()
}
}

companion object {
const val datePattern = "\\w+\\s\\d{1,2}\\/\\d{1,2}\\s\\@\\s\\d{1,2}\\:\\d{1,2}\\s[A|P][M]"
const val buildAndVersionPattern =
"(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)\\s\\((Build)\\s\\#\\d+\\)\\n([^\\x20-\\x7E]+)\\:\\s" +
"(\\d+\\.)?(\\d+\\.)?(\\*|\\d+),\\s\\w+\\n([^\\x20-\\x7E]+|GV):\\s(\\d+\\.)?" +
"(\\d+\\-)?(\\d+)"
}
}

private fun assertFirefoxPreviewPage() {
assertBuildAndVersionNumber()
assertProductCompany()
assertCurrentTimestamp()
assertOpenSourcedLibraries()
}

private fun assertBuildAndVersionNumber() {
onView(withId(R.id.about_text))
.check(matches(withPattern(buildAndVersionPattern)))
}

private fun assertProductCompany() {
onView(withId(R.id.about_content))
.check(matches(withText(containsString("is produced by Mozilla."))))
}

private fun assertCurrentTimestamp() {
onView(withId(R.id.build_date))
.check(matches(withPattern(datePattern)))
}

private fun assertOpenSourcedLibraries() {
val view = onView(withId(R.id.view_licenses_button))
view.check(matches(withText(containsString("Open source libraries we use"))))
view.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
view.perform(click())

onView(withId(R.id.action_bar)).check(matches(hasDescendant(withText(containsString("Firefox Preview")))))
}

private fun goBackButton() =
Espresso.onView(CoreMatchers.allOf(ViewMatchers.withContentDescription("Navigate up")))
onView(CoreMatchers.allOf(withContentDescription("Navigate up")))

0 comments on commit 019943e

Please sign in to comment.