Skip to content

Commit

Permalink
Various UI test fixes and disabling of intermittents
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronMT authored and mergify[bot] committed Sep 22, 2021
1 parent cd61ef1 commit 87e4a25
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class CollectionTest {
}.openTabDrawer {
}.openNewTab {
}.submitQuery(secondWebPage.url.toString()) {
mDevice.waitForIdle()
}.openTabDrawer {
longClickTab(firstWebPage.title)
verifyTabsMultiSelectionCounter(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class HistoryTest {
}.openTabDrawer {
}.openNewTab {
}.submitQuery(secondWebPage.url.toString()) {
mDevice.waitForIdle()
}.openThreeDotMenu {
}.openHistory {
verifyHistoryListExists()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SearchTest {
}
}

@Ignore("Currently failing at assertSearchEngineResults, will need a re-check")
@Test
fun shortcutButtonTest() {
homeScreen {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class SettingsPrivacyTest {
}
}

@Ignore("Disabled for failing with new Compose Awesomebar")
@Test
fun saveLoginFromPromptTest() {
val saveLoginTest =
Expand Down Expand Up @@ -269,6 +270,7 @@ class SettingsPrivacyTest {
}
}

@Ignore("Disabled for failing with new Compose Awesomebar")
@Test
fun openExternalLinksInPrivateTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
Expand Down
2 changes: 2 additions & 0 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ class SmokeTest {
}
}

@Ignore("Disabled for failing with new Compose Awesomebar")
@Test
// Test running on beta/release builds in CI:
// caution when making changes to it, so they don't block the builds
Expand Down Expand Up @@ -583,6 +584,7 @@ class SmokeTest {
}
}

@Ignore("Will need to check other solutions to properly swipe")
@Test
// Swipes the nav bar left/right to switch between tabs
fun swipeToSwitchTabTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ 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.hamcrest.Matchers.not
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.mozilla.fenix.R
Expand Down Expand Up @@ -451,21 +450,21 @@ class BrowserRobot {
fun swipeNavBarRight(tabUrl: String) {
// failing to swipe on Firebase sometimes, so it tries again
try {
navURLBar().perform(ViewActions.swipeRight())
navURLBar().swipeRight(3)
assertTrue(mDevice.findObject(UiSelector().text(tabUrl)).waitUntilGone(waitingTime))
} catch (e: AssertionError) {
navURLBar().perform(ViewActions.swipeRight())
navURLBar().swipeRight(3)
assertTrue(mDevice.findObject(UiSelector().text(tabUrl)).waitUntilGone(waitingTime))
}
}

fun swipeNavBarLeft(tabUrl: String) {
// failing to swipe on Firebase sometimes, so it tries again
try {
navURLBar().perform(ViewActions.swipeLeft())
navURLBar().swipeRight(3)
assertTrue(mDevice.findObject(UiSelector().text(tabUrl)).waitUntilGone(waitingTime))
} catch (e: AssertionError) {
navURLBar().perform(ViewActions.swipeLeft())
navURLBar().swipeRight(3)
assertTrue(mDevice.findObject(UiSelector().text(tabUrl)).waitUntilGone(waitingTime))
}
}
Expand All @@ -489,7 +488,8 @@ class BrowserRobot {
}

fun openNavigationToolbar(interact: NavigationToolbarRobot.() -> Unit): NavigationToolbarRobot.Transition {
mDevice.waitForIdle(waitingTime)
mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))
.waitForExists(waitingTime)
navURLBar().click()

NavigationToolbarRobot().interact()
Expand All @@ -498,6 +498,11 @@ class BrowserRobot {

fun openTabDrawer(interact: TabDrawerRobot.() -> Unit): TabDrawerRobot.Transition {
mDevice.waitForIdle(waitingTime)
mDevice.findObject(
UiSelector()
.resourceId("$packageName:id/counter_box")
.descriptionContains("The tab counter toolbar button.")
).waitForExists(waitingTime)
tabsCounter().click()
mDevice.waitNotNull(
Until.findObject(By.res("$packageName:id/tab_layout")),
Expand All @@ -511,9 +516,7 @@ class BrowserRobot {
fun openTabButtonShortcutsMenu(interact: NavigationToolbarRobot.() -> Unit): NavigationToolbarRobot.Transition {
mDevice.waitForIdle(waitingTime)

tabsCounter().perform(
ViewActions.longClick()
)
tabsCounter().click(LONG_CLICK_DURATION)

NavigationToolbarRobot().interact()
return NavigationToolbarRobot.Transition()
Expand Down Expand Up @@ -563,13 +566,11 @@ fun browserScreen(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
return BrowserRobot.Transition()
}

fun navURLBar() = onView(withId(R.id.toolbar))
fun navURLBar() = mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))

private fun assertNavURLBar() = navURLBar()
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertNavURLBar() = assertTrue(navURLBar().waitForExists(waitingTime))

private fun assertNavURLBarHidden() = navURLBar()
.check(matches(not(isDisplayed())))
private fun assertNavURLBarHidden() = assertTrue(navURLBar().waitUntilGone(waitingTime))

private fun assertEnhancedTrackingProtectionSwitch() {
withText(R.id.trackingProtectionSwitch)
Expand All @@ -593,7 +594,7 @@ private fun assertMenuButton() {
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

private fun tabsCounter() = onView(withId(R.id.counter_box))
private fun tabsCounter() = mDevice.findObject(By.res("$packageName:id/counter_box"))

private fun mediaPlayerPlayButton() =
mDevice.findObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class HomeScreenRobot {
fun openSearch(interact: SearchRobot.() -> Unit): SearchRobot.Transition {
mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))
.waitForExists(waitingTime)
navigationToolbar().perform(click())
navigationToolbar().click()

SearchRobot().interact()
return SearchRobot.Transition()
Expand Down Expand Up @@ -229,7 +229,7 @@ class HomeScreenRobot {
fun openNavigationToolbar(interact: NavigationToolbarRobot.() -> Unit): NavigationToolbarRobot.Transition {
mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))
.waitForExists(waitingTime)
navigationToolbar().perform(click())
navigationToolbar().click()

NavigationToolbarRobot().interact()
return NavigationToolbarRobot.Transition()
Expand Down Expand Up @@ -344,10 +344,9 @@ private fun assertKeyboardVisibility(isExpectedToBeVisible: Boolean) =
.contains("mInputShown=true")
)

private fun navigationToolbar() = onView(withId(R.id.toolbar))
private fun navigationToolbar() = mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))

private fun assertNavigationToolbar() =
navigationToolbar().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertNavigationToolbar() = assertTrue(navigationToolbar().waitForExists(waitingTime))

private fun assertFocusedNavigationToolbar() =
onView(allOf(withHint("Search or enter address")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.IdlingResource
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.pressImeActionButton
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
Expand All @@ -33,8 +30,8 @@ import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.anyOf
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.CoreMatchers.not
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.SessionLoadedIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
Expand All @@ -57,7 +54,7 @@ class NavigationToolbarRobot {
fun verifyCloseReaderViewDetected(visible: Boolean = false) =
assertCloseReaderViewDetected(visible)

fun typeSearchTerm(searchTerm: String) = awesomeBar().perform(typeText(searchTerm))
fun typeSearchTerm(searchTerm: String) = awesomeBar().setText(searchTerm)

fun toggleReaderView() {
mDevice.findObject(
Expand All @@ -77,7 +74,14 @@ class NavigationToolbarRobot {
fun goBackToWebsite(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
openEditURLView()
clearAddressBar().click()
awesomeBar().check((matches(withText(containsString("")))))
assertTrue(
mDevice.findObject(
UiSelector()
.resourceId("$packageName:id/mozac_browser_toolbar_edit_url_view")
.textContains("")
).waitForExists(waitingTime)
)

goBackButton()

BrowserRobot().interact()
Expand All @@ -92,7 +96,8 @@ class NavigationToolbarRobot {

openEditURLView()

awesomeBar().perform(replaceText(url.toString()), pressImeActionButton())
awesomeBar().setText(url.toString())
mDevice.pressEnter()

runWithIdleRes(sessionLoadedIdlingResource) {
onView(
Expand All @@ -114,7 +119,8 @@ class NavigationToolbarRobot {

openEditURLView()

awesomeBar().perform(replaceText(crashUrl), pressImeActionButton())
awesomeBar().setText(crashUrl)
mDevice.pressEnter()

runWithIdleRes(sessionLoadedIdlingResource) {
mDevice.findObject(UiSelector().resourceId("$packageName:id/crash_tab_image"))
Expand Down Expand Up @@ -151,7 +157,8 @@ class NavigationToolbarRobot {
sessionLoadedIdlingResource = SessionLoadedIdlingResource()
mDevice.waitNotNull(Until.findObject(By.res("$packageName:id/toolbar")), waitingTime)
urlBar().click()
awesomeBar().perform(replaceText(url.toString()), pressImeActionButton())
awesomeBar().setText(url.toString())
mDevice.pressEnter()

runWithIdleRes(sessionLoadedIdlingResource) {
onView(ViewMatchers.withResourceName("browserLayout"))
Expand Down Expand Up @@ -286,12 +293,14 @@ private fun assertTabButtonShortcutMenuItems() {
.check(matches(hasDescendant(withText("New tab"))))
}

private fun urlBar() = onView(withId(R.id.toolbar))
private fun awesomeBar() = onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
private fun urlBar() = mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))
private fun awesomeBar() =
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_edit_url_view"))
private fun threeDotButton() = onView(withId(R.id.mozac_browser_toolbar_menu))
private fun tabTrayButton() = onView(withId(R.id.tab_button))
private fun fillLinkButton() = onView(withId(R.id.fill_link_from_clipboard))
private fun clearAddressBar() = onView(withId(R.id.mozac_browser_toolbar_clear_view))
private fun clearAddressBar() =
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_clear_view"))
private fun goBackButton() = mDevice.pressBack()
private fun readerViewToggle() =
onView(withParent(withId(R.id.mozac_browser_toolbar_page_actions)))
Expand Down

0 comments on commit 87e4a25

Please sign in to comment.