[Ui Tests] Closes #11944: changes the way the system notifications are verified according to their visibility

pull/35/head
Oana Horvath 4 years ago
parent 316b70940f
commit 4ebb070ed7

@ -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()
} }
} }

@ -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)

@ -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 notificationFound = try {
) notificationTray().getChildByText(
UiSelector().text(notificationMessage), notificationMessage, true
).exists()
} catch (e: UiObjectNotFoundException) {
false
}
var notificationFound = false if (!notificationFound) {
while (!notificationFound) { // swipe 2 times to expand the silent notifications on API 28 and higher, single-swipe doesn't do it
try { notificationTray().swipeUp(2)
val notification = notificationTray().getChildByText( val notification = mDevice.findObject(UiSelector().textContains(notificationMessage))
UiSelector().text(notificationMessage), notificationMessage, assertTrue(notification.exists())
true
)
notification.exists()
notificationFound = true
} catch (e: Resources.NotFoundException) {
e.printStackTrace()
}
} }
} }

Loading…
Cancel
Save