Bug 1878868 - Create TestSetup helper: Test classes A-C

fenix/124.1.0
oana.horvath 4 months ago committed by mergify[bot]
parent 499e533ac2
commit 95cf640fdc

@ -14,11 +14,11 @@ import android.content.pm.PackageManager
import android.content.res.Configuration import android.content.res.Configuration
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Environment
import android.os.storage.StorageManager import android.os.storage.StorageManager
import android.os.storage.StorageVolume import android.os.storage.StorageVolume
import android.provider.Settings import android.provider.Settings
import android.util.Log import android.util.Log
import androidx.annotation.RequiresApi
import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.espresso.Espresso import androidx.test.espresso.Espresso
import androidx.test.espresso.IdlingRegistry import androidx.test.espresso.IdlingRegistry
@ -33,6 +33,7 @@ import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiSelector import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until import androidx.test.uiautomator.Until
import junit.framework.AssertionFailedError import junit.framework.AssertionFailedError
import kotlinx.coroutines.runBlocking
import org.junit.Assert import org.junit.Assert
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.mozilla.fenix.Config import org.mozilla.fenix.Config
@ -60,46 +61,88 @@ object AppAndSystemHelper {
} }
} }
@RequiresApi(Build.VERSION_CODES.R) /**
* Checks if a specific download file is inside the device storage and deletes it.
* Different implementation needed for newer API levels,
* as Environment.getExternalStorageDirectory() is deprecated starting with API 29.
*
*/
fun deleteDownloadedFileOnStorage(fileName: String) { fun deleteDownloadedFileOnStorage(fileName: String) {
val storageManager: StorageManager? = TestHelper.appContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager? if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
val storageVolumes = storageManager!!.storageVolumes val storageManager: StorageManager? =
val storageVolume: StorageVolume = storageVolumes[0] TestHelper.appContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager?
val file = File(storageVolume.directory!!.path + "/Download/" + fileName) val storageVolumes = storageManager!!.storageVolumes
try { val storageVolume: StorageVolume = storageVolumes[0]
if (file.exists()) { val file = File(storageVolume.directory!!.path + "/Download/" + fileName)
try {
if (file.exists()) {
file.delete()
Log.d("TestLog", "File delete try 1")
Assert.assertFalse("The file was not deleted", file.exists())
}
} catch (e: AssertionError) {
file.delete() file.delete()
Log.d("TestLog", "File delete try 1") Log.d("TestLog", "File delete retried")
Assert.assertFalse("The file was not deleted", file.exists()) Assert.assertFalse("The file was not deleted", file.exists())
} }
} catch (e: AssertionError) { } else {
file.delete() runBlocking {
Log.d("TestLog", "File delete retried") val downloadedFile = File(
Assert.assertFalse("The file was not deleted", file.exists()) Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
fileName,
)
if (downloadedFile.exists()) {
Log.i(TAG, "deleteDownloadedFileOnStorage: Verifying if $downloadedFile exists.")
downloadedFile.delete()
Log.i(TAG, "deleteDownloadedFileOnStorage: $downloadedFile deleted.")
}
}
} }
} }
@RequiresApi(Build.VERSION_CODES.R) /**
* Checks if there are download files inside the device storage and deletes all of them.
* Different implementation needed for newer API levels, as
* Environment.getExternalStorageDirectory() is deprecated starting with API 29.
*/
fun clearDownloadsFolder() { fun clearDownloadsFolder() {
val storageManager: StorageManager? = TestHelper.appContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager? if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
val storageVolumes = storageManager!!.storageVolumes Log.i(TAG, "clearDownloadsFolder: API > 29")
val storageVolume: StorageVolume = storageVolumes[0] val storageManager: StorageManager? =
val downloadsFolder = File(storageVolume.directory!!.path + "/Download/") TestHelper.appContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager?
val storageVolumes = storageManager!!.storageVolumes
// Check if the downloads folder exists val storageVolume: StorageVolume = storageVolumes[0]
if (downloadsFolder.exists() && downloadsFolder.isDirectory) { val downloadsFolder = File(storageVolume.directory!!.path + "/Download/")
Log.i(TAG, "clearDownloadsFolder: Verified that \"DOWNLOADS\" folder exists")
val files = downloadsFolder.listFiles() // Check if the downloads folder exists
if (downloadsFolder.exists() && downloadsFolder.isDirectory) {
// Check if the folder is not empty Log.i(TAG, "clearDownloadsFolder: Verified that \"DOWNLOADS\" folder exists")
if (files != null && files.isNotEmpty()) { val files = downloadsFolder.listFiles()
Log.i(TAG, "clearDownloadsFolder: Verified that \"DOWNLOADS\" folder is not empty")
// Delete all files in the folder // Check if the folder is not empty
for (file in files) { if (files != null && files.isNotEmpty()) {
file.delete() Log.i(
Log.i(TAG, "clearDownloadsFolder: Deleted $file from \"DOWNLOADS\" folder") TAG,
"clearDownloadsFolder: Verified that \"DOWNLOADS\" folder is not empty",
)
// Delete all files in the folder
for (file in files) {
file.delete()
Log.i(TAG, "clearDownloadsFolder: Deleted $file from \"DOWNLOADS\" folder")
}
} }
} }
} else {
runBlocking {
Log.i(TAG, "clearDownloadsFolder: API <= 29")
Log.i(TAG, "clearDownloadsFolder: Verifying if any download files exist.")
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.listFiles()?.forEach {
it.delete()
Log.i(TAG, "clearDownloadsFolder: Download file $it deleted.")
}
}
} }
} }

