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

Commit

Permalink
For #17484, #18003 UI tests: retry closing tab if it fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Horvath committed Feb 16, 2021
1 parent f5cb3a9 commit 9c04d4c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
Expand Down Expand Up @@ -54,16 +53,6 @@ class TabbedBrowsingTest {
}
}

// changing the device preference for Touch and Hold delay, to avoid long-clicks instead of a single-click
companion object {
@BeforeClass
@JvmStatic
fun setDevicePreference() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.executeShellCommand("settings put secure long_press_timeout 3000")
}
}

@After
fun tearDown() {
mockWebServer.shutdown()
Expand Down Expand Up @@ -95,24 +84,17 @@ class TabbedBrowsingTest {

@Test
fun openNewPrivateTabTest() {
homeScreen { }.dismissOnboarding()

val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

homeScreen { }.togglePrivateBrowsingMode()

homeScreen {
verifyPrivateSessionMessage()
verifyTabButton()
}
homeScreen {}.togglePrivateBrowsingMode()

navigationToolbar {
}.openNewTabAndEnterToBrowser(defaultWebPage.url) {
mDevice.waitForIdle()
verifyTabCounter("1")
}.openTabDrawer {
verifyExistingTabList()
verifyCloseTabsButton("Test_Page_1")
verifyPrivateModeSelected()
}.toggleToNormalTabs {
verifyNoTabsOpened()
}.toggleToPrivateTabs {
Expand Down Expand Up @@ -160,7 +142,6 @@ class TabbedBrowsingTest {
}.openNewTabAndEnterToBrowser(genericURL.url) {
}.openTabDrawer {
verifyExistingOpenTabs("Test_Page_1")
verifyCloseTabsButton("Test_Page_1")
closeTabViaXButton("Test_Page_1")
verifySnackBarText("Tab closed")
snackBarButtonClick("UNDO")
Expand Down Expand Up @@ -191,8 +172,7 @@ class TabbedBrowsingTest {
browserScreen {
}.openTabDrawer {
verifyExistingOpenTabs("Test_Page_1")
}.openNewTab {
}.dismissSearchBar { }
}.closeTabDrawer { }
}

@Test
Expand Down Expand Up @@ -283,8 +263,6 @@ class TabbedBrowsingTest {

@Test
fun verifyEmptyTabTray() {
homeScreen { }.dismissOnboarding()

navigationToolbar {
}.openTabTray {
verifyNoTabsOpened()
Expand All @@ -299,8 +277,6 @@ class TabbedBrowsingTest {

@Test
fun verifyOpenTabDetails() {
homeScreen { }.dismissOnboarding()

val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

navigationToolbar {
Expand All @@ -318,8 +294,6 @@ class TabbedBrowsingTest {

@Test
fun verifyContextMenuShortcuts() {
homeScreen { }.dismissOnboarding()

val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)

navigationToolbar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,46 @@ class TabDrawerRobot {
mDevice.findObject(
UiSelector().resourceId("org.mozilla.fenix.debug:id/mozac_browser_tabstray_close")
).waitForExists(waitingTime)
closeTabButton().click()

var retries = 0 // number of retries before failing, will stop at 2
do {
closeTabButton().click()
retries++
} while (mDevice.findObject(
UiSelector().resourceId("org.mozilla.fenix.debug:id/mozac_browser_tabstray_close")
).exists() && retries < 3
)
}

fun swipeTabRight(title: String) =
tab(title).perform(ViewActions.swipeRight())
fun swipeTabRight(title: String) {
var retries = 0 // number of retries before failing, will stop at 2
while (mDevice.findObject(UiSelector().text(title)).exists() && retries < 3) {
tab(title).perform(ViewActions.swipeRight())
retries++
}
}

fun swipeTabLeft(title: String) =
tab(title).perform(ViewActions.swipeLeft())
fun swipeTabLeft(title: String) {
var retries = 0 // number of retries before failing, will stop at 2
while (mDevice.findObject(UiSelector().text(title)).exists() && retries < 3) {
tab(title).perform(ViewActions.swipeLeft())
retries++
}
}

fun closeTabViaXButton(title: String) {
val closeButton = onView(
allOf(
withId(R.id.mozac_browser_tabstray_close),
withContentDescription("Close tab $title")
mDevice.findObject(UiSelector().text(title)).waitForExists(waitingTime)
var retries = 0 // number of retries before failing, will stop at 2
do {
val closeButton = onView(
allOf(
withId(R.id.mozac_browser_tabstray_close),
withContentDescription("Close tab $title")
)
)
)
closeButton.perform(click())
closeButton.perform(click())
retries++
} while (mDevice.findObject(UiSelector().text(title)).exists() && retries < 3)
}

fun verifySnackBarText(expectedText: String) {
Expand Down

0 comments on commit 9c04d4c

Please sign in to comment.