@ -31,7 +31,6 @@ import androidx.test.uiautomator.By.textContains
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.not
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants
@ -58,23 +57,29 @@ import org.mozilla.fenix.tabstray.TabsTrayTestTag
* Implementation of Robot Pattern for the URL toolbar .
* /
class NavigationToolbarRobot {
fun verifyUrl ( url : String ) =
fun verifyUrl ( url : String ) {
Log . i ( TAG , " verifyUrl: Trying to verify toolbar text matches $url " )
onView ( withId ( R . id . mozac _browser _toolbar _url _view ) ) . check ( matches ( withText ( url ) ) )
Log . i ( TAG , " verifyUrl: Verified toolbar text matches $url " )
}
fun verifyTabButtonShortcutMenuItems ( ) {
Log . i ( TAG , " verifyTabButtonShortcutMenuItems: Trying to verify tab counter shortcut options " )
onView ( withId ( R . id . mozac _browser _menu _recyclerView ) )
. check ( matches ( hasDescendant ( withText ( " Close tab " ) ) ) )
. check ( matches ( hasDescendant ( withText ( " New private tab " ) ) ) )
. check ( matches ( hasDescendant ( withText ( " New tab " ) ) ) )
Log . i ( TAG , " verifyTabButtonShortcutMenuItems: Verified tab counter shortcut options " )
}
fun verifyReaderViewDetected ( visible : Boolean = false ) {
Log . i ( TAG , " verifyReaderViewDetected: Waiting for $waitingTime ms for reader view button to exist " )
mDevice . findObject (
UiSelector ( )
. description ( " Reader view " ) ,
)
. waitForExists ( waitingTime )
) . waitForExists ( waitingTime )
Log . i ( TAG , " verifyReaderViewDetected: Waited for $waitingTime ms for reader view button to exist " )
Log . i ( TAG , " verifyReaderViewDetected: Trying to verify that the reader view button is visible " )
onView (
allOf (
withParent ( withId ( R . id . mozac _browser _toolbar _page _actions ) ) ,
@ -87,16 +92,20 @@ class NavigationToolbarRobot {
ViewAssertions . doesNotExist ( )
} ,
)
Log . i ( TAG , " verifyReaderViewDetected: Verified that the reader view button is visible " )
}
fun toggleReaderView ( ) {
Log . i ( TAG , " toggleReaderView: Waiting for $waitingTime ms for reader view button to exist " )
mDevice . findObject (
UiSelector ( )
. resourceId ( " $packageName :id/mozac_browser_toolbar_page_actions " ) ,
)
. waitForExists ( waitingTime )
Log . i ( TAG , " toggleReaderView: Waited for $waitingTime ms for reader view button to exist " )
Log . i ( TAG , " toggleReaderView: Trying to click the reader view button " )
readerViewToggle ( ) . click ( )
Log . i ( TAG , " toggleReaderView: Clicked the reader view button " )
}
fun verifyClipboardSuggestionsAreDisplayed ( link : String = " " , shouldBeDisplayed : Boolean ) =
@ -109,28 +118,42 @@ class NavigationToolbarRobot {
exists = shouldBeDisplayed ,
)
fun longClickEditModeToolbar ( ) =
mDevice . findObject ( By . res ( " $packageName :id/mozac_browser_toolbar_edit_url_view " ) ) . click ( LONG _CLICK _DURATION )
fun longClickEditModeToolbar ( ) {
Log . i ( TAG , " longClickEditModeToolbar: Trying to long click the edit mode toolbar " )
mDevice . findObject ( By . res ( " $packageName :id/mozac_browser_toolbar_edit_url_view " ) )
. click ( LONG _CLICK _DURATION )
Log . i ( TAG , " longClickEditModeToolbar: Long clicked the edit mode toolbar " )
}
fun clickContextMenuItem ( item : String ) {
mDevice . waitNotNull (
Until . findObject ( By . text ( item ) ) ,
waitingTime ,
)
Log . i ( TAG , " clickContextMenuItem: Trying click context menu item: $item " )
mDevice . findObject ( By . text ( item ) ) . click ( )
Log . i ( TAG , " clickContextMenuItem: Clicked context menu item: $item " )
}
fun clickClearToolbarButton ( ) = clearAddressBarButton ( ) . click ( )
fun clickClearToolbarButton ( ) {
Log . i ( TAG , " clickClearToolbarButton: Trying click the clear address button " )
clearAddressBarButton ( ) . click ( )
Log . i ( TAG , " clickClearToolbarButton: Clicked the clear address button " )
}
fun verifyToolbarIsEmpty ( ) =
itemWithResIdContainingText (
" $packageName :id/mozac_browser_toolbar_edit_url_view " ,
getStringResource ( R . string . search _hint ) ,
assertUIObjectExists (
itemWithResIdContainingText (
" $packageName :id/mozac_browser_toolbar_edit_url_view " ,
getStringResource ( R . string . search _hint ) ,
) ,
)
// New unified search UI selector
fun verifySearchBarPlaceholder ( text : String ) {
Log . i ( TAG , " verifySearchBarPlaceholder: Waiting for $waitingTime ms for the toolbar to exist " )
urlBar ( ) . waitForExists ( waitingTime )
Log . i ( TAG , " verifySearchBarPlaceholder: Waited for $waitingTime ms for the toolbar to exist " )
assertItemTextEquals ( urlBar ( ) , expectedText = text )
}
@ -156,19 +179,21 @@ class NavigationToolbarRobot {
sessionLoadedIdlingResource = SessionLoadedIdlingResource ( )
openEditURLView ( )
Log . i ( TAG , " enterURLAndEnterToBrowser: Opened edit mode URL view " )
Log . i ( TAG , " enterURLAndEnterToBrowser: Trying to set toolbar text to: $url " )
awesomeBar ( ) . setText ( url . toString ( ) )
Log . i ( TAG , " enterURLAndEnterToBrowser: Set toolbar text to: $url " )
Log . i ( TAG , " enterURLAndEnterToBrowser: Toolbar text was set to: $url " )
Log . i ( TAG , " enterURLAndEnterToBrowser: Trying to press device enter button " )
mDevice . pressEnter ( )
Log . i ( TAG , " enterURLAndEnterToBrowser: Clicked enter on keyboard, submitted query " )
Log . i ( TAG , " enterURLAndEnterToBrowser: Pressed device enter button " )
runWithIdleRes ( sessionLoadedIdlingResource ) {
Log . i ( TAG , " enterURLAndEnterToBrowser: Trying to assert that home screen layout or download button or the total cookie protection contextual hint exist " )
assertTrue (
itemWithResId ( " $packageName :id/browserLayout " ) . waitForExists ( waitingTime ) ||
itemWithResId ( " $packageName :id/download_button " ) . waitForExists ( waitingTime ) ||
itemWithResId ( " cfr.dismiss " ) . waitForExists ( waitingTime ) ,
)
Log . i ( TAG , " enterURLAndEnterToBrowser: Asserted that home screen layout or download button or the total cookie protection contextual hint exist " )
}
BrowserRobot ( ) . interact ( )
@ -180,9 +205,12 @@ class NavigationToolbarRobot {
interact : BrowserRobot . ( ) -> Unit ,
) : BrowserRobot . Transition {
openEditURLView ( )
Log . i ( TAG , " enterURLAndEnterToBrowserForTCPCFR: Trying to set toolbar text to: $url " )
awesomeBar ( ) . setText ( url . toString ( ) )
Log . i ( TAG , " enterURLAndEnterToBrowserForTCPCFR: Toolbar text was set to: $url " )
Log . i ( TAG , " enterURLAndEnterToBrowserForTCPCFR: Trying to press device enter button " )
mDevice . pressEnter ( )
Log . i ( TAG , " enterURLAndEnterToBrowserForTCPCFR: Pressed device enter button " )
BrowserRobot ( ) . interact ( )
return BrowserRobot . Transition ( )
@ -194,12 +222,17 @@ class NavigationToolbarRobot {
sessionLoadedIdlingResource = SessionLoadedIdlingResource ( )
openEditURLView ( )
Log . i ( TAG , " openTabCrashReporter: Trying to set toolbar text to: $crashUrl " )
awesomeBar ( ) . setText ( crashUrl )
Log . i ( TAG , " openTabCrashReporter: Toolbar text was set to: $crashUrl " )
Log . i ( TAG , " openTabCrashReporter: Trying to press device enter button " )
mDevice . pressEnter ( )
Log . i ( TAG , " openTabCrashReporter: Pressed device enter button " )
runWithIdleRes ( sessionLoadedIdlingResource ) {
Log . i ( TAG , " openTabCrashReporter: Trying to find the tab crasher image " )
mDevice . findObject ( UiSelector ( ) . resourceId ( " $packageName :id/crash_tab_image " ) )
Log . i ( TAG , " openTabCrashReporter: Found the tab crasher image " )
}
BrowserRobot ( ) . interact ( )
@ -208,15 +241,21 @@ class NavigationToolbarRobot {
fun openThreeDotMenu ( interact : ThreeDotMenuMainRobot . ( ) -> Unit ) : ThreeDotMenuMainRobot . Transition {
mDevice . waitNotNull ( Until . findObject ( By . res ( " $packageName :id/mozac_browser_toolbar_menu " ) ) , waitingTime )
Log . i ( TAG , " openThreeDotMenu: Trying to click the main menu button " )
threeDotButton ( ) . click ( )
Log . i ( TAG , " openThreeDotMenu: Clicked the main menu button " )
ThreeDotMenuMainRobot ( ) . interact ( )
return ThreeDotMenuMainRobot . Transition ( )
}
fun openTabTray ( interact : TabDrawerRobot . ( ) -> Unit ) : TabDrawerRobot . Transition {
Log . i ( TAG , " openTabTray: Waiting for device to be idle for $waitingTime ms " )
mDevice . waitForIdle ( waitingTime )
Log . i ( TAG , " openTabTray: Waited for device to be idle for $waitingTime ms " )
Log . i ( TAG , " openTabTray: Trying to click the tabs tray button " )
tabTrayButton ( ) . click ( )
Log . i ( TAG , " openTabTray: Clicked the tabs tray button " )
mDevice . waitNotNull (
Until . findObject ( By . res ( " $packageName :id/tab_layout " ) ) ,
waitingTime ,
@ -229,6 +268,7 @@ class NavigationToolbarRobot {
fun openComposeTabDrawer ( composeTestRule : HomeActivityComposeTestRule , interact : ComposeTabDrawerRobot . ( ) -> Unit ) : ComposeTabDrawerRobot . Transition {
for ( i in 1. . Constants . RETRY _COUNT ) {
try {
Log . i ( TAG , " openComposeTabDrawer: Started try # $i " )
mDevice . waitForObjects (
mDevice . findObject (
UiSelector ( )
@ -236,30 +276,40 @@ class NavigationToolbarRobot {
) ,
waitingTime ,
)
Log . i ( TAG , " openComposeTabDrawer: Trying to click the tabs tray button " )
tabTrayButton ( ) . click ( )
Log . i ( TAG , " openComposeTabDrawer: Clicked the tabs tray button " )
Log . i ( TAG , " openComposeTabDrawer: Trying to verify that the tabs tray exists " )
composeTestRule . onNodeWithTag ( TabsTrayTestTag . tabsTray ) . assertExists ( )
Log . i ( TAG , " openComposeTabDrawer: Verified that the tabs tray exists " )
break
} catch ( e : AssertionError ) {
Log . i ( TAG , " openComposeTabDrawer: AssertionError caught, executing fallback methods " )
if ( i == Constants . RETRY _COUNT ) {
throw e
} else {
Log . i ( TAG , " openComposeTabDrawer: Waiting for device to be idle " )
mDevice . waitForIdle ( )
Log . i ( TAG , " openComposeTabDrawer: Waited for device to be idle " )
}
}
}
Log . i ( TAG , " openComposeTabDrawer: Trying to verify the tabs tray new tab FAB button exists " )
composeTestRule . onNodeWithTag ( TabsTrayTestTag . fab ) . assertExists ( )
Log . i ( TAG , " openComposeTabDrawer: Verified the tabs tray new tab FAB button exists " )
ComposeTabDrawerRobot ( composeTestRule ) . interact ( )
return ComposeTabDrawerRobot . Transition ( composeTestRule )
}
fun visitLinkFromClipboard ( interact : BrowserRobot . ( ) -> Unit ) : BrowserRobot . Transition {
Log . i ( TAG , " visitLinkFromClipboard: Waiting for $waitingTimeShort ms for clear address button to exist " )
if ( clearAddressBarButton ( ) . waitForExists ( waitingTimeShort ) ) {
Log . i ( TAG , " visitLinkFromClipboard: Waited for $waitingTimeShort ms for clear address button to exist " )
Log . i ( TAG , " visitLinkFromClipboard: Trying to click the clear address button " )
clearAddressBarButton ( ) . click ( )
Log . i ( TAG , " visitLinkFromClipboard: Clicked the clear address button " )
}
mDevice . waitNotNull (
@ -275,26 +325,33 @@ class NavigationToolbarRobot {
waitingTime ,
)
}
Log . i ( TAG , " visitLinkFromClipboard: Trying to click the fill link from clipboard button " )
fillLinkButton ( ) . click ( )
Log . i ( TAG , " visitLinkFromClipboard: Clicked the fill link from clipboard button " )
BrowserRobot ( ) . interact ( )
return BrowserRobot . Transition ( )
}
fun goBackToHomeScreen ( interact : HomeScreenRobot . ( ) -> Unit ) : HomeScreenRobot . Transition {
Log . i ( TAG , " goBackToHomeScreen: Trying to click the device back button " )
mDevice . pressBack ( )
Log . i ( TAG , " goBackToHomeScreen: Clicked the device back button " )
Log . i ( TAG , " goBackToHomeScreen: Waiting for $waitingTimeShort ms for $packageName window to be updated " )
mDevice . waitForWindowUpdate ( packageName , waitingTimeShort )
Log . i ( TAG , " goBackToHomeScreen: Waited for $waitingTimeShort ms for $packageName window to be updated " )
HomeScreenRobot ( ) . interact ( )
return HomeScreenRobot . Transition ( )
}
fun goBackToBrowserScreen ( interact : BrowserRobot . ( ) -> Unit ) : BrowserRobot . Transition {
Log . i ( TAG , " goBackToBrowserScreen: Trying to click the device back button " )
mDevice . pressBack ( )
Log . i ( TAG , " goBackToBrowserScreen: Dismiss awesome bar using device back button " )
Log . i ( TAG , " goBackToBrowserScreen: Clicked the device back button " )
Log . i ( TAG , " goBackToBrowserScreen: Waiting for $waitingTimeShort ms for $packageName window to be updated " )
mDevice . waitForWindowUpdate ( packageName , waitingTimeShort )
Log . i ( TAG , " goBackToBrowserScreen: Waited $waitingTimeShort for window update" )
Log . i ( TAG , " goBackToBrowserScreen: Waited for $waitingTimeShort ms for $packageName window to be updated " )
BrowserRobot ( ) . interact ( )
return BrowserRobot . Transition ( )
@ -302,16 +359,19 @@ class NavigationToolbarRobot {
fun openTabButtonShortcutsMenu ( interact : NavigationToolbarRobot . ( ) -> Unit ) : Transition {
mDevice . waitNotNull ( Until . findObject ( By . res ( " $packageName :id/counter_root " ) ) )
Log . i ( TAG , " openTabButtonShortcutsMenu: Trying to long click the tab counter button " )
tabsCounter ( ) . perform ( longClick ( ) )
Log . i ( TAG , " Tabs counter long-click successful. " )
Log . i ( TAG , " openTabButtonShortcutsMenu: Long clicked the tab counter button " )
NavigationToolbarRobot ( ) . interact ( )
return Transition ( )
}
fun closeTabFromShortcutsMenu ( interact : NavigationToolbarRobot . ( ) -> Unit ) : Transition {
Log . i ( TAG , " closeTabFromShortcutsMenu: Waiting for device to be idle for $waitingTime ms " )
mDevice . waitForIdle ( waitingTime )
Log . i ( TAG , " closeTabFromShortcutsMenu: Waited for device to be idle for $waitingTime ms " )
Log . i ( TAG , " closeTabFromShortcutsMenu: Trying to click the \" Close tab \" button " )
onView ( withId ( R . id . mozac _browser _menu _recyclerView ) )
. perform (
RecyclerViewActions . actionOnItem < RecyclerView . ViewHolder > (
@ -321,15 +381,17 @@ class NavigationToolbarRobot {
ViewActions . click ( ) ,
) ,
)
Log . i ( TAG , " Clicked the tab shortcut Close tab button. " )
Log . i ( TAG , " closeTabFromShortcutsMenu: Clicked the \" Close tab \" button " )
NavigationToolbarRobot ( ) . interact ( )
return Transition ( )
}
fun openNewTabFromShortcutsMenu ( interact : SearchRobot . ( ) -> Unit ) : SearchRobot . Transition {
Log . i ( TAG , " openNewTabFromShortcutsMenu: Waiting for device to be idle for $waitingTime ms " )
mDevice . waitForIdle ( waitingTime )
Log . i ( TAG , " Looking for tab shortcut New tab button. " )
Log . i ( TAG , " openNewTabFromShortcutsMenu: Waited for device to be idle for $waitingTime ms " )
Log . i ( TAG , " openNewTabFromShortcutsMenu: Trying to click the \" New tab \" button " )
onView ( withId ( R . id . mozac _browser _menu _recyclerView ) )
. perform (
RecyclerViewActions . actionOnItem < RecyclerView . ViewHolder > (
@ -339,15 +401,17 @@ class NavigationToolbarRobot {
ViewActions . click ( ) ,
) ,
)
Log . i ( TAG , " Clicked the tab shortcut New tab button. " )
Log . i ( TAG , " openNewTabFromShortcutsMenu: Clicked the \" New tab \" button " )
SearchRobot ( ) . interact ( )
return SearchRobot . Transition ( )
}
fun openNewPrivateTabFromShortcutsMenu ( interact : SearchRobot . ( ) -> Unit ) : SearchRobot . Transition {
Log . i ( TAG , " openNewPrivateTabFromShortcutsMenu: Waiting for device to be idle for $waitingTime ms " )
mDevice . waitForIdle ( waitingTime )
Log . i ( TAG , " Looking for tab shortcut New private tab button. " )
Log . i ( TAG , " openNewPrivateTabFromShortcutsMenu: Waited for device to be idle for $waitingTime ms " )
Log . i ( TAG , " openNewPrivateTabFromShortcutsMenu: Trying to click the \" New private tab \" button " )
onView ( withId ( R . id . mozac _browser _menu _recyclerView ) )
. perform (
RecyclerViewActions . actionOnItem < RecyclerView . ViewHolder > (
@ -357,26 +421,33 @@ class NavigationToolbarRobot {
ViewActions . click ( ) ,
) ,
)
Log . i ( TAG , " Clicked the tab shortcut New private tab button. " )
Log . i ( TAG , " openNewPrivateTabFromShortcutsMenu: Clicked the \" New private tab \" button " )
SearchRobot ( ) . interact ( )
return SearchRobot . Transition ( )
}
fun clickUrlbar ( interact : SearchRobot . ( ) -> Unit ) : SearchRobot . Transition {
Log . i ( TAG , " clickUrlbar: Trying to click the toolbar " )
urlBar ( ) . click ( )
Log . i ( TAG , " clickUrlbar: Clicked the toolbar " )
Log . i ( TAG , " clickUrlbar: Waiting for $waitingTime ms for the edit mode toolbar to exist " )
mDevice . findObject (
UiSelector ( ) . resourceId ( " $packageName :id/mozac_browser_toolbar_edit_url_view " ) ,
) . waitForExists ( waitingTime )
Log . i ( TAG , " clickUrlbar: Waited for $waitingTime ms for the edit mode toolbar to exist " )
SearchRobot ( ) . interact ( )
return SearchRobot . Transition ( )
}
fun clickSearchSelectorButton ( interact : SearchRobot . ( ) -> Unit ) : SearchRobot . Transition {
Log . i ( TAG , " clickSearchSelectorButton: Waiting for $waitingTime ms for the search selector button to exist " )
searchSelectorButton ( ) . waitForExists ( waitingTime )
Log . i ( TAG , " clickSearchSelectorButton: Waited for $waitingTime ms for the search selector button to exist " )
Log . i ( TAG , " clickSearchSelectorButton: Trying to click the search selector button " )
searchSelectorButton ( ) . click ( )
Log . i ( TAG , " clickSearchSelectorButton: Clicked the search selector button " )
SearchRobot ( ) . interact ( )
return SearchRobot . Transition ( )
@ -390,11 +461,15 @@ fun navigationToolbar(interact: NavigationToolbarRobot.() -> Unit): NavigationTo
}
fun openEditURLView ( ) {
Log . i ( TAG , " openEditURLView: Waiting for $waitingTime ms for the toolbar to exist " )
urlBar ( ) . waitForExists ( waitingTime )
Log . i ( TAG , " openEditURLView: Waited for $waitingTime ms for the toolbar to exist " )
Log . i ( TAG , " openEditURLView: Trying to click the toolbar " )
urlBar ( ) . click ( )
Log . i ( TAG , " openEditURLView: URL bar clicked. " )
Log . i ( TAG , " openEditURLView: Clicked the toolbar " )
Log . i ( TAG , " openEditURLView: Waiting for $waitingTime ms for the edit mode toolbar to exist " )
itemWithResId ( " $packageName :id/mozac_browser_toolbar_edit_url_view " ) . waitForExists ( waitingTime )
Log . i ( TAG , " openEditURLView: Edit URL bar displayed. " )
Log . i ( TAG , " openEditURLView: Waited for $waitingTime ms for the edit mode toolbar to exist " )
}
private fun urlBar ( ) = mDevice . findObject ( UiSelector ( ) . resourceId ( " $packageName :id/toolbar " ) )