From 2f66da6180fcf9a43eb3fbaf38a90811b82a814a Mon Sep 17 00:00:00 2001 From: AndiAJ Date: Fri, 3 Mar 2023 17:08:47 +0200 Subject: [PATCH] Bug 1820193 - new addPDFToHomeScreenTest UI smoke test and other refactoring work --- .../mozilla/fenix/ui/AddToHomeScreenTest.kt | 109 ++++++++++++++++++ .../java/org/mozilla/fenix/ui/SmokeTest.kt | 50 -------- 2 files changed, 109 insertions(+), 50 deletions(-) create mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/AddToHomeScreenTest.kt diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/AddToHomeScreenTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/AddToHomeScreenTest.kt new file mode 100644 index 0000000000..bf9c462360 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/AddToHomeScreenTest.kt @@ -0,0 +1,109 @@ +package org.mozilla.fenix.ui + +import androidx.core.net.toUri +import okhttp3.mockwebserver.MockWebServer +import org.junit.After +import org.junit.Before +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.HomeActivityIntentTestRule +import org.mozilla.fenix.helpers.TestAssetHelper +import org.mozilla.fenix.helpers.TestHelper +import org.mozilla.fenix.ui.robots.browserScreen +import org.mozilla.fenix.ui.robots.homeScreen +import org.mozilla.fenix.ui.robots.navigationToolbar +import org.mozilla.fenix.ui.robots.searchScreen + +class AddToHomeScreenTest { + private lateinit var mockWebServer: MockWebServer + private val downloadTestPage = + "https://storage.googleapis.com/mobile_test_assets/test_app/downloads.html" + private val pdfFileName = "washington.pdf" + private val pdfFileURL = "storage.googleapis.com/mobile_test_assets/public/washington.pdf" + private val pdfFileContent = "Washington Crossing the Delaware" + + @get:Rule + val activityIntentTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides() + + @Before + fun setUp() { + mockWebServer = MockWebServer().apply { + dispatcher = AndroidAssetDispatcher() + start() + } + } + + @After + fun tearDown() { + mockWebServer.shutdown() + } + + // Verifies the Add to home screen option in a tab's 3 dot menu + @Test + fun mainMenuAddToHomeScreenTest() { + val website = TestAssetHelper.getGenericAsset(mockWebServer, 1) + val shortcutTitle = TestHelper.generateRandomString(5) + + homeScreen { + }.openNavigationToolbar { + }.enterURLAndEnterToBrowser(website.url) { + }.openThreeDotMenu { + expandMenu() + }.openAddToHomeScreen { + clickCancelShortcutButton() + } + + browserScreen { + }.openThreeDotMenu { + expandMenu() + }.openAddToHomeScreen { + verifyShortcutTextFieldTitle("Test_Page_1") + addShortcutName(shortcutTitle) + clickAddShortcutButton() + clickAddAutomaticallyButton() + }.openHomeScreenShortcut(shortcutTitle) { + verifyUrl(website.url.toString()) + verifyTabCounter("1") + } + } + + @Test + fun addPrivateBrowsingShortcutTest() { + homeScreen { + }.dismissOnboarding() + + homeScreen { + }.triggerPrivateBrowsingShortcutPrompt { + verifyNoThanksPrivateBrowsingShortcutButton() + verifyAddPrivateBrowsingShortcutButton() + clickAddPrivateBrowsingShortcutButton() + clickAddAutomaticallyButton() + }.openHomeScreenShortcut("Private ${TestHelper.appName}") {} + searchScreen { + verifySearchView() + }.dismissSearchBar { + verifyPrivateSessionMessage() + } + } + + @SmokeTest + @Test + fun addPDFToHomeScreenTest() { + navigationToolbar { + }.enterURLAndEnterToBrowser(downloadTestPage.toUri()) { + clickLinkMatchingText(pdfFileName) + verifyUrl(pdfFileURL) + verifyPageContent(pdfFileContent) + }.openThreeDotMenu { + expandMenu() + }.openAddToHomeScreen { + verifyShortcutTextFieldTitle(pdfFileName) + clickAddShortcutButton() + clickAddAutomaticallyButton() + }.openHomeScreenShortcut(pdfFileName) { + verifyUrl(pdfFileURL) + } + } +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt index 73dfd6d8d4..d7df4192c2 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt @@ -29,10 +29,8 @@ import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.RecyclerViewIdlingResource import org.mozilla.fenix.helpers.RetryTestRule import org.mozilla.fenix.helpers.TestAssetHelper -import org.mozilla.fenix.helpers.TestHelper.appName import org.mozilla.fenix.helpers.TestHelper.assertNativeAppOpens import org.mozilla.fenix.helpers.TestHelper.createCustomTabIntent -import org.mozilla.fenix.helpers.TestHelper.generateRandomString import org.mozilla.fenix.helpers.TestHelper.registerAndCleanupIdlingResources import org.mozilla.fenix.helpers.ViewVisibilityIdlingResource import org.mozilla.fenix.ui.robots.browserScreen @@ -220,35 +218,6 @@ class SmokeTest { } } - // Verifies the Add to home screen option in a tab's 3 dot menu - @Test - fun mainMenuAddToHomeScreenTest() { - val website = TestAssetHelper.getGenericAsset(mockWebServer, 1) - val shortcutTitle = generateRandomString(5) - - homeScreen { - }.openNavigationToolbar { - }.enterURLAndEnterToBrowser(website.url) { - }.openThreeDotMenu { - expandMenu() - }.openAddToHomeScreen { - clickCancelShortcutButton() - } - - browserScreen { - }.openThreeDotMenu { - expandMenu() - }.openAddToHomeScreen { - verifyShortcutTextFieldTitle("Test_Page_1") - addShortcutName(shortcutTitle) - clickAddShortcutButton() - clickAddAutomaticallyButton() - }.openHomeScreenShortcut(shortcutTitle) { - verifyUrl(website.url.toString()) - verifyTabCounter("1") - } - } - // Verifies the Add to collection option in a tab's 3 dot menu @Test fun openMainMenuAddToCollectionTest() { @@ -538,25 +507,6 @@ class SmokeTest { } } - @Test - fun addPrivateBrowsingShortcutTest() { - homeScreen { - }.dismissOnboarding() - - homeScreen { - }.triggerPrivateBrowsingShortcutPrompt { - verifyNoThanksPrivateBrowsingShortcutButton() - verifyAddPrivateBrowsingShortcutButton() - clickAddPrivateBrowsingShortcutButton() - clickAddAutomaticallyButton() - }.openHomeScreenShortcut("Private $appName") {} - searchScreen { - verifySearchView() - }.dismissSearchBar { - verifyPrivateSessionMessage() - } - } - @Test fun mainMenuInstallPWATest() { val pwaPage = "https://mozilla-mobile.github.io/testapp/"