@ -6,24 +6,17 @@
package org.mozilla.fenix.ui.robots
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.swipeDown
import androidx.test.espresso.action.ViewActions.swipeUp
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.RootMatchers
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
@ -35,10 +28,9 @@ import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.click
@ -74,6 +66,11 @@ class ThreeDotMenuMainRobot {
}
fun clickShareButton ( ) {
var maxSwipes = 3
while ( ! shareButton ( ) . exists ( ) && maxSwipes != 0 ) {
threeDotMenuRecyclerView ( ) . perform ( swipeUp ( ) )
maxSwipes --
}
shareButton ( ) . click ( )
mDevice . waitNotNull ( Until . findObject ( By . text ( " ALL ACTIONS " ) ) , waitingTime )
}
@ -90,73 +87,41 @@ class ThreeDotMenuMainRobot {
addNewCollectionButton ( ) . click ( )
}
fun clickAddBookmarkButton ( ) {
mDevice . waitNotNull (
Until . findObject ( By . desc ( " Bookmark " ) ) ,
waitingTime
)
addBookmarkButton ( ) . perform (
click (
/ * no - op rollback action for when clicks randomly perform a long click , Espresso should attempt to click again
https : //issuetracker.google.com/issues/37078920#comment9
* /
object : ViewAction {
override fun getDescription ( ) : String {
return " Handle tap->longclick. "
}
override fun getConstraints ( ) : Matcher < View > {
return isAssignableFrom ( View :: class . java )
}
override fun perform ( uiController : UiController ? , view : View ? ) {
// do nothing
}
}
)
)
}
fun verifyCollectionNameTextField ( ) = assertCollectionNameTextField ( )
fun verifyFindInPageButton ( ) = assertFindInPageButton ( )
fun verifyShareScrim ( ) = assertShareScrim ( )
fun verifySendToDeviceTitle ( ) = assertSendToDeviceTitle ( )
fun verifyShareALinkTitle ( ) = assertShareALinkTitle ( )
fun verifyWhatsNewButton ( ) = assertWhatsNewButton ( )
fun verifyAdd FirefoxHome( ) = assertAddToFirefoxHome ( )
fun verifyAddToTopSitesButton ( ) = assertAddToTopSitesButton ( )
fun verifyAddToMobileHome ( ) = assertAddToMobileHome ( )
fun verifyDesktopSite ( ) = assertDesktopSite ( )
fun verifyDownloadsButton ( ) = assertDownloadsButton ( )
fun verifyShareTabsOverlay ( ) = assertShareTabsOverlay ( )
fun verifyThreeDotMainMenuItems ( ) {
if ( FeatureFlags . toolbarMenuFeature ) {
verifyDownloadsButton ( )
verifyHistoryButton ( )
verifyBookmarksButton ( )
verifySettingsButton ( )
verifyDesktopSite ( )
verifySaveCollection ( )
verifyShareButton ( )
verifyForwardButton ( )
verifyRefreshButton ( )
} else {
verifyAddOnsButton ( )
verifyDownloadsButton ( )
verifyHistoryButton ( )
verifyBookmarksButton ( )
verifySyncedTabsButton ( )
verifySettingsButton ( )
verifyFindInPageButton ( )
verifyAddFirefoxHome ( )
verifyAddToMobileHome ( )
verifyDesktopSite ( )
verifySaveCollection ( )
verifyAddBookmarkButton ( )
verifyShareButton ( )
verifyForwardButton ( )
verifyRefreshButton ( )
}
fun verifySignInToSyncButton ( ) = assertSignInToSyncButton ( )
fun verifyNewTabButton ( ) = assertNewTabButton ( )
fun verifyReportSiteIssueButton ( ) = assertReportSiteIssueButton ( )
fun verifyPageThreeDotMainMenuItems ( ) {
verifyNewTabButton ( )
verifyBookmarksButton ( )
verifyAddBookmarkButton ( )
verifyHistoryButton ( )
verifyDownloadsButton ( )
verifyAddOnsButton ( )
verifySignInToSyncButton ( )
threeDotMenuRecyclerView ( ) . perform ( swipeUp ( ) )
verifyFindInPageButton ( )
verifyDesktopSite ( )
threeDotMenuRecyclerView ( ) . perform ( swipeUp ( ) )
verifyReportSiteIssueButton ( )
verifyAddToTopSitesButton ( )
verifyAddToMobileHome ( )
verifySaveCollection ( )
verifySettingsButton ( )
verifyShareButton ( )
verifyForwardButton ( )
verifyRefreshButton ( )
}
private fun assertShareTabsOverlay ( ) {
@ -171,11 +136,12 @@ class ThreeDotMenuMainRobot {
private val mDevice = UiDevice . getInstance ( InstrumentationRegistry . getInstrumentation ( ) )
fun openSettings ( interact : SettingsRobot . ( ) -> Unit ) : SettingsRobot . Transition {
onView ( withId ( R . id . mozac _browser _menu _recyclerView ) ) . perform ( swipeDown ( ) )
onView ( allOf ( withResourceName ( " text " ) , withText ( R . string . browser _menu _settings ) ) )
. check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
. check ( matches ( isCompletelyDisplayed ( ) ) )
. perform ( ViewActions . click ( ) )
var maxSwipes = 3
while ( ! settingsButton ( ) . exists ( ) && maxSwipes != 0 ) {
threeDotMenuRecyclerView ( ) . perform ( swipeUp ( ) )
maxSwipes --
}
settingsButton ( ) . click ( )
SettingsRobot ( ) . interact ( )
return SettingsRobot . Transition ( )
@ -219,7 +185,7 @@ class ThreeDotMenuMainRobot {
}
fun bookmarkPage ( interact : BrowserRobot . ( ) -> Unit ) : BrowserRobot . Transition {
mDevice . waitNotNull ( Until . findObject ( By . desc( " Bookmark " ) ) , waitingTime )
mDevice . waitNotNull ( Until . findObject ( By . text( " Bookmarks " ) ) , waitingTime )
addBookmarkButton ( ) . click ( )
BrowserRobot ( ) . interact ( )
@ -227,10 +193,12 @@ class ThreeDotMenuMainRobot {
}
fun sharePage ( interact : LibrarySubMenusMultipleSelectionToolbarRobot . ( ) -> Unit ) : LibrarySubMenusMultipleSelectionToolbarRobot . Transition {
mDevice . waitNotNull ( Until . findObject ( By . desc ( " Share " ) ) , waitingTime )
var maxSwipes = 3
while ( ! shareButton ( ) . exists ( ) && maxSwipes != 0 ) {
threeDotMenuRecyclerView ( ) . perform ( swipeUp ( ) )
maxSwipes --
}
shareButton ( ) . click ( )
pressBack ( )
LibrarySubMenusMultipleSelectionToolbarRobot ( ) . interact ( )
return LibrarySubMenusMultipleSelectionToolbarRobot . Transition ( )
}
@ -244,7 +212,11 @@ class ThreeDotMenuMainRobot {
}
fun goForward ( interact : BrowserRobot . ( ) -> Unit ) : BrowserRobot . Transition {
mDevice . waitNotNull ( Until . findObject ( By . desc ( " Forward " ) ) , waitingTime )
var maxSwipes = 3
while ( ! forwardButton ( ) . exists ( ) && maxSwipes != 0 ) {
threeDotMenuRecyclerView ( ) . perform ( swipeUp ( ) )
maxSwipes --
}
forwardButton ( ) . click ( )
BrowserRobot ( ) . interact ( )
@ -278,8 +250,12 @@ class ThreeDotMenuMainRobot {
}
fun refreshPage ( interact : BrowserRobot . ( ) -> Unit ) : BrowserRobot . Transition {
// TODO: this is not finding the button correctly
mDevice . waitNotNull ( Until . findObject ( By . desc ( " Refresh " ) ) , waitingTime )
var maxSwipes = 3
while ( ! refreshButton ( ) . exists ( ) && maxSwipes != 0 ) {
threeDotMenuRecyclerView ( ) . perform ( swipeUp ( ) )
maxSwipes --
}
assertRefreshButton ( )
refreshButton ( ) . click ( )
BrowserRobot ( ) . interact ( )
@ -346,6 +322,11 @@ class ThreeDotMenuMainRobot {
}
fun openReaderViewAppearance ( interact : ReaderViewRobot . ( ) -> Unit ) : ReaderViewRobot . Transition {
var maxSwipes = 3
while ( ! readerViewAppearanceToggle ( ) . exists ( ) && maxSwipes != 0 ) {
threeDotMenuRecyclerView ( ) . perform ( swipeUp ( ) )
maxSwipes --
}
readerViewAppearanceToggle ( ) . click ( )
ReaderViewRobot ( ) . interact ( )
@ -353,7 +334,7 @@ class ThreeDotMenuMainRobot {
}
fun addToFirefoxHome ( interact : BrowserRobot . ( ) -> Unit ) : BrowserRobot . Transition {
addTo FirefoxHome Button( ) . click ( )
addTo TopSites Button( ) . click ( )
BrowserRobot ( ) . interact ( )
return BrowserRobot . Transition ( )
@ -368,6 +349,11 @@ class ThreeDotMenuMainRobot {
}
fun clickInstall ( interact : AddToHomeScreenRobot . ( ) -> Unit ) : AddToHomeScreenRobot . Transition {
var maxSwipes = 3
while ( !in stallPWAButton ( ) . exists ( ) && maxSwipes != 0 ) {
threeDotMenuRecyclerView ( ) . perform ( swipeUp ( ) )
maxSwipes --
}
installPWAButton ( ) . click ( )
AddToHomeScreenRobot ( ) . interact ( )
@ -407,15 +393,15 @@ class ThreeDotMenuMainRobot {
}
}
}
private fun threeDotMenuRecyclerView ( ) =
onView ( withId ( R . id . mozac _browser _menu _recyclerView ) )
private fun threeDotMenuRecyclerViewExists ( ) {
onView( withId ( R . id . mozac _browser _menu _recyclerView ) ) . check ( matches ( isDisplayed ( ) ) )
threeDotMenuRecyclerView( ) . check ( matches ( isDisplayed ( ) ) )
}
private fun settingsButton ( ) = onView ( allOf ( withResourceName ( " text " ) , withText ( R . string . browser _menu _settings ) ) )
private fun assertSettingsButton ( ) = settingsButton ( )
. check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
. check ( matches ( isCompletelyDisplayed ( ) ) )
private fun settingsButton ( ) = mDevice . findObject ( UiSelector ( ) . text ( " Settings " ) )
private fun assertSettingsButton ( ) = assertTrue ( settingsButton ( ) . waitForExists ( waitingTime ) )
private fun addOnsButton ( ) = onView ( allOf ( withText ( " Add-ons " ) ) )
private fun assertAddOnsButton ( ) {
@ -435,27 +421,28 @@ private fun syncedTabsButton() = onView(allOf(withText(R.string.library_synced_t
private fun assertSyncedTabsButton ( ) = syncedTabsButton ( )
. check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
private fun signInToSyncButton ( ) = onView ( withText ( " Sign in to sync " ) )
private fun assertSignInToSyncButton ( ) = signInToSyncButton ( ) . check ( matches ( isDisplayed ( ) ) )
private fun helpButton ( ) = onView ( allOf ( withText ( R . string . browser _menu _help ) ) )
private fun assertHelpButton ( ) = helpButton ( )
. check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
private fun forwardButton ( ) = onView ( ViewMatchers . withContentDescription ( " Forward " ) )
private fun assertForwardButton ( ) = forwardButton ( )
. check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
private fun forwardButton ( ) = mDevice . findObject ( UiSelector ( ) . description ( " Forward " ) )
private fun assertForwardButton ( ) = assertTrue ( forwardButton ( ) . waitForExists ( waitingTime ) )
private fun addBookmarkButton ( ) = onView ( ViewMatchers . withContentDescription ( " Bookmark " ) )
private fun addBookmarkButton ( ) = onView ( allOf ( withId ( R . id . checkbox ) , withText ( " Add " ) ) )
private fun assertAddBookmarkButton ( ) {
onView ( withId ( R . id . mozac _browser _menu _menuView ) ) . perform ( swipeUp ( ) )
addBookmarkButton ( ) . check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
}
private fun editBookmarkButton ( ) = onView ( ViewMatchers . withContentDescription ( " Edit bookmark " ) )
private fun editBookmarkButton ( ) = onView ( withText ( " Edit " ) )
private fun assertEditBookmarkButton ( ) = editBookmarkButton ( )
. check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
private fun refreshButton ( ) = onView ( ViewMatchers . withContentDescription ( " Refresh " ) )
private fun assertRefreshButton ( ) = refreshButton ( )
. check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
private fun refreshButton ( ) = mDevice . findObject ( UiSelector ( ) . description ( " Refresh " ) )
private fun assertRefreshButton ( ) = assertTrue ( refreshButton ( ) . waitForExists ( waitingTime ) )
private fun stopLoadingButton ( ) = onView ( ViewMatchers . withContentDescription ( " Stop " ) )
@ -467,9 +454,8 @@ private fun shareTabButton() = onView(allOf(withText("Share all tabs"))).inRoot(
private fun assertShareTabButton ( ) = shareTabButton ( )
. check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
private fun shareButton ( ) = onView ( ViewMatchers . withContentDescription ( " Share " ) )
private fun assertShareButton ( ) = shareButton ( )
. check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
private fun shareButton ( ) = mDevice . findObject ( UiSelector ( ) . description ( " Share " ) )
private fun assertShareButton ( ) = assertTrue ( shareButton ( ) . waitForExists ( waitingTime ) )
private fun browserViewSaveCollectionButton ( ) = onView (
allOf (
@ -497,6 +483,7 @@ private fun assertCollectionNameTextField() = collectionNameTextField()
. check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
private fun reportSiteIssueButton ( ) = onView ( withText ( " Report Site Issue… " ) )
private fun assertReportSiteIssueButton ( ) = reportSiteIssueButton ( ) . check ( matches ( isDisplayed ( ) ) )
private fun findInPageButton ( ) = onView ( allOf ( withText ( " Find in page " ) ) )
@ -531,17 +518,29 @@ private fun assertWhatsNewButton() = whatsNewButton()
private fun addToHomeScreenButton ( ) = onView ( withText ( " Add to Home screen " ) )
private fun readerViewAppearanceToggle ( ) =
onView ( allOf ( withText ( R . string . browser _menu _read _appearance ) ) )
private fun assertReaderViewAppearanceButton ( visible : Boolean ) = readerViewAppearanceToggle ( )
. check (
if ( visible ) matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) else ViewAssertions . doesNotExist ( )
)
mDevice . findObject ( UiSelector ( ) . text ( " Customize reader view " ) )
private fun assertReaderViewAppearanceButton ( visible : Boolean ) {
var maxSwipes = 3
if ( visible ) {
while ( ! readerViewAppearanceToggle ( ) . exists ( ) && maxSwipes != 0 ) {
threeDotMenuRecyclerView ( ) . perform ( swipeUp ( ) )
maxSwipes --
}
assertTrue ( readerViewAppearanceToggle ( ) . exists ( ) )
} else {
while ( ! readerViewAppearanceToggle ( ) . exists ( ) && maxSwipes != 0 ) {
threeDotMenuRecyclerView ( ) . perform ( swipeUp ( ) )
maxSwipes --
}
assertFalse ( readerViewAppearanceToggle ( ) . exists ( ) )
}
}
private fun addToFirefoxHomeButton ( ) =
private fun addTo TopSites Button( ) =
onView ( allOf ( withText ( R . string . browser _menu _add _to _top _sites ) ) )
private fun assertAddToFirefoxHome ( ) {
private fun assertAddTo TopSitesButton ( ) {
onView ( withId ( R . id . mozac _browser _menu _recyclerView ) )
. perform (
RecyclerViewActions . scrollTo < RecyclerView . ViewHolder > (
@ -562,7 +561,7 @@ private fun assertAddToMobileHome() {
) . check ( matches ( withEffectiveVisibility ( Visibility . VISIBLE ) ) )
}
private fun installPWAButton ( ) = onView( allOf ( withId ( R . id . highlight _text ) , withT ext( " Install " ) ) )
private fun installPWAButton ( ) = mDevice. findObject ( UiSelector ( ) . t ext( " Install " ) )
private fun desktopSiteButton ( ) =
onView ( allOf ( withText ( R . string . browser _menu _desktop _site ) ) )
@ -610,3 +609,5 @@ private fun assertShareAllTabsButton() {
. check (
matches ( isDisplayed ( ) ) )
}
private fun assertNewTabButton ( ) = onView ( withText ( " New tab " ) ) . check ( matches ( isDisplayed ( ) ) )