From b19419224dbe0736de4bd5ab06e72775d8622509 Mon Sep 17 00:00:00 2001 From: "oana.horvath" Date: Mon, 26 Feb 2024 14:51:25 +0200 Subject: [PATCH] Bug 1880796 - Create TestSetup helper: Test classes O-R --- .../org/mozilla/fenix/ui/OnboardingTest.kt | 3 +- .../org/mozilla/fenix/ui/PDFViewerTest.kt | 29 ++----------------- .../java/org/mozilla/fenix/ui/PocketTest.kt | 11 +++---- .../java/org/mozilla/fenix/ui/PwaTest.kt | 3 +- .../org/mozilla/fenix/ui/ReaderViewTest.kt | 26 ++--------------- .../fenix/ui/RecentlyClosedTabsTest.kt | 29 +++---------------- .../java/org/mozilla/fenix/ui/SearchTest.kt | 10 +++---- 7 files changed, 22 insertions(+), 89 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/OnboardingTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/OnboardingTest.kt index 9913b7769..6b305496e 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/OnboardingTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/OnboardingTest.kt @@ -6,9 +6,10 @@ import org.junit.Test import org.mozilla.fenix.customannotations.SmokeTest import org.mozilla.fenix.helpers.AppAndSystemHelper.runWithLauncherIntent import org.mozilla.fenix.helpers.HomeActivityIntentTestRule +import org.mozilla.fenix.helpers.TestSetup import org.mozilla.fenix.ui.robots.homeScreen -class OnboardingTest { +class OnboardingTest : TestSetup() { @get:Rule val activityTestRule = diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/PDFViewerTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/PDFViewerTest.kt index 340cbd08e..913d1c7d2 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/PDFViewerTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/PDFViewerTest.kt @@ -5,17 +5,10 @@ package org.mozilla.fenix.ui import androidx.core.net.toUri -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.uiautomator.UiDevice -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.AppAndSystemHelper.assertExternalAppOpens -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 @@ -23,12 +16,11 @@ import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText import org.mozilla.fenix.helpers.MatcherHelper.itemWithText import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset -import org.mozilla.fenix.helpers.TestHelper.mDevice +import org.mozilla.fenix.helpers.TestSetup import org.mozilla.fenix.ui.robots.clickPageObject import org.mozilla.fenix.ui.robots.navigationToolbar -class PDFViewerTest { - private lateinit var mockWebServer: MockWebServer +class PDFViewerTest : TestSetup() { private val downloadTestPage = "https://storage.googleapis.com/mobile_test_assets/test_app/downloads.html" private val pdfFileName = "washington.pdf" @@ -38,23 +30,6 @@ class PDFViewerTest { @get:Rule val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides() - @Before - fun setUp() { - mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - mockWebServer = MockWebServer().apply { - dispatcher = AndroidAssetDispatcher() - start() - } - } - - @After - fun tearDown() { - mockWebServer.shutdown() - - // Check and clear the downloads folder - clearDownloadsFolder() - } - // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2048140 @SmokeTest @Test diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/PocketTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/PocketTest.kt index 885fa80c0..674924c95 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/PocketTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/PocketTest.kt @@ -1,22 +1,20 @@ package org.mozilla.fenix.ui import androidx.compose.ui.test.junit4.AndroidComposeTestRule -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.uiautomator.UiDevice import org.junit.Before import org.junit.Rule import org.junit.Test import org.mozilla.fenix.helpers.Constants import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.helpers.RetryTestRule +import org.mozilla.fenix.helpers.TestSetup import org.mozilla.fenix.ui.robots.homeScreen /** * Tests for verifying the presence of the Pocket section and its elements */ -class PocketTest { - private lateinit var mDevice: UiDevice +class PocketTest : TestSetup() { private lateinit var firstPocketStoryPublisher: String @get:Rule(order = 0) @@ -28,9 +26,8 @@ class PocketTest { val retryTestRule = RetryTestRule(3) @Before - fun setUp() { - mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - + override fun setUp() { + super.setUp() // Workaround to make sure the Pocket articles are populated before starting the tests. homeScreen { }.openThreeDotMenu { diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/PwaTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/PwaTest.kt index 4ccfa4a97..6ce798c2f 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/PwaTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/PwaTest.kt @@ -11,12 +11,13 @@ import org.mozilla.fenix.customannotations.SmokeTest import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText import org.mozilla.fenix.helpers.TestHelper.mDevice +import org.mozilla.fenix.helpers.TestSetup import org.mozilla.fenix.ui.robots.clickPageObject import org.mozilla.fenix.ui.robots.customTabScreen import org.mozilla.fenix.ui.robots.navigationToolbar import org.mozilla.fenix.ui.robots.pwaScreen -class PwaTest { +class PwaTest : TestSetup() { /* Updated externalLinks.html to v2.0, changed the hypertext reference to mozilla-mobile.github.io/testapp/downloads for "External link" */ diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/ReaderViewTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/ReaderViewTest.kt index aa2215fdd..8e138aa8b 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/ReaderViewTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/ReaderViewTest.kt @@ -5,20 +5,16 @@ package org.mozilla.fenix.ui import android.view.View -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.uiautomator.UiDevice -import okhttp3.mockwebserver.MockWebServer -import org.junit.After -import org.junit.Before import org.junit.Rule 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.registerAndCleanupIdlingResources import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.RetryTestRule import org.mozilla.fenix.helpers.TestAssetHelper +import org.mozilla.fenix.helpers.TestHelper.mDevice +import org.mozilla.fenix.helpers.TestSetup import org.mozilla.fenix.helpers.ViewVisibilityIdlingResource import org.mozilla.fenix.ui.robots.browserScreen import org.mozilla.fenix.ui.robots.navigationToolbar @@ -32,9 +28,7 @@ import org.mozilla.fenix.ui.robots.navigationToolbar * */ -class ReaderViewTest { - private lateinit var mockWebServer: MockWebServer - private lateinit var mDevice: UiDevice +class ReaderViewTest : TestSetup() { private val estimatedReadingTime = "1 - 2 minutes" @get:Rule @@ -44,20 +38,6 @@ class ReaderViewTest { @JvmField val retryTestRule = RetryTestRule(3) - @Before - fun setUp() { - mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) - mockWebServer = MockWebServer().apply { - dispatcher = AndroidAssetDispatcher() - start() - } - } - - @After - fun tearDown() { - mockWebServer.shutdown() - } - /** * Verify that Reader View capable pages * diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/RecentlyClosedTabsTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/RecentlyClosedTabsTest.kt index ca4084655..044696b36 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/RecentlyClosedTabsTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/RecentlyClosedTabsTest.kt @@ -6,21 +6,17 @@ package org.mozilla.fenix.ui import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu -import androidx.test.espresso.intent.Intents -import okhttp3.mockwebserver.MockWebServer -import org.junit.After -import org.junit.Before import org.junit.Rule 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.registerAndCleanupIdlingResources -import org.mozilla.fenix.helpers.HomeActivityTestRule +import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.RecyclerViewIdlingResource import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset import org.mozilla.fenix.helpers.TestHelper.longTapSelectItem import org.mozilla.fenix.helpers.TestHelper.mDevice +import org.mozilla.fenix.helpers.TestSetup import org.mozilla.fenix.ui.robots.browserScreen import org.mozilla.fenix.ui.robots.homeScreen import org.mozilla.fenix.ui.robots.navigationToolbar @@ -29,31 +25,14 @@ import org.mozilla.fenix.ui.robots.navigationToolbar * Tests for verifying basic functionality of recently closed tabs history * */ -class RecentlyClosedTabsTest { - private lateinit var mockWebServer: MockWebServer - +class RecentlyClosedTabsTest : TestSetup() { @get:Rule val activityTestRule = AndroidComposeTestRule( - HomeActivityTestRule.withDefaultSettingsOverrides( + HomeActivityIntentTestRule.withDefaultSettingsOverrides( tabsTrayRewriteEnabled = true, ), ) { it.activity } - @Before - fun setUp() { - mockWebServer = MockWebServer().apply { - dispatcher = AndroidAssetDispatcher() - start() - } - - Intents.init() - } - - @After - fun tearDown() { - mockWebServer.shutdown() - } - // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1065414 // Verifies that a recently closed item is properly opened @SmokeTest diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt index d1d0076cd..ede7b06b5 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt @@ -21,7 +21,6 @@ import org.junit.Test import org.mozilla.fenix.customannotations.SmokeTest import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings -import org.mozilla.fenix.helpers.AppAndSystemHelper import org.mozilla.fenix.helpers.AppAndSystemHelper.assertNativeAppOpens import org.mozilla.fenix.helpers.AppAndSystemHelper.denyPermission import org.mozilla.fenix.helpers.AppAndSystemHelper.grantSystemPermission @@ -45,6 +44,7 @@ import org.mozilla.fenix.helpers.TestHelper.exitMenu import org.mozilla.fenix.helpers.TestHelper.longTapSelectItem import org.mozilla.fenix.helpers.TestHelper.mDevice import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText +import org.mozilla.fenix.helpers.TestSetup import org.mozilla.fenix.ui.robots.clickContextMenuItem import org.mozilla.fenix.ui.robots.clickPageObject import org.mozilla.fenix.ui.robots.homeScreen @@ -64,7 +64,7 @@ import java.util.Locale * */ -class SearchTest { +class SearchTest : TestSetup() { private lateinit var searchMockServer: MockWebServer private var queryString = "firefox" private val generalEnginesList = listOf("DuckDuckGo", "Google", "Bing") @@ -84,7 +84,8 @@ class SearchTest { ) { it.activity } @Before - fun setUp() { + override fun setUp() { + super.setUp() searchMockServer = MockWebServer().apply { dispatcher = SearchDispatcher() start() @@ -92,9 +93,8 @@ class SearchTest { } @After - fun tearDown() { + override fun tearDown() { searchMockServer.shutdown() - AppAndSystemHelper.resetSystemLocaleToEnUS() } // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2154189