Bug 1863319 - Replaced Browser Robot class variables with functions, to prevent unnecessary logging.

fenix/121.0
oana.horvath 7 months ago committed by mergify[bot]
parent 75f6a6c66b
commit 1fd30414f5

@ -15,6 +15,7 @@ import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.PickerActions
@ -70,7 +71,7 @@ class BrowserRobot {
private lateinit var sessionLoadedIdlingResource: SessionLoadedIdlingResource
fun waitForPageToLoad() {
progressBar.waitUntilGone(waitingTime)
progressBar().waitUntilGone(waitingTime)
Log.i(TAG, "waitForPageToLoad: The page was loaded, the progress bar is gone")
}
@ -109,7 +110,6 @@ class BrowserRobot {
* document.querySelector('#testContent').innerText == expectedText
*
*/
fun verifyPageContent(expectedText: String) {
sessionLoadedIdlingResource = SessionLoadedIdlingResource()
@ -190,10 +190,10 @@ class BrowserRobot {
// If the link is not re-directing to an external app the "Open link in external app" option is not available
assertItemContainingTextExists(
contextMenuLinkUrl(containsURL.toString()),
contextMenuOpenLinkInNewTab,
contextMenuOpenLinkInPrivateTab,
contextMenuCopyLink,
contextMenuShareLink,
contextMenuOpenLinkInNewTab(),
contextMenuOpenLinkInPrivateTab(),
contextMenuCopyLink(),
contextMenuShareLink(),
)
}
@ -202,12 +202,12 @@ class BrowserRobot {
// If the link is not directing to another local asset the "Download link" option is not available
assertItemContainingTextExists(
contextMenuLinkUrl(containsURL),
contextMenuOpenLinkInNewTab,
contextMenuOpenLinkInPrivateTab,
contextMenuCopyLink,
contextMenuDownloadLink,
contextMenuShareLink,
contextMenuOpenInExternalApp,
contextMenuOpenLinkInNewTab(),
contextMenuOpenLinkInPrivateTab(),
contextMenuCopyLink(),
contextMenuDownloadLink(),
contextMenuShareLink(),
contextMenuOpenInExternalApp(),
)
}
@ -216,11 +216,11 @@ class BrowserRobot {
// If the link is not re-directing to an external app the "Open link in external app" option is not available
assertItemContainingTextExists(
contextMenuLinkUrl(containsURL.toString()),
contextMenuOpenLinkInNewTab,
contextMenuOpenLinkInPrivateTab,
contextMenuCopyLink,
contextMenuDownloadLink,
contextMenuShareLink,
contextMenuOpenLinkInNewTab(),
contextMenuOpenLinkInPrivateTab(),
contextMenuCopyLink(),
contextMenuDownloadLink(),
contextMenuShareLink(),
)
}
@ -382,9 +382,9 @@ class BrowserRobot {
fun clickSuggestedLoginsButton() {
for (i in 1..RETRY_COUNT) {
try {
mDevice.waitForObjects(suggestedLogins)
suggestedLogins.click()
mDevice.waitForObjects(suggestedLogins)
mDevice.waitForObjects(suggestedLogins())
suggestedLogins().click()
mDevice.waitForObjects(suggestedLogins())
break
} catch (e: UiObjectNotFoundException) {
if (i == RETRY_COUNT) {
@ -411,8 +411,8 @@ class BrowserRobot {
fun clickSelectAddressButton() {
for (i in 1..RETRY_COUNT) {
try {
assertTrue(selectAddressButton.waitForExists(waitingTime))
selectAddressButton.clickAndWaitForNewWindow(waitingTime)
assertTrue(selectAddressButton().waitForExists(waitingTime))
selectAddressButton().clickAndWaitForNewWindow(waitingTime)
break
} catch (e: AssertionError) {
@ -428,7 +428,7 @@ class BrowserRobot {
}
}
fun verifySelectAddressButtonExists(exists: Boolean) = assertItemWithResIdExists(selectAddressButton, exists = exists)
fun verifySelectAddressButtonExists(exists: Boolean) = assertItemWithResIdExists(selectAddressButton(), exists = exists)
fun changeCreditCardExpiryDate(expiryDate: String) =
itemWithResId("expiryMonthAndYear").setText(expiryDate)
@ -461,7 +461,7 @@ class BrowserRobot {
)
fun verifySelectCreditCardPromptExists(exists: Boolean) =
assertItemWithResIdExists(selectCreditCardButton, exists = exists)
assertItemWithResIdExists(selectCreditCardButton(), exists = exists)
fun verifyCreditCardSuggestion(vararg creditCardNumbers: String) {
for (creditCardNumber in creditCardNumbers) {
@ -622,7 +622,7 @@ class BrowserRobot {
}
}
fun selectTime(hour: Int, minute: Int) =
fun selectTime(hour: Int, minute: Int): ViewInteraction =
onView(
isAssignableFrom(TimePicker::class.java),
).inRoot(
@ -630,6 +630,11 @@ class BrowserRobot {
).perform(PickerActions.setTime(hour, minute))
fun verifySelectedDate() {
val currentDate = LocalDate.now()
val currentDay = currentDate.dayOfMonth
val currentMonth = currentDate.month
val currentYear = currentDate.year
for (i in 1..RETRY_COUNT) {
try {
assertTrue(
@ -659,6 +664,8 @@ class BrowserRobot {
}
fun verifyNoDateIsSelected() {
val currentDate = LocalDate.now()
assertFalse(
mDevice.findObject(
UiSelector()
@ -782,7 +789,7 @@ class BrowserRobot {
fun verifyCookieBannerExists(exists: Boolean) {
for (i in 1..RETRY_COUNT) {
try {
assertItemWithResIdExists(cookieBanner, exists = exists)
assertItemWithResIdExists(cookieBanner(), exists = exists)
break
} catch (e: AssertionError) {
if (i == RETRY_COUNT) {
@ -796,7 +803,7 @@ class BrowserRobot {
}
}
}
assertItemWithResIdExists(cookieBanner, exists = exists)
assertItemWithResIdExists(cookieBanner(), exists = exists)
}
fun verifyOpenLinkInAnotherAppPrompt() {
@ -893,7 +900,7 @@ class BrowserRobot {
browserScreen {
}.openThreeDotMenu {
}.refreshPage {
progressBar.waitUntilGone(waitingTimeLong)
waitForPageToLoad()
}
}
}
@ -1294,23 +1301,24 @@ class BrowserRobot {
}
fun clickSurveyButton(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
surveyButton.waitForExists(waitingTime)
surveyButton.click()
surveyButton().waitForExists(waitingTime)
surveyButton().click()
BrowserRobot().interact()
return Transition()
}
fun clickNoThanksSurveyButton(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
surveyNoThanksButton.waitForExists(waitingTime)
surveyNoThanksButton.click()
surveyNoThanksButton().waitForExists(waitingTime)
surveyNoThanksButton().click()
BrowserRobot().interact()
return Transition()
}
fun clickHomeScreenSurveyCloseButton(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
homescreenSurveyCloseButton.waitForExists(waitingTime)
homescreenSurveyCloseButton.click()
homescreenSurveyCloseButton().waitForExists(waitingTime)
homescreenSurveyCloseButton().click()
BrowserRobot().interact()
return Transition()
@ -1323,9 +1331,9 @@ fun browserScreen(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
return BrowserRobot.Transition()
}
fun navURLBar() = itemWithResId("$packageName:id/toolbar")
private fun navURLBar() = itemWithResId("$packageName:id/toolbar")
fun searchBar() = itemWithResId("$packageName:id/mozac_browser_toolbar_url_view")
private fun searchBar() = itemWithResId("$packageName:id/mozac_browser_toolbar_url_view")
fun homeScreenButton() = onView(withContentDescription(R.string.browser_toolbar_home))
@ -1334,19 +1342,15 @@ private fun threeDotButton() = onView(withContentDescription("Menu"))
private fun tabsCounter() =
mDevice.findObject(By.res("$packageName:id/counter_root"))
private val progressBar =
private fun progressBar() =
itemWithResId("$packageName:id/mozac_browser_toolbar_progress")
private val suggestedLogins = itemWithResId("$packageName:id/loginSelectBar")
private val selectAddressButton = itemWithResId("$packageName:id/select_address_header")
private val selectCreditCardButton = itemWithResId("$packageName:id/select_credit_card_header")
private fun suggestedLogins() = itemWithResId("$packageName:id/loginSelectBar")
private fun selectAddressButton() = itemWithResId("$packageName:id/select_address_header")
private fun selectCreditCardButton() = itemWithResId("$packageName:id/select_credit_card_header")
private fun creditCardSuggestion(creditCardNumber: String) =
mDevice.findObject(
UiSelector()
.resourceId("$packageName:id/credit_card_number")
.textContains(creditCardNumber),
)
itemWithResIdAndText("$packageName:id/credit_card_number", "$creditCardNumber")
private fun siteSecurityToolbarButton() =
itemWithResId("$packageName:id/mozac_browser_toolbar_security_indicator")
@ -1371,7 +1375,7 @@ fun clickPageObject(item: UiObject) {
}.openThreeDotMenu {
Log.i(TAG, "clickPageObject: Opened main menu")
}.refreshPage {
progressBar.waitUntilGone(waitingTime)
waitForPageToLoad()
Log.i(TAG, "clickPageObject: Page refreshed, progress bar is gone")
}
}
@ -1393,7 +1397,7 @@ fun longClickPageObject(item: UiObject) {
browserScreen {
}.openThreeDotMenu {
}.refreshPage {
progressBar.waitUntilGone(waitingTime)
waitForPageToLoad()
}
}
}
@ -1425,7 +1429,7 @@ fun setPageObjectText(webPageItem: UiObject, text: String) {
browserScreen {
}.openThreeDotMenu {
}.refreshPage {
progressBar.waitUntilGone(waitingTime)
waitForPageToLoad()
}
}
}
@ -1437,11 +1441,7 @@ fun clearTextFieldItem(item: UiObject) {
item.clearTextField()
}
private val currentDate = LocalDate.now()
private val currentDay = currentDate.dayOfMonth
private val currentMonth = currentDate.month
private val currentYear = currentDate.year
private val cookieBanner = itemWithResId("startsiden-gdpr-disclaimer")
private fun cookieBanner() = itemWithResId("startsiden-gdpr-disclaimer")
// Context menu items
// Link URL
@ -1449,34 +1449,34 @@ private fun contextMenuLinkUrl(linkUrl: String) =
itemContainingText(linkUrl)
// Open link in new tab option
private val contextMenuOpenLinkInNewTab =
private fun contextMenuOpenLinkInNewTab() =
itemContainingText(getStringResource(R.string.mozac_feature_contextmenu_open_link_in_new_tab))
// Open link in private tab option
private val contextMenuOpenLinkInPrivateTab =
private fun contextMenuOpenLinkInPrivateTab() =
itemContainingText(getStringResource(R.string.mozac_feature_contextmenu_open_link_in_private_tab))
// Copy link option
private val contextMenuCopyLink =
private fun contextMenuCopyLink() =
itemContainingText(getStringResource(R.string.mozac_feature_contextmenu_copy_link))
// Download link option
private val contextMenuDownloadLink =
private fun contextMenuDownloadLink() =
itemContainingText(getStringResource(R.string.mozac_feature_contextmenu_download_link))
// Share link option
private val contextMenuShareLink =
private fun contextMenuShareLink() =
itemContainingText(getStringResource(R.string.mozac_feature_contextmenu_share_link))
// Open in external app option
private val contextMenuOpenInExternalApp =
private fun contextMenuOpenInExternalApp() =
itemContainingText(getStringResource(R.string.mozac_feature_contextmenu_open_link_in_external_app))
private val surveyButton =
private fun surveyButton() =
itemContainingText(getStringResource(R.string.preferences_take_survey))
private val surveyNoThanksButton =
private fun surveyNoThanksButton() =
itemContainingText(getStringResource(R.string.preferences_not_take_survey))
private val homescreenSurveyCloseButton =
private fun homescreenSurveyCloseButton() =
itemWithDescription("Close")

Loading…
Cancel
Save