Fixes #10064: Updates UI tests for About Page

fennec/production
ValentinTimisica 4 years ago
parent 9f265fd62f
commit 29be9e4b9f

@ -7,6 +7,10 @@ package org.mozilla.fenix.helpers
import android.graphics.Bitmap import android.graphics.Bitmap
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import junit.framework.AssertionFailedError
import org.hamcrest.CoreMatchers.not import org.hamcrest.CoreMatchers.not
import org.hamcrest.Description import org.hamcrest.Description
import org.hamcrest.Matcher import org.hamcrest.Matcher
@ -56,3 +60,13 @@ fun nthChildOf(
} }
} }
} }
fun ViewInteraction.isVisibleForUser(): Boolean {
try {
check(matches(ViewMatchers.isCompletelyDisplayed()))
} catch (assertionError: AssertionFailedError) {
return false
}
return true
}

@ -17,6 +17,7 @@ import androidx.test.espresso.action.GeneralClickAction
import androidx.test.espresso.action.Press import androidx.test.espresso.action.Press
import androidx.test.espresso.action.Tap import androidx.test.espresso.action.Tap
import androidx.test.espresso.action.ViewActions.longClick import androidx.test.espresso.action.ViewActions.longClick
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
@ -24,6 +25,7 @@ import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiScrollable import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.allOf import org.hamcrest.CoreMatchers.allOf
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.ext.waitNotNull import org.mozilla.fenix.helpers.ext.waitNotNull
@ -79,6 +81,11 @@ object TestHelper {
) )
} }
fun verifyUrl(urlSubstring: String, resourceName: String, resId: Int) {
waitUntilObjectIsFound(resourceName)
onView(withId(resId)).check(ViewAssertions.matches(withText(CoreMatchers.containsString(urlSubstring))))
}
fun openAppFromExternalLink(url: String) { fun openAppFromExternalLink(url: String) {
val context = InstrumentationRegistry.getInstrumentation().getTargetContext() val context = InstrumentationRegistry.getInstrumentation().getTargetContext()
val intent = Intent().apply { val intent = Intent().apply {

@ -12,21 +12,24 @@ import androidx.core.content.pm.PackageInfoCompat
import androidx.test.espresso.Espresso import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewAssertion import androidx.test.espresso.ViewAssertion
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.espresso.action.ViewActions
import androidx.test.uiautomator.UiDevice
import org.hamcrest.CoreMatchers
import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.matcher.ViewMatchers
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.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.Visibility import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.containsString import org.hamcrest.CoreMatchers.containsString
import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestHelper import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.isVisibleForUser
import org.mozilla.fenix.settings.SupportUtils
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.format.DateTimeFormatterBuilder import java.time.format.DateTimeFormatterBuilder
@ -57,12 +60,25 @@ private fun assertFirefoxPreviewPage() {
assertVersionNumber() assertVersionNumber()
assertProductCompany() assertProductCompany()
assertCurrentTimestamp() assertCurrentTimestamp()
verifyListElements()
}
private fun navigateBackToAboutPage(itemToInteract: () -> Unit) {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAboutFirefoxPreview {
itemToInteract()
}
}
private fun verifyListElements() {
assertWhatIsNewInFirefoxPreview() assertWhatIsNewInFirefoxPreview()
assertSupport() navigateBackToAboutPage(::assertSupport)
assertPrivacyNotice() navigateBackToAboutPage(::assertPrivacyNotice)
assertKnowYourRights() navigateBackToAboutPage(::assertKnowYourRights)
assertLicensingInformation() navigateBackToAboutPage(::assertLicensingInformation)
assertLibrariesUsed() navigateBackToAboutPage(::assertLibrariesUsed)
} }
private fun assertVersionNumber() { private fun assertVersionNumber() {
@ -100,106 +116,102 @@ private fun assertCurrentTimestamp() {
} }
private fun assertWhatIsNewInFirefoxPreview() { private fun assertWhatIsNewInFirefoxPreview() {
TestHelper.scrollToElementByText("Whats new in Firefox Preview") if (!onView(withText("Whats new in Firefox Preview")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
onView(withText("Whats new in Firefox Preview")) onView(withText("Whats new in Firefox Preview"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE))) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.perform(click()) .perform(click())
// This is used to wait for the webpage to fully load TestHelper.verifyUrl(
TestHelper.waitUntilObjectIsFound("org.mozilla.fenix.debug:id/mozac_browser_toolbar_title_view") SupportUtils.SumoTopic.WHATS_NEW.topicStr,
"org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view",
onView(withId(R.id.mozac_browser_toolbar_title_view)).check( R.id.mozac_browser_toolbar_url_view
matches(
withText(
containsString("What's new in Firefox Preview")
)
)
) )
Espresso.pressBack() Espresso.pressBack()
} }
private fun assertSupport() { private fun assertSupport() {
TestHelper.scrollToElementByText("Support") if (!onView(withText("Support")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
onView(withText("Support")) onView(withText("Support"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE))) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.perform(click()) .perform(click())
// This is used to wait for the webpage to fully load TestHelper.verifyUrl(
TestHelper.waitUntilObjectIsFound("org.mozilla.fenix.debug:id/mozac_browser_toolbar_title_view") "support.mozilla.org",
"org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view",
onView(withId(R.id.mozac_browser_toolbar_title_view)).check( R.id.mozac_browser_toolbar_url_view
matches(
withText(
containsString("Firefox Preview Help")
)
)
) )
Espresso.pressBack() Espresso.pressBack()
} }
private fun assertPrivacyNotice() { private fun assertPrivacyNotice() {
TestHelper.scrollToElementByText("Privacy Notice") if (!onView(withText("Privacy notice")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
onView(withText("Privacy notice")) onView(withText("Privacy notice"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE))) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.perform(click()) .perform(click())
// This is used to wait for the webpage to fully load TestHelper.verifyUrl(
TestHelper.waitUntilObjectIsFound("org.mozilla.fenix.debug:id/mozac_browser_toolbar_title_view") "/privacy/firefox",
"org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view",
onView(withId(R.id.mozac_browser_toolbar_title_view)).check( R.id.mozac_browser_toolbar_url_view
matches(
withText(
containsString("Firefox Privacy Notice")
)
)
) )
Espresso.pressBack() Espresso.pressBack()
} }
private fun assertKnowYourRights() { private fun assertKnowYourRights() {
TestHelper.scrollToElementByText("Know your rights") if (!onView(withText("Know your rights")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
onView(withText("Know your rights")) onView(withText("Know your rights"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE))) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.perform(click()) .perform(click())
// This is used to wait for the webpage to fully load TestHelper.verifyUrl(
TestHelper.waitUntilObjectIsFound("org.mozilla.fenix.debug:id/mozac_browser_toolbar_title_view") SupportUtils.SumoTopic.YOUR_RIGHTS.topicStr,
"org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view",
onView(withId(R.id.mozac_browser_toolbar_title_view)).check( R.id.mozac_browser_toolbar_url_view
matches(
withText(
containsString("Firefox Preview - Your Rights | Firefox Preview Help")
)
)
) )
Espresso.pressBack() Espresso.pressBack()
} }
private fun assertLicensingInformation() { private fun assertLicensingInformation() {
TestHelper.scrollToElementByText("Libraries that we use") if (!onView(withText("Licensing information")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
onView(withText("Licensing information")) onView(withText("Licensing information"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE))) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.perform(click()) .perform(click())
// This is used to wait for the webpage to fully load TestHelper.verifyUrl(
TestHelper.waitUntilObjectIsFound("org.mozilla.fenix.debug:id/mozac_browser_toolbar_title_view") "about:license",
"org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view",
onView(withId(R.id.mozac_browser_toolbar_title_view)).check( R.id.mozac_browser_toolbar_url_view
matches(
withText(
containsString("Licenses")
)
)
) )
Espresso.pressBack() Espresso.pressBack()
} }
private fun assertLibrariesUsed() { private fun assertLibrariesUsed() {
TestHelper.scrollToElementByText("Libraries that we use") if (!onView(withText("Libraries that we use")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
onView(withText("Libraries that we use")) onView(withText("Libraries that we use"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE))) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.perform(click()) .perform(click())
onView(withId(R.id.action_bar)).check(matches(hasDescendant(withText(containsString("Firefox Preview | OSS Libraries"))))) onView(withId(R.id.action_bar)).check(matches(hasDescendant(withText(containsString("Firefox Preview | OSS Libraries")))))

Loading…
Cancel
Save