@ -0,0 +1,52 @@
package org.mozilla.fenix.helpers
import android.util.Log
import kotlinx.coroutines.runBlocking
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.storage.sync.PlacesBookmarksStorage
import okhttp3.mockwebserver.MockWebServer
import org.junit.Before
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.ui.robots.notificationShade
open class TestSetup {
lateinit var mockWebServer: MockWebServer
private val bookmarksStorage = PlacesBookmarksStorage(appContext.applicationContext)
@Before
fun setUp() {
Log.i(TAG, "TestSetup: Starting the @Before setup")
// Clear pre-existing notifications
notificationShade {
cancelAllShownNotifications()
}
runBlocking {
// Reset locale to EN-US if needed.
AppAndSystemHelper.resetSystemLocaleToEnUS()
// Check and clear the downloads folder
AppAndSystemHelper.clearDownloadsFolder()
// Make sure the Wifi and Mobile Data connections are on
AppAndSystemHelper.setNetworkEnabled(true)
// Clear bookmarks left after a failed test
val bookmarks = bookmarksStorage.getTree(BookmarkRoot.Mobile.id)?.children
Log.i(TAG, "Before cleanup: Bookmarks storage contains: $bookmarks")
bookmarks?.forEach {
bookmarksStorage.deleteNode(it.guid)
// TODO: Follow-up with a method to handle the DB update; the logs will still show the bookmarks in the storage before the test starts.
Log.i(TAG, "After cleanup: Bookmarks storage contains: $bookmarks")
}
}
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
}
try {
Log.i(TAG, "Try starting mockWebServer")
mockWebServer.start()
} catch (e: Exception) {
Log.i(TAG, "Exception caught. Re-starting mockWebServer")
mockWebServer.shutdown()
mockWebServer.start()
}
}
}

