Bug 1865072 - Remove redundant assertions

fenix/121.0
AndiAJ 6 months ago committed by mergify[bot]
parent 16ba3ae896
commit db2aa84bf0

@ -89,28 +89,7 @@ object MatcherHelper {
return mDevice.findObject(UiSelector().resourceId(resourceId).textContains(text))
}
fun assertItemWithResIdExists(vararg appItems: UiObject, exists: Boolean = true) {
if (exists) {
for (appItem in appItems) {
assertTrue("${appItem.selector} does not exist", appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemWithResIdExists: Verified ${appItem.selector} exists")
}
} else {
for (appItem in appItems) {
assertFalse("${appItem.selector} exists", appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertItemWithResIdExists: Verified ${appItem.selector} does not exist")
}
}
}
fun assertItemWithResIdIsGone(vararg appItems: UiObject) {
for (appItem in appItems) {
assertTrue("${appItem.selector} is not gone", appItem.waitUntilGone(waitingTime))
Log.i(TAG, "assertItemWithResIdIsGone: Verified ${appItem.selector} is gone")
}
}
fun assertItemContainingTextExists(
fun assertUIObjectExists(
vararg appItems: UiObject,
exists: Boolean = true,
waitingTime: Long = TestAssetHelper.waitingTime,
@ -118,18 +97,18 @@ object MatcherHelper {
for (appItem in appItems) {
if (exists) {
assertTrue("${appItem.selector} does not exist", appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemContainingTextExists: Verified ${appItem.selector} exists")
Log.i(TAG, "assertUIObjectExists: Verified ${appItem.selector} exists")
} else {
assertFalse("${appItem.selector} exists", appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertItemContainingTextExists: Verified ${appItem.selector} does not exist")
Log.i(TAG, "assertUIObjectExists: Verified ${appItem.selector} does not exist")
}
}
}
fun assertItemContainingTextIsGone(vararg appItems: UiObject) {
fun assertUIObjectIsGone(vararg appItems: UiObject) {
for (appItem in appItems) {
assertTrue("${appItem.selector} is not gone", appItem.waitUntilGone(waitingTime))
Log.i(TAG, "assertItemContainingTextIsGone: Verified ${appItem.selector} is gone")
Log.i(TAG, "assertUIObjectIsGone: Verified ${appItem.selector} is gone")
}
}
@ -161,119 +140,6 @@ object MatcherHelper {
}
}
fun assertItemWithDescriptionExists(vararg appItems: UiObject, exists: Boolean = true) {
for (appItem in appItems) {
if (exists) {
assertTrue("${appItem.selector} does not exist", appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemWithDescriptionExists: Verified ${appItem.selector} exists")
} else {
assertFalse("${appItem.selector} exists", appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertItemWithDescriptionExists: Verified ${appItem.selector} does not exist")
}
}
}
fun assertItemWithIndexExists(vararg appItems: UiObject, exists: Boolean = true) {
if (exists) {
for (appItem in appItems) {
assertTrue("${appItem.selector} does not exist", appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemWithIndexExists: Verified ${appItem.selector} exists")
}
} else {
for (appItem in appItems) {
assertFalse("${appItem.selector} exists", appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertItemWithIndexExists: Verified ${appItem.selector} does not exist")
}
}
}
fun assertItemWithClassNameExists(vararg appItems: UiObject, exists: Boolean = true) {
if (exists) {
for (appItem in appItems) {
assertTrue("${appItem.selector} does not exist", appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemWithClassNameExists: Verified ${appItem.selector} exists")
}
} else {
for (appItem in appItems) {
assertFalse("${appItem.selector} exists", appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertItemWithClassNameExists: Verified ${appItem.selector} does not exist")
}
}
}
fun assertItemWithResIdAndIndexExists(vararg appItems: UiObject, exists: Boolean = true) {
if (exists) {
for (appItem in appItems) {
assertTrue("${appItem.selector} does not exist", appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemWithResIdAndIndexExists: Verified ${appItem.selector} exists")
}
} else {
for (appItem in appItems) {
assertFalse("${appItem.selector} exists", appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertItemWithResIdAndIndexExists: Verified ${appItem.selector} does not exist")
}
}
}
fun assertItemWithClassNameAndIndexExists(vararg appItems: UiObject, exists: Boolean = true) {
if (exists) {
for (appItem in appItems) {
assertTrue("${appItem.selector} does not exist", appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemWithClassNameAndIndexExists: Verified ${appItem.selector} exists")
}
} else {
for (appItem in appItems) {
assertFalse("${appItem.selector} exists", appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertItemWithClassNameAndIndexExists: Verified ${appItem.selector} does not exist")
}
}
}
fun assertCheckedItemWithResIdExists(vararg appItems: UiObject, exists: Boolean = true) {
for (appItem in appItems) {
if (exists) {
assertTrue("${appItem.selector} does not exist", appItem.waitForExists(waitingTime))
Log.i(TAG, "assertCheckedItemWithResIdExists: Verified ${appItem.selector} exists")
} else {
assertFalse("${appItem.selector} exists", appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertCheckedItemWithResIdExists: Verified ${appItem.selector} does not exist")
}
}
}
fun assertCheckedItemWithResIdAndTextExists(vararg appItems: UiObject) {
for (appItem in appItems) {
assertTrue(appItem.waitForExists(waitingTime))
Log.i(TAG, "assertCheckedItemWithResIdAndTextExists: Verified ${appItem.selector} exists")
}
}
fun assertItemWithResIdAndDescriptionExists(vararg appItems: UiObject) {
for (appItem in appItems) {
assertTrue(appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemWithResIdAndDescriptionExists: Verified ${appItem.selector} exists")
}
}
fun assertItemWithResIdAndTextExists(vararg appItems: UiObject, exists: Boolean = true) {
for (appItem in appItems) {
if (exists) {
assertTrue("${appItem.selector} does not exist", appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemWithResIdAndTextExists: Verified ${appItem.selector} exists")
} else {
assertFalse("${appItem.selector} exists", appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertItemWithResIdAndTextExists: Verified ${appItem.selector} does not exist")
}
}
}
fun assertItemWithResIdAndTextIsGone(vararg appItems: UiObject) {
for (appItem in appItems) {
assertTrue("${appItem.selector} is not gone", appItem.waitUntilGone(waitingTime))
Log.i(TAG, "assertItemWithResIdAndTextIsGone: Verified ${appItem.selector} is gone")
}
}
fun assertItemIsEnabledAndVisible(vararg appItems: UiObject) {
for (appItem in appItems) {
assertTrue(appItem.waitForExists(waitingTime) && appItem.isEnabled)

@ -13,7 +13,7 @@ import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText
@ -38,7 +38,7 @@ class AddToHomeScreenRobot {
fun addShortcutName(title: String) = shortcutTextField.setText(title)
fun verifyShortcutTextFieldTitle(title: String) = assertItemContainingTextExists(shortcutTitle(title))
fun verifyShortcutTextFieldTitle(title: String) = assertUIObjectExists(shortcutTitle(title))
fun clickAddShortcutButton() =
confirmAddToHomeScreenButton.clickAndWaitForNewWindow(waitingTime)
@ -61,7 +61,7 @@ class AddToHomeScreenRobot {
}
fun verifyShortcutAdded(shortcutTitle: String) =
assertItemContainingTextExists(itemContainingText(shortcutTitle))
assertUIObjectExists(itemContainingText(shortcutTitle))
class Transition {
fun openHomeScreenShortcut(title: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {

@ -33,9 +33,7 @@ import org.hamcrest.Matchers.containsString
import org.junit.Assert.assertEquals
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
@ -101,17 +99,16 @@ class BookmarksRobot {
fun verifyCopySnackBarText() = assertSnackBarText("URL copied")
fun verifyEditBookmarksView() {
assertItemWithDescriptionExists(itemWithDescription("Navigate up"))
assertItemContainingTextExists(itemWithText(getStringResource(R.string.edit_bookmark_fragment_title)))
assertItemWithResIdExists(
fun verifyEditBookmarksView() =
assertUIObjectExists(
itemWithDescription("Navigate up"),
itemWithText(getStringResource(R.string.edit_bookmark_fragment_title)),
itemWithResId("$packageName:id/delete_bookmark_button"),
itemWithResId("$packageName:id/save_bookmark_button"),
itemWithResId("$packageName:id/bookmarkNameEdit"),
itemWithResId("$packageName:id/bookmarkUrlEdit"),
itemWithResId("$packageName:id/bookmarkParentFolderSelector"),
)
}
fun verifyKeyboardHidden() = assertKeyboardVisibility(isExpectedToBeVisible = false)
@ -260,7 +257,7 @@ class BookmarksRobot {
}
fun verifySearchedBookmarkExists(bookmarkUrl: String, exists: Boolean = true) =
assertItemContainingTextExists(itemContainingText(bookmarkUrl), exists = exists)
assertUIObjectExists(itemContainingText(bookmarkUrl), exists = exists)
fun dismissBookmarksSearchBar() = mDevice.pressBack()
@ -403,7 +400,7 @@ private fun assertBookmarkFolderIsNotCreated(title: String) {
.resourceId("$packageName:id/bookmarks_wrapper"),
).waitForExists(waitingTime)
assertItemContainingTextExists(itemContainingText(title), exists = false)
assertUIObjectExists(itemContainingText(title), exists = false)
}
private fun assertBookmarkFavicon(forUrl: Uri) = bookmarkFavicon(forUrl.toString()).check(
@ -429,7 +426,7 @@ private fun assertBookmarkIsDeleted(expectedTitle: String) {
.resourceId("$packageName:id/bookmarks_wrapper"),
).waitForExists(waitingTime)
assertItemContainingTextExists(
assertUIObjectExists(
itemWithResIdContainingText(
"$packageName:id/title",
expectedTitle,

@ -45,13 +45,9 @@ import org.mozilla.fenix.helpers.Constants.RETRY_COUNT
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.HomeActivityComposeTestRule
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextIsGone
import org.mozilla.fenix.helpers.MatcherHelper.assertItemTextEquals
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdIsGone
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectIsGone
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
@ -74,7 +70,7 @@ import java.time.LocalDate
class BrowserRobot {
private lateinit var sessionLoadedIdlingResource: SessionLoadedIdlingResource
fun waitForPageToLoad() = assertItemWithResIdIsGone(progressBar())
fun waitForPageToLoad() = assertUIObjectIsGone(progressBar())
fun verifyCurrentPrivateSession(context: Context) {
val selectedTab = context.components.core.store.state.selectedTab
@ -85,7 +81,7 @@ class BrowserRobot {
sessionLoadedIdlingResource = SessionLoadedIdlingResource()
runWithIdleRes(sessionLoadedIdlingResource) {
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdContainingText(
"$packageName:id/mozac_browser_toolbar_url_view",
url.replace("http://", ""),
@ -119,7 +115,7 @@ class BrowserRobot {
)
runWithIdleRes(sessionLoadedIdlingResource) {
assertItemContainingTextExists(itemContainingText(expectedText))
assertUIObjectExists(itemContainingText(expectedText))
}
}
@ -151,7 +147,7 @@ class BrowserRobot {
for (i in 1..RETRY_COUNT) {
try {
assertItemContainingTextExists(cacheSizeInfo)
assertUIObjectExists(cacheSizeInfo)
break
} catch (e: AssertionError) {
browserScreen {
@ -162,7 +158,7 @@ class BrowserRobot {
}
fun verifyTabCounter(expectedText: String) =
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdContainingText(
"$packageName:id/counter_text",
expectedText,
@ -171,13 +167,13 @@ class BrowserRobot {
fun verifySnackBarText(expectedText: String) {
mDevice.waitForObjects(mDevice.findObject(UiSelector().textContains(expectedText)))
assertItemContainingTextExists(itemContainingText(expectedText))
assertUIObjectExists(itemContainingText(expectedText))
}
fun verifyContextMenuForLocalHostLinks(containsURL: Uri) {
// If the link is directing to another local asset the "Download link" option is not available
// If the link is not re-directing to an external app the "Open link in external app" option is not available
assertItemContainingTextExists(
assertUIObjectExists(
contextMenuLinkUrl(containsURL.toString()),
contextMenuOpenLinkInNewTab(),
contextMenuOpenLinkInPrivateTab(),
@ -189,7 +185,7 @@ class BrowserRobot {
fun verifyContextMenuForLinksToOtherApps(containsURL: String) {
// If the link is re-directing to an external app the "Open link in external app" option is available
// If the link is not directing to another local asset the "Download link" option is not available
assertItemContainingTextExists(
assertUIObjectExists(
contextMenuLinkUrl(containsURL),
contextMenuOpenLinkInNewTab(),
contextMenuOpenLinkInPrivateTab(),
@ -203,7 +199,7 @@ class BrowserRobot {
fun verifyContextMenuForLinksToOtherHosts(containsURL: Uri) {
// If the link is re-directing to another host the "Download link" option is available
// If the link is not re-directing to an external app the "Open link in external app" option is not available
assertItemContainingTextExists(
assertUIObjectExists(
contextMenuLinkUrl(containsURL.toString()),
contextMenuOpenLinkInNewTab(),
contextMenuOpenLinkInPrivateTab(),
@ -236,7 +232,7 @@ class BrowserRobot {
)
}
fun verifyNavURLBarHidden() = assertItemWithResIdIsGone(navURLBar())
fun verifyNavURLBarHidden() = assertUIObjectIsGone(navURLBar())
fun verifySecureConnectionLockIcon() =
onView(withId(R.id.mozac_browser_toolbar_security_indicator))
@ -258,16 +254,16 @@ class BrowserRobot {
}
fun verifyNotificationDotOnMainMenu() =
assertItemWithResIdExists(itemWithResId("$packageName:id/notification_dot"))
assertUIObjectExists(itemWithResId("$packageName:id/notification_dot"))
fun verifyHomeScreenButton() =
homeScreenButton().check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
fun verifySearchBar() = assertItemWithResIdExists(searchBar())
fun verifySearchBar() = assertUIObjectExists(searchBar())
fun dismissContentContextMenu() {
mDevice.pressBack()
assertItemWithResIdExists(itemWithResId("$packageName:id/engineView"))
assertUIObjectExists(itemWithResId("$packageName:id/engineView"))
}
fun createBookmark(url: Uri, folder: String? = null) {
@ -289,13 +285,13 @@ class BrowserRobot {
fun longClickPDFImage() = longClickPageObject(itemWithResId("pdfjs_internal_id_13R"))
fun verifyPDFReaderToolbarItems() =
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdContainingText("download", "Download"),
itemWithResIdContainingText("openInApp", "Open in app"),
)
fun clickSubmitLoginButton() {
clickPageObject(itemWithResId("submit"))
assertItemWithResIdIsGone(itemWithResId("submit"))
assertUIObjectIsGone(itemWithResId("submit"))
mDevice.waitForIdle(waitingTimeLong)
}
@ -303,7 +299,7 @@ class BrowserRobot {
clickPageObject(itemWithResId("password"))
setPageObjectText(itemWithResId("password"), password)
assertItemContainingTextIsGone(itemWithText(password))
assertUIObjectIsGone(itemWithText(password))
}
/**
@ -339,10 +335,10 @@ class BrowserRobot {
// failing to swipe on Firebase sometimes, so it tries again
try {
navURLBar().swipeRight(2)
assertItemContainingTextIsGone(itemWithText(tabUrl))
assertUIObjectIsGone(itemWithText(tabUrl))
} catch (e: AssertionError) {
navURLBar().swipeRight(2)
assertItemContainingTextIsGone(itemWithText(tabUrl))
assertUIObjectIsGone(itemWithText(tabUrl))
}
}
@ -350,10 +346,10 @@ class BrowserRobot {
// failing to swipe on Firebase sometimes, so it tries again
try {
navURLBar().swipeLeft(2)
assertItemContainingTextIsGone(itemWithText(tabUrl))
assertUIObjectIsGone(itemWithText(tabUrl))
} catch (e: AssertionError) {
navURLBar().swipeLeft(2)
assertItemContainingTextIsGone(itemWithText(tabUrl))
assertUIObjectIsGone(itemWithText(tabUrl))
}
}
@ -389,7 +385,7 @@ class BrowserRobot {
fun clickSelectAddressButton() {
for (i in 1..RETRY_COUNT) {
try {
assertItemWithResIdExists(selectAddressButton())
assertUIObjectExists(selectAddressButton())
selectAddressButton().clickAndWaitForNewWindow(waitingTime)
break
@ -406,7 +402,7 @@ class BrowserRobot {
}
}
fun verifySelectAddressButtonExists(exists: Boolean) = assertItemWithResIdExists(selectAddressButton(), exists = exists)
fun verifySelectAddressButtonExists(exists: Boolean) = assertUIObjectExists(selectAddressButton(), exists = exists)
fun changeCreditCardExpiryDate(expiryDate: String) =
itemWithResId("expiryMonthAndYear").setText(expiryDate)
@ -433,17 +429,17 @@ class BrowserRobot {
}
fun verifyUpdateOrSaveCreditCardPromptExists(exists: Boolean) =
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResId("$packageName:id/save_credit_card_header"),
exists = exists,
)
fun verifySelectCreditCardPromptExists(exists: Boolean) =
assertItemWithResIdExists(selectCreditCardButton(), exists = exists)
assertUIObjectExists(selectCreditCardButton(), exists = exists)
fun verifyCreditCardSuggestion(vararg creditCardNumbers: String) {
for (creditCardNumber in creditCardNumbers) {
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdContainingText(
"$packageName:id/credit_card_number",
creditCardNumber,
@ -457,7 +453,7 @@ class BrowserRobot {
UiSelector()
.resourceId("$packageName:id/mozac_feature_login_multiselect_expand"),
).waitForExists(waitingTime)
assertItemContainingTextExists(itemContainingText(userName))
assertUIObjectExists(itemContainingText(userName))
}
fun verifyPrefilledLoginCredentials(userName: String, password: String, credentialsArePrefilled: Boolean) {
@ -490,17 +486,17 @@ class BrowserRobot {
fun verifyAutofilledAddress(streetAddress: String) {
mDevice.waitForObjects(itemWithResIdAndText("streetAddress", streetAddress))
assertItemWithResIdAndTextExists(itemWithResIdAndText("streetAddress", streetAddress))
assertUIObjectExists(itemWithResIdAndText("streetAddress", streetAddress))
}
fun verifyManuallyFilledAddress(apartment: String) {
mDevice.waitForObjects(itemWithResIdAndText("apartment", apartment))
assertItemWithResIdAndTextExists(itemWithResIdAndText("apartment", apartment))
assertUIObjectExists(itemWithResIdAndText("apartment", apartment))
}
fun verifyAutofilledCreditCard(creditCardNumber: String) {
mDevice.waitForObjects(itemWithResIdAndText("cardNumber", creditCardNumber))
assertItemWithResIdAndTextExists(itemWithResIdAndText("cardNumber", creditCardNumber))
assertUIObjectExists(itemWithResIdAndText("cardNumber", creditCardNumber))
}
fun verifyPrefilledPWALoginCredentials(userName: String, shortcutTitle: String) {
@ -509,7 +505,7 @@ class BrowserRobot {
var currentTries = 0
while (currentTries++ < 3) {
try {
assertItemWithResIdExists(itemWithResId("submit"))
assertUIObjectExists(itemWithResId("submit"))
itemWithResId("submit").click()
assertItemTextEquals(itemWithResId("username"), expectedText = userName)
break
@ -521,12 +517,12 @@ class BrowserRobot {
}
fun verifySaveLoginPromptIsDisplayed() =
assertItemWithResIdExists(
assertUIObjectExists(
itemWithResId("$packageName:id/feature_prompt_login_fragment"),
)
fun verifySaveLoginPromptIsNotDisplayed() =
assertItemWithResIdExists(
assertUIObjectExists(
itemWithResId("$packageName:id/feature_prompt_login_fragment"),
exists = false,
)
@ -534,7 +530,7 @@ class BrowserRobot {
fun verifyTrackingProtectionWebContent(state: String) {
for (i in 1..RETRY_COUNT) {
try {
assertItemContainingTextExists(itemContainingText(state))
assertUIObjectExists(itemContainingText(state))
break
} catch (e: AssertionError) {
@ -595,7 +591,7 @@ class BrowserRobot {
for (i in 1..RETRY_COUNT) {
try {
assertItemContainingTextExists(itemContainingText("Selected date is: $currentDate"))
assertUIObjectExists(itemContainingText("Selected date is: $currentDate"))
break
} catch (e: AssertionError) {
@ -608,12 +604,12 @@ class BrowserRobot {
}
}
assertItemContainingTextExists(itemContainingText("Selected date is: $currentDate"))
assertUIObjectExists(itemContainingText("Selected date is: $currentDate"))
}
fun verifyNoDateIsSelected() {
val currentDate = LocalDate.now()
assertItemContainingTextExists(
assertUIObjectExists(
itemContainingText("Selected date is: $currentDate"),
exists = false,
)
@ -622,7 +618,7 @@ class BrowserRobot {
fun verifySelectedTime(hour: Int, minute: Int) {
for (i in 1..RETRY_COUNT) {
try {
assertItemContainingTextExists(itemContainingText("Selected time is: $hour:$minute"))
assertUIObjectExists(itemContainingText("Selected time is: $hour:$minute"))
break
} catch (e: AssertionError) {
@ -636,13 +632,13 @@ class BrowserRobot {
clickPageObject(itemWithResId("submitTime"))
}
}
assertItemContainingTextExists(itemContainingText("Selected time is: $hour:$minute"))
assertUIObjectExists(itemContainingText("Selected time is: $hour:$minute"))
}
fun verifySelectedColor(hexValue: String) {
for (i in 1..RETRY_COUNT) {
try {
assertItemContainingTextExists(itemContainingText("Selected color is: $hexValue"))
assertUIObjectExists(itemContainingText("Selected color is: $hexValue"))
break
} catch (e: AssertionError) {
@ -655,7 +651,7 @@ class BrowserRobot {
}
}
assertItemContainingTextExists(itemContainingText("Selected color is: $hexValue"))
assertUIObjectExists(itemContainingText("Selected color is: $hexValue"))
}
fun verifySelectedDropDownOption(optionName: String) {
@ -667,7 +663,7 @@ class BrowserRobot {
.resourceId("submitOption"),
).waitForExists(waitingTime)
assertItemContainingTextExists(itemContainingText("Selected option is: $optionName"))
assertUIObjectExists(itemContainingText("Selected option is: $optionName"))
break
} catch (e: AssertionError) {
@ -679,19 +675,19 @@ class BrowserRobot {
}
}
assertItemContainingTextExists(itemContainingText("Selected option is: $optionName"))
assertUIObjectExists(itemContainingText("Selected option is: $optionName"))
}
fun verifyNoTimeIsSelected(hour: Int, minute: Int) =
assertItemContainingTextExists(itemContainingText("Selected date is: $hour:$minute"), exists = false)
assertUIObjectExists(itemContainingText("Selected date is: $hour:$minute"), exists = false)
fun verifyColorIsNotSelected(hexValue: String) =
assertItemContainingTextExists(itemContainingText("Selected date is: $hexValue"), exists = false)
assertUIObjectExists(itemContainingText("Selected date is: $hexValue"), exists = false)
fun verifyCookieBannerExists(exists: Boolean) {
for (i in 1..RETRY_COUNT) {
try {
assertItemWithResIdExists(cookieBanner(), exists = exists)
assertUIObjectExists(cookieBanner(), exists = exists)
break
} catch (e: AssertionError) {
if (i == RETRY_COUNT) {
@ -705,12 +701,12 @@ class BrowserRobot {
}
}
}
assertItemWithResIdExists(cookieBanner(), exists = exists)
assertUIObjectExists(cookieBanner(), exists = exists)
}
fun verifyOpenLinkInAnotherAppPrompt() {
assertItemWithResIdExists(itemWithResId("$packageName:id/parentPanel"))
assertItemContainingTextExists(
assertUIObjectExists(
itemWithResId("$packageName:id/parentPanel"),
itemContainingText(
getStringResource(R.string.mozac_feature_applinks_normal_confirm_dialog_title),
),
@ -723,7 +719,7 @@ class BrowserRobot {
fun verifyPrivateBrowsingOpenLinkInAnotherAppPrompt(url: String, pageObject: UiObject) {
for (i in 1..RETRY_COUNT) {
try {
assertItemContainingTextExists(
assertUIObjectExists(
itemContainingText(
getStringResource(R.string.mozac_feature_applinks_confirm_dialog_title),
),
@ -747,40 +743,34 @@ class BrowserRobot {
}
fun verifyFindInPageBar(exists: Boolean) =
assertItemWithResIdExists(
assertUIObjectExists(
itemWithResId("$packageName:id/findInPageView"),
exists = exists,
)
fun verifyConnectionErrorMessage() {
assertItemContainingTextExists(
fun verifyConnectionErrorMessage() =
assertUIObjectExists(
itemContainingText(getStringResource(R.string.mozac_browser_errorpages_connection_failure_title)),
itemWithResId("errorTryAgain"),
)
assertItemWithResIdExists(itemWithResId("errorTryAgain"))
}
fun verifyAddressNotFoundErrorMessage() {
assertItemContainingTextExists(
fun verifyAddressNotFoundErrorMessage() =
assertUIObjectExists(
itemContainingText(getStringResource(R.string.mozac_browser_errorpages_unknown_host_title)),
itemWithResId("errorTryAgain"),
)
assertItemWithResIdExists(itemWithResId("errorTryAgain"))
}
fun verifyNoInternetConnectionErrorMessage() {
assertItemContainingTextExists(
fun verifyNoInternetConnectionErrorMessage() =
assertUIObjectExists(
itemContainingText(getStringResource(R.string.mozac_browser_errorpages_no_internet_title)),
itemWithResId("errorTryAgain"),
)
assertItemWithResIdExists(itemWithResId("errorTryAgain"))
}
fun verifyOpenLinksInAppsCFRExists(exists: Boolean) {
for (i in 1..RETRY_COUNT) {
try {
assertItemWithResIdExists(
assertUIObjectExists(
itemWithResId("$packageName:id/banner_container"),
exists = exists,
)
assertItemWithResIdAndTextExists(
itemWithResIdContainingText(
"$packageName:id/banner_info_message",
getStringResource(R.string.open_in_app_cfr_info_message_2),
@ -809,18 +799,18 @@ class BrowserRobot {
}
}
fun verifySurveyButton() = assertItemContainingTextExists(itemContainingText(getStringResource(R.string.preferences_take_survey)))
fun verifySurveyButton() = assertUIObjectExists(itemContainingText(getStringResource(R.string.preferences_take_survey)))
fun verifySurveyButtonDoesNotExist() =
assertItemContainingTextIsGone(itemWithText(getStringResource(R.string.preferences_take_survey)))
assertUIObjectIsGone(itemWithText(getStringResource(R.string.preferences_take_survey)))
fun verifySurveyNoThanksButton() =
assertItemContainingTextExists(
assertUIObjectExists(
itemContainingText(getStringResource(R.string.preferences_not_take_survey)),
)
fun verifyHomeScreenSurveyCloseButton() =
assertItemWithDescriptionExists(itemWithDescription("Close"))
assertUIObjectExists(itemWithDescription("Close"))
fun clickOpenLinksInAppsDismissCFRButton() =
itemWithResIdContainingText(
@ -854,13 +844,13 @@ class BrowserRobot {
fun longClickToolbar() = mDevice.findObject(By.res("$packageName:id/mozac_browser_toolbar_url_view")).click(LONG_CLICK_DURATION)
fun verifyDownloadPromptIsDismissed() =
assertItemWithResIdExists(
assertUIObjectExists(
itemWithResId("$packageName:id/viewDynamicDownloadDialog"),
exists = false,
)
fun verifyCancelPrivateDownloadsPrompt(numberOfActiveDownloads: String) {
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdContainingText(
"$packageName:id/title",
getStringResource(R.string.mozac_feature_downloads_cancel_active_downloads_warning_content_title),
@ -949,7 +939,7 @@ class BrowserRobot {
)
tabsCounter().click()
assertItemWithResIdExists(itemWithResId("$packageName:id/new_tab_button"))
assertUIObjectExists(itemWithResId("$packageName:id/new_tab_button"))
break
} catch (e: AssertionError) {
@ -961,7 +951,7 @@ class BrowserRobot {
}
}
assertItemWithResIdExists(itemWithResId("$packageName:id/new_tab_button"))
assertUIObjectExists(itemWithResId("$packageName:id/new_tab_button"))
TabDrawerRobot().interact()
return TabDrawerRobot.Transition()

@ -22,11 +22,9 @@ import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextIsGone
import org.mozilla.fenix.helpers.MatcherHelper.assertItemTextEquals
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectIsGone
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
@ -41,17 +39,16 @@ import org.mozilla.fenix.helpers.ext.waitNotNull
class CollectionRobot {
fun verifySelectCollectionScreen() {
assertItemContainingTextExists(
fun verifySelectCollectionScreen() =
assertUIObjectExists(
itemContainingText("Select collection"),
itemContainingText("Add new collection"),
itemWithResId("$packageName:id/collections_list"),
)
assertItemWithResIdExists(itemWithResId("$packageName:id/collections_list"))
}
fun clickAddNewCollection() = addNewCollectionButton().click()
fun verifyCollectionNameTextField() = assertItemWithResIdExists(mainMenuEditCollectionNameField())
fun verifyCollectionNameTextField() = assertUIObjectExists(mainMenuEditCollectionNameField())
// names a collection saved from tab drawer
fun typeCollectionNameAndSave(collectionName: String) {
@ -77,17 +74,17 @@ class CollectionRobot {
fun verifyTabSavedInCollection(title: String, visible: Boolean = true) {
if (visible) {
scrollToElementByText(title)
assertItemContainingTextExists(collectionListItem(title))
assertUIObjectExists(collectionListItem(title))
} else {
assertItemContainingTextIsGone(collectionListItem(title))
assertUIObjectIsGone(collectionListItem(title))
}
}
fun verifyCollectionTabUrl(visible: Boolean, url: String) =
assertItemContainingTextExists(itemContainingText(url), exists = visible)
assertUIObjectExists(itemContainingText(url), exists = visible)
fun verifyShareCollectionButtonIsVisible(visible: Boolean) =
assertItemWithDescriptionExists(shareCollectionButton(), exists = visible)
assertUIObjectExists(shareCollectionButton(), exists = visible)
fun verifyCollectionMenuIsVisible(visible: Boolean, rule: ComposeTestRule) {
if (visible) {
@ -134,7 +131,7 @@ class CollectionRobot {
}
fun verifyCollectionItemRemoveButtonIsVisible(title: String, visible: Boolean) =
assertItemContainingTextExists(removeTabFromCollectionButton(title), exists = visible)
assertUIObjectExists(removeTabFromCollectionButton(title), exists = visible)
fun removeTabFromCollection(title: String) = removeTabFromCollectionButton(title).click()
@ -166,9 +163,9 @@ class CollectionRobot {
title: String,
interact: HomeScreenRobot.() -> Unit,
): HomeScreenRobot.Transition {
assertItemContainingTextExists(itemContainingText(title))
assertUIObjectExists(itemContainingText(title))
itemContainingText(title).clickAndWaitForNewWindow(waitingTimeShort)
assertItemWithDescriptionExists(itemWithDescription(getStringResource(R.string.remove_tab_from_collection)), exists = false)
assertUIObjectExists(itemWithDescription(getStringResource(R.string.remove_tab_from_collection)), exists = false)
HomeScreenRobot().interact()
return HomeScreenRobot.Transition()

@ -44,7 +44,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.HomeActivityComposeTestRule
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
@ -86,7 +86,7 @@ class ComposeTabDrawerRobot(private val composeTestRule: HomeActivityComposeTest
fun verifySyncedTabsListWhenUserIsNotSignedIn() {
verifySyncedTabsList()
assertItemContainingTextExists(
assertUIObjectExists(
itemContainingText(getStringResource(R.string.synced_tabs_sign_in_message)),
itemContainingText(getStringResource(R.string.sync_sign_in)),
itemContainingText(getStringResource(R.string.tab_drawer_fab_sync)),
@ -108,7 +108,7 @@ class ComposeTabDrawerRobot(private val composeTestRule: HomeActivityComposeTest
fun verifyNoExistingOpenTabs(vararg titles: String) {
titles.forEach { title ->
assertItemContainingTextExists(
assertUIObjectExists(
itemContainingText(title),
exists = false,
)

@ -15,10 +15,7 @@ import androidx.test.uiautomator.UiSelector
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.LONG_CLICK_DURATION
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
@ -37,16 +34,16 @@ import org.mozilla.fenix.helpers.click
class CustomTabRobot {
fun verifyCustomTabsSiteInfoButton() =
assertItemWithResIdExists(
assertUIObjectExists(
itemWithResId("$packageName:id/mozac_browser_toolbar_security_indicator"),
)
fun verifyCustomTabsShareButton() =
assertItemWithDescriptionExists(
assertUIObjectExists(
itemWithDescription(getStringResource(R.string.mozac_feature_customtabs_share_link)),
)
fun verifyMainMenuButton() = assertItemWithResIdExists(mainMenuButton)
fun verifyMainMenuButton() = assertUIObjectExists(mainMenuButton)
fun verifyDesktopSiteButtonExists() {
desktopSiteButton().check(matches(isDisplayed()))
@ -57,19 +54,19 @@ class CustomTabRobot {
}
fun verifyPoweredByTextIsDisplayed() =
assertItemContainingTextExists(itemContainingText("POWERED BY $appName"))
assertUIObjectExists(itemContainingText("POWERED BY $appName"))
fun verifyOpenInBrowserButtonExists() {
openInBrowserButton().check(matches(isDisplayed()))
}
fun verifyBackButtonExists() = assertItemWithDescriptionExists(itemWithDescription("Back"))
fun verifyBackButtonExists() = assertUIObjectExists(itemWithDescription("Back"))
fun verifyForwardButtonExists() = assertItemWithDescriptionExists(itemWithDescription("Forward"))
fun verifyForwardButtonExists() = assertUIObjectExists(itemWithDescription("Forward"))
fun verifyRefreshButtonExists() = assertItemWithDescriptionExists(itemWithDescription("Refresh"))
fun verifyRefreshButtonExists() = assertUIObjectExists(itemWithDescription("Refresh"))
fun verifyCustomMenuItem(label: String) = assertItemContainingTextExists(itemContainingText(label))
fun verifyCustomMenuItem(label: String) = assertUIObjectExists(itemContainingText(label))
fun verifyCustomTabCloseButton() {
closeButton().check(matches(isDisplayed()))
@ -90,13 +87,13 @@ class CustomTabRobot {
waitingTime,
)
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdContainingText("$packageName:id/mozac_browser_toolbar_title_view", title),
)
}
fun verifyCustomTabUrl(Url: String) {
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdContainingText("$packageName:id/mozac_browser_toolbar_url_view", Url.drop(7)),
)
}
@ -126,10 +123,10 @@ class CustomTabRobot {
fun clickCustomTabCloseButton() = closeButton().click()
fun verifyCustomTabActionButton(customTabActionButtonDescription: String) =
assertItemWithDescriptionExists(itemWithDescription(customTabActionButtonDescription))
assertUIObjectExists(itemWithDescription(customTabActionButtonDescription))
fun verifyPDFReaderToolbarItems() =
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdAndText("download", "Download"),
itemWithResIdAndText("openInApp", "Open in app"),
)

@ -30,9 +30,7 @@ import org.mozilla.fenix.helpers.AppAndSystemHelper.getPermissionAllowID
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_APPS_PHOTOS
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
@ -56,8 +54,10 @@ class DownloadRobot {
Log.i(TAG, "verifyDownloadPrompt: While loop currentTries = $currentTries")
try {
Log.i(TAG, "verifyDownloadPrompt: Try block")
assertItemWithResIdExists(itemWithResId("$packageName:id/download_button"))
assertItemContainingTextExists(itemContainingText(fileName))
assertUIObjectExists(
itemWithResId("$packageName:id/download_button"),
itemContainingText(fileName),
)
break
} catch (e: AssertionError) {
@ -71,17 +71,16 @@ class DownloadRobot {
}
}
fun verifyDownloadCompleteNotificationPopup() {
assertItemContainingTextExists(
fun verifyDownloadCompleteNotificationPopup() =
assertUIObjectExists(
itemContainingText(getStringResource(R.string.mozac_feature_downloads_button_open)),
itemContainingText(getStringResource(R.string.mozac_feature_downloads_completed_notification_text2)),
itemWithResId("$packageName:id/download_dialog_filename"),
)
assertItemWithResIdExists(itemWithResId("$packageName:id/download_dialog_filename"))
}
fun verifyDownloadFailedPrompt(fileName: String) {
assertItemWithResIdExists(itemWithResId("$packageName:id/download_dialog_icon"))
assertItemWithResIdAndTextExists(
fun verifyDownloadFailedPrompt(fileName: String) =
assertUIObjectExists(
itemWithResId("$packageName:id/download_dialog_icon"),
itemWithResIdContainingText(
"$packageName:id/download_dialog_title",
getStringResource(R.string.mozac_feature_downloads_failed_notification_text2),
@ -95,7 +94,6 @@ class DownloadRobot {
getStringResource(R.string.mozac_feature_downloads_button_try_again),
),
)
}
fun clickTryAgainButton() {
itemWithResIdAndText(
@ -108,9 +106,9 @@ class DownloadRobot {
fun verifyPhotosAppOpens() = assertExternalAppOpens(GOOGLE_APPS_PHOTOS)
fun verifyDownloadedFileName(fileName: String) =
assertItemContainingTextExists(itemContainingText(fileName))
assertUIObjectExists(itemContainingText(fileName))
fun verifyDownloadedFileIcon() = assertItemWithResIdExists(itemWithResId("$packageName:id/favicon"))
fun verifyDownloadedFileIcon() = assertUIObjectExists(itemWithResId("$packageName:id/favicon"))
fun verifyEmptyDownloadsList() {
Log.i(TAG, "verifyEmptyDownloadsList: Looking for empty download list")
@ -121,7 +119,7 @@ class DownloadRobot {
}
fun waitForDownloadsListToExist() =
assertItemWithResIdExists(itemWithResId("$packageName:id/download_list"))
assertUIObjectExists(itemWithResId("$packageName:id/download_list"))
fun openDownloadedFile(fileName: String) {
downloadedFile(fileName)

@ -22,8 +22,7 @@ import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.not
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
@ -43,7 +42,7 @@ class EnhancedTrackingProtectionRobot {
fun verifyETPSwitchVisibility(visible: Boolean) = assertETPSwitchVisibility(visible)
fun verifyCrossSiteCookiesBlocked(isBlocked: Boolean) {
assertItemWithResIdExists(itemWithResId("$packageName:id/cross_site_tracking"))
assertUIObjectExists(itemWithResId("$packageName:id/cross_site_tracking"))
crossSiteCookiesBlockListButton.click()
// Verifies the trackers block/allow list
onView(withId(R.id.details_blocking_header))
@ -61,7 +60,7 @@ class EnhancedTrackingProtectionRobot {
}
fun verifySocialMediaTrackersBlocked(isBlocked: Boolean) {
assertItemWithResIdExists(itemWithResId("$packageName:id/social_media_trackers"))
assertUIObjectExists(itemWithResId("$packageName:id/social_media_trackers"))
socialTrackersBlockListButton.click()
// Verifies the trackers block/allow list
onView(withId(R.id.details_blocking_header))
@ -80,7 +79,7 @@ class EnhancedTrackingProtectionRobot {
}
fun verifyFingerprintersBlocked(isBlocked: Boolean) {
assertItemWithResIdExists(itemWithResId("$packageName:id/fingerprinters"))
assertUIObjectExists(itemWithResId("$packageName:id/fingerprinters"))
fingerprintersBlockListButton.click()
// Verifies the trackers block/allow list
onView(withId(R.id.details_blocking_header))
@ -99,7 +98,7 @@ class EnhancedTrackingProtectionRobot {
}
fun verifyCryptominersBlocked(isBlocked: Boolean) {
assertItemWithResIdExists(itemWithResId("$packageName:id/cryptominers"))
assertUIObjectExists(itemWithResId("$packageName:id/cryptominers"))
cryptominersBlockListButton.click()
// Verifies the trackers block/allow list
onView(withId(R.id.details_blocking_header))
@ -118,7 +117,7 @@ class EnhancedTrackingProtectionRobot {
}
fun verifyTrackingContentBlocked(isBlocked: Boolean) {
assertItemContainingTextExists(itemWithText("Tracking Content"))
assertUIObjectExists(itemWithText("Tracking Content"))
trackingContentBlockListButton.click()
// Verifies the trackers block/allow list
onView(withId(R.id.details_blocking_header))
@ -152,7 +151,7 @@ class EnhancedTrackingProtectionRobot {
}
fun verifyETPSectionIsDisplayedInQuickSettingsSheet(isDisplayed: Boolean) =
assertItemWithResIdExists(
assertUIObjectExists(
itemWithResId("$packageName:id/trackingProtectionLayout"),
exists = isDisplayed,
)
@ -290,5 +289,5 @@ private val fingerprintersBlockListButton =
private fun assertSecuritySheetIsCompletelyDisplayed() {
mDevice.findObject(UiSelector().description(getStringResource(R.string.quick_settings_sheet)))
.waitForExists(waitingTime)
assertItemWithResIdExists(itemWithResId("$packageName:id/quick_action_sheet"))
assertUIObjectExists(itemWithResId("$packageName:id/quick_action_sheet"))
}

@ -23,8 +23,7 @@ import org.hamcrest.Matchers
import org.hamcrest.Matchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
@ -62,7 +61,7 @@ class HistoryRobot {
}
fun verifyHistoryItemExists(shouldExist: Boolean, item: String) =
assertItemContainingTextExists(itemContainingText(item), exists = shouldExist)
assertUIObjectExists(itemContainingText(item), exists = shouldExist)
fun verifyFirstTestPageTitle(title: String) = assertTestPageTitle(title)
@ -109,7 +108,7 @@ class HistoryRobot {
fun verifySearchGroupDisplayed(shouldBeDisplayed: Boolean, searchTerm: String, groupSize: Int) =
// checks if the search group exists in the Recently visited section
assertItemContainingTextExists(
assertUIObjectExists(
itemContainingText(searchTerm)
.getFromParent(
UiSelector().text("$groupSize sites"),
@ -198,7 +197,7 @@ private fun assertTestPageTitle(title: String) = testPageTitle()
.check(matches(withText(title)))
private fun assertDeleteConfirmationMessage() =
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdContainingText("$packageName:id/title", getStringResource(R.string.delete_history_prompt_title)),
itemWithResIdContainingText("$packageName:id/body", getStringResource(R.string.delete_history_prompt_body_2)),
)

@ -55,13 +55,8 @@ import org.mozilla.fenix.helpers.Constants.LONG_CLICK_DURATION
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.HomeActivityComposeTestRule
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextIsGone
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithIndexExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndIndexExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectIsGone
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithIndex
@ -91,40 +86,38 @@ class HomeScreenRobot {
" service provider, it makes it easier to keep what you do online private from anyone" +
" else who uses this device."
fun verifyNavigationToolbar() = assertItemWithResIdExists(navigationToolbar)
fun verifyNavigationToolbar() = assertUIObjectExists(navigationToolbar)
fun verifyHomeScreen() = assertItemWithResIdExists(homeScreen)
fun verifyHomeScreen() = assertUIObjectExists(homeScreen)
fun verifyPrivateBrowsingHomeScreenItems() {
verifyHomeScreenAppBarItems()
assertItemContainingTextExists(itemContainingText(privateSessionMessage))
assertUIObjectExists(itemContainingText(privateSessionMessage))
verifyCommonMythsLink()
}
fun verifyHomeScreenAppBarItems() =
assertItemWithResIdExists(homeScreen, privateBrowsingButton, homepageWordmark)
assertUIObjectExists(homeScreen, privateBrowsingButton, homepageWordmark)
fun verifyNavigationToolbarItems(numberOfOpenTabs: String = "0") {
assertItemWithResIdExists(navigationToolbar, menuButton)
assertItemWithResIdAndTextExists(tabCounter(numberOfOpenTabs))
}
fun verifyNavigationToolbarItems(numberOfOpenTabs: String = "0") =
assertUIObjectExists(navigationToolbar, menuButton, tabCounter(numberOfOpenTabs))
fun verifyHomePrivateBrowsingButton() = assertItemWithResIdExists(privateBrowsingButton)
fun verifyHomeMenuButton() = assertItemWithResIdExists(menuButton)
fun verifyHomePrivateBrowsingButton() = assertUIObjectExists(privateBrowsingButton)
fun verifyHomeMenuButton() = assertUIObjectExists(menuButton)
fun verifyTabButton() = assertTabButton()
fun verifyCollectionsHeader() = assertCollectionsHeader()
fun verifyNoCollectionsText() = assertNoCollectionsText()
fun verifyHomeWordmark() {
homeScreenList().scrollToBeginning(3)
assertItemWithResIdExists(homepageWordmark)
assertUIObjectExists(homepageWordmark)
}
fun verifyHomeComponent() = assertHomeComponent()
fun verifyTabCounter(numberOfOpenTabs: String) =
assertItemWithResIdAndTextExists(tabCounter(numberOfOpenTabs))
assertUIObjectExists(tabCounter(numberOfOpenTabs))
fun verifyWallpaperImageApplied(isEnabled: Boolean) =
assertItemWithResIdExists(itemWithResId("$packageName:id/wallpaperImageView"), exists = isEnabled)
assertUIObjectExists(itemWithResId("$packageName:id/wallpaperImageView"), exists = isEnabled)
// Upgrading users onboarding dialog
fun verifyUpgradingUserOnboardingFirstScreen(testRule: ComposeTestRule) {
@ -220,12 +213,12 @@ class HomeScreenRobot {
.performClick()
fun verifyCommonMythsLink() =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.private_browsing_common_myths)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.private_browsing_common_myths)))
fun verifyExistingTopSitesList() = assertExistingTopSitesList()
fun verifyNotExistingTopSitesList(title: String) = assertNotExistingTopSitesList(title)
fun verifySponsoredShortcutDoesNotExist(sponsoredShortcutTitle: String, position: Int) =
assertItemWithResIdAndIndexExists(
assertUIObjectExists(
itemWithResIdAndIndex("$packageName:id/top_site_item", index = position - 1)
.getChild(
UiSelector()
@ -247,10 +240,10 @@ class HomeScreenRobot {
fun verifyJumpBackInSectionIsDisplayed() {
scrollToElementByText(getStringResource(R.string.recent_tabs_header))
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.recent_tabs_header)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.recent_tabs_header)))
}
fun verifyJumpBackInSectionIsNotDisplayed() =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.recent_tabs_header)), exists = false)
assertUIObjectExists(itemContainingText(getStringResource(R.string.recent_tabs_header)), exists = false)
fun verifyJumpBackInItemTitle(testRule: ComposeTestRule, itemTitle: String) =
assertJumpBackInItemTitle(testRule, itemTitle)
fun verifyJumpBackInItemWithUrl(testRule: ComposeTestRule, itemUrl: String) =
@ -264,12 +257,12 @@ class HomeScreenRobot {
// checks if the search group exists in the Recently visited section
if (shouldBeDisplayed) {
scrollToElementByText("Recently visited")
assertItemContainingTextExists(
assertUIObjectExists(
itemContainingText(searchTerm)
.getFromParent(UiSelector().text("$groupSize sites")),
)
} else {
assertItemContainingTextIsGone(
assertUIObjectIsGone(
itemContainingText(searchTerm)
.getFromParent(UiSelector().text("$groupSize sites")),
)
@ -279,9 +272,9 @@ class HomeScreenRobot {
// Collections elements
fun verifyCollectionIsDisplayed(title: String, collectionExists: Boolean = true) {
if (collectionExists) {
assertItemContainingTextExists(itemContainingText(title))
assertUIObjectExists(itemContainingText(title))
} else {
assertItemContainingTextIsGone(itemWithText(title))
assertUIObjectIsGone(itemWithText(title))
}
}
@ -304,10 +297,10 @@ class HomeScreenRobot {
fun verifyThoughtProvokingStories(enabled: Boolean) {
if (enabled) {
scrollToElementByText(getStringResource(R.string.pocket_stories_header_1))
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.pocket_stories_header_1)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.pocket_stories_header_1)))
} else {
homeScreenList().scrollToEnd(LISTS_MAXSWIPES)
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.pocket_stories_header_1)), exists = false)
assertUIObjectExists(itemContainingText(getStringResource(R.string.pocket_stories_header_1)), exists = false)
}
}
@ -321,7 +314,7 @@ class HomeScreenRobot {
for (position in 0..8) {
pocketStoriesList
.scrollIntoView(UiSelector().index(position))
assertItemWithIndexExists(itemWithIndex(position))
assertUIObjectExists(itemWithIndex(position))
}
}
@ -343,16 +336,16 @@ class HomeScreenRobot {
fun verifyDiscoverMoreStoriesButton() {
pocketStoriesList
.scrollIntoView(UiSelector().text("Discover more"))
assertItemContainingTextExists(itemWithText("Discover more"))
assertUIObjectExists(itemWithText("Discover more"))
}
fun verifyStoriesByTopic(enabled: Boolean) {
if (enabled) {
scrollToElementByText(getStringResource(R.string.pocket_stories_categories_header))
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.pocket_stories_categories_header)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.pocket_stories_categories_header)))
} else {
homeScreenList().scrollToEnd(LISTS_MAXSWIPES)
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.pocket_stories_categories_header)), exists = false)
assertUIObjectExists(itemContainingText(getStringResource(R.string.pocket_stories_categories_header)), exists = false)
}
}
@ -378,16 +371,16 @@ class HomeScreenRobot {
fun verifyPoweredByPocket() {
homeScreenList().scrollIntoView(mDevice.findObject(UiSelector().resourceId("pocket.header")))
assertItemWithResIdAndTextExists(itemWithResId("pocket.header.title"))
assertUIObjectExists(itemWithResId("pocket.header.title"))
}
fun verifyCustomizeHomepageButton(enabled: Boolean) {
if (enabled) {
scrollToElementByText(getStringResource(R.string.browser_menu_customize_home_1))
assertItemContainingTextExists(itemContainingText("Customize homepage"))
assertUIObjectExists(itemContainingText("Customize homepage"))
} else {
homeScreenList().scrollToEnd(LISTS_MAXSWIPES)
assertItemContainingTextExists(itemContainingText("Customize homepage"), exists = false)
assertUIObjectExists(itemContainingText("Customize homepage"), exists = false)
}
}
@ -674,9 +667,9 @@ class HomeScreenRobot {
}
fun expandCollection(title: String, interact: CollectionRobot.() -> Unit): CollectionRobot.Transition {
assertItemContainingTextExists(itemContainingText(title))
assertUIObjectExists(itemContainingText(title))
itemContainingText(title).clickAndWaitForNewWindow(waitingTimeShort)
assertItemWithDescriptionExists(itemWithDescription(getStringResource(R.string.remove_tab_from_collection)))
assertUIObjectExists(itemWithDescription(getStringResource(R.string.remove_tab_from_collection)))
CollectionRobot().interact()
return CollectionRobot.Transition()
@ -851,7 +844,7 @@ private fun assertHomeComponent() =
private fun threeDotButton() = onView(allOf(withId(R.id.menuButton)))
private fun assertExistingTopSitesList() =
assertItemWithResIdExists(itemWithResId("$packageName:id/top_sites_list"))
assertUIObjectExists(itemWithResId("$packageName:id/top_sites_list"))
private fun assertExistingTopSitesTabs(title: String) {
mDevice.findObject(
@ -866,7 +859,7 @@ private fun assertExistingTopSitesTabs(title: String) {
}
private fun assertSponsoredShortcutLogoIsDisplayed(position: Int) =
assertItemWithResIdAndIndexExists(
assertUIObjectExists(
itemWithResIdAndIndex(resourceId = "$packageName:id/top_site_item", index = position - 1)
.getChild(
UiSelector()
@ -875,7 +868,7 @@ private fun assertSponsoredShortcutLogoIsDisplayed(position: Int) =
)
private fun assertSponsoredSubtitleIsDisplayed(position: Int) =
assertItemWithResIdAndIndexExists(
assertUIObjectExists(
itemWithResIdAndIndex(resourceId = "$packageName:id/top_site_item", index = position - 1)
.getChild(
UiSelector()
@ -884,7 +877,7 @@ private fun assertSponsoredSubtitleIsDisplayed(position: Int) =
)
private fun assertSponsoredShortcutTitle(sponsoredShortcutTitle: String, position: Int) =
assertItemWithResIdAndIndexExists(
assertUIObjectExists(
itemWithResIdAndIndex(resourceId = "$packageName:id/top_site_item", index = position - 1)
.getChild(
UiSelector()
@ -894,7 +887,7 @@ private fun assertSponsoredShortcutTitle(sponsoredShortcutTitle: String, positio
private fun assertNotExistingTopSitesList(title: String) {
mDevice.findObject(UiSelector().text(title)).waitUntilGone(waitingTime)
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdContainingText(
"$packageName:id/top_site_title",
title,
@ -904,7 +897,7 @@ private fun assertNotExistingTopSitesList(title: String) {
}
private fun assertSponsoredTopSitesNotDisplayed() =
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdContainingText(
"$packageName:id/top_site_subtitle",
getStringResource(R.string.top_sites_sponsored_label),
@ -930,16 +923,16 @@ private fun assertJumpBackInItemWithUrl(testRule: ComposeTestRule, itemUrl: Stri
testRule.onNodeWithTag("recent.tab.url", useUnmergedTree = true).assert(hasText(itemUrl))
private fun assertJumpBackInShowAllButton() =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.recent_tabs_show_all)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.recent_tabs_show_all)))
private fun assertRecentlyVisitedSectionIsDisplayed(exists: Boolean) =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.history_metadata_header_2)), exists = exists)
assertUIObjectExists(itemContainingText(getStringResource(R.string.history_metadata_header_2)), exists = exists)
private fun assertRecentBookmarksSectionIsDisplayed(exists: Boolean) =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.recently_saved_title)), exists = exists)
assertUIObjectExists(itemContainingText(getStringResource(R.string.recently_saved_title)), exists = exists)
private fun assertPocketSectionIsDisplayed(exists: Boolean) =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.pocket_stories_header_1)), exists = exists)
assertUIObjectExists(itemContainingText(getStringResource(R.string.pocket_stories_header_1)), exists = exists)
private fun saveTabsToCollectionButton() = onView(withId(R.id.add_tabs_to_collections_button))

@ -39,8 +39,7 @@ import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.HomeActivityComposeTestRule
import org.mozilla.fenix.helpers.MatcherHelper.assertItemTextEquals
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
@ -82,19 +81,15 @@ class NavigationToolbarRobot {
readerViewToggle().click()
}
fun verifyClipboardSuggestionsAreDisplayed(link: String = "", shouldBeDisplayed: Boolean) {
assertItemWithResIdExists(
fun verifyClipboardSuggestionsAreDisplayed(link: String = "", shouldBeDisplayed: Boolean) =
assertUIObjectExists(
itemWithResId("$packageName:id/fill_link_from_clipboard"),
exists = shouldBeDisplayed,
)
assertItemWithResIdAndTextExists(
itemWithResIdAndText(
"$packageName:id/clipboard_url",
link,
),
exists = shouldBeDisplayed,
)
}
fun longClickEditModeToolbar() =
mDevice.findObject(By.res("$packageName:id/mozac_browser_toolbar_edit_url_view")).click(LONG_CLICK_DURATION)
@ -123,7 +118,7 @@ class NavigationToolbarRobot {
// New unified search UI selector
fun verifyDefaultSearchEngine(engineName: String) =
assertItemWithResIdExists(
assertUIObjectExists(
searchSelectorButton.getChild(UiSelector().description(engineName)),
)

@ -11,9 +11,7 @@ import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import org.mozilla.fenix.helpers.Constants.RETRY_COUNT
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
@ -37,7 +35,7 @@ class NotificationRobot {
notificationFound = mDevice.findObject(notification).waitForExists(waitingTime)
}
assertItemContainingTextExists(itemWithText(notificationMessage))
assertUIObjectExists(itemWithText(notificationMessage))
}
fun clearNotifications() {
@ -67,7 +65,7 @@ class NotificationRobot {
fun verifySystemNotificationDoesNotExist(notificationMessage: String) {
Log.i(TAG, "verifySystemNotificationDoesNotExist: Waiting for $notificationMessage notification to be gone")
mDevice.findObject(UiSelector().textContains(notificationMessage)).waitUntilGone(waitingTime)
assertItemContainingTextExists(itemContainingText(notificationMessage), exists = false)
assertUIObjectExists(itemContainingText(notificationMessage), exists = false)
Log.i(TAG, "verifySystemNotificationDoesNotExist: Verified that $notificationMessage notification does not exist")
}
@ -85,10 +83,10 @@ class NotificationRobot {
for (i in 1..RETRY_COUNT) {
Log.i(TAG, "clickPageObject: For loop i = $i")
try {
assertItemWithResIdAndTextExists(downloadSystemNotificationButton(action))
assertUIObjectExists(downloadSystemNotificationButton(action))
downloadSystemNotificationButton(action).clickAndWaitForNewWindow(waitingTimeShort)
Log.i(TAG, "clickDownloadNotificationControlButton: Clicked app notification $action button and waits for a new window for $waitingTimeShort ms")
assertItemWithResIdAndTextExists(
assertUIObjectExists(
downloadSystemNotificationButton(action),
exists = false,
)
@ -106,7 +104,7 @@ class NotificationRobot {
}
fun verifyMediaSystemNotificationButtonState(action: String) =
assertItemWithResIdAndDescriptionExists(mediaSystemNotificationButton(action))
assertUIObjectExists(mediaSystemNotificationButton(action))
fun expandNotificationMessage() {
while (!notificationHeader.exists()) {
@ -164,9 +162,9 @@ class NotificationRobot {
}
// Not all download related system notifications can be dismissed
if (shouldDismissNotification) {
assertItemContainingTextExists(itemContainingText(appName), exists = false)
assertUIObjectExists(itemContainingText(appName), exists = false)
} else {
assertItemContainingTextExists(itemContainingText(appName))
assertUIObjectExists(itemContainingText(appName))
Log.i(TAG, "swipeDownloadNotification: Verified that $appName notification exist")
}
@ -206,7 +204,7 @@ class NotificationRobot {
fun clickClosePrivateTabsNotification(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
try {
assertItemContainingTextExists(closePrivateTabsNotification())
assertUIObjectExists(closePrivateTabsNotification())
} catch (e: AssertionError) {
notificationTray().flingToEnd(1)
}

@ -7,12 +7,12 @@ package org.mozilla.fenix.ui.robots
import androidx.test.uiautomator.UiSelector
import org.junit.Assert.assertTrue
import org.mozilla.fenix.helpers.AppAndSystemHelper.isExternalAppBrowserActivityInCurrentTask
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName
class PwaRobot {
fun verifyCustomTabToolbarIsNotDisplayed() = assertItemWithResIdExists(customTabToolbar(), exists = false)
fun verifyCustomTabToolbarIsNotDisplayed() = assertUIObjectExists(customTabToolbar(), exists = false)
fun verifyPwaActivityInCurrentTask() = assertTrue(isExternalAppBrowserActivityInCurrentTask())
class Transition

@ -18,7 +18,7 @@ import org.hamcrest.Matchers
import org.hamcrest.Matchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.HomeActivityComposeTestRule
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
@ -57,7 +57,7 @@ class RecentlyClosedTabsRobot {
}
fun verifyRecentlyClosedTabsPageTitle(title: String) =
assertItemWithResIdAndTextExists(
assertUIObjectExists(
recentlyClosedTabsPageTitle(title),
)

@ -38,12 +38,10 @@ import org.mozilla.fenix.helpers.Constants.LONG_CLICK_DURATION
import org.mozilla.fenix.helpers.Constants.RETRY_COUNT
import org.mozilla.fenix.helpers.Constants.SPEECH_RECOGNITION
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemTextContains
import org.mozilla.fenix.helpers.MatcherHelper.assertItemTextEquals
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdIsGone
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectIsGone
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
@ -58,19 +56,19 @@ import org.mozilla.fenix.helpers.TestHelper.waitForObjects
* Implementation of Robot Pattern for the search fragment.
*/
class SearchRobot {
fun verifySearchView() = assertItemWithResIdExists(itemWithResId("$packageName:id/search_wrapper"))
fun verifySearchView() = assertUIObjectExists(itemWithResId("$packageName:id/search_wrapper"))
fun verifySearchToolbar(isDisplayed: Boolean) =
assertItemWithResIdExists(
assertUIObjectExists(
itemWithResId("$packageName:id/mozac_browser_toolbar_edit_url_view"),
exists = isDisplayed,
)
fun verifyScanButtonVisibility(visible: Boolean = true) =
assertItemWithDescriptionExists(scanButton, exists = visible)
assertUIObjectExists(scanButton, exists = visible)
fun verifyVoiceSearchButtonVisibility(enabled: Boolean) =
assertItemWithDescriptionExists(voiceSearchButton, exists = enabled)
assertUIObjectExists(voiceSearchButton, exists = enabled)
// Device or AVD requires a Google Services Android OS installation
fun startVoiceSearch() {
@ -141,7 +139,7 @@ class SearchRobot {
}
fun verifyAllowSuggestionsInPrivateModeDialog() =
assertItemContainingTextExists(
assertUIObjectExists(
itemWithText(getStringResource(R.string.search_suggestions_onboarding_title)),
itemWithText(getStringResource(R.string.search_suggestions_onboarding_text)),
itemWithText("Learn more"),
@ -161,14 +159,14 @@ class SearchRobot {
).click()
}
fun verifySearchSelectorButton() = assertItemWithResIdExists(searchSelectorButton)
fun verifySearchSelectorButton() = assertUIObjectExists(searchSelectorButton)
fun clickSearchSelectorButton() {
searchSelectorButton.waitForExists(waitingTime)
searchSelectorButton.click()
}
fun verifySearchEngineIcon(name: String) = assertItemWithDescriptionExists(itemWithDescription(name))
fun verifySearchEngineIcon(name: String) = assertUIObjectExists(itemWithDescription(name))
fun verifySearchBarPlaceholder(text: String) {
browserToolbarEditView().waitForExists(waitingTime)
@ -178,11 +176,11 @@ class SearchRobot {
fun verifySearchShortcutListContains(vararg searchEngineName: String, shouldExist: Boolean = true) {
searchEngineName.forEach {
if (shouldExist) {
assertItemWithResIdExists(
assertUIObjectExists(
searchShortcutList.getChild(UiSelector().text(it)),
)
} else {
assertItemWithResIdIsGone(searchShortcutList.getChild(UiSelector().text(it)))
assertUIObjectIsGone(searchShortcutList.getChild(UiSelector().text(it)))
}
}
}
@ -295,10 +293,10 @@ class SearchRobot {
try {
searchWrapper().waitForExists(waitingTime)
mDevice.pressBack()
assertItemWithResIdIsGone(searchWrapper())
assertUIObjectIsGone(searchWrapper())
} catch (e: AssertionError) {
mDevice.pressBack()
assertItemWithResIdIsGone(searchWrapper())
assertUIObjectIsGone(searchWrapper())
}
HomeScreenRobot().interact()
@ -321,7 +319,7 @@ class SearchRobot {
mDevice.pressEnter()
runWithIdleRes(sessionLoadedIdlingResource) {
assertItemWithResIdExists(itemWithResId("$packageName:id/browserLayout"))
assertUIObjectExists(itemWithResId("$packageName:id/browserLayout"))
}
BrowserRobot().interact()

@ -48,7 +48,7 @@ import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_PLAY_SERVICES
import org.mozilla.fenix.helpers.Constants.RETRY_COUNT
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
@ -77,7 +77,7 @@ class SettingsRobot {
fun verifyAccessibilityButton() = assertAccessibilityButton()
fun verifySetAsDefaultBrowserButton() = assertSetAsDefaultBrowserButton()
fun verifyTabsButton() =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.preferences_tabs)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.preferences_tabs)))
fun verifyHomepageButton() = assertHomepageButton()
fun verifyAutofillButton() = assertAutofillButton()
fun verifyLanguageButton() = assertLanguageButton()
@ -186,8 +186,8 @@ class SettingsRobot {
// ABOUT SECTION
fun verifyAboutHeading() = assertAboutHeading()
fun verifyRateOnGooglePlay() = assertItemContainingTextExists(rateOnGooglePlayHeading())
fun verifyAboutFirefoxPreview() = assertItemContainingTextExists(aboutFirefoxHeading())
fun verifyRateOnGooglePlay() = assertUIObjectExists(rateOnGooglePlayHeading())
fun verifyAboutFirefoxPreview() = assertUIObjectExists(aboutFirefoxHeading())
fun verifyGooglePlayRedirect() = assertGooglePlayRedirect()
fun verifySettingsOptionSummary(setting: String, summary: String) {
@ -639,7 +639,7 @@ private fun aboutFirefoxHeading(): UiObject {
for (i in 1..RETRY_COUNT) {
try {
settingsList().scrollToEnd(LISTS_MAXSWIPES)
assertItemContainingTextExists(itemWithText("About $appName"))
assertUIObjectExists(itemWithText("About $appName"))
break
} catch (e: AssertionError) {

@ -29,7 +29,7 @@ import org.hamcrest.CoreMatchers.containsString
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.LISTS_MAXSWIPES
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.appName
@ -155,7 +155,7 @@ private fun assertCrashes() {
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.perform(click())
assertItemContainingTextExists(itemContainingText("No crash reports have been submitted."))
assertUIObjectExists(itemContainingText("No crash reports have been submitted."))
for (i in 1..3) {
Espresso.pressBack()

@ -35,8 +35,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.RETRY_COUNT
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeLong
@ -54,7 +53,7 @@ import org.mozilla.fenix.helpers.ext.waitNotNull
class SettingsSubMenuAddonsManagerRobot {
fun verifyAddonsListIsDisplayed(shouldBeDisplayed: Boolean) =
assertItemWithResIdExists(addonsList(), exists = shouldBeDisplayed)
assertUIObjectExists(addonsList(), exists = shouldBeDisplayed)
fun verifyAddonPermissionPrompt(addonName: String) {
mDevice.waitNotNull(Until.findObject(By.text("Add $addonName?")), waitingTime)
@ -96,7 +95,7 @@ class SettingsSubMenuAddonsManagerRobot {
fun verifyAddonInstallCompleted(addonName: String, activityTestRule: HomeActivityIntentTestRule) {
for (i in 1..RETRY_COUNT) {
try {
assertItemContainingTextExists(itemWithText("Okay, Got it"), waitingTime = waitingTimeLong)
assertUIObjectExists(itemWithText("Okay, Got it"), waitingTime = waitingTimeLong)
break
} catch (e: AssertionError) {
@ -151,7 +150,7 @@ class SettingsSubMenuAddonsManagerRobot {
fun verifyAddonCanBeInstalled(addonName: String) = assertAddonCanBeInstalled(addonName)
fun selectAllowInPrivateBrowsing() {
assertItemContainingTextExists(itemWithText("Allow in private browsing"), waitingTime = waitingTimeLong)
assertUIObjectExists(itemWithText("Allow in private browsing"), waitingTime = waitingTimeLong)
onView(withId(R.id.allow_in_private_browsing)).click()
}

@ -20,9 +20,7 @@ import org.junit.Assert.assertEquals
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
@ -36,16 +34,16 @@ import org.mozilla.fenix.helpers.click
class SettingsSubMenuAutofillRobot {
fun verifyAutofillToolbarTitle() {
assertItemContainingTextExists(autofillToolbarTitle)
assertUIObjectExists(autofillToolbarTitle)
Log.i(TAG, "verifyAutofillToolbarTitle: Verified \"Autofill\" toolbar title exists")
}
fun verifyManageAddressesToolbarTitle() {
assertItemContainingTextExists(manageAddressesToolbarTitle)
assertUIObjectExists(manageAddressesToolbarTitle)
Log.i(TAG, "verifyManageAddressesToolbarTitle: Verified \"Manage addresses\" toolbar title exists")
}
fun verifyAddressAutofillSection(isAddressAutofillEnabled: Boolean, userHasSavedAddress: Boolean) {
assertItemContainingTextExists(
assertUIObjectExists(
autofillToolbarTitle,
addressesSectionTitle,
saveAndAutofillAddressesOption,
@ -53,16 +51,16 @@ class SettingsSubMenuAutofillRobot {
)
if (userHasSavedAddress) {
assertItemContainingTextExists(manageAddressesButton)
assertUIObjectExists(manageAddressesButton)
} else {
assertItemContainingTextExists(addAddressButton)
assertUIObjectExists(addAddressButton)
}
verifyAddressesAutofillToggle(isAddressAutofillEnabled)
}
fun verifyCreditCardsAutofillSection(isAddressAutofillEnabled: Boolean, userHasSavedCreditCard: Boolean) {
assertItemContainingTextExists(
assertUIObjectExists(
autofillToolbarTitle,
creditCardsSectionTitle,
saveAndAutofillCreditCardsOption,
@ -72,29 +70,29 @@ class SettingsSubMenuAutofillRobot {
)
if (userHasSavedCreditCard) {
assertItemContainingTextExists(manageSavedCreditCardsButton)
assertUIObjectExists(manageSavedCreditCardsButton)
} else {
assertItemContainingTextExists(addCreditCardButton)
assertUIObjectExists(addCreditCardButton)
}
verifySaveAndAutofillCreditCardsToggle(isAddressAutofillEnabled)
}
fun verifyManageAddressesSection(vararg savedAddressDetails: String) {
assertItemWithDescriptionExists(navigateBackButton)
assertItemContainingTextExists(
assertUIObjectExists(
navigateBackButton,
manageAddressesToolbarTitle,
addAddressButton,
)
for (savedAddressDetail in savedAddressDetails) {
assertItemContainingTextExists(itemContainingText(savedAddressDetail))
assertUIObjectExists(itemContainingText(savedAddressDetail))
Log.i(TAG, "verifyManageAddressesSection: Verified saved address detail: $savedAddressDetail exists")
}
}
fun verifySavedCreditCardsSection(creditCardLastDigits: String, creditCardExpiryDate: String) {
assertItemWithDescriptionExists(navigateBackButton)
assertItemContainingTextExists(
assertUIObjectExists(
navigateBackButton,
savedCreditCardsToolbarTitle,
addCreditCardButton,
itemContainingText(creditCardLastDigits),
@ -139,34 +137,34 @@ class SettingsSubMenuAutofillRobot {
)
fun verifyAddAddressView() {
assertItemContainingTextExists(addAddressToolbarTitle)
assertItemWithDescriptionExists(navigateBackButton)
assertItemWithResIdExists(
assertUIObjectExists(
addAddressToolbarTitle,
navigateBackButton,
toolbarCheckmarkButton,
firstNameTextInput,
middleNameTextInput,
)
scrollToElementByText(getStringResource(R.string.addresses_street_address))
Log.i(TAG, "verifyAddAddressView: Scrolled to \"Street Address\" text input")
assertItemWithResIdExists(
assertUIObjectExists(
lastNameTextInput,
streetAddressTextInput,
)
scrollToElementByText(getStringResource(R.string.addresses_country))
Log.i(TAG, "verifyAddAddressView: Scrolled to \"Country or region\" dropdown")
assertItemWithResIdExists(
assertUIObjectExists(
cityTextInput,
subRegionDropDown,
zipCodeTextInput,
)
scrollToElementByText(getStringResource(R.string.addresses_save_button))
Log.i(TAG, "verifyAddAddressView: Scrolled to \"Save\" button")
assertItemWithResIdExists(
assertUIObjectExists(
countryDropDown,
phoneTextInput,
emailTextInput,
)
assertItemWithResIdExists(
assertUIObjectExists(
saveButton,
cancelButton,
)
@ -177,18 +175,18 @@ class SettingsSubMenuAutofillRobot {
Log.i(TAG, "verifyCountryOption: Scrolled to \"Country or region\" dropdown")
mDevice.pressBack()
Log.i(TAG, "fillAndSaveAddress: Dismissed \"Country or region\" dropdown using device back button")
assertItemContainingTextExists(itemContainingText(country))
assertUIObjectExists(itemContainingText(country))
}
fun verifyStateOption(state: String) {
assertItemContainingTextExists(itemContainingText(state))
assertUIObjectExists(itemContainingText(state))
}
fun verifyCountryOptions(vararg countries: String) {
countryDropDown.click()
Log.i(TAG, "verifyCountryOptions: Clicked \"Country or region\" dropdown")
for (country in countries) {
assertItemContainingTextExists(itemContainingText(country))
assertUIObjectExists(itemContainingText(country))
}
}
@ -200,9 +198,9 @@ class SettingsSubMenuAutofillRobot {
}
fun verifyEditAddressView() {
assertItemContainingTextExists(editAddressToolbarTitle)
assertItemWithDescriptionExists(navigateBackButton)
assertItemWithResIdExists(
assertUIObjectExists(
editAddressToolbarTitle,
navigateBackButton,
toolbarDeleteAddressButton,
toolbarCheckmarkButton,
firstNameTextInput,
@ -210,29 +208,29 @@ class SettingsSubMenuAutofillRobot {
)
scrollToElementByText(getStringResource(R.string.addresses_street_address))
Log.i(TAG, "verifyEditAddressView: Scrolled to \"Street Address\" text input")
assertItemWithResIdExists(
assertUIObjectExists(
lastNameTextInput,
streetAddressTextInput,
)
scrollToElementByText(getStringResource(R.string.addresses_country))
Log.i(TAG, "verifyEditAddressView: Scrolled to \"Country or region\" dropdown")
assertItemWithResIdExists(
assertUIObjectExists(
cityTextInput,
subRegionDropDown,
zipCodeTextInput,
)
scrollToElementByText(getStringResource(R.string.addresses_save_button))
Log.i(TAG, "verifyEditAddressView: Scrolled to \"Save\" button")
assertItemWithResIdExists(
assertUIObjectExists(
countryDropDown,
phoneTextInput,
emailTextInput,
)
assertItemWithResIdExists(
assertUIObjectExists(
saveButton,
cancelButton,
)
assertItemContainingTextExists(deleteAddressButton)
assertUIObjectExists(deleteAddressButton)
}
fun clickSaveAndAutofillAddressesOption() {
@ -284,7 +282,7 @@ class SettingsSubMenuAutofillRobot {
Log.i(TAG, "clickCountryOption: Clicked \"Country or region\" $country dropdown option")
}
fun verifyAddAddressButton() {
assertItemContainingTextExists(addAddressButton)
assertUIObjectExists(addAddressButton)
Log.i(TAG, "verifyAddAddressButton: Verified \"Add address\" button exists")
}
@ -376,7 +374,7 @@ class SettingsSubMenuAutofillRobot {
expiryYearOption(expiryYear).click()
}
fun verifyAddCreditCardsButton() = assertItemContainingTextExists(addCreditCardButton)
fun verifyAddCreditCardsButton() = assertUIObjectExists(addCreditCardButton)
fun fillAndSaveCreditCard(cardNumber: String, cardName: String, expiryMonth: String, expiryYear: String) {
creditCardNumberTextInput.waitForExists(waitingTime)
@ -411,10 +409,9 @@ class SettingsSubMenuAutofillRobot {
expiryMonth: String,
expiryYear: String,
) {
assertItemContainingTextExists(editCreditCardToolbarTitle)
assertItemWithDescriptionExists(navigateBackButton)
assertItemWithResIdExists(
assertUIObjectExists(
editCreditCardToolbarTitle,
navigateBackButton,
deleteCreditCardToolbarButton,
saveCreditCardToolbarButton,
)
@ -423,31 +420,31 @@ class SettingsSubMenuAutofillRobot {
assertEquals(cardName, nameOnCreditCardTextInput.text)
// Can't get the text from the drop-down items, need to verify them individually
assertItemWithResIdExists(
assertUIObjectExists(
expiryYearDropDown,
expiryMonthDropDown,
)
assertItemContainingTextExists(
assertUIObjectExists(
itemContainingText(expiryMonth),
itemContainingText(expiryYear),
)
assertItemWithResIdExists(
assertUIObjectExists(
saveButton,
cancelButton,
)
assertItemContainingTextExists(deleteCreditCardMenuButton)
assertUIObjectExists(deleteCreditCardMenuButton)
}
fun verifyEditCreditCardToolbarTitle() = assertItemContainingTextExists(editCreditCardToolbarTitle)
fun verifyEditCreditCardToolbarTitle() = assertUIObjectExists(editCreditCardToolbarTitle)
fun verifyCreditCardNumberErrorMessage() =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.credit_cards_number_validation_error_message)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.credit_cards_number_validation_error_message)))
fun verifyNameOnCreditCardErrorMessage() =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.credit_cards_name_on_card_validation_error_message)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.credit_cards_name_on_card_validation_error_message)))
class Transition {
fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {

@ -1,142 +1,140 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ui.robots
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
import androidx.test.espresso.matcher.ViewMatchers.withClassName
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.endsWith
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.TestHelper.hasCousin
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.click
/**
* Implementation of Robot Pattern for the settings Data Collection sub menu.
*/
class SettingsSubMenuDataCollectionRobot {
fun verifyDataCollectionView(
isUsageAndTechnicalDataEnabled: Boolean,
isMarketingDataEnabled: Boolean,
studiesSummary: String,
) {
assertItemWithDescriptionExists(goBackButton())
assertItemContainingTextExists(
itemContainingText(getStringResource(R.string.preferences_data_collection)),
itemContainingText(getStringResource(R.string.preference_usage_data)),
itemContainingText(getStringResource(R.string.preferences_usage_data_description)),
)
verifyUsageAndTechnicalDataToggle(isUsageAndTechnicalDataEnabled)
assertItemContainingTextExists(
itemContainingText(getStringResource(R.string.preferences_marketing_data)),
itemContainingText(getStringResource(R.string.preferences_marketing_data_description2)),
)
verifyMarketingDataToggle(isMarketingDataEnabled)
assertItemContainingTextExists(
itemContainingText(getStringResource(R.string.preference_experiments_2)),
itemContainingText(studiesSummary),
)
}
fun verifyUsageAndTechnicalDataToggle(enabled: Boolean) =
onView(withText(R.string.preference_usage_data))
.check(
matches(
hasCousin(
allOf(
withClassName(endsWith("Switch")),
if (enabled) {
isChecked()
} else {
isNotChecked()
},
),
),
),
)
fun verifyMarketingDataToggle(enabled: Boolean) =
onView(withText(R.string.preferences_marketing_data))
.check(
matches(
hasCousin(
allOf(
withClassName(endsWith("Switch")),
if (enabled) {
isChecked()
} else {
isNotChecked()
},
),
),
),
)
fun verifyStudiesToggle(enabled: Boolean) =
onView(withId(R.id.studies_switch))
.check(
matches(
if (enabled) {
isChecked()
} else {
isNotChecked()
},
),
)
fun clickUsageAndTechnicalDataToggle() =
itemContainingText(getStringResource(R.string.preference_usage_data)).click()
fun clickMarketingDataToggle() =
itemContainingText(getStringResource(R.string.preferences_marketing_data)).click()
fun clickStudiesOption() =
itemContainingText(getStringResource(R.string.preference_experiments_2)).click()
fun clickStudiesToggle() =
itemWithResId("$packageName:id/studies_switch").click()
fun verifyStudiesDialog() {
assertItemWithResIdExists(itemWithResId("$packageName:id/alertTitle"))
assertItemContainingTextExists(
itemContainingText(getStringResource(R.string.studies_restart_app)),
)
studiesDialogOkButton.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
studiesDialogCancelButton.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
fun clickStudiesDialogCancelButton() = studiesDialogCancelButton.click()
fun clickStudiesDialogOkButton() = studiesDialogOkButton.click()
class Transition {
fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
goBackButton().click()
SettingsRobot().interact()
return SettingsRobot.Transition()
}
}
}
private fun goBackButton() = itemWithDescription("Navigate up")
private val studiesDialogOkButton = onView(withId(android.R.id.button1)).inRoot(RootMatchers.isDialog())
private val studiesDialogCancelButton = onView(withId(android.R.id.button2)).inRoot(RootMatchers.isDialog())
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ui.robots
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
import androidx.test.espresso.matcher.ViewMatchers.withClassName
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.endsWith
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.TestHelper.hasCousin
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.click
/**
* Implementation of Robot Pattern for the settings Data Collection sub menu.
*/
class SettingsSubMenuDataCollectionRobot {
fun verifyDataCollectionView(
isUsageAndTechnicalDataEnabled: Boolean,
isMarketingDataEnabled: Boolean,
studiesSummary: String,
) {
assertUIObjectExists(
goBackButton(),
itemContainingText(getStringResource(R.string.preferences_data_collection)),
itemContainingText(getStringResource(R.string.preference_usage_data)),
itemContainingText(getStringResource(R.string.preferences_usage_data_description)),
)
verifyUsageAndTechnicalDataToggle(isUsageAndTechnicalDataEnabled)
assertUIObjectExists(
itemContainingText(getStringResource(R.string.preferences_marketing_data)),
itemContainingText(getStringResource(R.string.preferences_marketing_data_description2)),
)
verifyMarketingDataToggle(isMarketingDataEnabled)
assertUIObjectExists(
itemContainingText(getStringResource(R.string.preference_experiments_2)),
itemContainingText(studiesSummary),
)
}
fun verifyUsageAndTechnicalDataToggle(enabled: Boolean) =
onView(withText(R.string.preference_usage_data))
.check(
matches(
hasCousin(
allOf(
withClassName(endsWith("Switch")),
if (enabled) {
isChecked()
} else {
isNotChecked()
},
),
),
),
)
fun verifyMarketingDataToggle(enabled: Boolean) =
onView(withText(R.string.preferences_marketing_data))
.check(
matches(
hasCousin(
allOf(
withClassName(endsWith("Switch")),
if (enabled) {
isChecked()
} else {
isNotChecked()
},
),
),
),
)
fun verifyStudiesToggle(enabled: Boolean) =
onView(withId(R.id.studies_switch))
.check(
matches(
if (enabled) {
isChecked()
} else {
isNotChecked()
},
),
)
fun clickUsageAndTechnicalDataToggle() =
itemContainingText(getStringResource(R.string.preference_usage_data)).click()
fun clickMarketingDataToggle() =
itemContainingText(getStringResource(R.string.preferences_marketing_data)).click()
fun clickStudiesOption() =
itemContainingText(getStringResource(R.string.preference_experiments_2)).click()
fun clickStudiesToggle() =
itemWithResId("$packageName:id/studies_switch").click()
fun verifyStudiesDialog() {
assertUIObjectExists(
itemWithResId("$packageName:id/alertTitle"),
itemContainingText(getStringResource(R.string.studies_restart_app)),
)
studiesDialogOkButton.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
studiesDialogCancelButton.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
fun clickStudiesDialogCancelButton() = studiesDialogCancelButton.click()
fun clickStudiesDialogOkButton() = studiesDialogOkButton.click()
class Transition {
fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
goBackButton().click()
SettingsRobot().interact()
return SettingsRobot.Transition()
}
}
}
private fun goBackButton() = itemWithDescription("Navigate up")
private val studiesDialogOkButton = onView(withId(android.R.id.button1)).inRoot(RootMatchers.isDialog())
private val studiesDialogCancelButton = onView(withId(android.R.id.button2)).inRoot(RootMatchers.isDialog())

@ -1,210 +1,210 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ui.robots
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.UiSelector
import org.hamcrest.CoreMatchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextIsGone
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.assertIsChecked
import org.mozilla.fenix.helpers.click
/**
* Implementation of Robot Pattern for the settings Delete Browsing Data sub menu.
*/
class SettingsSubMenuDeleteBrowsingDataRobot {
fun verifyAllCheckBoxesAreChecked() = assertAllCheckBoxesAreChecked()
fun verifyOpenTabsCheckBox(status: Boolean) = assertOpenTabsCheckBox(status)
fun verifyBrowsingHistoryDetails(status: Boolean) = assertBrowsingHistoryCheckBox(status)
fun verifyCookiesCheckBox(status: Boolean) = assertCookiesCheckBox(status)
fun verifyCachedFilesCheckBox(status: Boolean) = assertCachedFilesCheckBox(status)
fun verifySitePermissionsCheckBox(status: Boolean) = assertSitePermissionsCheckBox(status)
fun verifyDownloadsCheckBox(status: Boolean) = assertDownloadsCheckBox(status)
fun verifyOpenTabsDetails(tabNumber: String) = assertOpenTabsDescription(tabNumber)
fun verifyBrowsingHistoryDetails(addresses: String) = assertBrowsingHistoryDescription(addresses)
fun verifyDeleteBrowsingDataDialog() {
dialogMessage().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
dialogCancelButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
dialogDeleteButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
fun switchOpenTabsCheckBox() = clickOpenTabsCheckBox()
fun switchBrowsingHistoryCheckBox() = clickBrowsingHistoryCheckBox()
fun switchCookiesCheckBox() = clickCookiesCheckBox()
fun switchCachedFilesCheckBox() = clickCachedFilesCheckBox()
fun switchSitePermissionsCheckBox() = clickSitePermissionsCheckBox()
fun switchDownloadsCheckBox() = clickDownloadsCheckBox()
fun clickDeleteBrowsingDataButton() = deleteBrowsingDataButton().click()
fun clickDialogCancelButton() = dialogCancelButton().click()
fun selectOnlyOpenTabsCheckBox() {
clickBrowsingHistoryCheckBox()
assertBrowsingHistoryCheckBox(false)
clickCookiesCheckBox()
assertCookiesCheckBox(false)
clickCachedFilesCheckBox()
assertCachedFilesCheckBox(false)
clickSitePermissionsCheckBox()
assertSitePermissionsCheckBox(false)
clickDownloadsCheckBox()
assertDownloadsCheckBox(false)
assertOpenTabsCheckBox(true)
}
fun selectOnlyBrowsingHistoryCheckBox() {
clickOpenTabsCheckBox()
assertOpenTabsCheckBox(false)
clickCookiesCheckBox()
assertCookiesCheckBox(false)
clickCachedFilesCheckBox()
assertCachedFilesCheckBox(false)
clickSitePermissionsCheckBox()
assertSitePermissionsCheckBox(false)
clickDownloadsCheckBox()
assertDownloadsCheckBox(false)
assertBrowsingHistoryCheckBox(true)
}
fun selectOnlyCookiesCheckBox() {
clickOpenTabsCheckBox()
assertOpenTabsCheckBox(false)
assertCookiesCheckBox(true)
clickCachedFilesCheckBox()
assertCachedFilesCheckBox(false)
clickSitePermissionsCheckBox()
assertSitePermissionsCheckBox(false)
clickDownloadsCheckBox()
assertDownloadsCheckBox(false)
clickBrowsingHistoryCheckBox()
assertBrowsingHistoryCheckBox(false)
}
fun selectOnlyCachedFilesCheckBox() {
clickOpenTabsCheckBox()
assertOpenTabsCheckBox(false)
clickBrowsingHistoryCheckBox()
assertBrowsingHistoryCheckBox(false)
clickCookiesCheckBox()
assertCookiesCheckBox(false)
assertCachedFilesCheckBox(true)
clickSitePermissionsCheckBox()
assertSitePermissionsCheckBox(false)
clickDownloadsCheckBox()
assertDownloadsCheckBox(false)
}
fun confirmDeletionAndAssertSnackbar() {
dialogDeleteButton().click()
assertDeleteBrowsingDataSnackbar()
}
class Transition {
fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
goBackButton().click()
SettingsRobot().interact()
return SettingsRobot.Transition()
}
}
}
private fun goBackButton() =
onView(allOf(withContentDescription("Navigate up")))
private fun deleteBrowsingDataButton() = onView(withId(R.id.delete_data))
private fun dialogDeleteButton() = onView(withText("Delete")).inRoot(isDialog())
private fun dialogCancelButton() = onView(withText("Cancel")).inRoot(isDialog())
private fun openTabsDescription(tabNumber: String) = onView(withText("$tabNumber tabs"))
private fun openTabsCheckBox() = onView(allOf(withId(R.id.checkbox), hasSibling(withText("Open tabs"))))
private fun browsingHistoryDescription(addresses: String) = mDevice.findObject(UiSelector().textContains("$addresses addresses"))
private fun browsingHistoryCheckBox() =
onView(allOf(withId(R.id.checkbox), hasSibling(withText("Browsing history"))))
private fun cookiesAndSiteDataCheckBox() =
onView(allOf(withId(R.id.checkbox), hasSibling(withText("Cookies and site data"))))
private fun cachedFilesCheckBox() =
onView(allOf(withId(R.id.checkbox), hasSibling(withText("Cached images and files"))))
private fun sitePermissionsCheckBox() =
onView(allOf(withId(R.id.checkbox), hasSibling(withText("Site permissions"))))
private fun downloadsCheckBox() =
onView(allOf(withId(R.id.checkbox), hasSibling(withText("Downloads"))))
private fun dialogMessage() =
onView(withText("$appName will delete the selected browsing data."))
.inRoot(isDialog())
private fun assertAllCheckBoxesAreChecked() {
openTabsCheckBox().assertIsChecked(true)
browsingHistoryCheckBox().assertIsChecked(true)
cookiesAndSiteDataCheckBox().assertIsChecked(true)
cachedFilesCheckBox().assertIsChecked(true)
sitePermissionsCheckBox().assertIsChecked(true)
downloadsCheckBox().assertIsChecked(true)
}
private fun assertOpenTabsDescription(tabNumber: String) =
openTabsDescription(tabNumber).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertBrowsingHistoryDescription(addresses: String) =
assertItemContainingTextExists(browsingHistoryDescription(addresses))
private fun assertDeleteBrowsingDataSnackbar() = assertItemContainingTextIsGone(itemWithText("Browsing data deleted"))
private fun clickOpenTabsCheckBox() = openTabsCheckBox().click()
private fun assertOpenTabsCheckBox(status: Boolean) = openTabsCheckBox().assertIsChecked(status)
private fun clickBrowsingHistoryCheckBox() = browsingHistoryCheckBox().click()
private fun assertBrowsingHistoryCheckBox(status: Boolean) = browsingHistoryCheckBox().assertIsChecked(status)
private fun clickCookiesCheckBox() = cookiesAndSiteDataCheckBox().click()
private fun assertCookiesCheckBox(status: Boolean) = cookiesAndSiteDataCheckBox().assertIsChecked(status)
private fun clickCachedFilesCheckBox() = cachedFilesCheckBox().click()
private fun assertCachedFilesCheckBox(status: Boolean) = cachedFilesCheckBox().assertIsChecked(status)
private fun clickSitePermissionsCheckBox() = sitePermissionsCheckBox().click()
private fun assertSitePermissionsCheckBox(status: Boolean) = sitePermissionsCheckBox().assertIsChecked(status)
private fun clickDownloadsCheckBox() = downloadsCheckBox().click()
private fun assertDownloadsCheckBox(status: Boolean) = downloadsCheckBox().assertIsChecked(status)
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ui.robots
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.UiSelector
import org.hamcrest.CoreMatchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectIsGone
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.assertIsChecked
import org.mozilla.fenix.helpers.click
/**
* Implementation of Robot Pattern for the settings Delete Browsing Data sub menu.
*/
class SettingsSubMenuDeleteBrowsingDataRobot {
fun verifyAllCheckBoxesAreChecked() = assertAllCheckBoxesAreChecked()
fun verifyOpenTabsCheckBox(status: Boolean) = assertOpenTabsCheckBox(status)
fun verifyBrowsingHistoryDetails(status: Boolean) = assertBrowsingHistoryCheckBox(status)
fun verifyCookiesCheckBox(status: Boolean) = assertCookiesCheckBox(status)
fun verifyCachedFilesCheckBox(status: Boolean) = assertCachedFilesCheckBox(status)
fun verifySitePermissionsCheckBox(status: Boolean) = assertSitePermissionsCheckBox(status)
fun verifyDownloadsCheckBox(status: Boolean) = assertDownloadsCheckBox(status)
fun verifyOpenTabsDetails(tabNumber: String) = assertOpenTabsDescription(tabNumber)
fun verifyBrowsingHistoryDetails(addresses: String) = assertBrowsingHistoryDescription(addresses)
fun verifyDeleteBrowsingDataDialog() {
dialogMessage().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
dialogCancelButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
dialogDeleteButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
fun switchOpenTabsCheckBox() = clickOpenTabsCheckBox()
fun switchBrowsingHistoryCheckBox() = clickBrowsingHistoryCheckBox()
fun switchCookiesCheckBox() = clickCookiesCheckBox()
fun switchCachedFilesCheckBox() = clickCachedFilesCheckBox()
fun switchSitePermissionsCheckBox() = clickSitePermissionsCheckBox()
fun switchDownloadsCheckBox() = clickDownloadsCheckBox()
fun clickDeleteBrowsingDataButton() = deleteBrowsingDataButton().click()
fun clickDialogCancelButton() = dialogCancelButton().click()
fun selectOnlyOpenTabsCheckBox() {
clickBrowsingHistoryCheckBox()
assertBrowsingHistoryCheckBox(false)
clickCookiesCheckBox()
assertCookiesCheckBox(false)
clickCachedFilesCheckBox()
assertCachedFilesCheckBox(false)
clickSitePermissionsCheckBox()
assertSitePermissionsCheckBox(false)
clickDownloadsCheckBox()
assertDownloadsCheckBox(false)
assertOpenTabsCheckBox(true)
}
fun selectOnlyBrowsingHistoryCheckBox() {
clickOpenTabsCheckBox()
assertOpenTabsCheckBox(false)
clickCookiesCheckBox()
assertCookiesCheckBox(false)
clickCachedFilesCheckBox()
assertCachedFilesCheckBox(false)
clickSitePermissionsCheckBox()
assertSitePermissionsCheckBox(false)
clickDownloadsCheckBox()
assertDownloadsCheckBox(false)
assertBrowsingHistoryCheckBox(true)
}
fun selectOnlyCookiesCheckBox() {
clickOpenTabsCheckBox()
assertOpenTabsCheckBox(false)
assertCookiesCheckBox(true)
clickCachedFilesCheckBox()
assertCachedFilesCheckBox(false)
clickSitePermissionsCheckBox()
assertSitePermissionsCheckBox(false)
clickDownloadsCheckBox()
assertDownloadsCheckBox(false)
clickBrowsingHistoryCheckBox()
assertBrowsingHistoryCheckBox(false)
}
fun selectOnlyCachedFilesCheckBox() {
clickOpenTabsCheckBox()
assertOpenTabsCheckBox(false)
clickBrowsingHistoryCheckBox()
assertBrowsingHistoryCheckBox(false)
clickCookiesCheckBox()
assertCookiesCheckBox(false)
assertCachedFilesCheckBox(true)
clickSitePermissionsCheckBox()
assertSitePermissionsCheckBox(false)
clickDownloadsCheckBox()
assertDownloadsCheckBox(false)
}
fun confirmDeletionAndAssertSnackbar() {
dialogDeleteButton().click()
assertDeleteBrowsingDataSnackbar()
}
class Transition {
fun goBack(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
goBackButton().click()
SettingsRobot().interact()
return SettingsRobot.Transition()
}
}
}
private fun goBackButton() =
onView(allOf(withContentDescription("Navigate up")))
private fun deleteBrowsingDataButton() = onView(withId(R.id.delete_data))
private fun dialogDeleteButton() = onView(withText("Delete")).inRoot(isDialog())
private fun dialogCancelButton() = onView(withText("Cancel")).inRoot(isDialog())
private fun openTabsDescription(tabNumber: String) = onView(withText("$tabNumber tabs"))
private fun openTabsCheckBox() = onView(allOf(withId(R.id.checkbox), hasSibling(withText("Open tabs"))))
private fun browsingHistoryDescription(addresses: String) = mDevice.findObject(UiSelector().textContains("$addresses addresses"))
private fun browsingHistoryCheckBox() =
onView(allOf(withId(R.id.checkbox), hasSibling(withText("Browsing history"))))
private fun cookiesAndSiteDataCheckBox() =
onView(allOf(withId(R.id.checkbox), hasSibling(withText("Cookies and site data"))))
private fun cachedFilesCheckBox() =
onView(allOf(withId(R.id.checkbox), hasSibling(withText("Cached images and files"))))
private fun sitePermissionsCheckBox() =
onView(allOf(withId(R.id.checkbox), hasSibling(withText("Site permissions"))))
private fun downloadsCheckBox() =
onView(allOf(withId(R.id.checkbox), hasSibling(withText("Downloads"))))
private fun dialogMessage() =
onView(withText("$appName will delete the selected browsing data."))
.inRoot(isDialog())
private fun assertAllCheckBoxesAreChecked() {
openTabsCheckBox().assertIsChecked(true)
browsingHistoryCheckBox().assertIsChecked(true)
cookiesAndSiteDataCheckBox().assertIsChecked(true)
cachedFilesCheckBox().assertIsChecked(true)
sitePermissionsCheckBox().assertIsChecked(true)
downloadsCheckBox().assertIsChecked(true)
}
private fun assertOpenTabsDescription(tabNumber: String) =
openTabsDescription(tabNumber).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertBrowsingHistoryDescription(addresses: String) =
assertUIObjectExists(browsingHistoryDescription(addresses))
private fun assertDeleteBrowsingDataSnackbar() = assertUIObjectIsGone(itemWithText("Browsing data deleted"))
private fun clickOpenTabsCheckBox() = openTabsCheckBox().click()
private fun assertOpenTabsCheckBox(status: Boolean) = openTabsCheckBox().assertIsChecked(status)
private fun clickBrowsingHistoryCheckBox() = browsingHistoryCheckBox().click()
private fun assertBrowsingHistoryCheckBox(status: Boolean) = browsingHistoryCheckBox().assertIsChecked(status)
private fun clickCookiesCheckBox() = cookiesAndSiteDataCheckBox().click()
private fun assertCookiesCheckBox(status: Boolean) = cookiesAndSiteDataCheckBox().assertIsChecked(status)
private fun clickCachedFilesCheckBox() = cachedFilesCheckBox().click()
private fun assertCachedFilesCheckBox(status: Boolean) = cachedFilesCheckBox().assertIsChecked(status)
private fun clickSitePermissionsCheckBox() = sitePermissionsCheckBox().click()
private fun assertSitePermissionsCheckBox(status: Boolean) = sitePermissionsCheckBox().assertIsChecked(status)
private fun clickDownloadsCheckBox() = downloadsCheckBox().click()
private fun assertDownloadsCheckBox(status: Boolean) = downloadsCheckBox().assertIsChecked(status)

@ -17,7 +17,7 @@ import androidx.test.uiautomator.UiSelector
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
@ -33,7 +33,7 @@ class SettingsSubMenuEnhancedTrackingProtectionExceptionsRobot {
fun verifyNavigationToolBarHeader() = assertNavigationToolBarHeader()
fun verifyTPExceptionsDefaultView() {
assertItemContainingTextExists(
assertUIObjectExists(
itemWithText("Exceptions let you disable tracking protection for selected sites."),
)
learnMoreLink.check(matches(isDisplayed()))
@ -48,7 +48,7 @@ class SettingsSubMenuEnhancedTrackingProtectionExceptionsRobot {
fun verifySiteExceptionExists(siteUrl: String, shouldExist: Boolean) {
exceptionsList.waitForExists(waitingTime)
assertItemContainingTextExists(itemContainingText(siteUrl), exists = shouldExist)
assertUIObjectExists(itemContainingText(siteUrl), exists = shouldExist)
}
class Transition {

@ -8,7 +8,7 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.uiautomator.UiSelector
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.TestHelper.packageName
@ -48,13 +48,13 @@ class SettingsSubMenuExperimentsRobot {
fun verifyExperimentEnrolled(title: String) {
itemContainingText(title).click()
assertItemWithResIdExists(checkIcon())
assertUIObjectExists(checkIcon())
goBackButton().click()
}
fun verifyExperimentNotEnrolled(title: String) {
itemContainingText(title).click()
assertItemWithResIdExists(checkIcon(), exists = false)
assertUIObjectExists(checkIcon(), exists = false)
goBackButton().click()
}
@ -62,9 +62,9 @@ class SettingsSubMenuExperimentsRobot {
val branch = itemWithResId("$packageName:id/nimbus_branch_name")
itemContainingText(title).click()
assertItemWithResIdExists(checkIcon())
assertUIObjectExists(checkIcon())
branch.click()
assertItemWithResIdExists(checkIcon(), exists = false)
assertUIObjectExists(checkIcon(), exists = false)
}
}
private fun goBackButton() = onView(withContentDescription(R.string.action_bar_up_description))

@ -21,7 +21,7 @@ import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.Matchers
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
import org.mozilla.fenix.helpers.TestHelper
@ -99,7 +99,7 @@ class SettingsSubMenuHomepageRobot {
mDevice.findObject(UiSelector().description(wallpaperName)).click()
fun verifySnackBarText(expectedText: String) =
assertItemContainingTextExists(
assertUIObjectExists(
itemContainingText(expectedText),
)

@ -12,8 +12,7 @@ import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import org.hamcrest.CoreMatchers
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.mDevice
@ -33,11 +32,11 @@ class SettingsSubMenuLanguageRobot {
language(languageName).click()
}
fun verifyLanguageHeaderIsTranslated(translation: String) = assertItemContainingTextExists(itemWithText(translation))
fun verifyLanguageHeaderIsTranslated(translation: String) = assertUIObjectExists(itemWithText(translation))
fun verifySelectedLanguage(language: String) {
languagesList.waitForExists(waitingTime)
assertItemWithResIdExists(
assertUIObjectExists(
languagesList
.getChildByText(UiSelector().text(language), language, true)
.getFromParent(UiSelector().resourceId("$packageName:id/locale_selected_icon")),
@ -54,13 +53,13 @@ class SettingsSubMenuLanguageRobot {
}
fun verifySearchResultsContains(languageName: String) =
assertItemContainingTextExists(language(languageName))
assertUIObjectExists(language(languageName))
fun clearSearchBar() {
onView(withId(R.id.search_close_btn)).click()
}
fun verifyLanguageListIsDisplayed() = assertItemWithResIdExists(languagesList)
fun verifyLanguageListIsDisplayed() = assertUIObjectExists(languagesList)
class Transition {

@ -24,11 +24,8 @@ import org.hamcrest.CoreMatchers.containsString
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.MatcherHelper.assertCheckedItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemIsEnabledAndVisible
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithClassNameAndIndexExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.checkedItemWithResId
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithClassNameAndIndex
@ -72,25 +69,25 @@ class SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot {
itemContainingText(getStringResource(R.string.preferences_logins_add_login)).click()
fun verifyAddNewLoginView() {
assertItemWithResIdExists(
assertUIObjectExists(
siteHeader,
siteTextInput,
usernameHeader,
usernameTextInput,
passwordHeader,
passwordTextInput,
siteDescription,
)
assertItemContainingTextExists(siteDescription)
siteTextInputHint.check(matches(withHint(R.string.add_login_hostname_hint_text)))
}
fun enterSiteCredential(website: String) = siteTextInput.setText(website)
fun verifyHostnameErrorMessage() =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.add_login_hostname_invalid_text_2)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.add_login_hostname_invalid_text_2)))
fun verifyPasswordErrorMessage() =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.saved_login_password_required)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.saved_login_password_required)))
fun verifyPasswordClearButtonEnabled() =
assertItemIsEnabledAndVisible(itemWithResId("$packageName:id/clearPasswordTextButton"))
@ -103,15 +100,15 @@ class SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot {
fun clickSavedLoginsChevronIcon() = itemWithResId("$packageName:id/toolbar_chevron_icon").click()
fun verifyLoginsSortingOptions() {
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.saved_logins_sort_strategy_alphabetically)))
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.saved_logins_sort_strategy_last_used)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.saved_logins_sort_strategy_alphabetically)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.saved_logins_sort_strategy_last_used)))
}
fun clickLastUsedSortingOption() =
itemContainingText(getStringResource(R.string.saved_logins_sort_strategy_last_used)).click()
fun verifySortedLogin(position: Int, loginTitle: String) =
assertItemWithClassNameAndIndexExists(
assertUIObjectExists(
itemWithClassNameAndIndex(className = "android.view.ViewGroup", index = position)
.getChild(
UiSelector()
@ -126,7 +123,7 @@ class SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot {
fun verifySavedLoginsSectionUsername(username: String) =
mDevice.waitNotNull(Until.findObjects(By.text(username)))
fun verifyLoginItemUsername(username: String) = assertItemContainingTextExists(itemContainingText(username))
fun verifyLoginItemUsername(username: String) = assertUIObjectExists(itemContainingText(username))
fun verifyNotSavedLoginFromPrompt() = onView(withText("test@example.com"))
.check(ViewAssertions.doesNotExist())
@ -144,7 +141,7 @@ class SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot {
fun clickDeleteLoginButton() = itemContainingText("Delete").click()
fun verifyLoginDeletionPrompt() =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.login_deletion_confirmation)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.login_deletion_confirmation)))
fun clickConfirmDeleteLogin() =
onView(withId(android.R.id.button1)).inRoot(RootMatchers.isDialog()).click()
@ -163,7 +160,7 @@ class SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot {
fun saveEditedLogin() = itemWithResId("$packageName:id/save_login_button").click()
fun verifySaveLoginButtonIsEnabled(isEnabled: Boolean) =
assertCheckedItemWithResIdExists(
assertUIObjectExists(
checkedItemWithResId("$packageName:id/save_login_button", isChecked = true),
exists = isEnabled,
)
@ -174,10 +171,10 @@ class SettingsSubMenuLoginsAndPasswordsSavedLoginsRobot {
onView(withId(R.id.passwordText)).check(matches(withText(password)))
fun verifyUserNameRequiredErrorMessage() =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.saved_login_username_required)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.saved_login_username_required)))
fun verifyPasswordRequiredErrorMessage() =
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.saved_login_password_required)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.saved_login_password_required)))
fun clickGoBackButton() = goBackButton().click()

@ -12,8 +12,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import org.hamcrest.CoreMatchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.TestHelper.mDevice
@ -25,8 +24,8 @@ import org.mozilla.fenix.helpers.isChecked
class SettingsSubMenuOpenLinksInAppsRobot {
fun verifyOpenLinksInAppsView(selectedOpenLinkInAppsOption: String) {
assertItemWithDescriptionExists(goBackButton)
assertItemContainingTextExists(
assertUIObjectExists(
goBackButton,
itemContainingText(getStringResource(R.string.preferences_open_links_in_apps)),
itemContainingText(getStringResource(R.string.preferences_open_links_in_apps_always)),
itemContainingText(getStringResource(R.string.preferences_open_links_in_apps_ask)),
@ -36,8 +35,8 @@ class SettingsSubMenuOpenLinksInAppsRobot {
}
fun verifyPrivateOpenLinksInAppsView(selectedOpenLinkInAppsOption: String) {
assertItemWithDescriptionExists(goBackButton)
assertItemContainingTextExists(
assertUIObjectExists(
goBackButton,
itemContainingText(getStringResource(R.string.preferences_open_links_in_apps)),
itemContainingText(getStringResource(R.string.preferences_open_links_in_apps_ask)),
itemContainingText(getStringResource(R.string.preferences_open_links_in_apps_never)),

@ -21,7 +21,7 @@ import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.MatcherHelper.assertCheckedItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.checkedItemWithResId
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.appName
@ -138,7 +138,7 @@ private fun assertOpenLinksInPrivateTabEnabled() =
openLinksInPrivateTabSwitch().check(matches(isEnabled(true)))
private fun assertOpenLinksInPrivateTabOff() {
assertCheckedItemWithResIdExists(
assertUIObjectExists(
checkedItemWithResId("android:id/switch_widget", isChecked = true),
exists = false,
)

@ -45,8 +45,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getAvailableSearchEngines
import org.mozilla.fenix.helpers.DataGenerationHelper.getRegionSearchEnginesList
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
@ -95,7 +94,7 @@ class SettingsSubMenuSearchRobot {
}
fun verifyEnginesShortcutsListHeader() =
assertItemContainingTextExists(itemWithText("Engines visible on the search menu"))
assertUIObjectExists(itemWithText("Engines visible on the search menu"))
fun verifyAddressBarSectionHeader() {
onView(withText("Address bar - Firefox Suggest")).check(matches(isDisplayed()))
@ -111,7 +110,7 @@ class SettingsSubMenuSearchRobot {
defaultSearchEngineOption("DuckDuckGo")
.check(matches(hasSibling(withId(R.id.engine_icon))))
.check(matches(isDisplayed()))
assertItemContainingTextExists(addSearchEngineButton)
assertUIObjectExists(addSearchEngineButton)
}
fun verifyManageShortcutsList(testRule: ComposeTestRule) {
@ -123,7 +122,7 @@ class SettingsSubMenuSearchRobot {
.assertIsDisplayed()
}
assertItemContainingTextExists(addSearchEngineButton)
assertUIObjectExists(addSearchEngineButton)
}
/**
@ -242,7 +241,7 @@ class SettingsSubMenuSearchRobot {
fun openAddSearchEngineMenu() = addSearchEngineButton.click()
fun verifyEngineListContains(searchEngineName: String, shouldExist: Boolean) =
assertItemContainingTextExists(itemWithText(searchEngineName), exists = shouldExist)
assertUIObjectExists(itemWithText(searchEngineName), exists = shouldExist)
fun verifyDefaultSearchEngineSelected(searchEngineName: String) {
defaultSearchEngineOption(searchEngineName).check(matches(isChecked(true)))
@ -261,13 +260,13 @@ class SettingsSubMenuSearchRobot {
try {
mDevice.findObject(By.res("$packageName:id/edit_engine_name")).clear()
mDevice.findObject(By.res("$packageName:id/edit_engine_name")).text = engineName
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdAndText("$packageName:id/edit_engine_name", engineName),
)
mDevice.findObject(By.res("$packageName:id/edit_search_string")).clear()
mDevice.findObject(By.res("$packageName:id/edit_search_string")).text = engineURL
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdAndText("$packageName:id/edit_search_string", engineURL),
)
} catch (e: AssertionError) {
@ -275,12 +274,12 @@ class SettingsSubMenuSearchRobot {
mDevice.findObject(By.res("$packageName:id/edit_engine_name")).clear()
mDevice.findObject(By.res("$packageName:id/edit_engine_name")).setText(engineName)
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdAndText("$packageName:id/edit_engine_name", engineName),
)
mDevice.findObject(By.res("$packageName:id/edit_search_string")).clear()
mDevice.findObject(By.res("$packageName:id/edit_search_string")).setText(engineURL)
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdAndText("$packageName:id/edit_search_string", engineURL),
)
}
@ -324,7 +323,7 @@ class SettingsSubMenuSearchRobot {
fun saveEditSearchEngine() {
onView(withId(R.id.save_button)).click()
assertItemContainingTextExists(itemContainingText("Saved"))
assertUIObjectExists(itemContainingText("Saved"))
}
fun verifyInvalidTemplateSearchStringFormatError() {

@ -16,9 +16,7 @@ import androidx.test.uiautomator.UiSelector
import org.hamcrest.CoreMatchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithClassNameExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithClassName
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
@ -28,7 +26,6 @@ import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.assertIsChecked
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.helpers.isChecked
/**
* Implementation of Robot Pattern for the settings Site Permissions sub menu.
@ -137,7 +134,7 @@ class SettingsSubMenuSitePermissionsCommonRobot {
}
fun verifySystemGrantedPermission(permissionCategory: String) {
assertItemWithClassNameExists(
assertUIObjectExists(
itemWithClassName("android.widget.RelativeLayout")
.getChild(
UiSelector()
@ -153,10 +150,11 @@ class SettingsSubMenuSitePermissionsCommonRobot {
)
}
fun verifyNotificationToolbar() {
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.preference_phone_feature_notification)))
assertItemWithDescriptionExists(itemWithDescription(getStringResource(R.string.action_bar_up_description)))
}
fun verifyNotificationToolbar() =
assertUIObjectExists(
itemContainingText(getStringResource(R.string.preference_phone_feature_notification)),
itemWithDescription(getStringResource(R.string.action_bar_up_description)),
)
fun selectAutoplayOption(text: String) {
when (text) {
@ -235,12 +233,12 @@ private fun assertCheckAutoPayRadioButtonDefault() {
private fun assertBlockedByAndroid() {
blockedByAndroidContainer().waitForExists(waitingTime)
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.phone_feature_blocked_by_android)))
assertUIObjectExists(itemContainingText(getStringResource(R.string.phone_feature_blocked_by_android)))
}
private fun assertUnblockedByAndroid() {
blockedByAndroidContainer().waitUntilGone(waitingTime)
assertItemContainingTextExists(itemContainingText(getStringResource(R.string.phone_feature_blocked_by_android)), exists = false)
assertUIObjectExists(itemContainingText(getStringResource(R.string.phone_feature_blocked_by_android)), exists = false)
}
private fun blockedByAndroidContainer() = mDevice.findObject(UiSelector().resourceId("$packageName:id/permissions_blocked_container"))

@ -16,7 +16,7 @@ import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextIsGone
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectIsGone
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.mDevice
@ -38,7 +38,7 @@ class SettingsSubMenuSitePermissionsExceptionsRobot {
exceptionsList.waitForExists(waitingTime)
onView(withText(containsString(url))).check(matches(isDisplayed()))
} else {
assertItemContainingTextIsGone(itemContainingText(url))
assertUIObjectIsGone(itemContainingText(url))
}
}

@ -23,9 +23,7 @@ import org.hamcrest.Matchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
@ -56,7 +54,7 @@ class ShareOverlayRobot {
// This function verifies the share layout when a single tab is shared - no tab info shown
fun verifyShareTabLayout() {
assertItemWithResIdExists(
assertUIObjectExists(
// Share layout
itemWithResId("$packageName:id/sharingLayout"),
// Send to device section
@ -65,8 +63,6 @@ class ShareOverlayRobot {
itemWithResId("$packageName:id/recentAppsContainer"),
// All actions sections
itemWithResId("$packageName:id/appsList"),
)
assertItemWithResIdAndTextExists(
// Send to device header
itemWithResIdContainingText(
"$packageName:id/accountHeaderText",
@ -82,9 +78,6 @@ class ShareOverlayRobot {
"$packageName:id/apps_link_header",
getStringResource(R.string.share_link_all_apps_subheader),
),
)
assertItemContainingTextExists(
// Save as PDF button
itemContainingText(getStringResource(R.string.share_save_to_pdf)),
)

@ -11,8 +11,8 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.uiautomator.UiSelector
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemTextEquals
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.mDevice
@ -22,7 +22,7 @@ import org.mozilla.fenix.helpers.click
class SitePermissionsRobot {
fun verifyMicrophonePermissionPrompt(url: String) {
try {
assertItemContainingTextExists(itemWithText("Allow $url to use your microphone?"))
assertUIObjectExists(itemWithText("Allow $url to use your microphone?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Dont allow")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Allow")
} catch (e: AssertionError) {
@ -30,7 +30,7 @@ class SitePermissionsRobot {
}.openThreeDotMenu {
}.refreshPage {
}.clickStartMicrophoneButton {
assertItemContainingTextExists(itemWithText("Allow $url to use your microphone?"))
assertUIObjectExists(itemWithText("Allow $url to use your microphone?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Dont allow")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Allow")
}
@ -39,7 +39,7 @@ class SitePermissionsRobot {
fun verifyCameraPermissionPrompt(url: String) {
try {
assertItemContainingTextExists(itemWithText("Allow $url to use your camera?"))
assertUIObjectExists(itemWithText("Allow $url to use your camera?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Dont allow")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Allow")
} catch (e: AssertionError) {
@ -47,7 +47,7 @@ class SitePermissionsRobot {
}.openThreeDotMenu {
}.refreshPage {
}.clickStartCameraButton {
assertItemContainingTextExists(itemWithText("Allow $url to use your camera?"))
assertUIObjectExists(itemWithText("Allow $url to use your camera?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Dont allow")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Allow")
}
@ -55,14 +55,14 @@ class SitePermissionsRobot {
}
fun verifyAudioVideoPermissionPrompt(url: String) {
assertItemContainingTextExists(itemWithText("Allow $url to use your camera and microphone?"))
assertUIObjectExists(itemWithText("Allow $url to use your camera and microphone?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Dont allow")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Allow")
}
fun verifyLocationPermissionPrompt(url: String) {
try {
assertItemContainingTextExists(itemWithText("Allow $url to use your location?"))
assertUIObjectExists(itemWithText("Allow $url to use your location?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Dont allow")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Allow")
} catch (e: AssertionError) {
@ -70,7 +70,7 @@ class SitePermissionsRobot {
}.openThreeDotMenu {
}.refreshPage {
}.clickGetLocationButton {
assertItemContainingTextExists(itemWithText("Allow $url to use your location?"))
assertUIObjectExists(itemWithText("Allow $url to use your location?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Dont allow")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Allow")
}
@ -80,7 +80,7 @@ class SitePermissionsRobot {
fun verifyNotificationsPermissionPrompt(url: String, blocked: Boolean = false) {
if (!blocked) {
try {
assertItemContainingTextExists(itemWithText("Allow $url to send notifications?"))
assertUIObjectExists(itemWithText("Allow $url to send notifications?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Never")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Always")
} catch (e: AssertionError) {
@ -88,7 +88,7 @@ class SitePermissionsRobot {
}.openThreeDotMenu {
}.refreshPage {
}.clickOpenNotificationButton {
assertItemContainingTextExists(itemWithText("Allow $url to send notifications?"))
assertUIObjectExists(itemWithText("Allow $url to send notifications?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Never")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Always")
}
@ -96,13 +96,13 @@ class SitePermissionsRobot {
} else {
/* if "Never" was selected in a previous step, or if the app is not allowed,
the Notifications permission prompt won't be displayed anymore */
assertItemContainingTextExists(itemWithText("Allow $url to send notifications?"), exists = false)
assertUIObjectExists(itemWithText("Allow $url to send notifications?"), exists = false)
}
}
fun verifyPersistentStoragePermissionPrompt(url: String) {
try {
assertItemContainingTextExists(itemWithText("Allow $url to store data in persistent storage?"))
assertUIObjectExists(itemWithText("Allow $url to store data in persistent storage?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Dont allow")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Allow")
} catch (e: AssertionError) {
@ -110,7 +110,7 @@ class SitePermissionsRobot {
}.openThreeDotMenu {
}.refreshPage {
}.clickRequestPersistentStorageAccessButton {
assertItemContainingTextExists(itemWithText("Allow $url to store data in persistent storage?"))
assertUIObjectExists(itemWithText("Allow $url to store data in persistent storage?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Dont allow")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Allow")
}
@ -119,7 +119,7 @@ class SitePermissionsRobot {
fun verifyDRMContentPermissionPrompt(url: String) {
try {
assertItemContainingTextExists(itemWithText("Allow $url to store data in persistent storage?"))
assertUIObjectExists(itemWithText("Allow $url to store data in persistent storage?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Dont allow")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Allow")
} catch (e: AssertionError) {
@ -127,7 +127,7 @@ class SitePermissionsRobot {
}.openThreeDotMenu {
}.refreshPage {
}.clickRequestDRMControlledContentAccessButton {
assertItemContainingTextExists(itemWithText("Allow $url to store data in persistent storage?"))
assertUIObjectExists(itemWithText("Allow $url to store data in persistent storage?"))
assertItemTextEquals(denyPagePermissionButton, expectedText = "Dont allow")
assertItemTextEquals(allowPagePermissionButton, expectedText = "Allow")
}

@ -15,8 +15,7 @@ import androidx.test.uiautomator.UiSelector
import mozilla.components.support.ktx.kotlin.tryGetHostFromUrl
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertCheckedItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
import org.mozilla.fenix.helpers.TestHelper.mDevice
@ -42,11 +41,9 @@ class SiteSecurityRobot {
private fun assertQuickActionSheet(url: String = "", isConnectionSecure: Boolean) {
quickActionSheet().waitForExists(waitingTime)
assertCheckedItemWithResIdAndTextExists(
assertUIObjectExists(
quickActionSheetUrl(url.tryGetHostFromUrl()),
quickActionSheetSecurityInfo(isConnectionSecure),
)
assertItemWithResIdExists(
quickActionSheetTrackingProtectionSwitch(),
quickActionSheetClearSiteData(),
)
@ -54,19 +51,17 @@ private fun assertQuickActionSheet(url: String = "", isConnectionSecure: Boolean
private fun assertSecureConnectionSubMenu(pageTitle: String = "", url: String = "", isConnectionSecure: Boolean) {
secureConnectionSubMenu().waitForExists(waitingTime)
assertCheckedItemWithResIdAndTextExists(
assertUIObjectExists(
secureConnectionSubMenuPageTitle(pageTitle),
secureConnectionSubMenuPageUrl(url),
secureConnectionSubMenuSecurityInfo(isConnectionSecure),
)
assertItemWithResIdExists(
secureConnectionSubMenuLockIcon(),
secureConnectionSubMenuCertificateInfo(),
)
}
private fun assertClearSiteDataPrompt(url: String) {
assertCheckedItemWithResIdAndTextExists(clearSiteDataPrompt(url))
assertUIObjectExists(clearSiteDataPrompt(url))
cancelClearSiteDataButton.check(matches(isDisplayed()))
deleteSiteDataButton.check(matches(isDisplayed()))
}

@ -13,7 +13,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.UiSelector
import org.hamcrest.CoreMatchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.mDevice
@ -28,7 +28,7 @@ class SyncSignInRobot {
fun verifyAccountSettingsMenuHeader() = assertAccountSettingsMenuHeader()
fun verifyTurnOnSyncMenu() {
mDevice.findObject(UiSelector().resourceId("$packageName:id/container")).waitForExists(waitingTime)
assertItemWithResIdExists(
assertUIObjectExists(
itemWithResId("$packageName:id/signInScanButton"),
itemWithResId("$packageName:id/signInEmailButton"),
)

@ -9,7 +9,7 @@ import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import androidx.test.uiautomator.UiSelector
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndDescription
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
@ -65,7 +65,7 @@ fun systemSettings(interact: SystemSettingsRobot.() -> Unit): SystemSettingsRobo
private fun assertSystemNotificationsView() {
mDevice.findObject(UiSelector().resourceId("com.android.settings:id/list"))
.waitForExists(waitingTime)
assertItemContainingTextExists(itemContainingText("All ${TestHelper.appName} notifications"))
assertUIObjectExists(itemContainingText("All ${TestHelper.appName} notifications"))
}
private val allSystemSettingsNotificationsToggle =

@ -39,11 +39,8 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.LONG_CLICK_DURATION
import org.mozilla.fenix.helpers.Constants.RETRY_COUNT
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextIsGone
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectIsGone
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
@ -125,7 +122,7 @@ class TabDrawerRobot {
fun verifyHalfExpandedRatio() = assertMinisculeHalfExpandedRatio()
fun verifyBehaviorState(expectedState: Int) = assertBehaviorState(expectedState)
fun verifyOpenedTabThumbnail() =
assertItemWithResIdExists(itemWithResId("$packageName:id/mozac_browser_tabstray_thumbnail"))
assertUIObjectExists(itemWithResId("$packageName:id/mozac_browser_tabstray_thumbnail"))
fun closeTab() {
closeTabButton().waitForExists(waitingTime)
@ -162,7 +159,7 @@ class TabDrawerRobot {
),
).perform(swipeRight())
Log.i("MozTestLog", "Tab $title swiped right from tabs tray. Retry # $i")
assertItemWithResIdAndTextIsGone(
assertUIObjectIsGone(
itemWithResIdContainingText(
"$packageName:id/mozac_browser_tabstray_title",
title,
@ -193,7 +190,7 @@ class TabDrawerRobot {
),
).perform(swipeLeft())
Log.i("MozTestLog", "Tab $title swiped left from tabs tray. Retry # $i")
assertItemWithResIdAndTextIsGone(
assertUIObjectIsGone(
itemWithResIdContainingText(
"$packageName:id/mozac_browser_tabstray_title",
title,
@ -210,7 +207,7 @@ class TabDrawerRobot {
}
fun verifySnackBarText(expectedText: String) =
assertItemContainingTextExists(itemContainingText(expectedText))
assertUIObjectExists(itemContainingText(expectedText))
fun snackBarButtonClick(expectedText: String) {
val snackBarButton =
@ -224,7 +221,7 @@ class TabDrawerRobot {
snackBarButton.click()
}
fun verifyTabMediaControlButtonState(action: String) = assertItemWithDescriptionExists(tabMediaControlButton(action))
fun verifyTabMediaControlButtonState(action: String) = assertUIObjectExists(tabMediaControlButton(action))
fun clickTabMediaControlButton(action: String) {
tabMediaControlButton(action).also {
@ -284,18 +281,17 @@ class TabDrawerRobot {
}
fun verifyTabsMultiSelectionCounter(numOfTabs: Int) =
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResId("$packageName:id/multiselect_title"),
itemContainingText("$numOfTabs selected"),
)
fun verifySyncedTabsListWhenUserIsNotSignedIn() {
assertItemWithResIdExists(itemWithResId("$packageName:id/tabsTray"))
assertItemContainingTextExists(
fun verifySyncedTabsListWhenUserIsNotSignedIn() =
assertUIObjectExists(
itemWithResId("$packageName:id/tabsTray"),
itemContainingText(getStringResource(R.string.synced_tabs_sign_in_message)),
itemContainingText(getStringResource(R.string.sync_sign_in)),
)
}
class Transition {
fun openTabDrawer(interact: TabDrawerRobot.() -> Unit): Transition {
@ -482,7 +478,7 @@ private fun closeTabButton() =
mDevice.findObject(UiSelector().descriptionContains("Close tab"))
private fun assertCloseTabsButton(title: String) =
assertItemWithDescriptionExists(
assertUIObjectExists(
itemWithDescription("Close tab").getFromParent(UiSelector().textContains(title)),
)
@ -507,14 +503,14 @@ private fun assertExistingOpenTabs(vararg tabTitles: String) {
while (!tabItem(title).waitForExists(waitingTime) && retries++ < 3) {
tabsList
.getChildByText(UiSelector().text(title), title, true)
assertItemContainingTextExists(tabItem(title), waitingTime = waitingTimeLong)
assertUIObjectExists(tabItem(title), waitingTime = waitingTimeLong)
}
}
}
private fun assertNoExistingOpenTabs(vararg tabTitles: String) {
for (title in tabTitles) {
assertItemContainingTextExists(tabItem(title), exists = false)
assertUIObjectExists(tabItem(title), exists = false)
}
}
@ -522,7 +518,7 @@ private fun assertExistingTabList() {
mDevice.findObject(
UiSelector().resourceId("$packageName:id/tabsTray"),
).waitForExists(waitingTime)
assertItemWithResIdExists(itemWithResId("$packageName:id/tray_list_item"))
assertUIObjectExists(itemWithResId("$packageName:id/tray_list_item"))
}
private fun assertNoOpenTabsInNormalBrowsing() =

@ -32,11 +32,7 @@ import org.mozilla.fenix.helpers.Constants.LONG_CLICK_DURATION
import org.mozilla.fenix.helpers.Constants.RETRY_COUNT
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertCheckedItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.checkedItemWithResIdAndText
import org.mozilla.fenix.helpers.MatcherHelper.itemContainingText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
@ -57,10 +53,10 @@ import org.mozilla.fenix.nimbus.FxNimbus
@Suppress("ForbiddenComment")
class ThreeDotMenuMainRobot {
fun verifyShareAllTabsButton() = assertShareAllTabsButton()
fun verifySettingsButton() = assertItemContainingTextExists(settingsButton())
fun verifyHistoryButton() = assertItemContainingTextExists(historyButton)
fun verifySettingsButton() = assertUIObjectExists(settingsButton())
fun verifyHistoryButton() = assertUIObjectExists(historyButton)
fun verifyThreeDotMenuExists() = threeDotMenuRecyclerViewExists()
fun verifyAddBookmarkButton() = assertItemWithResIdAndTextExists(addBookmarkButton)
fun verifyAddBookmarkButton() = assertUIObjectExists(addBookmarkButton)
fun verifyEditBookmarkButton() = assertEditBookmarkButton()
fun verifyCloseAllTabsButton() = assertCloseAllTabsButton()
fun verifyReaderViewAppearance(visible: Boolean) = assertReaderViewAppearanceButton(visible)
@ -70,7 +66,7 @@ class ThreeDotMenuMainRobot {
// In case it reaches the end, the second swipe is no-op.
expandMenu()
expandMenu()
assertItemContainingTextExists(itemWithText("Quit"))
assertUIObjectExists(itemWithText("Quit"))
}
fun expandMenu() {
@ -80,20 +76,20 @@ class ThreeDotMenuMainRobot {
fun verifyShareTabButton() = assertShareTabButton()
fun verifySelectTabs() = assertSelectTabsButton()
fun verifyFindInPageButton() = assertItemContainingTextExists(findInPageButton)
fun verifyFindInPageButton() = assertUIObjectExists(findInPageButton)
fun verifyAddToShortcutsButton(shouldExist: Boolean) =
assertItemContainingTextExists(addToShortcutsButton, exists = shouldExist)
assertUIObjectExists(addToShortcutsButton, exists = shouldExist)
fun verifyRemoveFromShortcutsButton() = assertRemoveFromShortcutsButton()
fun verifyShareTabsOverlay() = assertShareTabsOverlay()
fun verifyDesktopSiteModeEnabled(isRequestDesktopSiteEnabled: Boolean) {
expandMenu()
assertCheckedItemWithResIdAndTextExists(desktopSiteToggle(isRequestDesktopSiteEnabled))
assertUIObjectExists(desktopSiteToggle(isRequestDesktopSiteEnabled))
}
fun verifyPageThreeDotMainMenuItems(isRequestDesktopSiteEnabled: Boolean) {
expandMenu()
assertItemContainingTextExists(
assertUIObjectExists(
normalBrowsingNewTabButton,
bookmarksButton,
historyButton,
@ -106,18 +102,18 @@ class ThreeDotMenuMainRobot {
addToHomeScreenButton,
addToShortcutsButton,
saveToCollectionButton,
addBookmarkButton,
desktopSiteToggle(isRequestDesktopSiteEnabled),
)
assertCheckedItemWithResIdAndTextExists(addBookmarkButton)
assertCheckedItemWithResIdAndTextExists(desktopSiteToggle(isRequestDesktopSiteEnabled))
// Swipe to second part of menu
expandMenu()
assertItemContainingTextExists(
assertUIObjectExists(
settingsButton(),
)
if (FxNimbus.features.print.value().browserPrintEnabled) {
assertItemContainingTextExists(printContentButton)
assertUIObjectExists(printContentButton)
}
assertItemWithDescriptionExists(
assertUIObjectExists(
backButton,
forwardButton,
shareButton,
@ -126,7 +122,7 @@ class ThreeDotMenuMainRobot {
}
fun verifyHomeThreeDotMainMenuItems(isRequestDesktopSiteEnabled: Boolean) {
assertItemContainingTextExists(
assertUIObjectExists(
bookmarksButton,
historyButton,
downloadsButton,
@ -138,9 +134,8 @@ class ThreeDotMenuMainRobot {
helpButton,
customizeHomeButton,
settingsButton(),
desktopSiteToggle(isRequestDesktopSiteEnabled),
)
assertCheckedItemWithResIdAndTextExists(desktopSiteToggle(isRequestDesktopSiteEnabled))
}
private fun assertShareTabsOverlay() {
@ -159,7 +154,7 @@ class ThreeDotMenuMainRobot {
fun verifyAddonAvailableInMainMenu(addonName: String) {
for (i in 1..RETRY_COUNT) {
try {
assertItemContainingTextExists(itemContainingText(addonName))
assertUIObjectExists(itemContainingText(addonName))
break
} catch (e: AssertionError) {
if (i == RETRY_COUNT) {
@ -176,7 +171,7 @@ class ThreeDotMenuMainRobot {
}
fun verifyTrackersBlockedByUblock() {
assertItemWithResIdExists(itemWithResId("$packageName:id/badge_text"))
assertUIObjectExists(itemWithResId("$packageName:id/badge_text"))
assertTrue(itemWithResId("$packageName:id/badge_text").text.toInt() > 0)
}
@ -228,7 +223,7 @@ class ThreeDotMenuMainRobot {
mDevice.waitNotNull(Until.findObject(By.text("Bookmarks")), waitingTime)
bookmarksButton.click()
assertItemWithResIdExists(itemWithResId("$packageName:id/bookmark_list"))
assertUIObjectExists(itemWithResId("$packageName:id/bookmark_list"))
BookmarksRobot().interact()
return BookmarksRobot.Transition()
@ -529,13 +524,13 @@ private fun assertReaderViewAppearanceButton(visible: Boolean) {
threeDotMenuRecyclerView().perform(swipeUp())
maxSwipes--
}
assertItemContainingTextExists(readerViewAppearanceToggle())
assertUIObjectExists(readerViewAppearanceToggle())
} else {
while (!readerViewAppearanceToggle().exists() && maxSwipes != 0) {
threeDotMenuRecyclerView().perform(swipeUp())
maxSwipes--
}
assertItemContainingTextExists(readerViewAppearanceToggle(), exists = false)
assertUIObjectExists(readerViewAppearanceToggle(), exists = false)
}
}

Loading…
Cancel
Save