Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Bug 1880087 - Create TestSetup helper: Test classes D-L
Browse files Browse the repository at this point in the history
  • Loading branch information
sv-ohorvath committed Feb 26, 2024
1 parent 1898c06 commit 19afa4d
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
package org.mozilla.fenix.ui

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.Ignore
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestSetup
import org.mozilla.fenix.ui.robots.DeepLinkRobot

/**
Expand All @@ -31,29 +27,12 @@ import org.mozilla.fenix.ui.robots.DeepLinkRobot
**/

@Ignore("All tests perma-failing, see: https://github.com/mozilla-mobile/fenix/issues/13491")
class DeepLinkTest {
private lateinit var mDevice: UiDevice
private lateinit var mockWebServer: MockWebServer

class DeepLinkTest : TestSetup() {
private val robot = DeepLinkRobot()

@get:Rule
val activityIntentTestRule = HomeActivityIntentTestRule()

@Before
fun setUp() {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}

@After
fun tearDown() {
mockWebServer.shutdown()
}

@Test
fun openHomeScreen() {
robot.openHomeScreen {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
package org.mozilla.fenix.ui

import androidx.core.net.toUri
import org.junit.After
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AppAndSystemHelper.clearDownloadsFolder
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestSetup
import org.mozilla.fenix.ui.robots.downloadRobot

/**
Expand All @@ -22,20 +21,14 @@ import org.mozilla.fenix.ui.robots.downloadRobot
* - Verifies downloading of varying file types and the appearance inside the Downloads listing.
**/
@RunWith(Parameterized::class)
class DownloadFileTypesTest(fileName: String) {
class DownloadFileTypesTest(fileName: String) : TestSetup() {
/* Remote test page managed by Mozilla Mobile QA team at https://github.com/mozilla-mobile/testapp */
private val downloadTestPage = "https://storage.googleapis.com/mobile_test_assets/test_app/downloads.html"
private var downloadFile: String = fileName

@get:Rule
val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()

@After
fun tearDown() {
// Check and clear the downloads folder
clearDownloadsFolder()
}

companion object {
// Creating test data. The test will take each file name as a parameter and run it individually.
@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
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.Ignore
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.AppAndSystemHelper.deleteDownloadedFileOnStorage
import org.mozilla.fenix.helpers.AppAndSystemHelper.setNetworkEnabled
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_APPS_PHOTOS
Expand All @@ -25,6 +20,7 @@ import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.clickSnackbarButton
import org.mozilla.fenix.helpers.TestHelper.exitMenu
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.clickPageObject
import org.mozilla.fenix.ui.robots.downloadRobot
Expand All @@ -40,44 +36,14 @@ import org.mozilla.fenix.ui.robots.notificationShade
* - Verifies download notification and actions
* - Verifies managing downloads inside the Downloads listing.
**/
class DownloadTest {
private lateinit var mockWebServer: MockWebServer

class DownloadTest : TestSetup() {
/* Remote test page managed by Mozilla Mobile QA team at https://github.com/mozilla-mobile/testapp */
private val downloadTestPage = "https://storage.googleapis.com/mobile_test_assets/test_app/downloads.html"
private var downloadFile: String = ""

@get:Rule
val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()

@Before
fun setUp() {
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}

// clear all existing notifications
notificationShade {
mDevice.openNotification()
clearNotifications()
}
}

@After
fun tearDown() {
notificationShade {
cancelAllShownNotifications()
}

mockWebServer.shutdown()

setNetworkEnabled(enabled = true)

// Check and clear the downloads folder
clearDownloadsFolder()
}

// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/243844
@Test
fun verifyTheDownloadPromptsTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ package org.mozilla.fenix.ui

import androidx.core.net.toUri
import androidx.test.espresso.Espresso.pressBack
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.ext.settings
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper.getEnhancedTrackingProtectionAsset
import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
Expand All @@ -22,6 +18,7 @@ import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.restartApp
import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText
import org.mozilla.fenix.helpers.TestSetup
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.enhancedTrackingProtection
import org.mozilla.fenix.ui.robots.homeScreen
Expand All @@ -40,29 +37,14 @@ import org.mozilla.fenix.ui.robots.navigationToolbar
* - Verifying Enhanced Tracking Protection site exceptions
*/

class EnhancedTrackingProtectionTest {
private lateinit var mockWebServer: MockWebServer

class EnhancedTrackingProtectionTest : TestSetup() {
@get:Rule
val activityTestRule = HomeActivityIntentTestRule(
isJumpBackInCFREnabled = false,
isTCPCFREnabled = false,
isWallpaperOnboardingEnabled = false,
)

@Before
fun setUp() {
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}

@After
fun tearDown() {
mockWebServer.shutdown()
}

// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/416046
@Test
fun testETPSettingsItemsAndSubMenus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import org.mozilla.fenix.helpers.AppAndSystemHelper.runWithCondition
import org.mozilla.fenix.helpers.DataGenerationHelper.getSponsoredFxSuggestPlaceHolder
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestSetup
import org.mozilla.fenix.ui.robots.navigationToolbar

/**
* Tests for verifying the Firefox suggest search fragment
*
*/

class FirefoxSuggestTest {
class FirefoxSuggestTest : TestSetup() {

@get:Rule
val activityTestRule = AndroidComposeTestRule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,21 @@

package org.mozilla.fenix.ui

import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper.TestAsset
import org.mozilla.fenix.helpers.TestAssetHelper.getGPCTestAsset
import org.mozilla.fenix.helpers.TestSetup
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar

/**
* Tests for Global Privacy Control setting.
*/

class GlobalPrivacyControlTest {
private lateinit var mockWebServer: MockWebServer
class GlobalPrivacyControlTest : TestSetup() {
private lateinit var gpcPage: TestAsset

@get:Rule
Expand All @@ -33,20 +30,11 @@ class GlobalPrivacyControlTest {
)

@Before
fun setUp() {
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}

override fun setUp() {
super.setUp()
gpcPage = getGPCTestAsset(mockWebServer)
}

@After
fun tearDown() {
mockWebServer.shutdown()
}

// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2429327
@Test
fun testGPCinNormalBrowsing() {
Expand Down
43 changes: 4 additions & 39 deletions fenix/app/src/androidTest/java/org/mozilla/fenix/ui/HistoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,24 @@

package org.mozilla.fenix.ui

import android.content.Context
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
import androidx.test.espresso.Espresso.pressBack
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import kotlinx.coroutines.runBlocking
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
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.R
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.AppAndSystemHelper.registerAndCleanupIdlingResources
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.MockBrowserDataHelper
import org.mozilla.fenix.helpers.RecyclerViewIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper
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.browserScreen
import org.mozilla.fenix.ui.robots.historyMenu
import org.mozilla.fenix.ui.robots.homeScreen
Expand All @@ -40,40 +32,13 @@ import org.mozilla.fenix.ui.robots.navigationToolbar
* Tests for verifying basic functionality of history
*
*/
class HistoryTest {
private lateinit var mockWebServer: MockWebServer
private lateinit var mDevice: UiDevice

class HistoryTest : TestSetup() {
@get:Rule
val activityTestRule =
AndroidComposeTestRule(
HomeActivityIntentTestRule.withDefaultSettingsOverrides(),
HomeActivityIntentTestRule(isJumpBackInCFREnabled = false),
) { it.activity }

@Before
fun setUp() {
InstrumentationRegistry.getInstrumentation().targetContext.settings()
.shouldShowJumpBackInCFR = false

mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}

@After
fun tearDown() {
mockWebServer.shutdown()
// Clearing all history data after each test to avoid overlapping data
val applicationContext: Context = activityTestRule.activity.applicationContext
val historyStorage = PlacesHistoryStorage(applicationContext)

runBlocking {
historyStorage.deleteEverything()
}
}

// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/243285
@Test
fun verifyEmptyHistoryMenuTest() {
Expand Down
Loading

0 comments on commit 19afa4d

Please sign in to comment.