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

Commit

Permalink
For #15624 & #17484: improves tab drawer locator & avoids homescreen …
Browse files Browse the repository at this point in the history
…features refreshing
  • Loading branch information
Oana Horvath committed Oct 25, 2021
1 parent 1a7b486 commit f6b9a98
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ import org.mozilla.fenix.ui.robots.notificationShade
class TabbedBrowsingTest {
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private lateinit var mockWebServer: MockWebServer
private val settings = InstrumentationRegistry.getInstrumentation().targetContext.settings()

// saving default values of feature flags
private var jumpBackInCFRDefault: Boolean = settings.shouldShowJumpBackInCFR
private var recentTabsFeatureDefault: Boolean = settings.showRecentTabsFeature
private var showPocketDefault: Boolean = settings.showPocketRecommendationsFeature

/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
@get:Rule
val activityTestRule = HomeActivityTestRule()

@Before
fun setUp() {
activityTestRule.activity.applicationContext.settings().shouldShowJumpBackInCFR = false
settings.shouldShowJumpBackInCFR = false
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
Expand All @@ -58,6 +64,10 @@ class TabbedBrowsingTest {
@After
fun tearDown() {
mockWebServer.shutdown()
// resetting the default values of these features flags
settings.shouldShowJumpBackInCFR = jumpBackInCFRDefault
settings.showRecentTabsFeature = recentTabsFeatureDefault
settings.showPocketRecommendationsFeature = showPocketDefault
}

@Test
Expand Down Expand Up @@ -138,48 +148,52 @@ class TabbedBrowsingTest {

@Test
fun closeTabTest() {
// disabling these features because they interfere with the snackbar visibility
settings.showRecentTabsFeature = false
settings.showPocketRecommendationsFeature = false

val genericURL = TestAssetHelper.getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
mDevice.waitForIdle()
}.openTabDrawer {
verifyExistingOpenTabs("Test_Page_1")
closeTab()
verifySnackBarText("Tab closed")
snackBarButtonClick("UNDO")
}

mDevice.waitForIdle()

browserScreen {
verifyTabCounter("1")
}.openTabDrawer {
verifyExistingOpenTabs("Test_Page_1")
swipeTabRight("Test_Page_1")
verifySnackBarText("Tab closed")
snackBarButtonClick("UNDO")
}

mDevice.waitForIdle()

browserScreen {
verifyTabCounter("1")
}.openTabDrawer {
verifyExistingOpenTabs("Test_Page_1")
swipeTabLeft("Test_Page_1")
verifySnackBarText("Tab closed")
snackBarButtonClick("UNDO")
}

mDevice.waitForIdle()

browserScreen {
verifyTabCounter("1")
}.openTabDrawer {
verifyExistingOpenTabs("Test_Page_1")
}.closeTabDrawer { }
}

@Test
fun closePrivateTabTest() {
// disabling these features because they interfere with the snackbar visibility
settings.showRecentTabsFeature = false
settings.showPocketRecommendationsFeature = false

val genericURL = TestAssetHelper.getGenericAsset(mockWebServer, 1)

homeScreen { }.togglePrivateBrowsingMode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.mediasession.MediaSession
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.mozilla.fenix.R
Expand Down Expand Up @@ -104,8 +103,13 @@ class BrowserRobot {
}

fun verifyTabCounter(expectedText: String) {
onView(withId(R.id.counter_text))
.check((matches(withText(containsString(expectedText)))))
val counter =
mDevice.findObject(
UiSelector()
.resourceId("$packageName:id/counter_text")
.text(expectedText)
)
assertTrue(counter.waitForExists(waitingTime))
}

fun verifySnackBarText(expectedText: String) {
Expand Down Expand Up @@ -524,7 +528,10 @@ class BrowserRobot {
}

fun openTabDrawer(interact: TabDrawerRobot.() -> Unit): TabDrawerRobot.Transition {
mDevice.waitNotNull(Until.findObject(By.desc("Tabs")))
mDevice.findObject(
UiSelector().descriptionContains("open tab. Tap to switch tabs.")
).waitForExists(waitingTime)

tabsCounter().click()
mDevice.waitNotNull(Until.findObject(By.res("$packageName:id/tab_layout")))

Expand Down Expand Up @@ -613,7 +620,7 @@ private fun assertMenuButton() {
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

private fun tabsCounter() = mDevice.findObject(By.desc("Tabs"))
private fun tabsCounter() = mDevice.findObject(By.res("$packageName:id/counter_root"))

private fun mediaPlayerPlayButton() =
mDevice.findObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import org.hamcrest.CoreMatchers.anyOf
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.Matcher
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.click
Expand Down Expand Up @@ -116,17 +115,23 @@ class TabDrawerRobot {
}

fun verifySnackBarText(expectedText: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(findObject(By.text(expectedText)), TestAssetHelper.waitingTime)
assertTrue(
mDevice.findObject(
UiSelector().text(expectedText)
).waitForExists(waitingTime)
)
}

fun snackBarButtonClick(expectedText: String) {
mDevice.findObject(
UiSelector().resourceId("$packageName:id/snackbar_btn")
).waitForExists(waitingTime)
onView(allOf(withId(R.id.snackbar_btn), withText(expectedText))).check(
matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))
).perform(click())
val snackBarButton =
mDevice.findObject(
UiSelector()
.resourceId("$packageName:id/snackbar_btn")
.text(expectedText)
)

snackBarButton.waitForExists(waitingTime)
snackBarButton.click()
}

fun verifyTabMediaControlButtonState(action: String) {
Expand Down

0 comments on commit f6b9a98

Please sign in to comment.