@ -4,27 +4,22 @@
package org.mozilla.fenix.ui package org.mozilla.fenix.ui
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.exitMenu import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.packageName import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestSetup
import org.mozilla.fenix.ui.robots.autofillScreen import org.mozilla.fenix.ui.robots.autofillScreen
import org.mozilla.fenix.ui.robots.clickPageObject import org.mozilla.fenix.ui.robots.clickPageObject
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
class AddressAutofillTest { class AddressAutofillTest : TestSetup() {
private lateinit var mockWebServer: MockWebServer
object FirstAddressAutofillDetails { object FirstAddressAutofillDetails {
var navigateToAutofillSettings = true var navigateToAutofillSettings = true
var isAddressAutofillEnabled = true var isAddressAutofillEnabled = true
@ -58,19 +53,6 @@ class AddressAutofillTest {
@get:Rule @get:Rule
val activityIntentTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides() val activityIntentTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()
@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/1836845 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1836845
@SmokeTest @SmokeTest
@Test @Test

@ -8,20 +8,13 @@ import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu
import androidx.test.espresso.Espresso.pressBack import androidx.test.espresso.Espresso.pressBack
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.UiDevice
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import mozilla.appservices.places.BookmarkRoot
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Ignore import org.junit.Ignore
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.customannotations.SmokeTest import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.ext.bookmarkStorage
import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.AppAndSystemHelper.registerAndCleanupIdlingResources import org.mozilla.fenix.helpers.AppAndSystemHelper.registerAndCleanupIdlingResources
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.MockBrowserDataHelper.createBookmarkItem import org.mozilla.fenix.helpers.MockBrowserDataHelper.createBookmarkItem
@ -31,8 +24,10 @@ import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.appContext import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.helpers.TestHelper.clickSnackbarButton import org.mozilla.fenix.helpers.TestHelper.clickSnackbarButton
import org.mozilla.fenix.helpers.TestHelper.longTapSelectItem import org.mozilla.fenix.helpers.TestHelper.longTapSelectItem
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.restartApp import org.mozilla.fenix.helpers.TestHelper.restartApp
import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText
import org.mozilla.fenix.helpers.TestSetup
import org.mozilla.fenix.ui.robots.bookmarksMenu import org.mozilla.fenix.ui.robots.bookmarksMenu
import org.mozilla.fenix.ui.robots.browserScreen import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.homeScreen import org.mozilla.fenix.ui.robots.homeScreen
@ -42,9 +37,7 @@ import org.mozilla.fenix.ui.robots.navigationToolbar
/** /**
* Tests for verifying basic functionality of bookmarks * Tests for verifying basic functionality of bookmarks
*/ */
class BookmarksTest { class BookmarksTest : TestSetup() {
private lateinit var mockWebServer: MockWebServer
private lateinit var mDevice: UiDevice
private val bookmarksFolderName = "New Folder" private val bookmarksFolderName = "New Folder"
private val testBookmark = object { private val testBookmark = object {
var title: String = "Bookmark title" var title: String = "Bookmark title"
@ -61,26 +54,6 @@ class BookmarksTest {
@JvmField @JvmField
val retryTestRule = RetryTestRule(3) val retryTestRule = RetryTestRule(3)
@Before
fun setUp() {
mDevice = UiDevice.getInstance(getInstrumentation())
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
mockWebServer.shutdown()
// Clearing all bookmarks data after each test to avoid overlapping data
val bookmarksStorage = activityTestRule.activity?.bookmarkStorage
runBlocking {
val bookmarks = bookmarksStorage?.getTree(BookmarkRoot.Mobile.id)?.children
bookmarks?.forEach { bookmarksStorage.deleteNode(it.guid) }
}
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/522919 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/522919
@Test @Test
fun verifyEmptyBookmarksMenuTest() { fun verifyEmptyBookmarksMenuTest() {

@ -5,20 +5,17 @@
package org.mozilla.fenix.ui package org.mozilla.fenix.ui
import androidx.core.net.toUri import androidx.core.net.toUri
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.customannotations.SmokeTest import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.AppAndSystemHelper.setNetworkEnabled import org.mozilla.fenix.helpers.AppAndSystemHelper.setNetworkEnabled
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.RetryTestRule import org.mozilla.fenix.helpers.RetryTestRule
import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
import org.mozilla.fenix.helpers.TestSetup
import org.mozilla.fenix.ui.robots.browserScreen import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.clickPageObject import org.mozilla.fenix.ui.robots.clickPageObject
import org.mozilla.fenix.ui.robots.navigationToolbar import org.mozilla.fenix.ui.robots.navigationToolbar
@ -26,13 +23,12 @@ import org.mozilla.fenix.ui.robots.navigationToolbar
/** /**
* Tests that verify errors encountered while browsing websites: unsafe pages, connection errors, etc * Tests that verify errors encountered while browsing websites: unsafe pages, connection errors, etc
*/ */
class BrowsingErrorPagesTest { class BrowsingErrorPagesTest : TestSetup() {
private val malwareWarning = getStringResource(R.string.mozac_browser_errorpages_safe_browsing_malware_uri_title) private val malwareWarning = getStringResource(R.string.mozac_browser_errorpages_safe_browsing_malware_uri_title)
private val phishingWarning = getStringResource(R.string.mozac_browser_errorpages_safe_phishing_uri_title) private val phishingWarning = getStringResource(R.string.mozac_browser_errorpages_safe_phishing_uri_title)
private val unwantedSoftwareWarning = private val unwantedSoftwareWarning =
getStringResource(R.string.mozac_browser_errorpages_safe_browsing_unwanted_uri_title) getStringResource(R.string.mozac_browser_errorpages_safe_browsing_unwanted_uri_title)
private val harmfulSiteWarning = getStringResource(R.string.mozac_browser_errorpages_safe_harmful_uri_title) private val harmfulSiteWarning = getStringResource(R.string.mozac_browser_errorpages_safe_harmful_uri_title)
private lateinit var mockWebServer: MockWebServer
@get: Rule @get: Rule
val mActivityTestRule = HomeActivityTestRule.withDefaultSettingsOverrides() val mActivityTestRule = HomeActivityTestRule.withDefaultSettingsOverrides()
@ -41,21 +37,6 @@ class BrowsingErrorPagesTest {
@JvmField @JvmField
val retryTestRule = RetryTestRule(3) val retryTestRule = RetryTestRule(3)
@Before
fun setUp() {
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
// Restoring network connection
setNetworkEnabled(true)
mockWebServer.shutdown()
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2326774 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/2326774
@SmokeTest @SmokeTest
@Test @Test

@ -5,20 +5,16 @@
package org.mozilla.fenix.ui package org.mozilla.fenix.ui
import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.compose.ui.test.junit4.AndroidComposeTestRule
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.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
import org.mozilla.fenix.helpers.TestHelper.clickSnackbarButton import org.mozilla.fenix.helpers.TestHelper.clickSnackbarButton
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText 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.browserScreen
import org.mozilla.fenix.ui.robots.collectionRobot import org.mozilla.fenix.ui.robots.collectionRobot
import org.mozilla.fenix.ui.robots.homeScreen import org.mozilla.fenix.ui.robots.homeScreen
@ -30,9 +26,7 @@ import org.mozilla.fenix.ui.robots.tabDrawer
* *
*/ */
class CollectionTest { class CollectionTest : TestSetup() {
private lateinit var mDevice: UiDevice
private lateinit var mockWebServer: MockWebServer
private val firstCollectionName = "testcollection_1" private val firstCollectionName = "testcollection_1"
private val secondCollectionName = "testcollection_2" private val secondCollectionName = "testcollection_2"
private val collectionName = "First Collection" private val collectionName = "First Collection"
@ -51,20 +45,6 @@ class CollectionTest {
), ),
) { it.activity } ) { it.activity }
@Before
fun setUp() {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
mockWebServer.shutdown()
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/353823 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/353823
@SmokeTest @SmokeTest
@Test @Test

@ -5,15 +5,8 @@
package org.mozilla.fenix.ui package org.mozilla.fenix.ui
import androidx.core.net.toUri 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.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.AppAndSystemHelper.assertExternalAppOpens import org.mozilla.fenix.helpers.AppAndSystemHelper.assertExternalAppOpens
import org.mozilla.fenix.helpers.Constants.PackageName.YOUTUBE_APP import org.mozilla.fenix.helpers.Constants.PackageName.YOUTUBE_APP
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
@ -22,7 +15,9 @@ import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.RetryTestRule import org.mozilla.fenix.helpers.RetryTestRule
import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.clickSnackbarButton import org.mozilla.fenix.helpers.TestHelper.clickSnackbarButton
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.verifySnackBarText 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.clickContextMenuItem
import org.mozilla.fenix.ui.robots.clickPageObject import org.mozilla.fenix.ui.robots.clickPageObject
import org.mozilla.fenix.ui.robots.downloadRobot import org.mozilla.fenix.ui.robots.downloadRobot
@ -44,32 +39,15 @@ import org.mozilla.fenix.ui.robots.shareOverlay
* *
*/ */
class ContextMenusTest { class ContextMenusTest : TestSetup() {
private lateinit var mDevice: UiDevice
private lateinit var mockWebServer: MockWebServer
@get:Rule @get:Rule
val activityIntentTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides() val activityIntentTestRule = HomeActivityIntentTestRule(isJumpBackInCFREnabled = false)
@Rule @Rule
@JvmField @JvmField
val retryTestRule = RetryTestRule(3) val retryTestRule = RetryTestRule(3)
@Before
fun setUp() {
activityIntentTestRule.activity.applicationContext.settings().shouldShowJumpBackInCFR = false
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
mockWebServer.shutdown()
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/243837 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/243837
@Test @Test
fun verifyOpenLinkNewTabContextMenuOptionTest() { fun verifyOpenLinkNewTabContextMenuOptionTest() {

@ -12,13 +12,14 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.AppAndSystemHelper.runWithCondition import org.mozilla.fenix.helpers.AppAndSystemHelper.runWithCondition
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestHelper.appContext import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.helpers.TestSetup
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
/** /**
* Tests for verifying the new Cookie banner blocker option and functionality. * Tests for verifying the new Cookie banner blocker option and functionality.
*/ */
class CookieBannerBlockerTest { class CookieBannerBlockerTest : TestSetup() {
@get:Rule @get:Rule
val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides(skipOnboarding = true) val activityTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides(skipOnboarding = true)

@ -5,29 +5,23 @@
package org.mozilla.fenix.ui package org.mozilla.fenix.ui
import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.compose.ui.test.junit4.AndroidComposeTestRule
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.Ignore
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.customannotations.SmokeTest import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestSetup
import org.mozilla.fenix.ui.robots.clickPageObject import org.mozilla.fenix.ui.robots.clickPageObject
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
class CrashReportingTest { class CrashReportingTest : TestSetup() {
private lateinit var mDevice: UiDevice
private lateinit var mockWebServer: MockWebServer
private val tabCrashMessage = getStringResource(R.string.tab_crash_title_2) private val tabCrashMessage = getStringResource(R.string.tab_crash_title_2)
@get:Rule @get:Rule
@ -40,20 +34,6 @@ class CrashReportingTest {
), ),
) { it.activity } ) { it.activity }
@Before
fun setUp() {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
mockWebServer.shutdown()
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/308906 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/308906
@Test @Test
fun closeTabFromCrashedTabReporterTest() { fun closeTabFromCrashedTabReporterTest() {

@ -4,13 +4,9 @@
package org.mozilla.fenix.ui package org.mozilla.fenix.ui
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.AppAndSystemHelper.bringAppToForeground import org.mozilla.fenix.helpers.AppAndSystemHelper.bringAppToForeground
import org.mozilla.fenix.helpers.AppAndSystemHelper.putAppToBackground import org.mozilla.fenix.helpers.AppAndSystemHelper.putAppToBackground
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
@ -19,14 +15,13 @@ import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.exitMenu import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.packageName import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestSetup
import org.mozilla.fenix.ui.robots.clickPageObject import org.mozilla.fenix.ui.robots.clickPageObject
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 java.time.LocalDate import java.time.LocalDate
class CreditCardAutofillTest { class CreditCardAutofillTest : TestSetup() {
private lateinit var mockWebServer: MockWebServer
object MockCreditCard1 { object MockCreditCard1 {
const val MOCK_CREDIT_CARD_NUMBER = "5555555555554444" const val MOCK_CREDIT_CARD_NUMBER = "5555555555554444"
const val MOCK_LAST_CARD_DIGITS = "4444" const val MOCK_LAST_CARD_DIGITS = "4444"
@ -48,19 +43,6 @@ class CreditCardAutofillTest {
@get:Rule @get:Rule
val activityIntentTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides() val activityIntentTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()
@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/1512792 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1512792
@SmokeTest @SmokeTest
@Test @Test

@ -7,25 +7,20 @@
package org.mozilla.fenix.ui package org.mozilla.fenix.ui
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.ActivityTestRule import androidx.test.rule.ActivityTestRule
import androidx.test.uiautomator.UiDevice
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.IntentReceiverActivity import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.customannotations.SmokeTest import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.AppAndSystemHelper.openAppFromExternalLink import org.mozilla.fenix.helpers.AppAndSystemHelper.openAppFromExternalLink
import org.mozilla.fenix.helpers.DataGenerationHelper.createCustomTabIntent import org.mozilla.fenix.helpers.DataGenerationHelper.createCustomTabIntent
import org.mozilla.fenix.helpers.FeatureSettingsHelperDelegate
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.exitMenu 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.browserScreen
import org.mozilla.fenix.ui.robots.clickPageObject import org.mozilla.fenix.ui.robots.clickPageObject
import org.mozilla.fenix.ui.robots.customTabScreen import org.mozilla.fenix.ui.robots.customTabScreen
@ -36,9 +31,7 @@ import org.mozilla.fenix.ui.robots.notificationShade
import org.mozilla.fenix.ui.robots.openEditURLView import org.mozilla.fenix.ui.robots.openEditURLView
import org.mozilla.fenix.ui.robots.searchScreen import org.mozilla.fenix.ui.robots.searchScreen
class CustomTabsTest { class CustomTabsTest : TestSetup() {
private lateinit var mDevice: UiDevice
private lateinit var mockWebServer: MockWebServer
private val customMenuItem = "TestMenuItem" private val customMenuItem = "TestMenuItem"
private val customTabActionButton = "CustomActionButton" private val customTabActionButton = "CustomActionButton"
@ -58,23 +51,6 @@ class CustomTabsTest {
false, false,
) )
private val featureSettingsHelper = FeatureSettingsHelperDelegate()
@Before
fun setUp() {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
mockWebServer.shutdown()
featureSettingsHelper.resetAllFeatureFlags()
}
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/249659 // TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/249659
@SmokeTest @SmokeTest
@Test @Test

Loading…
Cancel
Save