Bug 1839810 - New downloads related UI tests

fenix/116.0
AndiAJ 1 year ago committed by mergify[bot]
parent a1570e70d6
commit 649b451cd8

@ -9,7 +9,7 @@
<a href="https://play.google.com/store/apps/details?id=org.mozilla.fenix">Mozilla Playstore link</a>
</p>
<p>
<a href="../resources/washington.pdf">PDF file</a>
<a href="../resources/pdfForm.pdf">PDF form file</a>
</p>
</h1>
</body>

@ -13,6 +13,7 @@ object Constants {
const val GOOGLE_PLAY_SERVICES = "com.android.vending"
const val GOOGLE_APPS_PHOTOS = "com.google.android.apps.photos"
const val GOOGLE_QUICK_SEARCH = "com.google.android.googlequicksearchbox"
const val GOOGLE_DOCS = "com.google.android.apps.docs"
const val YOUTUBE_APP = "com.google.android.youtube"
const val GMAIL_APP = "com.google.android.gm"
const val PHONE_APP = "com.android.dialer"

@ -267,7 +267,8 @@ class ContextMenusTest {
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
clickPageObject(itemWithText("PDF file"))
clickPageObject(itemWithText("PDF form file"))
waitForPageToLoad()
longClickPageObject(itemWithText("Wikipedia link"))
verifyLinkContextMenuItems("wikipedia.org".toUri(), false)
dismissContentContextMenu()

@ -12,16 +12,20 @@ import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_DOCS
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.assertExternalAppOpens
import org.mozilla.fenix.helpers.TestHelper.clickSnackbarButton
import org.mozilla.fenix.helpers.TestHelper.deleteDownloadedFileOnStorage
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.setNetworkEnabled
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.clickPageObject
import org.mozilla.fenix.ui.robots.downloadRobot
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
import org.mozilla.fenix.ui.robots.notificationShade
@ -39,7 +43,6 @@ class DownloadTest {
/* Remote test page managed by Mozilla Mobile QA team at https://github.com/mozilla-mobile/testapp */
private val downloadTestPage = "https://storage.googleapis.com/mobile_test_assets/test_app/downloads.html"
private var downloadFile: String = ""
private val pdfFileName = "washington.pdf"
@get:Rule
val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()
@ -65,6 +68,8 @@ class DownloadTest {
}
mockWebServer.shutdown()
setNetworkEnabled(enabled = true)
}
@Test
@ -83,6 +88,7 @@ class DownloadTest {
verifyPhotosAppOpens()
}
mDevice.pressBack()
deleteDownloadedFileOnStorage(downloadFile)
}
@Test
@ -117,6 +123,7 @@ class DownloadTest {
notificationShade {
verifySystemNotificationExists("Download completed")
}
deleteDownloadedFileOnStorage(downloadFile)
}
@SmokeTest
@ -149,6 +156,7 @@ class DownloadTest {
}.openDownloadsManager {
verifyEmptyDownloadsList()
}
deleteDownloadedFileOnStorage(downloadFile)
}
/* Verifies downloads in the Downloads Menu:
@ -205,6 +213,7 @@ class DownloadTest {
verifyPhotosAppOpens()
mDevice.pressBack()
}
deleteDownloadedFileOnStorage(downloadFile)
}
@SmokeTest
@ -215,27 +224,382 @@ class DownloadTest {
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
clickPageObject(itemContainingText("PDF file"))
clickPageObject(itemContainingText("PDF form file"))
verifyPageContent("Washington Crossing the Delaware")
}
}
// Save PDF file from the share overlay
@SmokeTest
@Test
fun saveAndOpenPdfTest() {
val genericURL =
TestAssetHelper.getGenericAsset(mockWebServer, 3)
downloadFile = "pdfForm.pdf"
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
clickPageObject(itemWithText("PDF form file"))
}.openThreeDotMenu {
}.clickShareButton {
}.clickSaveAsPDF {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
}.clickOpen("application/pdf") {
assertExternalAppOpens(GOOGLE_DOCS)
}
deleteDownloadedFileOnStorage(downloadFile)
}
// Download PDF file using the download toolbar button
@Test
fun pdfViewerDownloadButtonTest() {
val genericURL =
TestAssetHelper.getGenericAsset(mockWebServer, 3)
downloadFile = "pdfForm.pdf"
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
clickPageObject(itemWithText("PDF form file"))
}.clickDownloadPDFButton {
verifyDownloadedFileName(downloadFile)
}.clickOpen("application/pdf") {
assertExternalAppOpens(GOOGLE_DOCS)
}
deleteDownloadedFileOnStorage(downloadFile)
}
@Test
fun deleteDownloadedFileTest() {
downloadFile = "smallZip.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
verifyDownloadedFileName(downloadFile)
}
browserScreen {
}.openThreeDotMenu {
}.openDownloadsManager {
verifyDownloadedFileName(downloadFile)
deleteDownloadedItem(downloadFile)
verifyEmptyDownloadsList()
}
deleteDownloadedFileOnStorage(downloadFile)
}
@Test
fun undoDeleteDownloadedFileTest() {
downloadFile = "smallZip.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
verifyDownloadedFileName(downloadFile)
}
browserScreen {
}.openThreeDotMenu {
}.openDownloadsManager {
verifyDownloadedFileName(downloadFile)
deleteDownloadedItem(downloadFile)
clickSnackbarButton("UNDO")
verifyDownloadedFileName(downloadFile)
}
deleteDownloadedFileOnStorage(downloadFile)
}
@Test
fun deleteMultipleDownloadedFilesTest() {
val firstDownloadedFile = "smallZip.zip"
val secondDownloadedFile = "textfile.txt"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(firstDownloadedFile) {
verifyDownloadPrompt(firstDownloadedFile)
}.clickDownload {
verifyDownloadedFileName(firstDownloadedFile)
}.closeCompletedDownloadPrompt {
}.clickDownloadLink(secondDownloadedFile) {
verifyDownloadPrompt(secondDownloadedFile)
}.clickDownload {
verifyDownloadedFileName(secondDownloadedFile)
}
browserScreen {
}.openThreeDotMenu {
}.openDownloadsManager {
verifyDownloadedFileName(firstDownloadedFile)
verifyDownloadedFileName(secondDownloadedFile)
longClickDownloadedItem(firstDownloadedFile)
selectDownloadedItem(secondDownloadedFile)
openMultiSelectMoreOptionsMenu()
clickMultiSelectRemoveButton()
verifyEmptyDownloadsList()
}
deleteDownloadedFileOnStorage(firstDownloadedFile)
deleteDownloadedFileOnStorage(secondDownloadedFile)
}
@Test
fun undoDeleteMultipleDownloadedFilesTest() {
val firstDownloadedFile = "smallZip.zip"
val secondDownloadedFile = "textfile.txt"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(firstDownloadedFile) {
verifyDownloadPrompt(firstDownloadedFile)
}.clickDownload {
verifyDownloadedFileName(firstDownloadedFile)
}.closeCompletedDownloadPrompt {
}.clickDownloadLink(secondDownloadedFile) {
verifyDownloadPrompt(secondDownloadedFile)
}.clickDownload {
verifyDownloadedFileName(secondDownloadedFile)
}
browserScreen {
}.openThreeDotMenu {
}.openDownloadsManager {
verifyDownloadedFileName(firstDownloadedFile)
verifyDownloadedFileName(secondDownloadedFile)
longClickDownloadedItem(firstDownloadedFile)
selectDownloadedItem(secondDownloadedFile)
openMultiSelectMoreOptionsMenu()
clickMultiSelectRemoveButton()
clickSnackbarButton("UNDO")
verifyDownloadedFileName(firstDownloadedFile)
verifyDownloadedFileName(secondDownloadedFile)
}
deleteDownloadedFileOnStorage(firstDownloadedFile)
deleteDownloadedFileOnStorage(secondDownloadedFile)
}
@Test
fun systemNotificationCantBeDismissedWhileDownloadingTest() {
// Clear the "Firefox Fenix default browser notification"
notificationShade {
cancelAllShownNotifications()
}
downloadFile = "1GB.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
}
browserScreen {
}.openNotificationShade {
verifySystemNotificationExists("Firefox Fenix")
expandNotificationMessage()
swipeDownloadNotification("Left", false)
verifySystemNotificationExists("Firefox Fenix")
}.closeNotificationTray {
}.openNotificationShade {
verifySystemNotificationExists("Firefox Fenix")
expandNotificationMessage()
swipeDownloadNotification("Right", false)
verifySystemNotificationExists("Firefox Fenix")
clickDownloadNotificationControlButton("CANCEL")
}
deleteDownloadedFileOnStorage(downloadFile)
}
@Test
fun systemNotificationCantBeDismissedWhileDownloadIsPausedTest() {
// Clear the "Firefox Fenix default browser notification"
notificationShade {
cancelAllShownNotifications()
}
downloadFile = "1GB.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
}
browserScreen {
}.openNotificationShade {
verifySystemNotificationExists("Firefox Fenix")
expandNotificationMessage()
clickDownloadNotificationControlButton("PAUSE")
swipeDownloadNotification("Left", false)
verifySystemNotificationExists("Firefox Fenix")
}.closeNotificationTray {
}.openNotificationShade {
verifySystemNotificationExists("Firefox Fenix")
expandNotificationMessage()
swipeDownloadNotification("Right", false)
verifySystemNotificationExists("Firefox Fenix")
clickDownloadNotificationControlButton("CANCEL")
}
deleteDownloadedFileOnStorage(downloadFile)
}
@Test
fun notificationCanBeDismissedIfDownloadIsInterruptedTest() {
// Clear the "Firefox Fenix default browser notification"
notificationShade {
cancelAllShownNotifications()
}
downloadFile = "1GB.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
}
setNetworkEnabled(enabled = false)
browserScreen {
}.openNotificationShade {
verifySystemNotificationExists("Download failed")
expandNotificationMessage()
swipeDownloadNotification("Left", true)
verifySystemNotificationDoesNotExist("Firefox Fenix")
}.closeNotificationTray {
}
downloadRobot {
}.closeDownloadPrompt {
verifyDownloadPromptIsDismissed()
}
deleteDownloadedFileOnStorage(downloadFile)
}
@Test
fun notificationCanBeDismissedIfDownloadIsCompletedTest() {
// Clear the "Firefox Fenix default browser notification"
notificationShade {
cancelAllShownNotifications()
}
downloadFile = "smallZip.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
}
browserScreen {
}.openNotificationShade {
verifySystemNotificationExists("Download completed")
swipeDownloadNotification("Left", true, false)
verifySystemNotificationDoesNotExist("Firefox Fenix")
}.closeNotificationTray {
}
downloadRobot {
}.closeDownloadPrompt {
verifyDownloadPromptIsDismissed()
}
deleteDownloadedFileOnStorage(downloadFile)
}
@Test
fun stayInPrivateBrowsingPromptTest() {
// Clear the "Firefox Fenix default browser notification"
notificationShade {
cancelAllShownNotifications()
}
downloadFile = "1GB.zip"
homeScreen {
}.togglePrivateBrowsingMode()
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
}
browserScreen {
}.openTabDrawer {
closeTab()
}
browserScreen {
verifyCancelPrivateDownloadsPrompt("1")
clickStayInPrivateBrowsingPromptButton()
}.openNotificationShade {
verifySystemNotificationExists("Firefox Fenix")
}
deleteDownloadedFileOnStorage(downloadFile)
}
@Test
fun cancelActiveDownloadsFromPrivateBrowsingPromptTest() {
// Clear the "Firefox Fenix default browser notification"
notificationShade {
cancelAllShownNotifications()
}
downloadFile = "1GB.zip"
homeScreen {
}.togglePrivateBrowsingMode()
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
}
browserScreen {
}.openTabDrawer {
closeTab()
}
browserScreen {
verifyCancelPrivateDownloadsPrompt("1")
clickCancelPrivateDownloadsPromptButton()
}.openNotificationShade {
verifySystemNotificationDoesNotExist("Firefox Fenix")
}
deleteDownloadedFileOnStorage(downloadFile)
}
// Save edited PDF file from the share overlay
@Test
fun saveEditedPdfTest() {
val genericURL =
TestAssetHelper.getGenericAsset(mockWebServer, 3)
downloadFile = "pdfForm.pdf"
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
clickPageObject(itemWithText("PDF file"))
clickPageObject(itemWithText("PDF form file"))
waitForPageToLoad()
fillPdfForm("Firefox")
}.openThreeDotMenu {
}.clickShareButton {
}.clickSaveAsPDF {
verifyDownloadPrompt(pdfFileName)
verifyDownloadPrompt("pdfForm.pdf")
}.clickDownload {
}.clickOpen("application/pdf") {
assertExternalAppOpens("com.google.android.apps.docs")
assertExternalAppOpens(GOOGLE_DOCS)
}
deleteDownloadedFileOnStorage(downloadFile)
}
}

@ -193,7 +193,7 @@ class NavigationToolbarTest {
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
clickPageObject(itemWithText("PDF file"))
clickPageObject(itemWithText("PDF form file"))
}.openThreeDotMenu {
verifyThreeDotMenuExists()
verifyFindInPageButton()
@ -201,7 +201,7 @@ class NavigationToolbarTest {
verifyFindInPageNextButton()
verifyFindInPagePrevButton()
verifyFindInPageCloseButton()
enterFindInPageQuery("o")
enterFindInPageQuery("l")
verifyFindNextInPageResult("1/2")
clickFindInPageNextButton()
verifyFindNextInPageResult("2/2")

@ -21,6 +21,7 @@ import org.mozilla.fenix.helpers.MatcherHelper
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestAssetHelper.getStorageTestAsset
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.deleteDownloadedFileOnStorage
import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.restartApp
@ -181,6 +182,7 @@ class SettingsDeleteBrowsingDataOnQuitTest {
}.openDownloadsManager {
verifyEmptyDownloadsList()
}
deleteDownloadedFileOnStorage("smallZip.zip")
}
@SmokeTest

@ -148,7 +148,7 @@ class TextSelectionTest {
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
clickPageObject(itemWithText("PDF file"))
clickPageObject(itemWithText("PDF form file"))
longClickPageObject(itemContainingText("Crossing"))
clickContextMenuItem("Select all")
clickContextMenuItem("Copy")
@ -160,7 +160,7 @@ class TextSelectionTest {
clickClearButton()
longClickToolbar()
clickPasteText()
verifyTypedToolbarText("Washington Crossing the Delaware Wikipedia link")
verifyTypedToolbarText("Washington Crossing the Delaware Wikipedia linkName: Android")
}
}
@ -172,7 +172,7 @@ class TextSelectionTest {
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
clickPageObject(itemWithText("PDF file"))
clickPageObject(itemWithText("PDF form file"))
longClickPageObject(itemContainingText("Crossing"))
clickContextMenuItem("Copy")
}.openNavigationToolbar {
@ -195,7 +195,7 @@ class TextSelectionTest {
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
clickPageObject(itemWithText("PDF file"))
clickPageObject(itemWithText("PDF form file"))
longClickPageObject(itemContainingText("Crossing"))
}.clickShareSelectedText {
verifyAndroidShareLayout()
@ -210,7 +210,7 @@ class TextSelectionTest {
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
clickPageObject(itemWithText("PDF file"))
clickPageObject(itemWithText("PDF form file"))
longClickPageObject(itemContainingText("Crossing"))
clickContextMenuItem("Search")
verifyTabCounter("2")
@ -229,7 +229,7 @@ class TextSelectionTest {
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
clickPageObject(itemWithText("PDF file"))
clickPageObject(itemWithText("PDF form file"))
longClickPageObject(itemContainingText("Crossing"))
clickContextMenuItem("Private Search")
verifyTabCounter("2")

@ -316,7 +316,7 @@ class BrowserRobot {
}
}
fun longClickPDFImage() = longClickPageObject(itemWithResId("pdfjs_internal_id_8R"))
fun longClickPDFImage() = longClickPageObject(itemWithResId("pdfjs_internal_id_13R"))
fun clickSubmitLoginButton() {
clickPageObject(itemWithResId("submit"))
@ -871,6 +871,55 @@ class BrowserRobot {
fun longClickToolbar() = mDevice.findObject(By.res("$packageName:id/mozac_browser_toolbar_url_view")).click(LONG_CLICK_DURATION)
fun verifyDownloadPromptIsDismissed() =
assertItemWithResIdExists(
itemWithResId("$packageName:id/viewDynamicDownloadDialog"),
exists = false,
)
fun verifyCancelPrivateDownloadsPrompt(numberOfActiveDownloads: String) {
assertItemWithResIdAndTextExists(
itemWithResIdContainingText(
"$packageName:id/title",
getStringResource(R.string.mozac_feature_downloads_cancel_active_downloads_warning_content_title),
),
itemWithResIdContainingText(
"$packageName:id/body",
"If you close all Private tabs now, $numberOfActiveDownloads download will be canceled. Are you sure you want to leave Private Browsing?",
),
itemWithResIdContainingText(
"$packageName:id/deny_button",
getStringResource(R.string.mozac_feature_downloads_cancel_active_private_downloads_deny),
),
itemWithResIdContainingText(
"$packageName:id/accept_button",
getStringResource(R.string.mozac_feature_downloads_cancel_active_downloads_accept),
),
)
}
fun clickStayInPrivateBrowsingPromptButton() =
itemWithResIdContainingText(
"$packageName:id/deny_button",
getStringResource(R.string.mozac_feature_downloads_cancel_active_private_downloads_deny),
).click()
fun clickCancelPrivateDownloadsPromptButton() {
itemWithResIdContainingText(
"$packageName:id/accept_button",
getStringResource(R.string.mozac_feature_downloads_cancel_active_downloads_accept),
).click()
mDevice.waitForWindowUpdate(packageName, waitingTime)
}
fun fillPdfForm(name: String) {
// Set PDF form text for the text box
itemWithResId("pdfjs_internal_id_10R").setText(name)
// Click PDF form check box
itemWithResId("pdfjs_internal_id_11R").click()
}
class Transition {
fun openThreeDotMenu(interact: ThreeDotMenuMainRobot.() -> Unit): ThreeDotMenuMainRobot.Transition {
mDevice.waitForIdle(waitingTime)
@ -1112,6 +1161,16 @@ class BrowserRobot {
SettingsRobot().interact()
return SettingsRobot.Transition()
}
fun clickDownloadPDFButton(interact: DownloadRobot.() -> Unit): DownloadRobot.Transition {
itemWithResIdContainingText(
"download",
"Download",
).click()
DownloadRobot().interact()
return DownloadRobot.Transition()
}
}
}

@ -9,9 +9,12 @@ package org.mozilla.fenix.ui.robots
import android.content.Intent
import android.util.Log
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.longClick
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
@ -20,13 +23,18 @@ import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.allOf
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_APPS_PHOTOS
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeLong
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.assertExternalAppOpens
import org.mozilla.fenix.helpers.TestHelper.getStringResource
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.click
@ -73,6 +81,36 @@ class DownloadRobot {
.click()
}
fun deleteDownloadedItem(fileName: String) =
onView(
allOf(
withId(R.id.overflow_menu),
hasSibling(withText(fileName)),
),
).click()
fun longClickDownloadedItem(title: String) =
onView(
allOf(
withId(R.id.title),
withText(title),
),
).perform(longClick())
fun selectDownloadedItem(title: String) =
onView(
allOf(
withId(R.id.title),
withText(title),
),
).perform(click())
fun openMultiSelectMoreOptionsMenu() =
itemWithDescription(getStringResource(R.string.content_description_menu)).click()
fun clickMultiSelectRemoveButton() =
itemWithResIdContainingText("$packageName:id/title", "Remove").click()
class Transition {
fun clickDownload(interact: DownloadRobot.() -> Unit): Transition {
downloadButton().click()
@ -95,6 +133,13 @@ class DownloadRobot {
return BrowserRobot.Transition()
}
fun closeDownloadPrompt(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
itemWithResId("$packageName:id/download_dialog_close_button").click()
BrowserRobot().interact()
return BrowserRobot.Transition()
}
fun clickOpen(type: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
openDownloadButton().waitForExists(waitingTime)
openDownloadButton().click()

@ -6,19 +6,17 @@ package org.mozilla.fenix.ui.robots
import android.app.NotificationManager
import android.content.Context
import androidx.test.uiautomator.By.text
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.ext.waitNotNull
import java.lang.AssertionError
import kotlin.AssertionError
class NotificationRobot {
@ -52,15 +50,9 @@ class NotificationRobot {
}
fun verifySystemNotificationDoesNotExist(notificationMessage: String) {
mDevice.waitNotNull(
Until.gone(text(notificationMessage)),
waitingTime,
)
mDevice.findObject(UiSelector().textContains(notificationMessage)).waitUntilGone(waitingTime)
assertFalse(
mDevice.findObject(
UiSelector().text(notificationMessage),
).exists(),
mDevice.findObject(UiSelector().textContains(notificationMessage)).waitForExists(waitingTimeShort),
)
}
@ -112,6 +104,60 @@ class NotificationRobot {
}
}
// Performs swipe action on download system notifications
fun swipeDownloadNotification(
direction: String,
shouldDismissNotification: Boolean,
canExpandNotification: Boolean = true,
) {
// In case it fails, retry max 6x the swipe action on download system notifications
for (i in 1..6) {
try {
// Swipe left the download system notification
if (direction == "Left") {
itemContainingText(appName)
.also {
it.waitForExists(waitingTime)
it.swipeLeft(3)
}
} else {
// Swipe right the download system notification
itemContainingText(appName)
.also {
it.waitForExists(waitingTime)
it.swipeRight(3)
}
}
// Not all download related system notifications can be dismissed
if (shouldDismissNotification) {
assertFalse(itemContainingText(appName).waitForExists(waitingTimeShort))
} else {
assertTrue(itemContainingText(appName).waitForExists(waitingTimeShort))
}
break
} catch (e: AssertionError) {
if (i == 6) {
throw e
} else {
notificationShade {
}.closeNotificationTray {
}.openNotificationShade {
// The download complete system notification can't be expanded
if (canExpandNotification) {
// In all cases the download system notification title will be the app name
verifySystemNotificationExists(appName)
expandNotificationMessage()
} else {
// Using the download completed system notification summary to bring in to view an properly verify it
verifySystemNotificationExists("Download completed")
}
}
}
}
}
}
class Transition {
fun clickClosePrivateTabsNotification(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {

Loading…
Cancel
Save