Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
run #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Horvath committed Apr 6, 2022
1 parent f73b254 commit 5475d16
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FeatureSettingsHelper {
private var isPocketEnabled: Boolean = settings.showPocketRecommendationsFeature
private var isJumpBackInCFREnabled: Boolean = settings.shouldShowJumpBackInCFR
private var isRecentTabsFeatureEnabled: Boolean = settings.showRecentTabsFeature
private var isRecentlyVisitedFeatureEnabled: Boolean = settings.historyMetadataUIFeature
private var isUserKnowsAboutPwasTrue: Boolean = settings.userKnowsAboutPwas

fun setPocketEnabled(enabled: Boolean) {
Expand All @@ -30,6 +31,10 @@ class FeatureSettingsHelper {
settings.showRecentTabsFeature = enabled
}

fun setRecentlyVisitedFeatureEnabled(enabled: Boolean) {
settings.historyMetadataUIFeature = enabled
}

fun setStrictETPEnabled() {
settings.setStrictETP()
}
Expand All @@ -45,6 +50,7 @@ class FeatureSettingsHelper {
settings.showPocketRecommendationsFeature = isPocketEnabled
settings.shouldShowJumpBackInCFR = isJumpBackInCFREnabled
settings.showRecentTabsFeature = isRecentTabsFeatureEnabled
settings.historyMetadataUIFeature = isRecentlyVisitedFeatureEnabled
settings.userKnowsAboutPwas = isUserKnowsAboutPwasTrue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import java.io.File
import kotlinx.coroutines.runBlocking
import mozilla.components.browser.state.search.SearchEngine
import mozilla.components.support.ktx.android.content.appName
Expand All @@ -55,6 +54,7 @@ import org.mozilla.fenix.helpers.idlingresource.NetworkConnectionIdlingResource
import org.mozilla.fenix.ui.robots.BrowserRobot
import org.mozilla.fenix.ui.robots.mDevice
import org.mozilla.fenix.utils.IntentUtils
import java.io.File

object TestHelper {

Expand Down
182 changes: 173 additions & 9 deletions app/src/androidTest/java/org/mozilla/fenix/ui/CollectionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.mozilla.fenix.ui

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.Direction
import androidx.test.uiautomator.UiDevice
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
Expand All @@ -14,10 +15,10 @@ import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.FeatureSettingsHelper
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.collectionRobot
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
import org.mozilla.fenix.ui.robots.tabDrawer
Expand All @@ -28,24 +29,23 @@ import org.mozilla.fenix.ui.robots.tabDrawer
*/

class CollectionTest {
/* ktlint-disable no-blank-line-before-rbrace */
// This imposes unreadable grouping.

private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private lateinit var mockWebServer: MockWebServer
private val firstCollectionName = "testcollection_1"
private val secondCollectionName = "testcollection_2"
private val collectionName = "First Collection"
private val featureSettingsHelper = FeatureSettingsHelper()

@get:Rule
val activityTestRule = HomeActivityTestRule()
val activityTestRule = HomeActivityIntentTestRule()

@Before
fun setUp() {
// disabling these features to have better visibility of Collections
featureSettingsHelper.setRecentTabsFeatureEnabled(false)
featureSettingsHelper.setPocketEnabled(false)
featureSettingsHelper.setJumpBackCFREnabled(false)
featureSettingsHelper.setRecentlyVisitedFeatureEnabled(false)

mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
Expand All @@ -61,6 +61,169 @@ class CollectionTest {
featureSettingsHelper.resetAllFeatureFlags()
}

@SmokeTest
@Test
fun createFirstCollectionTest() {
val firstWebPage = getGenericAsset(mockWebServer, 1)
val secondWebPage = getGenericAsset(mockWebServer, 2)

navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
mDevice.waitForIdle()
}.openTabDrawer {
}.openNewTab {
}.submitQuery(secondWebPage.url.toString()) {
mDevice.waitForIdle()
}.goToHomescreen {
swipeToBottom()
}.clickSaveTabsToCollectionButton {
longClickTab(firstWebPage.title)
selectTab(secondWebPage.title)
}.clickSaveCollection {
typeCollectionNameAndSave(collectionName)
}

tabDrawer {
verifySnackBarText("Collection saved!")
snackBarButtonClick("VIEW")
}

homeScreen {
verifyCollectionIsDisplayed(collectionName)
verifyCollectionIcon()
}
}

@SmokeTest
@Test
fun verifyExpandedCollectionItemsTest() {
val webPage = getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(webPage.url) {
}.openTabDrawer {
createCollection(webPage.title, collectionName)
snackBarButtonClick("VIEW")
}

homeScreen {
verifyCollectionIsDisplayed(collectionName)
verifyCollectionIcon()
}.expandCollection(collectionName) {
verifyTabSavedInCollection(webPage.title)
verifyCollectionTabLogo(true)
verifyCollectionTabUrl(true)
verifyShareCollectionButtonIsVisible(true)
verifyCollectionMenuIsVisible(true)
verifyCollectionItemRemoveButtonIsVisible(webPage.title, true)
}.collapseCollection(collectionName) {}

collectionRobot {
verifyTabSavedInCollection(webPage.title, false)
verifyShareCollectionButtonIsVisible(false)
verifyCollectionMenuIsVisible(false)
verifyCollectionTabLogo(false)
verifyCollectionTabUrl(false)
verifyCollectionItemRemoveButtonIsVisible(webPage.title, false)
}

homeScreen {
}.expandCollection(collectionName) {
verifyTabSavedInCollection(webPage.title)
verifyCollectionTabLogo(true)
verifyCollectionTabUrl(true)
verifyShareCollectionButtonIsVisible(true)
verifyCollectionMenuIsVisible(true)
verifyCollectionItemRemoveButtonIsVisible(webPage.title, true)
}.collapseCollection(collectionName) {}

collectionRobot {
verifyTabSavedInCollection(webPage.title, false)
verifyShareCollectionButtonIsVisible(false)
verifyCollectionMenuIsVisible(false)
verifyCollectionTabLogo(false)
verifyCollectionTabUrl(false)
verifyCollectionItemRemoveButtonIsVisible(webPage.title, false)
}
}

@SmokeTest
@Test
fun openAllTabsInCollectionTest() {
val webPage = getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(webPage.url) {
}.openTabDrawer {
createCollection(webPage.title, collectionName)
verifySnackBarText("Collection saved!")
closeTab()
}

homeScreen {
}.expandCollection(collectionName) {
clickCollectionThreeDotButton()
selectOpenTabs()
}
tabDrawer {
verifyExistingOpenTabs(webPage.title)
}
}

@SmokeTest
@Test
fun shareCollectionTest() {
val firstWebsite = getGenericAsset(mockWebServer, 1)
val secondWebsite = getGenericAsset(mockWebServer, 2)
val sharingApp = "Gmail"
val urlString = "${secondWebsite.url}\n\n${firstWebsite.url}"

navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebsite.url) {
verifyPageContent(firstWebsite.content)
}.openTabDrawer {
createCollection(firstWebsite.title, collectionName)
}.openNewTab {
}.submitQuery(secondWebsite.url.toString()) {
verifyPageContent(secondWebsite.content)
}.openThreeDotMenu {
}.openSaveToCollection {
}.selectExistingCollection(collectionName) {
}.goToHomescreen {
}.expandCollection(collectionName) {
}.clickShareCollectionButton {
verifyShareTabsOverlay(firstWebsite.title, secondWebsite.title)
verifySharingWithSelectedApp(sharingApp, urlString, collectionName)
}
}

// @Ignore("Failing, see: https://github.com/mozilla-mobile/fenix/issues/23296")
@SmokeTest
@Test
// Test running on beta/release builds in CI:
// caution when making changes to it, so they don't block the builds
fun deleteCollectionTest() {
val webPage = getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(webPage.url) {
}.openTabDrawer {
createCollection(webPage.title, collectionName)
snackBarButtonClick("VIEW")
}

homeScreen {
}.expandCollection(collectionName) {
clickCollectionThreeDotButton()
selectDeleteCollection()
}

homeScreen {
verifySnackBarText("Collection deleted")
verifyNoCollectionsText()
}
}

@Test
// open a webpage, and add currently opened tab to existing collection
fun mainMenuSaveToExistingCollection() {
Expand Down Expand Up @@ -169,6 +332,7 @@ class CollectionTest {

homeScreen {
}.expandCollection(firstCollectionName) {
verifyTabSavedInCollection(webPage.title, true)
removeTabFromCollection(webPage.title)
verifyTabSavedInCollection(webPage.title, false)
}
Expand Down Expand Up @@ -203,9 +367,9 @@ class CollectionTest {
homeScreen {
}.expandCollection(firstCollectionName) {
swipeToBottom()
swipeCollectionItemLeft(firstWebPage.title)
swipeCollectionItem(firstWebPage.title, Direction.RIGHT)
verifyTabSavedInCollection(firstWebPage.title, false)
swipeCollectionItemRight(secondWebPage.title)
swipeCollectionItem(secondWebPage.title, Direction.LEFT)
verifyTabSavedInCollection(secondWebPage.title, false)
}
// To add this step when https://github.com/mozilla-mobile/fenix/issues/13177 is fixed
Expand Down Expand Up @@ -279,7 +443,7 @@ class CollectionTest {
@SmokeTest
@Test
fun undoDeleteCollectionTest() {
val webPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val webPage = getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(webPage.url) {
Expand Down
Loading

0 comments on commit 5475d16

Please sign in to comment.