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

Commit

Permalink
For #20754: Fix scrolling issues and re-enable verifyAboutFirefoxPreview
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Horvath authored and mergify[bot] committed May 17, 2022
1 parent 4c223aa commit f6f1446
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ object Constants {
}

const val LONG_CLICK_DURATION: Long = 5000
const val LISTS_MAXSWIPES: Int = 3
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import okhttp3.mockwebserver.MockWebServer
import org.junit.Rule
import org.junit.Before
import org.junit.Ignore
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
Expand Down Expand Up @@ -75,7 +74,6 @@ class SettingsAboutTest {
}
}

@Ignore("Intermittent failures, see: https://github.com/mozilla-mobile/fenix/issues/20754")
@Test
fun verifyAboutFirefoxPreview() {
val settings = activityIntentTestRule.activity.settings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.endsWith
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.LISTS_MAXSWIPES
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_PLAY_SERVICES
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.appName
Expand Down Expand Up @@ -554,31 +555,22 @@ private fun assertLeakCanaryButton() {

// ABOUT SECTION
private fun assertAboutHeading(): ViewInteraction {
scrollToElementByText("About")
settingsList().scrollToEnd(LISTS_MAXSWIPES)
return onView(withText("About"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

private fun rateOnGooglePlayHeading(): UiObject {
val rateOnGooglePlay = mDevice.findObject(UiSelector().text("Rate on Google Play"))
scrollToElementByText("Rate on Google Play")
if (!rateOnGooglePlay.exists()) {
settingsList().swipeUp(2)
rateOnGooglePlay.waitForExists(waitingTime)
}
settingsList().scrollToEnd(LISTS_MAXSWIPES)
rateOnGooglePlay.waitForExists(waitingTime)

return rateOnGooglePlay
}

private fun aboutFirefoxHeading(): UiObject {
val aboutFirefoxHeading = mDevice.findObject(UiSelector().text("About $appName"))
scrollToElementByText("About $appName")
if (!aboutFirefoxHeading.exists()) {
settingsList().swipeUp(2)
aboutFirefoxHeading.waitForExists(waitingTime)
}

return aboutFirefoxHeading
settingsList().scrollToEnd(LISTS_MAXSWIPES)
return mDevice.findObject(UiSelector().text("About $appName"))
}

fun swipeToBottom() = onView(withId(R.id.recycler_view)).perform(ViewActions.swipeUp())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,35 @@ import androidx.core.content.pm.PackageInfoCompat
import androidx.test.espresso.Espresso
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewAssertion
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
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.withSubstring
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatterBuilder
import java.time.temporal.ChronoField
import java.util.Calendar
import java.util.Date
import org.hamcrest.CoreMatchers
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
import org.junit.Assert.assertTrue
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.LISTS_MAXSWIPES
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.isVisibleForUser
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.settings.SupportUtils
import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatterBuilder
import java.time.temporal.ChronoField
import java.util.Calendar
import java.util.Date

/**
* Implementation of Robot Pattern for the settings search sub menu.
Expand Down Expand Up @@ -129,20 +131,15 @@ private fun assertCurrentTimestamp() {
}

private fun assertWhatIsNewInFirefoxPreview() {

if (!onView(withText("What’s new in $appName")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
aboutMenuList.scrollToEnd(LISTS_MAXSWIPES)

onView(withText("What’s new in $appName"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.perform(click())
}

private fun assertSupport() {
if (!onView(withText("Support")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
aboutMenuList.scrollToEnd(LISTS_MAXSWIPES)

onView(withText("Support"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
Expand All @@ -159,29 +156,27 @@ private fun assertCrashes() {
navigationToolbar {
}.openThreeDotMenu {
}.openSettings {
}.openAboutFirefoxPreview {
}
}.openAboutFirefoxPreview {}

if (!onView(withText("Crashes")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
aboutMenuList.scrollToEnd(LISTS_MAXSWIPES)

onView(withText("Crashes"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.perform(click())

onView(withSubstring("No crash reports have been submitted"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
assertTrue(
mDevice.findObject(
UiSelector().textContains("No crash reports have been submitted.")
).waitForExists(waitingTime)
)

for (i in 1..3) {
Espresso.pressBack()
}
}

private fun assertPrivacyNotice() {
if (!onView(withText("Privacy notice")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
aboutMenuList.scrollToEnd(LISTS_MAXSWIPES)

onView(withText("Privacy notice"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
Expand All @@ -195,9 +190,7 @@ private fun assertPrivacyNotice() {
}

private fun assertKnowYourRights() {
if (!onView(withText("Know your rights")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
aboutMenuList.scrollToEnd(LISTS_MAXSWIPES)

onView(withText("Know your rights"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
Expand All @@ -211,9 +204,7 @@ private fun assertKnowYourRights() {
}

private fun assertLicensingInformation() {
if (!onView(withText("Licensing information")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
aboutMenuList.scrollToEnd(LISTS_MAXSWIPES)

onView(withText("Licensing information"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
Expand All @@ -227,9 +218,7 @@ private fun assertLicensingInformation() {
}

private fun assertLibrariesUsed() {
if (!onView(withText("Libraries that we use")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
aboutMenuList.scrollToEnd(LISTS_MAXSWIPES)

onView(withText("Libraries that we use"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
Expand All @@ -239,8 +228,10 @@ private fun assertLibrariesUsed() {
Espresso.pressBack()
}

private val aboutMenuList = UiScrollable(UiSelector().resourceId("$packageName:id/about_layout"))

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

class BuildDateAssertion {
// When the app is built on firebase, there are times where the BuildDate is off by a few seconds or a few minutes.
Expand Down

0 comments on commit f6f1446

Please sign in to comment.