From a9840d1abbe711bc1630727ca062b6b4f5cce882 Mon Sep 17 00:00:00 2001 From: AndiAJ Date: Wed, 4 Jan 2023 15:01:17 +0200 Subject: [PATCH] [fenix] No issue - Use android resource for positive/negative dialog buttons --- .../fenix/ui/robots/CollectionRobot.kt | 11 ++++--- .../ui/robots/SettingsSubMenuAutofillRobot.kt | 29 +++++++++---------- .../fenix/ui/robots/SiteSecurityRobot.kt | 13 ++++++--- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/CollectionRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/CollectionRobot.kt index 832ae631e8..b48c5644b0 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/CollectionRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/CollectionRobot.kt @@ -7,6 +7,7 @@ package org.mozilla.fenix.ui.robots import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.hasContentDescription import androidx.compose.ui.test.hasText +import androidx.compose.ui.test.isDialog import androidx.compose.ui.test.junit4.ComposeTestRule import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTouchInput @@ -15,6 +16,7 @@ import androidx.compose.ui.test.swipeRight import androidx.test.espresso.Espresso.onView import androidx.test.espresso.NoMatchingViewException import androidx.test.espresso.action.ViewActions.pressImeActionButton +import androidx.test.espresso.matcher.RootMatchers import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.uiautomator.By import androidx.test.uiautomator.UiScrollable @@ -28,6 +30,7 @@ import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime import org.mozilla.fenix.helpers.TestHelper.mDevice import org.mozilla.fenix.helpers.TestHelper.packageName import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText +import org.mozilla.fenix.helpers.click import org.mozilla.fenix.helpers.ext.waitNotNull class CollectionRobot { @@ -59,10 +62,7 @@ class CollectionRobot { fun typeCollectionNameAndSave(collectionName: String) { collectionNameTextField().text = collectionName addCollectionButtonPanel.waitForExists(waitingTime) - addCollectionOkButton.also { - it.waitForExists(waitingTime) - it.click() - } + addCollectionOkButton.click() } fun verifyTabsSelectedCounterText(numOfTabs: Int) { @@ -297,5 +297,4 @@ private fun backButton() = private val addCollectionButtonPanel = itemWithResId("$packageName:id/buttonPanel") -private val addCollectionOkButton = - itemWithResId("android:id/button1") +private val addCollectionOkButton = onView(withId(android.R.id.button1)).inRoot(RootMatchers.isDialog()) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuAutofillRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuAutofillRobot.kt index f133d03d82..f85402855c 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuAutofillRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsSubMenuAutofillRobot.kt @@ -4,6 +4,9 @@ package org.mozilla.fenix.ui.robots +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.matcher.RootMatchers +import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.uiautomator.UiSelector import org.junit.Assert.assertTrue import org.mozilla.fenix.R @@ -12,6 +15,7 @@ import org.mozilla.fenix.helpers.TestHelper.getStringResource import org.mozilla.fenix.helpers.TestHelper.mDevice import org.mozilla.fenix.helpers.TestHelper.packageName import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText +import org.mozilla.fenix.helpers.click class SettingsSubMenuAutofillRobot { @@ -22,14 +26,10 @@ class SettingsSubMenuAutofillRobot { deleteAddressButton.waitForExists(waitingTime) deleteAddressButton.click() } - fun clickCancelDeleteAddressButton() { - cancelDeleteAddressButton.waitForExists(waitingTime) - cancelDeleteAddressButton.click() - } - fun clickConfirmDeleteAddressButton() { - confirmDeleteAddressButton.waitForExists(waitingTime) - confirmDeleteAddressButton.click() - } + fun clickCancelDeleteAddressButton() = cancelDeleteAddressButton.click() + + fun clickConfirmDeleteAddressButton() = confirmDeleteAddressButton.click() + fun clickSubRegionOption(subRegion: String) { subRegionOption(subRegion).waitForExists(waitingTime) subRegionOption(subRegion).click() @@ -81,10 +81,7 @@ class SettingsSubMenuAutofillRobot { deleteCreditCardButton.click() } - fun clickConfirmDeleteCreditCardButton() { - confirmDeleteCreditCardButton.waitForExists(waitingTime) - confirmDeleteCreditCardButton.click() - } + fun clickConfirmDeleteCreditCardButton() = confirmDeleteCreditCardButton.click() fun clickExpiryMonthOption(expiryMonth: String) { expiryMonthOption(expiryMonth).waitForExists(waitingTime) @@ -142,8 +139,8 @@ private val phoneTextInput = mDevice.findObject(UiSelector().resourceId("$packag private val emailTextInput = mDevice.findObject(UiSelector().resourceId("$packageName:id/email_input")) private val saveButton = mDevice.findObject(UiSelector().resourceId("$packageName:id/save_button")) private val deleteAddressButton = mDevice.findObject(UiSelector().resourceId("$packageName:id/delete_address_button")) -private val cancelDeleteAddressButton = mDevice.findObject(UiSelector().resourceId("android:id/button2")) -private val confirmDeleteAddressButton = mDevice.findObject(UiSelector().resourceId("android:id/button1")) +private val cancelDeleteAddressButton = onView(withId(android.R.id.button2)).inRoot(RootMatchers.isDialog()) +private val confirmDeleteAddressButton = onView(withId(android.R.id.button1)).inRoot(RootMatchers.isDialog()) private val addCreditCardButton = mDevice.findObject(UiSelector().textContains(getStringResource(R.string.preferences_credit_cards_add_credit_card))) private val manageSavedCardsButton = mDevice.findObject(UiSelector().textContains(getStringResource(R.string.preferences_credit_cards_manage_saved_cards))) @@ -153,8 +150,8 @@ private val expiryMonthDropDown = mDevice.findObject(UiSelector().resourceId("$p private val expiryYearDropDown = mDevice.findObject(UiSelector().resourceId("$packageName:id/expiry_year_drop_down")) private val savedCreditCardNumber = mDevice.findObject(UiSelector().resourceId("$packageName:id/credit_card_logo")) private val deleteCreditCardButton = mDevice.findObject(UiSelector().resourceId("$packageName:id/delete_credit_card_button")) -private val confirmDeleteCreditCardButton = mDevice.findObject(UiSelector().resourceId("android:id/button1")) -private val securedCreditCardsLaterButton = mDevice.findObject(UiSelector().resourceId("android:id/button2")) +private val confirmDeleteCreditCardButton = onView(withId(android.R.id.button1)).inRoot(RootMatchers.isDialog()) +private val securedCreditCardsLaterButton = onView(withId(android.R.id.button2)).inRoot(RootMatchers.isDialog()) private fun savedAddress(firstName: String) = mDevice.findObject(UiSelector().textContains(firstName)) private fun subRegionOption(subRegion: String) = mDevice.findObject(UiSelector().textContains(subRegion)) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SiteSecurityRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SiteSecurityRobot.kt index 54a96f66ef..1ad88c91f2 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SiteSecurityRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SiteSecurityRobot.kt @@ -6,6 +6,11 @@ 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.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.uiautomator.UiSelector import mozilla.components.support.ktx.kotlin.tryGetHostFromUrl import org.junit.Assert.assertTrue @@ -50,8 +55,8 @@ private fun assertSecureConnectionSubMenu(pageTitle: String = "", url: String = private fun assertClearSiteDataPrompt(url: String) { assertTrue(clearSiteDataPrompt(url).waitForExists(waitingTime)) - assertTrue(cancelClearSiteDataButton.waitForExists(waitingTime)) - assertTrue(deleteSiteDataButton.waitForExists(waitingTime)) + cancelClearSiteDataButton.check(matches(isDisplayed())) + deleteSiteDataButton.check(matches(isDisplayed())) } private fun quickActionSheet() = @@ -145,5 +150,5 @@ private fun clearSiteDataPrompt(url: String) = .textContains(url), ) -private val cancelClearSiteDataButton = mDevice.findObject(UiSelector().resourceId("android:id/button2")) -private val deleteSiteDataButton = mDevice.findObject(UiSelector().resourceId("android:id/button1")) +private val cancelClearSiteDataButton = onView(withId(android.R.id.button2)).inRoot(RootMatchers.isDialog()) +private val deleteSiteDataButton = onView(withId(android.R.id.button1)).inRoot(RootMatchers.isDialog())