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

[fenix] [Ui Tests] Closes https://github.com/mozilla-mobile/fenix/issues/11944: changes the way the system notifications are verified according to their visibility

This commit is contained in:
Oana Horvath 2020-08-20 17:46:38 +03:00
parent 8025efc0d7
commit 17c25aabea
3 changed files with 24 additions and 34 deletions

View File

@ -21,6 +21,7 @@ import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.ui.robots.downloadRobot import org.mozilla.fenix.ui.robots.downloadRobot
import org.mozilla.fenix.ui.robots.homeScreen import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar import org.mozilla.fenix.ui.robots.navigationToolbar
import org.mozilla.fenix.ui.robots.notificationShade
import java.io.File import java.io.File
/** /**
@ -92,10 +93,7 @@ class DownloadTest {
} }
@Test @Test
@Ignore("Temp disable flakey test - see: https://github.com/mozilla-mobile/fenix/issues/5462")
fun testDownloadNotification() { fun testDownloadNotification() {
homeScreen { }.dismissOnboarding()
val defaultWebPage = TestAssetHelper.getDownloadAsset(mockWebServer) val defaultWebPage = TestAssetHelper.getDownloadAsset(mockWebServer)
navigationToolbar { navigationToolbar {
@ -108,7 +106,13 @@ class DownloadTest {
verifyDownloadPrompt() verifyDownloadPrompt()
}.clickDownload { }.clickDownload {
verifyDownloadNotificationPopup() verifyDownloadNotificationPopup()
verifyDownloadNotificationShade() }
}
mDevice.openNotification()
notificationShade {
verifySystemNotificationExists("Download completed")
}
// close notification shade before the next test
mDevice.pressBack()
} }
} }

View File

@ -37,8 +37,6 @@ class DownloadRobot {
fun verifyDownloadNotificationPopup() = assertDownloadNotificationPopup() fun verifyDownloadNotificationPopup() = assertDownloadNotificationPopup()
fun verifyDownloadNotificationShade() = assertDownloadNotificationShade()
fun verifyPhotosAppOpens() = assertPhotosOpens() fun verifyPhotosAppOpens() = assertPhotosOpens()
class Transition { class Transition {
@ -98,17 +96,6 @@ private fun assertDownloadPrompt() {
mDevice.waitNotNull(Until.findObjects(By.res("org.mozilla.fenix.debug:id/download_button"))) mDevice.waitNotNull(Until.findObjects(By.res("org.mozilla.fenix.debug:id/download_button")))
} }
private fun assertDownloadNotificationShade() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.openNotification()
mDevice.waitNotNull(
Until.findObjects(By.text("Download completed")), TestAssetHelper.waitingTime
)
// Go home (no UIDevice closeNotification) to close notification shade
mDevice.pressHome()
}
private fun assertDownloadNotificationPopup() { private fun assertDownloadNotificationPopup() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObjects(By.text("Open")), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObjects(By.text("Open")), TestAssetHelper.waitingTime)

View File

@ -1,11 +1,12 @@
package org.mozilla.fenix.ui.robots package org.mozilla.fenix.ui.robots
import android.content.res.Resources
import androidx.test.uiautomator.By.text import androidx.test.uiautomator.By.text
import androidx.test.uiautomator.UiObjectNotFoundException
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.junit.Assert.assertFalse import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.ext.waitNotNull import org.mozilla.fenix.helpers.ext.waitNotNull
@ -17,23 +18,21 @@ class NotificationRobot {
UiSelector().resourceId("com.android.systemui:id/notification_stack_scroller") UiSelector().resourceId("com.android.systemui:id/notification_stack_scroller")
) )
mDevice.waitNotNull( val notificationFound: Boolean
Until.hasObject(text(notificationMessage)),
waitingTime
)
var notificationFound = false notificationFound = try {
while (!notificationFound) { notificationTray().getChildByText(
try { UiSelector().text(notificationMessage), notificationMessage, true
val notification = notificationTray().getChildByText( ).exists()
UiSelector().text(notificationMessage), notificationMessage, } catch (e: UiObjectNotFoundException) {
true false
)
notification.exists()
notificationFound = true
} catch (e: Resources.NotFoundException) {
e.printStackTrace()
} }
if (!notificationFound) {
// swipe 2 times to expand the silent notifications on API 28 and higher, single-swipe doesn't do it
notificationTray().swipeUp(2)
val notification = mDevice.findObject(UiSelector().textContains(notificationMessage))
assertTrue(notification.exists())
} }
} }