2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

Bug 1863278 - Refactor navigation and storage deletion in downloads UI tests

This commit is contained in:
AndiAJ 2023-11-03 09:52:02 +02:00 committed by mergify[bot]
parent 5ee95765f2
commit f910dc008b
10 changed files with 156 additions and 203 deletions

View File

@ -78,6 +78,27 @@ object AppAndSystemHelper {
}
}
@RequiresApi(Build.VERSION_CODES.R)
fun clearDownloadsFolder() {
val storageManager: StorageManager? = TestHelper.appContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager?
val storageVolumes = storageManager!!.storageVolumes
val storageVolume: StorageVolume = storageVolumes[0]
val downloadsFolder = File(storageVolume.directory!!.path + "/Download/")
// Check if the downloads folder exists
if (downloadsFolder.exists() && downloadsFolder.isDirectory) {
val files = downloadsFolder.listFiles()
// Check if the folder is not empty
if (files != null && files.isNotEmpty()) {
// Delete all files in the folder
for (file in files) {
file.delete()
}
}
}
}
fun setNetworkEnabled(enabled: Boolean) {
val networkDisconnectedIdlingResource = NetworkConnectionIdlingResource(false)
val networkConnectedIdlingResource = NetworkConnectionIdlingResource(true)

View File

@ -17,7 +17,7 @@ import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.AppAndSystemHelper.deleteDownloadedFileOnStorage
import org.mozilla.fenix.helpers.AppAndSystemHelper.clearDownloadsFolder
import org.mozilla.fenix.helpers.AppAndSystemHelper.setNetworkEnabled
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
@ -28,6 +28,7 @@ import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.restartApp
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
@ -65,6 +66,9 @@ class ComposeSettingsDeleteBrowsingDataOnQuitTest {
@After
fun tearDown() {
mockWebServer.shutdown()
// Check and clear the downloads folder
clearDownloadsFolder()
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/416048
@ -198,11 +202,8 @@ class ComposeSettingsDeleteBrowsingDataOnQuitTest {
clickDeleteBrowsingOnQuitButtonSwitch()
exitMenu()
}
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
}.clickDownloadLink("smallZip.zip") {
verifyDownloadPrompt("smallZip.zip")
}.clickDownload {
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "smallZip.zip")
verifyDownloadCompleteNotificationPopup()
}.closeCompletedDownloadPrompt {
}.goToHomescreen {
@ -216,7 +217,6 @@ class ComposeSettingsDeleteBrowsingDataOnQuitTest {
}.openDownloadsManager {
verifyEmptyDownloadsList()
}
deleteDownloadedFileOnStorage("smallZip.zip")
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/416053

View File

@ -5,13 +5,15 @@
package org.mozilla.fenix.ui
import androidx.core.net.toUri
import org.junit.After
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AppAndSystemHelper.clearDownloadsFolder
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.ui.robots.navigationToolbar
import org.mozilla.fenix.ui.robots.downloadRobot
/**
* Test for verifying downloading a list of different file types:
@ -28,6 +30,12 @@ class DownloadFileTypesTest(fileName: String) {
@get:Rule
val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()
@After
fun tearDown() {
// Check and clear the downloads folder
clearDownloadsFolder()
}
companion object {
// Creating test data. The test will take each file name as a parameter and run it individually.
@JvmStatic
@ -49,11 +57,8 @@ class DownloadFileTypesTest(fileName: String) {
@SmokeTest
@Test
fun allFilesAppearInDownloadsMenuTest() {
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = downloadFile)
verifyDownloadCompleteNotificationPopup()
}.closeCompletedDownloadPrompt {
}.openThreeDotMenu {

View File

@ -14,6 +14,7 @@ import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.AppAndSystemHelper.assertExternalAppOpens
import org.mozilla.fenix.helpers.AppAndSystemHelper.clearDownloadsFolder
import org.mozilla.fenix.helpers.AppAndSystemHelper.deleteDownloadedFileOnStorage
import org.mozilla.fenix.helpers.AppAndSystemHelper.setNetworkEnabled
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_APPS_PHOTOS
@ -72,63 +73,45 @@ class DownloadTest {
mockWebServer.shutdown()
setNetworkEnabled(enabled = true)
// Check and clear the downloads folder
clearDownloadsFolder()
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/243844
@Test
fun verifyTheDownloadPromptsTest() {
downloadFile = "web_icon.png"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "web_icon.png")
verifyDownloadCompleteNotificationPopup()
}.clickOpen("image/png") {}
downloadRobot {
verifyPhotosAppOpens()
}
mDevice.pressBack()
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2299405
@Test
fun verifyTheDownloadFailedNotificationsTest() {
downloadFile = "1GB.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "1GB.zip")
setNetworkEnabled(enabled = false)
verifyDownloadFailedPrompt(downloadFile)
verifyDownloadFailedPrompt("1GB.zip")
setNetworkEnabled(enabled = true)
clickTryAgainButton()
}
mDevice.openNotification()
notificationShade {
verifySystemNotificationDoesNotExist("Download failed")
verifySystemNotificationExists(downloadFile)
verifySystemNotificationExists("1GB.zip")
}.closeNotificationTray {}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2298616
@Test
fun verifyDownloadCompleteNotificationTest() {
downloadFile = "web_icon.png"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "web_icon.png")
verifyDownloadCompleteNotificationPopup()
}
mDevice.openNotification()
@ -146,7 +129,6 @@ class DownloadTest {
)
verifySystemNotificationDoesNotExist("Firefox Fenix")
}.closeNotificationTray {}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/451563
@ -154,19 +136,9 @@ class DownloadTest {
@SmokeTest
@Test
fun pauseResumeCancelDownloadTest() {
// Clear the "Firefox Fenix default browser notification"
notificationShade {
cancelAllShownNotifications()
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "1GB.zip")
}
downloadFile = "1GB.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {}
mDevice.openNotification()
notificationShade {
verifySystemNotificationExists("Firefox Fenix")
@ -175,7 +147,7 @@ class DownloadTest {
verifySystemNotificationExists("Download paused")
clickDownloadNotificationControlButton("RESUME")
clickDownloadNotificationControlButton("CANCEL")
verifySystemNotificationDoesNotExist(downloadFile)
verifySystemNotificationDoesNotExist("1GB.zip")
mDevice.pressBack()
}
browserScreen {
@ -183,57 +155,41 @@ class DownloadTest {
}.openDownloadsManager {
verifyEmptyDownloadsList()
}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2301474
@Test
fun openDownloadedFileFromDownloadsMenuTest() {
downloadFile = "web_icon.png"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "web_icon.png")
verifyDownloadCompleteNotificationPopup()
}
browserScreen {
}.openThreeDotMenu {
}.openDownloadsManager {
verifyDownloadedFileName(downloadFile)
openDownloadedFile(downloadFile)
verifyDownloadedFileName("web_icon.png")
openDownloadedFile("web_icon.png")
verifyPhotosAppOpens()
mDevice.pressBack()
}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1114970
@Test
fun deleteDownloadedFileTest() {
downloadFile = "smallZip.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
verifyDownloadedFileName(downloadFile)
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "smallZip.zip")
}
browserScreen {
}.openThreeDotMenu {
}.openDownloadsManager {
verifyDownloadedFileName(downloadFile)
deleteDownloadedItem(downloadFile)
verifyDownloadedFileName("smallZip.zip")
deleteDownloadedItem("smallZip.zip")
clickSnackbarButton("UNDO")
verifyDownloadedFileName(downloadFile)
deleteDownloadedItem(downloadFile)
verifyDownloadedFileName("smallZip.zip")
deleteDownloadedItem("smallZip.zip")
verifyEmptyDownloadsList()
}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2302662
@ -242,12 +198,8 @@ class DownloadTest {
val firstDownloadedFile = "smallZip.zip"
val secondDownloadedFile = "textfile.txt"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(firstDownloadedFile) {
verifyDownloadPrompt(firstDownloadedFile)
}.clickDownload {
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = firstDownloadedFile)
verifyDownloadedFileName(firstDownloadedFile)
}.closeCompletedDownloadPrompt {
}.clickDownloadLink(secondDownloadedFile) {
@ -273,29 +225,21 @@ class DownloadTest {
clickMultiSelectRemoveButton()
verifyEmptyDownloadsList()
}
deleteDownloadedFileOnStorage(firstDownloadedFile)
deleteDownloadedFileOnStorage(secondDownloadedFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2301537
@Test
fun fileDeletedFromStorageIsDeletedEverywhereTest() {
val downloadFile = "smallZip.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "smallZip.zip")
verifyDownloadCompleteNotificationPopup()
}
browserScreen {
}.openThreeDotMenu {
}.openDownloadsManager {
waitForDownloadsListToExist()
verifyDownloadedFileName(downloadFile)
deleteDownloadedFileOnStorage(downloadFile)
verifyDownloadedFileName("smallZip.zip")
deleteDownloadedFileOnStorage("smallZip.zip")
}.exitDownloadsManagerToBrowser {
}.openThreeDotMenu {
}.openDownloadsManager {
@ -303,40 +247,24 @@ class DownloadTest {
exitMenu()
}
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "smallZip.zip")
verifyDownloadCompleteNotificationPopup()
}
browserScreen {
}.openThreeDotMenu {
}.openDownloadsManager {
waitForDownloadsListToExist()
verifyDownloadedFileName(downloadFile)
verifyDownloadedFileName("smallZip.zip")
}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/457112
@Ignore("Failing: https://bugzilla.mozilla.org/show_bug.cgi?id=1840994")
@Test
fun systemNotificationCantBeDismissedWhileInProgressTest() {
// Clear the "Firefox Fenix default browser notification"
notificationShade {
cancelAllShownNotifications()
}
downloadFile = "1GB.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "1GB.zip")
}
browserScreen {
}.openNotificationShade {
@ -347,26 +275,15 @@ class DownloadTest {
swipeDownloadNotification(direction = "Right", shouldDismissNotification = false)
clickDownloadNotificationControlButton("CANCEL")
}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2299297
@Test
fun notificationCanBeDismissedIfDownloadIsInterruptedTest() {
// Clear the "Firefox Fenix default browser notification"
notificationShade {
cancelAllShownNotifications()
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "1GB.zip")
}
downloadFile = "1GB.zip"
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {}
setNetworkEnabled(enabled = false)
browserScreen {
@ -381,27 +298,16 @@ class DownloadTest {
}.closeDownloadPrompt {
verifyDownloadPromptIsDismissed()
}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1632384
@Test
fun warningWhenClosingPrivateTabsWhileDownloadingTest() {
downloadFile = "1GB.zip"
// Clear the "Firefox Fenix default browser notification"
notificationShade {
cancelAllShownNotifications()
}
homeScreen {
}.togglePrivateBrowsingMode()
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {}
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "1GB.zip")
}
browserScreen {
}.openTabDrawer {
closeTab()
@ -412,28 +318,16 @@ class DownloadTest {
}.openNotificationShade {
verifySystemNotificationExists("Firefox Fenix")
}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2302663
@Test
fun cancelActivePrivateBrowsingDownloadsTest() {
downloadFile = "1GB.zip"
// Clear the "Firefox Fenix default browser notification"
notificationShade {
cancelAllShownNotifications()
}
homeScreen {
}.togglePrivateBrowsingMode()
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {}
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "1GB.zip")
}
browserScreen {
}.openTabDrawer {
closeTab()
@ -444,7 +338,6 @@ class DownloadTest {
}.openNotificationShade {
verifySystemNotificationDoesNotExist("Firefox Fenix")
}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2048448
@ -469,7 +362,6 @@ class DownloadTest {
}.clickOpen("application/pdf") {
assertExternalAppOpens(GOOGLE_DOCS)
}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/244125
@ -494,6 +386,5 @@ class DownloadTest {
expandNotificationMessage()
clickDownloadNotificationControlButton("CANCEL")
}
deleteDownloadedFileOnStorage(downloadFile)
}
}

View File

@ -15,7 +15,7 @@ import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.AppAndSystemHelper.assertExternalAppOpens
import org.mozilla.fenix.helpers.AppAndSystemHelper.deleteDownloadedFileOnStorage
import org.mozilla.fenix.helpers.AppAndSystemHelper.clearDownloadsFolder
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_DOCS
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.MatcherHelper
@ -50,6 +50,9 @@ class PDFViewerTest {
@After
fun tearDown() {
mockWebServer.shutdown()
// Check and clear the downloads folder
clearDownloadsFolder()
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2048140
@ -96,7 +99,6 @@ class PDFViewerTest {
}.clickOpen("application/pdf") {
assertExternalAppOpens(GOOGLE_DOCS)
}
deleteDownloadedFileOnStorage(downloadFile)
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2283305

View File

@ -16,7 +16,7 @@ import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.AppAndSystemHelper.deleteDownloadedFileOnStorage
import org.mozilla.fenix.helpers.AppAndSystemHelper
import org.mozilla.fenix.helpers.AppAndSystemHelper.setNetworkEnabled
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
@ -27,6 +27,7 @@ import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.restartApp
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
@ -58,6 +59,9 @@ class SettingsDeleteBrowsingDataOnQuitTest {
@After
fun tearDown() {
mockWebServer.shutdown()
// Check and clear the downloads folder
AppAndSystemHelper.clearDownloadsFolder()
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/416048
@ -191,11 +195,8 @@ class SettingsDeleteBrowsingDataOnQuitTest {
clickDeleteBrowsingOnQuitButtonSwitch()
exitMenu()
}
navigationToolbar {
}.enterURLAndEnterToBrowser(downloadTestPage.toUri()) {
}.clickDownloadLink("smallZip.zip") {
verifyDownloadPrompt("smallZip.zip")
}.clickDownload {
downloadRobot {
openPageAndDownloadFile(url = downloadTestPage.toUri(), downloadFile = "smallZip.zip")
verifyDownloadCompleteNotificationPopup()
}.closeCompletedDownloadPrompt {
}.goToHomescreen {
@ -209,7 +210,6 @@ class SettingsDeleteBrowsingDataOnQuitTest {
}.openDownloadsManager {
verifyEmptyDownloadsList()
}
deleteDownloadedFileOnStorage("smallZip.zip")
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/416053

View File

@ -68,7 +68,10 @@ import java.time.LocalDate
class BrowserRobot {
private lateinit var sessionLoadedIdlingResource: SessionLoadedIdlingResource
fun waitForPageToLoad() = progressBar.waitUntilGone(waitingTime)
fun waitForPageToLoad() {
progressBar.waitUntilGone(waitingTime)
Log.i("MozTestLog", "waitForPageToLoad: The page was loaded, the progress bar is gone")
}
fun verifyCurrentPrivateSession(context: Context) {
val selectedTab = context.components.core.store.state.selectedTab
@ -1031,7 +1034,9 @@ class BrowserRobot {
class Transition {
fun openThreeDotMenu(interact: ThreeDotMenuMainRobot.() -> Unit): ThreeDotMenuMainRobot.Transition {
mDevice.waitForIdle(waitingTime)
Log.i("MozTestLog", "openThreeDotMenu: Device was idle for $waitingTime")
threeDotButton().perform(click())
Log.i("MozTestLog", "openThreeDotMenu: Clicked the main menu button")
ThreeDotMenuMainRobot().interact()
return ThreeDotMenuMainRobot.Transition()
@ -1347,19 +1352,26 @@ private fun siteSecurityToolbarButton() =
fun clickPageObject(item: UiObject) {
for (i in 1..RETRY_COUNT) {
Log.i("MozTestLog", "clickPageObject: For loop i = $i")
try {
Log.i("MozTestLog", "clickPageObject: Try block")
item.waitForExists(waitingTime)
item.click()
Log.i("MozTestLog", "clickPageObject: Clicked ${item.selector}")
break
} catch (e: UiObjectNotFoundException) {
Log.i("MozTestLog", "clickPageObject: Catch block")
if (i == RETRY_COUNT) {
throw e
} else {
browserScreen {
Log.i("MozTestLog", "clickPageObject: Browser screen")
}.openThreeDotMenu {
Log.i("MozTestLog", "clickPageObject: Opened main menu")
}.refreshPage {
progressBar.waitUntilGone(waitingTime)
Log.i("MozTestLog", "clickPageObject: Page refreshed, progress bar is gone")
}
}
}

View File

@ -7,6 +7,7 @@
package org.mozilla.fenix.ui.robots
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
@ -47,7 +48,36 @@ import org.mozilla.fenix.helpers.ext.waitNotNull
class DownloadRobot {
fun verifyDownloadPrompt(fileName: String) = assertDownloadPrompt(fileName)
fun verifyDownloadPrompt(fileName: String) {
var currentTries = 0
while (currentTries++ < 3) {
Log.i("MozTestLog", "verifyDownloadPrompt: While loop currentTries = $currentTries")
try {
Log.i("MozTestLog", "verifyDownloadPrompt: Try block")
assertTrue(
"Download prompt button not visible",
mDevice.findObject(UiSelector().resourceId("$packageName:id/download_button"))
.waitForExists(waitingTimeLong),
)
Log.i("MozTestLog", "verifyDownloadPrompt: Verified that the \"DOWNLOAD\" prompt button exists")
assertTrue(
"$fileName title doesn't match",
mDevice.findObject(UiSelector().text(fileName))
.waitForExists(waitingTimeLong),
)
Log.i("MozTestLog", "verifyDownloadPrompt: Verified that the download prompt for $fileName exists")
break
} catch (e: AssertionError) {
Log.i("MozTestLog", "verifyDownloadPrompt: Catch block")
Log.e("DOWNLOAD_ROBOT", "Failed to find locator: ${e.localizedMessage}")
browserScreen {
}.clickDownloadLink(fileName) {
}
}
}
}
fun verifyDownloadCompleteNotificationPopup() {
assertTrue(
@ -163,9 +193,20 @@ class DownloadRobot {
fun clickMultiSelectRemoveButton() =
itemWithResIdContainingText("$packageName:id/title", "Remove").click()
fun openPageAndDownloadFile(url: Uri, downloadFile: String) {
navigationToolbar {
}.enterURLAndEnterToBrowser(url) {
waitForPageToLoad()
}.clickDownloadLink(downloadFile) {
verifyDownloadPrompt(downloadFile)
}.clickDownload {
}
}
class Transition {
fun clickDownload(interact: DownloadRobot.() -> Unit): Transition {
downloadButton().click()
Log.i("MozTestLog", "clickDownload: Clicked \"DOWNLOAD\" button from prompt")
DownloadRobot().interact()
return Transition()
@ -235,32 +276,6 @@ fun downloadRobot(interact: DownloadRobot.() -> Unit): DownloadRobot.Transition
return DownloadRobot.Transition()
}
private fun assertDownloadPrompt(fileName: String) {
var currentTries = 0
while (currentTries++ < 3) {
try {
assertTrue(
"Download prompt button not visible",
mDevice.findObject(UiSelector().resourceId("$packageName:id/download_button"))
.waitForExists(waitingTimeLong),
)
assertTrue(
"$fileName title doesn't match",
mDevice.findObject(UiSelector().text(fileName))
.waitForExists(waitingTimeLong),
)
break
} catch (e: AssertionError) {
Log.e("DOWNLOAD_ROBOT", "Failed to find locator: ${e.localizedMessage}")
browserScreen {
}.clickDownloadLink(fileName) {
}
}
}
}
private fun closeCompletedDownloadButton() =
onView(withId(R.id.download_dialog_close_button))

View File

@ -8,6 +8,7 @@ package org.mozilla.fenix.ui.robots
import android.net.Uri
import android.os.Build
import android.util.Log
import androidx.compose.ui.test.onNodeWithTag
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
@ -154,9 +155,12 @@ class NavigationToolbarRobot {
sessionLoadedIdlingResource = SessionLoadedIdlingResource()
openEditURLView()
Log.i("MozTestLog", "enterURLAndEnterToBrowser: Opened edit mode URL view")
awesomeBar().setText(url.toString())
Log.i("MozTestLog", "enterURLAndEnterToBrowser: Set toolbar text to: $url")
mDevice.pressEnter()
Log.i("MozTestLog", "enterURLAndEnterToBrowser: Clicked enter on keyboard, submitted query")
runWithIdleRes(sessionLoadedIdlingResource) {
assertTrue(

View File

@ -6,6 +6,7 @@
package org.mozilla.fenix.ui.robots
import android.util.Log
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.swipeDown
@ -321,8 +322,10 @@ class ThreeDotMenuMainRobot {
fun refreshPage(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
refreshButton.also {
Log.i("MozTestLog", "refreshPage: Looking for refresh button")
it.waitForExists(waitingTime)
it.click()
Log.i("MozTestLog", "refreshPage: Clicked the refresh button")
}
BrowserRobot().interact()