From 246348501c3fea9844afcc64160d8ad4716996a8 Mon Sep 17 00:00:00 2001 From: Oana Horvath Date: Tue, 30 Mar 2021 16:13:17 +0300 Subject: [PATCH] For #18644: fix metod to verify system notifications --- .../fenix/helpers/HomeActivityTestRule.kt | 13 ++++++++ .../java/org/mozilla/fenix/ui/DownloadTest.kt | 2 -- .../mozilla/fenix/ui/TabbedBrowsingTest.kt | 2 -- .../fenix/ui/robots/NotificationRobot.kt | 30 ++++++++----------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt b/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt index a3f049647..70247901f 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt @@ -9,6 +9,7 @@ import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.ActivityTestRule import androidx.test.uiautomator.UiDevice +import androidx.test.uiautomator.UiSelector import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.onboarding.FenixOnboarding import org.mozilla.fenix.ui.robots.appContext @@ -37,6 +38,7 @@ class HomeActivityTestRule( override fun afterActivityFinished() { super.afterActivityFinished() setLongTapTimeout(longTapUserPreference) + closeNotificationShade() } } @@ -65,6 +67,7 @@ class HomeActivityIntentTestRule( override fun afterActivityFinished() { super.afterActivityFinished() setLongTapTimeout(longTapUserPreference) + closeNotificationShade() } } @@ -79,3 +82,13 @@ private fun skipOnboardingBeforeLaunch() { // this API so it can be fragile. FenixOnboarding(appContext).finish() } + +private fun closeNotificationShade() { + val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + if (mDevice.findObject( + UiSelector().resourceId("com.android.systemui:id/notification_stack_scroller") + ).exists() + ) { + mDevice.pressHome() + } +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/DownloadTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/DownloadTest.kt index be66dadc3..92774c7aa 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/DownloadTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/DownloadTest.kt @@ -10,7 +10,6 @@ import androidx.test.uiautomator.UiDevice import okhttp3.mockwebserver.MockWebServer import org.junit.After import org.junit.Before -import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.mozilla.fenix.helpers.AndroidAssetDispatcher @@ -74,7 +73,6 @@ class DownloadTest { }.closePrompt {} } - @Ignore("Temporary disabled. See https://github.com/mozilla-mobile/fenix/issues/18644") @Test fun testDownloadNotification() { val defaultWebPage = TestAssetHelper.getDownloadAsset(mockWebServer) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt index a5a6c31d2..73a3a4977 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/TabbedBrowsingTest.kt @@ -10,7 +10,6 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior import okhttp3.mockwebserver.MockWebServer import org.junit.After import org.junit.Before -import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.mozilla.fenix.helpers.AndroidAssetDispatcher @@ -219,7 +218,6 @@ class TabbedBrowsingTest { } } - @Ignore("Temporary disabled. See https://github.com/mozilla-mobile/fenix/issues/18644") @Test fun closePrivateTabsNotificationTest() { val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NotificationRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NotificationRobot.kt index 2c7ffe6ac..7ebbb0528 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NotificationRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/NotificationRobot.kt @@ -13,27 +13,23 @@ import org.mozilla.fenix.helpers.ext.waitNotNull class NotificationRobot { fun verifySystemNotificationExists(notificationMessage: String) { - fun notificationTray() = UiScrollable( UiSelector().resourceId("com.android.systemui:id/notification_stack_scroller") ) - val notificationFound: Boolean - - notificationFound = try { - notificationTray().getChildByText( - UiSelector().text(notificationMessage), notificationMessage, true - ).exists() - } catch (e: UiObjectNotFoundException) { - false - } - - 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()) - } + var notificationFound = false + + do { + try { + notificationFound = notificationTray().getChildByText( + UiSelector().text(notificationMessage), notificationMessage, true + ).waitForExists(waitingTime) + assertTrue(notificationFound) + } catch (e: UiObjectNotFoundException) { + notificationTray().scrollForward() + mDevice.waitForIdle() + } + } while (!notificationFound) } fun verifySystemNotificationGone(notificationMessage: String) {