Bug 1863515 - Refactor navigation and add logs for address autofill UI tests

fenix/121.0
AndiAJ 7 months ago committed by mergify[bot]
parent c077f1597e
commit 008bc6f38f

@ -8,6 +8,9 @@ import org.mozilla.fenix.helpers.DataGenerationHelper.getSponsoredShortcutTitle
object Constants {
// Tag used for logging
const val TAG = "MozUITestLog"
// Device or AVD requires a Google Services Android OS installation
object PackageName {
const val GOOGLE_PLAY_SERVICES = "com.android.vending"

@ -4,10 +4,12 @@
package org.mozilla.fenix.helpers
import android.util.Log
import androidx.test.uiautomator.UiObject
import androidx.test.uiautomator.UiSelector
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
import org.mozilla.fenix.helpers.TestHelper.mDevice
@ -53,10 +55,12 @@ object MatcherHelper {
if (exists) {
for (appItem in appItems) {
assertTrue(appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemWithResIdExists: Verified ${appItem.selector} exists")
}
} else {
for (appItem in appItems) {
assertFalse(appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertItemWithResIdExists: Verified ${appItem.selector} does not exist")
}
}
}
@ -65,8 +69,10 @@ object MatcherHelper {
for (appItem in appItems) {
if (exists) {
assertTrue(appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemContainingTextExists: Verified ${appItem.selector} exists")
} else {
assertFalse(appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertItemContainingTextExists: Verified ${appItem.selector} does not exist")
}
}
}
@ -75,8 +81,10 @@ object MatcherHelper {
for (appItem in appItems) {
if (exists) {
assertTrue(appItem.waitForExists(waitingTime))
Log.i(TAG, "assertItemContainingTextExists: Verified ${appItem.selector} exists")
} else {
assertFalse(appItem.waitForExists(waitingTimeShort))
Log.i(TAG, "assertItemContainingTextExists: Verified ${appItem.selector} does not exist")
}
}
}

@ -18,6 +18,7 @@ import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.ui.robots.autofillScreen
import org.mozilla.fenix.ui.robots.clickPageObject
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
@ -25,6 +26,36 @@ import org.mozilla.fenix.ui.robots.navigationToolbar
class AddressAutofillTest {
private lateinit var mockWebServer: MockWebServer
object FirstAddressAutofillDetails {
var navigateToAutofillSettings = true
var isAddressAutofillEnabled = true
var userHasSavedAddress = false
var firstName = "Mozilla"
var middleName = "Fenix"
var lastName = "Firefox"
var streetAddress = "Harrison Street"
var city = "San Francisco"
var state = "Alaska"
var zipCode = "94105"
var country = "United States"
var phoneNumber = "555-5555"
var emailAddress = "foo@bar.com"
}
object SecondAddressAutofillDetails {
var navigateToAutofillSettings = false
var firstName = "Android"
var middleName = "Test"
var lastName = "Name"
var streetAddress = "Fort Street"
var city = "San Jose"
var state = "Arizona"
var zipCode = "95141"
var country = "United States"
var phoneNumber = "777-7777"
var emailAddress = "fuu@bar.org"
}
@get:Rule
val activityIntentTestRule = HomeActivityIntentTestRule.withDefaultSettingsOverrides()
@ -48,22 +79,21 @@ class AddressAutofillTest {
val addressFormPage =
TestAssetHelper.getAddressFormAsset(mockWebServer)
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAutofillSubMenu {
clickAddAddressButton()
autofillScreen {
fillAndSaveAddress(
"Mozilla",
"Fenix",
"Firefox",
"Harrison Street",
"San Francisco",
"Alaska",
"94105",
"United States",
"555-5555",
"foo@bar.com",
navigateToAutofillSettings = FirstAddressAutofillDetails.navigateToAutofillSettings,
isAddressAutofillEnabled = FirstAddressAutofillDetails.isAddressAutofillEnabled,
userHasSavedAddress = FirstAddressAutofillDetails.userHasSavedAddress,
firstName = FirstAddressAutofillDetails.firstName,
middleName = FirstAddressAutofillDetails.middleName,
lastName = FirstAddressAutofillDetails.lastName,
streetAddress = FirstAddressAutofillDetails.streetAddress,
city = FirstAddressAutofillDetails.city,
state = FirstAddressAutofillDetails.state,
zipCode = FirstAddressAutofillDetails.zipCode,
country = FirstAddressAutofillDetails.country,
phoneNumber = FirstAddressAutofillDetails.phoneNumber,
emailAddress = FirstAddressAutofillDetails.emailAddress,
)
}.goBack {
}.goBack {
@ -86,22 +116,21 @@ class AddressAutofillTest {
@SmokeTest
@Test
fun deleteSavedAddressTest() {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAutofillSubMenu {
clickAddAddressButton()
autofillScreen {
fillAndSaveAddress(
"Mozilla",
"Fenix",
"Firefox",
"Harrison Street",
"San Francisco",
"Alaska",
"94105",
"United States",
"555-5555",
"foo@bar.com",
navigateToAutofillSettings = FirstAddressAutofillDetails.navigateToAutofillSettings,
isAddressAutofillEnabled = FirstAddressAutofillDetails.isAddressAutofillEnabled,
userHasSavedAddress = FirstAddressAutofillDetails.userHasSavedAddress,
firstName = FirstAddressAutofillDetails.firstName,
middleName = FirstAddressAutofillDetails.middleName,
lastName = FirstAddressAutofillDetails.lastName,
streetAddress = FirstAddressAutofillDetails.streetAddress,
city = FirstAddressAutofillDetails.city,
state = FirstAddressAutofillDetails.state,
zipCode = FirstAddressAutofillDetails.zipCode,
country = FirstAddressAutofillDetails.country,
phoneNumber = FirstAddressAutofillDetails.phoneNumber,
emailAddress = FirstAddressAutofillDetails.emailAddress,
)
clickManageAddressesButton()
clickSavedAddress("Mozilla")
@ -130,22 +159,21 @@ class AddressAutofillTest {
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1836841
@Test
fun verifyEditAddressViewTest() {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAutofillSubMenu {
clickAddAddressButton()
autofillScreen {
fillAndSaveAddress(
"Mozilla",
"Fenix",
"Firefox",
"Harrison Street",
"San Francisco",
"Alaska",
"94105",
"United States",
"555-5555",
"foo@bar.com",
navigateToAutofillSettings = FirstAddressAutofillDetails.navigateToAutofillSettings,
isAddressAutofillEnabled = FirstAddressAutofillDetails.isAddressAutofillEnabled,
userHasSavedAddress = FirstAddressAutofillDetails.userHasSavedAddress,
firstName = FirstAddressAutofillDetails.firstName,
middleName = FirstAddressAutofillDetails.middleName,
lastName = FirstAddressAutofillDetails.lastName,
streetAddress = FirstAddressAutofillDetails.streetAddress,
city = FirstAddressAutofillDetails.city,
state = FirstAddressAutofillDetails.state,
zipCode = FirstAddressAutofillDetails.zipCode,
country = FirstAddressAutofillDetails.country,
phoneNumber = FirstAddressAutofillDetails.phoneNumber,
emailAddress = FirstAddressAutofillDetails.emailAddress,
)
clickManageAddressesButton()
clickSavedAddress("Mozilla")
@ -159,23 +187,21 @@ class AddressAutofillTest {
val addressFormPage =
TestAssetHelper.getAddressFormAsset(mockWebServer)
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAutofillSubMenu {
verifyAddressAutofillSection(true, false)
clickAddAddressButton()
autofillScreen {
fillAndSaveAddress(
"Mozilla",
"Fenix",
"Firefox",
"Harrison Street",
"San Francisco",
"Alaska",
"94105",
"United States",
"555-5555",
"foo@bar.com",
navigateToAutofillSettings = FirstAddressAutofillDetails.navigateToAutofillSettings,
isAddressAutofillEnabled = FirstAddressAutofillDetails.isAddressAutofillEnabled,
userHasSavedAddress = FirstAddressAutofillDetails.userHasSavedAddress,
firstName = FirstAddressAutofillDetails.firstName,
middleName = FirstAddressAutofillDetails.middleName,
lastName = FirstAddressAutofillDetails.lastName,
streetAddress = FirstAddressAutofillDetails.streetAddress,
city = FirstAddressAutofillDetails.city,
state = FirstAddressAutofillDetails.state,
zipCode = FirstAddressAutofillDetails.zipCode,
country = FirstAddressAutofillDetails.country,
phoneNumber = FirstAddressAutofillDetails.phoneNumber,
emailAddress = FirstAddressAutofillDetails.emailAddress,
)
}
@ -207,23 +233,21 @@ class AddressAutofillTest {
val addressFormPage =
TestAssetHelper.getAddressFormAsset(mockWebServer)
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAutofillSubMenu {
verifyAddressAutofillSection(true, false)
clickAddAddressButton()
autofillScreen {
fillAndSaveAddress(
"Mozilla",
"Fenix",
"Firefox",
"Harrison Street",
"San Francisco",
"Alaska",
"94105",
"United States",
"555-5555",
"foo@bar.com",
navigateToAutofillSettings = FirstAddressAutofillDetails.navigateToAutofillSettings,
isAddressAutofillEnabled = FirstAddressAutofillDetails.isAddressAutofillEnabled,
userHasSavedAddress = FirstAddressAutofillDetails.userHasSavedAddress,
firstName = FirstAddressAutofillDetails.firstName,
middleName = FirstAddressAutofillDetails.middleName,
lastName = FirstAddressAutofillDetails.lastName,
streetAddress = FirstAddressAutofillDetails.streetAddress,
city = FirstAddressAutofillDetails.city,
state = FirstAddressAutofillDetails.state,
zipCode = FirstAddressAutofillDetails.zipCode,
country = FirstAddressAutofillDetails.country,
phoneNumber = FirstAddressAutofillDetails.phoneNumber,
emailAddress = FirstAddressAutofillDetails.emailAddress,
)
}
@ -247,37 +271,36 @@ class AddressAutofillTest {
val addressFormPage =
TestAssetHelper.getAddressFormAsset(mockWebServer)
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAutofillSubMenu {
verifyAddressAutofillSection(true, false)
clickAddAddressButton()
autofillScreen {
fillAndSaveAddress(
"Mozilla",
"Fenix",
"Firefox",
"Harrison Street",
"San Francisco",
"Alaska",
"94105",
"United States",
"555-5555",
"foo@bar.com",
navigateToAutofillSettings = FirstAddressAutofillDetails.navigateToAutofillSettings,
isAddressAutofillEnabled = FirstAddressAutofillDetails.isAddressAutofillEnabled,
userHasSavedAddress = FirstAddressAutofillDetails.userHasSavedAddress,
firstName = FirstAddressAutofillDetails.firstName,
middleName = FirstAddressAutofillDetails.middleName,
lastName = FirstAddressAutofillDetails.lastName,
streetAddress = FirstAddressAutofillDetails.streetAddress,
city = FirstAddressAutofillDetails.city,
state = FirstAddressAutofillDetails.state,
zipCode = FirstAddressAutofillDetails.zipCode,
country = FirstAddressAutofillDetails.country,
phoneNumber = FirstAddressAutofillDetails.phoneNumber,
emailAddress = FirstAddressAutofillDetails.emailAddress,
)
clickManageAddressesButton()
clickAddAddressButton()
fillAndSaveAddress(
"Android",
"Test",
"Name",
"Fort Street",
"San Jose",
"Arizona",
"95141",
"United States",
"777-7777",
"fuu@bar.org",
navigateToAutofillSettings = SecondAddressAutofillDetails.navigateToAutofillSettings,
firstName = SecondAddressAutofillDetails.firstName,
middleName = SecondAddressAutofillDetails.middleName,
lastName = SecondAddressAutofillDetails.lastName,
streetAddress = SecondAddressAutofillDetails.streetAddress,
city = SecondAddressAutofillDetails.city,
state = SecondAddressAutofillDetails.state,
zipCode = SecondAddressAutofillDetails.zipCode,
country = SecondAddressAutofillDetails.country,
phoneNumber = SecondAddressAutofillDetails.phoneNumber,
emailAddress = SecondAddressAutofillDetails.emailAddress,
)
verifyManageAddressesToolbarTitle()
}
@ -311,37 +334,36 @@ class AddressAutofillTest {
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1836850
@Test
fun verifySavedAddressCanBeEditedTest() {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAutofillSubMenu {
verifyAddressAutofillSection(true, false)
clickAddAddressButton()
autofillScreen {
fillAndSaveAddress(
"Mozilla",
"Fenix",
"Firefox",
"Harrison Street",
"San Francisco",
"Alaska",
"94105",
"United States",
"555-5555",
"foo@bar.com",
navigateToAutofillSettings = FirstAddressAutofillDetails.navigateToAutofillSettings,
isAddressAutofillEnabled = FirstAddressAutofillDetails.isAddressAutofillEnabled,
userHasSavedAddress = FirstAddressAutofillDetails.userHasSavedAddress,
firstName = FirstAddressAutofillDetails.firstName,
middleName = FirstAddressAutofillDetails.middleName,
lastName = FirstAddressAutofillDetails.lastName,
streetAddress = FirstAddressAutofillDetails.streetAddress,
city = FirstAddressAutofillDetails.city,
state = FirstAddressAutofillDetails.state,
zipCode = FirstAddressAutofillDetails.zipCode,
country = FirstAddressAutofillDetails.country,
phoneNumber = FirstAddressAutofillDetails.phoneNumber,
emailAddress = FirstAddressAutofillDetails.emailAddress,
)
clickManageAddressesButton()
clickSavedAddress("Mozilla")
fillAndSaveAddress(
"Android",
"Test",
"Name",
"Fort Street",
"San Jose",
"Arizona",
"95141",
"United States",
"777-7777",
"fuu@bar.org",
navigateToAutofillSettings = SecondAddressAutofillDetails.navigateToAutofillSettings,
firstName = SecondAddressAutofillDetails.firstName,
middleName = SecondAddressAutofillDetails.middleName,
lastName = SecondAddressAutofillDetails.lastName,
streetAddress = SecondAddressAutofillDetails.streetAddress,
city = SecondAddressAutofillDetails.city,
state = SecondAddressAutofillDetails.state,
zipCode = SecondAddressAutofillDetails.zipCode,
country = SecondAddressAutofillDetails.country,
phoneNumber = SecondAddressAutofillDetails.phoneNumber,
emailAddress = SecondAddressAutofillDetails.emailAddress,
)
verifyManageAddressesToolbarTitle()
}
@ -370,22 +392,21 @@ class AddressAutofillTest {
val addressFormPage =
TestAssetHelper.getAddressFormAsset(mockWebServer)
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAutofillSubMenu {
clickAddAddressButton()
autofillScreen {
fillAndSaveAddress(
"Mozilla",
"Fenix",
"Firefox",
"Harrison Street",
"San Francisco",
"Alaska",
"94105",
"United States",
"555-5555",
"foo@bar.com",
navigateToAutofillSettings = FirstAddressAutofillDetails.navigateToAutofillSettings,
isAddressAutofillEnabled = FirstAddressAutofillDetails.isAddressAutofillEnabled,
userHasSavedAddress = FirstAddressAutofillDetails.userHasSavedAddress,
firstName = FirstAddressAutofillDetails.firstName,
middleName = FirstAddressAutofillDetails.middleName,
lastName = FirstAddressAutofillDetails.lastName,
streetAddress = FirstAddressAutofillDetails.streetAddress,
city = FirstAddressAutofillDetails.city,
state = FirstAddressAutofillDetails.state,
zipCode = FirstAddressAutofillDetails.zipCode,
country = FirstAddressAutofillDetails.country,
phoneNumber = FirstAddressAutofillDetails.phoneNumber,
emailAddress = FirstAddressAutofillDetails.emailAddress,
)
}
@ -410,23 +431,21 @@ class AddressAutofillTest {
// TestRail link: https://testrail.stage.mozaws.net/index.php?/cases/view/1836838
@Test
fun verifyAutofillAddressSectionTest() {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAutofillSubMenu {
verifyAddressAutofillSection(true, false)
clickAddAddressButton()
autofillScreen {
fillAndSaveAddress(
"Mozilla",
"Fenix",
"Firefox",
"Harrison Street",
"San Francisco",
"Alaska",
"94105",
"United States",
"555-5555",
"foo@bar.com",
navigateToAutofillSettings = FirstAddressAutofillDetails.navigateToAutofillSettings,
isAddressAutofillEnabled = FirstAddressAutofillDetails.isAddressAutofillEnabled,
userHasSavedAddress = FirstAddressAutofillDetails.userHasSavedAddress,
firstName = FirstAddressAutofillDetails.firstName,
middleName = FirstAddressAutofillDetails.middleName,
lastName = FirstAddressAutofillDetails.lastName,
streetAddress = FirstAddressAutofillDetails.streetAddress,
city = FirstAddressAutofillDetails.city,
state = FirstAddressAutofillDetails.state,
zipCode = FirstAddressAutofillDetails.zipCode,
country = FirstAddressAutofillDetails.country,
phoneNumber = FirstAddressAutofillDetails.phoneNumber,
emailAddress = FirstAddressAutofillDetails.emailAddress,
)
verifyAddressAutofillSection(true, true)
clickManageAddressesButton()

@ -41,6 +41,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
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.HomeActivityComposeTestRule
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
@ -70,7 +71,7 @@ class BrowserRobot {
fun waitForPageToLoad() {
progressBar.waitUntilGone(waitingTime)
Log.i("MozTestLog", "waitForPageToLoad: The page was loaded, the progress bar is gone")
Log.i(TAG, "waitForPageToLoad: The page was loaded, the progress bar is gone")
}
fun verifyCurrentPrivateSession(context: Context) {
@ -1034,9 +1035,9 @@ class BrowserRobot {
class Transition {
fun openThreeDotMenu(interact: ThreeDotMenuMainRobot.() -> Unit): ThreeDotMenuMainRobot.Transition {
mDevice.waitForIdle(waitingTime)
Log.i("MozTestLog", "openThreeDotMenu: Device was idle for $waitingTime")
Log.i(TAG, "openThreeDotMenu: Device was idle for $waitingTime")
threeDotButton().perform(click())
Log.i("MozTestLog", "openThreeDotMenu: Clicked the main menu button")
Log.i(TAG, "openThreeDotMenu: Clicked the main menu button")
ThreeDotMenuMainRobot().interact()
return ThreeDotMenuMainRobot.Transition()
@ -1352,26 +1353,26 @@ private fun siteSecurityToolbarButton() =
fun clickPageObject(item: UiObject) {
for (i in 1..RETRY_COUNT) {
Log.i("MozTestLog", "clickPageObject: For loop i = $i")
Log.i(TAG, "clickPageObject: For loop i = $i")
try {
Log.i("MozTestLog", "clickPageObject: Try block")
Log.i(TAG, "clickPageObject: Try block")
item.waitForExists(waitingTime)
item.click()
Log.i("MozTestLog", "clickPageObject: Clicked ${item.selector}")
Log.i(TAG, "clickPageObject: Clicked ${item.selector}")
break
} catch (e: UiObjectNotFoundException) {
Log.i("MozTestLog", "clickPageObject: Catch block")
Log.i(TAG, "clickPageObject: Catch block")
if (i == RETRY_COUNT) {
throw e
} else {
browserScreen {
Log.i("MozTestLog", "clickPageObject: Browser screen")
Log.i(TAG, "clickPageObject: Browser screen")
}.openThreeDotMenu {
Log.i("MozTestLog", "clickPageObject: Opened main menu")
Log.i(TAG, "clickPageObject: Opened main menu")
}.refreshPage {
progressBar.waitUntilGone(waitingTime)
Log.i("MozTestLog", "clickPageObject: Page refreshed, progress bar is gone")
Log.i(TAG, "clickPageObject: Page refreshed, progress bar is gone")
}
}
}

@ -30,6 +30,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.AppAndSystemHelper.assertExternalAppOpens
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.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
@ -51,25 +52,25 @@ class DownloadRobot {
fun verifyDownloadPrompt(fileName: String) {
var currentTries = 0
while (currentTries++ < 3) {
Log.i("MozTestLog", "verifyDownloadPrompt: While loop currentTries = $currentTries")
Log.i(TAG, "verifyDownloadPrompt: While loop currentTries = $currentTries")
try {
Log.i("MozTestLog", "verifyDownloadPrompt: Try block")
Log.i(TAG, "verifyDownloadPrompt: Try block")
assertTrue(
"Download prompt button not visible",
mDevice.findObject(UiSelector().resourceId("$packageName:id/download_button"))
.waitForExists(waitingTimeLong),
)
Log.i("MozTestLog", "verifyDownloadPrompt: Verified that the \"DOWNLOAD\" prompt button exists")
Log.i(TAG, "verifyDownloadPrompt: Verified that the \"DOWNLOAD\" prompt button exists")
assertTrue(
"$fileName title doesn't match",
mDevice.findObject(UiSelector().text(fileName))
.waitForExists(waitingTimeLong),
)
Log.i("MozTestLog", "verifyDownloadPrompt: Verified that the download prompt for $fileName exists")
Log.i(TAG, "verifyDownloadPrompt: Verified that the download prompt for $fileName exists")
break
} catch (e: AssertionError) {
Log.i("MozTestLog", "verifyDownloadPrompt: Catch block")
Log.i(TAG, "verifyDownloadPrompt: Catch block")
Log.e("DOWNLOAD_ROBOT", "Failed to find locator: ${e.localizedMessage}")
browserScreen {
@ -206,7 +207,7 @@ class DownloadRobot {
class Transition {
fun clickDownload(interact: DownloadRobot.() -> Unit): Transition {
downloadButton().click()
Log.i("MozTestLog", "clickDownload: Clicked \"DOWNLOAD\" button from prompt")
Log.i(TAG, "clickDownload: Clicked \"DOWNLOAD\" button from prompt")
DownloadRobot().interact()
return Transition()

@ -6,6 +6,7 @@
package org.mozilla.fenix.ui.robots
import android.util.Log
import android.view.View
import android.widget.EditText
import android.widget.TextView
@ -52,6 +53,7 @@ import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.LISTS_MAXSWIPES
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
@ -522,14 +524,20 @@ class HomeScreenRobot {
fun openThreeDotMenu(interact: ThreeDotMenuMainRobot.() -> Unit): ThreeDotMenuMainRobot.Transition {
// Issue: https://github.com/mozilla-mobile/fenix/issues/21578
try {
Log.i(TAG, "openThreeDotMenu: Try block")
Log.i(TAG, "openThreeDotMenu: Looking for main menu button")
mDevice.waitNotNull(
Until.findObject(By.res("$packageName:id/menuButton")),
waitingTime,
)
} catch (e: AssertionError) {
Log.i(TAG, "openThreeDotMenu: Catch block")
mDevice.pressBack()
Log.i(TAG, "openThreeDotMenu: Pressed device back button")
} finally {
Log.i(TAG, "openThreeDotMenu: Finally block")
threeDotButton().perform(click())
Log.i(TAG, "openThreeDotMenu: Clicked main menu button")
}
ThreeDotMenuMainRobot().interact()

@ -36,6 +36,7 @@ import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants
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.itemWithResId
@ -155,12 +156,12 @@ class NavigationToolbarRobot {
sessionLoadedIdlingResource = SessionLoadedIdlingResource()
openEditURLView()
Log.i("MozTestLog", "enterURLAndEnterToBrowser: Opened edit mode URL view")
Log.i(TAG, "enterURLAndEnterToBrowser: Opened edit mode URL view")
awesomeBar().setText(url.toString())
Log.i("MozTestLog", "enterURLAndEnterToBrowser: Set toolbar text to: $url")
Log.i(TAG, "enterURLAndEnterToBrowser: Set toolbar text to: $url")
mDevice.pressEnter()
Log.i("MozTestLog", "enterURLAndEnterToBrowser: Clicked enter on keyboard, submitted query")
Log.i(TAG, "enterURLAndEnterToBrowser: Clicked enter on keyboard, submitted query")
runWithIdleRes(sessionLoadedIdlingResource) {
assertTrue(

@ -8,6 +8,7 @@ package org.mozilla.fenix.ui.robots
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewInteraction
@ -46,6 +47,7 @@ import org.mozilla.fenix.helpers.AppAndSystemHelper.isPackageInstalled
import org.mozilla.fenix.helpers.Constants.LISTS_MAXSWIPES
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.itemContainingText
@ -272,8 +274,10 @@ class SettingsRobot {
fun openAutofillSubMenu(interact: SettingsSubMenuAutofillRobot.() -> Unit): SettingsSubMenuAutofillRobot.Transition {
mDevice.findObject(UiSelector().textContains(getStringResource(R.string.preferences_autofill)))
.also {
Log.i(TAG, "openAutofillSubMenu: Looking for \"Autofill\" settings button")
it.waitForExists(waitingTime)
it.click()
Log.i(TAG, "openAutofillSubMenu: Clicked \"Autofill\" settings button")
}
SettingsSubMenuAutofillRobot().interact()

@ -4,6 +4,7 @@
package org.mozilla.fenix.ui.robots
import android.util.Log
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.RootMatchers
@ -18,6 +19,7 @@ import org.hamcrest.CoreMatchers.endsWith
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
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
@ -34,8 +36,14 @@ import org.mozilla.fenix.helpers.click
class SettingsSubMenuAutofillRobot {
fun verifyAutofillToolbarTitle() = assertItemContainingTextExists(autofillToolbarTitle)
fun verifyManageAddressesToolbarTitle() = assertItemContainingTextExists(manageAddressesToolbarTitle)
fun verifyAutofillToolbarTitle() {
assertItemContainingTextExists(autofillToolbarTitle)
Log.i(TAG, "verifyAutofillToolbarTitle: Verified \"Autofill\" toolbar title exists")
}
fun verifyManageAddressesToolbarTitle() {
assertItemContainingTextExists(manageAddressesToolbarTitle)
Log.i(TAG, "verifyManageAddressesToolbarTitle: Verified \"Manage addresses\" toolbar title exists")
}
fun verifyAddressAutofillSection(isAddressAutofillEnabled: Boolean, userHasSavedAddress: Boolean) {
assertItemContainingTextExists(
@ -85,6 +93,7 @@ class SettingsSubMenuAutofillRobot {
UiSelector().textContains(savedAddressDetail),
).waitForExists(waitingTime),
)
Log.i(TAG, "verifyManageAddressesSection: Verified saved address detail: $savedAddressDetail exists")
}
}
@ -98,7 +107,7 @@ class SettingsSubMenuAutofillRobot {
)
}
fun verifyAddressesAutofillToggle(enabled: Boolean) =
fun verifyAddressesAutofillToggle(enabled: Boolean) {
onView(withText(R.string.preferences_addresses_save_and_autofill_addresses))
.check(
matches(
@ -114,6 +123,8 @@ class SettingsSubMenuAutofillRobot {
),
),
)
Log.i(TAG, "verifyAddressesAutofillToggle: Verified if address autofill toggle is enabled: $enabled")
}
fun verifySaveAndAutofillCreditCardsToggle(enabled: Boolean) =
onView(withText(R.string.preferences_credit_cards_save_and_autofill_cards))
@ -141,17 +152,20 @@ class SettingsSubMenuAutofillRobot {
middleNameTextInput,
)
scrollToElementByText(getStringResource(R.string.addresses_street_address))
Log.i(TAG, "verifyAddAddressView: Scrolled to \"Street Address\" text input")
assertItemWithResIdExists(
lastNameTextInput,
streetAddressTextInput,
)
scrollToElementByText(getStringResource(R.string.addresses_country))
Log.i(TAG, "verifyAddAddressView: Scrolled to \"Country or region\" dropdown")
assertItemWithResIdExists(
cityTextInput,
subRegionDropDown,
zipCodeTextInput,
)
scrollToElementByText(getStringResource(R.string.addresses_save_button))
Log.i(TAG, "verifyAddAddressView: Scrolled to \"Save\" button")
assertItemWithResIdExists(
countryDropDown,
phoneTextInput,
@ -165,15 +179,19 @@ class SettingsSubMenuAutofillRobot {
fun verifyCountryOption(country: String) {
scrollToElementByText(getStringResource(R.string.addresses_country))
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))
}
fun verifyStateOption(state: String) =
fun verifyStateOption(state: String) {
assertItemContainingTextExists(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))
}
@ -181,7 +199,9 @@ class SettingsSubMenuAutofillRobot {
fun selectCountry(country: String) {
countryDropDown.click()
Log.i(TAG, "selectCountry: Clicked \"Country or region\" dropdown")
countryOption(country).click()
Log.i(TAG, "selectCountry: Selected $country dropdown option")
}
fun verifyEditAddressView() {
@ -194,17 +214,20 @@ class SettingsSubMenuAutofillRobot {
middleNameTextInput,
)
scrollToElementByText(getStringResource(R.string.addresses_street_address))
Log.i(TAG, "verifyEditAddressView: Scrolled to \"Street Address\" text input")
assertItemWithResIdExists(
lastNameTextInput,
streetAddressTextInput,
)
scrollToElementByText(getStringResource(R.string.addresses_country))
Log.i(TAG, "verifyEditAddressView: Scrolled to \"Country or region\" dropdown")
assertItemWithResIdExists(
cityTextInput,
subRegionDropDown,
zipCodeTextInput,
)
scrollToElementByText(getStringResource(R.string.addresses_save_button))
Log.i(TAG, "verifyEditAddressView: Scrolled to \"Save\" button")
assertItemWithResIdExists(
countryDropDown,
phoneTextInput,
@ -217,32 +240,63 @@ class SettingsSubMenuAutofillRobot {
assertItemContainingTextExists(deleteAddressButton)
}
fun clickSaveAndAutofillAddressesOption() = saveAndAutofillAddressesOption.click()
fun clickAddAddressButton() = addAddressButton.click()
fun clickManageAddressesButton() = manageAddressesButton.click()
fun clickSavedAddress(firstName: String) = savedAddress(firstName).clickAndWaitForNewWindow(waitingTime)
fun clickSaveAndAutofillAddressesOption() {
saveAndAutofillAddressesOption.click()
Log.i(TAG, "clickSaveAndAutofillAddressesOption: Clicked \"Save and autofill addresses\" button")
}
fun clickAddAddressButton() {
addAddressButton.click()
Log.i(TAG, "clickAddAddressButton: Clicked \"Add address\" button")
}
fun clickManageAddressesButton() {
manageAddressesButton.click()
Log.i(TAG, "clickManageAddressesButton: Clicked \"Manage addresses\" button")
}
fun clickSavedAddress(firstName: String) {
savedAddress(firstName).clickAndWaitForNewWindow(waitingTime)
Log.i(TAG, "clickSavedAddress: Clicked $firstName saved address and waiting for a new window for $waitingTime")
}
fun clickDeleteAddressButton() {
Log.i(TAG, "clickDeleteAddressButton: Looking for delete address toolbar button")
toolbarDeleteAddressButton.waitForExists(waitingTime)
toolbarDeleteAddressButton.click()
Log.i(TAG, "clickDeleteAddressButton: Clicked delete address toolbar button")
}
fun clickCancelDeleteAddressButton() {
cancelDeleteAddressButton.click()
Log.i(TAG, "clickCancelDeleteAddressButton: Clicked \"CANCEL\" button from delete address dialog")
}
fun clickCancelDeleteAddressButton() = cancelDeleteAddressButton.click()
fun clickConfirmDeleteAddressButton() = confirmDeleteAddressButton.click()
fun clickConfirmDeleteAddressButton() {
confirmDeleteAddressButton.click()
Log.i(TAG, "clickConfirmDeleteAddressButton: Clicked \"DELETE\" button from delete address dialog")
}
fun clickSubRegionOption(subRegion: String) {
scrollToElementByText(subRegion)
Log.i(TAG, "clickSubRegionOption: Scrolled to \"State\" drop down")
subRegionOption(subRegion).also {
Log.i(TAG, "clickSubRegionOption: Looking for \"State\" $subRegion dropdown option")
it.waitForExists(waitingTime)
it.click()
Log.i(TAG, "clickSubRegionOption: Clicked \"State\" $subRegion dropdown option")
}
}
fun clickCountryOption(country: String) {
Log.i(TAG, "clickCountryOption: Looking for \"Country or region\" $country dropdown option")
countryOption(country).waitForExists(waitingTime)
countryOption(country).click()
Log.i(TAG, "clickCountryOption: Clicked \"Country or region\" $country dropdown option")
}
fun verifyAddAddressButton() {
assertTrue(addAddressButton.waitForExists(waitingTime))
Log.i(TAG, "verifyAddAddressButton: Verified \"Add address\" button exists")
}
fun verifyAddAddressButton() = assertTrue(addAddressButton.waitForExists(waitingTime))
fun fillAndSaveAddress(
navigateToAutofillSettings: Boolean,
isAddressAutofillEnabled: Boolean = true,
userHasSavedAddress: Boolean = false,
firstName: String,
middleName: String,
lastName: String,
@ -254,22 +308,48 @@ class SettingsSubMenuAutofillRobot {
phoneNumber: String,
emailAddress: String,
) {
if (navigateToAutofillSettings) {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openAutofillSubMenu {
verifyAddressAutofillSection(isAddressAutofillEnabled, userHasSavedAddress)
clickAddAddressButton()
}
}
Log.i(TAG, "fillAndSaveAddress: Looking for \"First Name\" text input")
firstNameTextInput.waitForExists(waitingTime)
mDevice.pressBack()
Log.i(TAG, "fillAndSaveAddress: Dismissed keyboard using device back button")
firstNameTextInput.setText(firstName)
Log.i(TAG, "fillAndSaveAddress: \"First Name\" set to $firstName")
middleNameTextInput.setText(middleName)
Log.i(TAG, "fillAndSaveAddress: \"Middle Name\" set to $middleName")
lastNameTextInput.setText(lastName)
Log.i(TAG, "fillAndSaveAddress: \"Last Name\" set to $lastName")
streetAddressTextInput.setText(streetAddress)
Log.i(TAG, "fillAndSaveAddress: \"Street Address\" set to $streetAddress")
cityTextInput.setText(city)
Log.i(TAG, "fillAndSaveAddress: \"City\" set to $city")
subRegionDropDown.click()
Log.i(TAG, "fillAndSaveAddress: Clicked \"State\" dropdown button")
clickSubRegionOption(state)
Log.i(TAG, "fillAndSaveAddress: Selected $state as \"State\"")
zipCodeTextInput.setText(zipCode)
Log.i(TAG, "fillAndSaveAddress: \"Zip\" set to $zipCode")
countryDropDown.click()
Log.i(TAG, "fillAndSaveAddress: Clicked \"Country or region\" dropdown button")
clickCountryOption(country)
Log.i(TAG, "fillAndSaveAddress: Selected $country as \"Country or region\"")
scrollToElementByText(getStringResource(R.string.addresses_save_button))
Log.i(TAG, "fillAndSaveAddress: Scrolled to \"Save\" button")
phoneTextInput.setText(phoneNumber)
Log.i(TAG, "fillAndSaveAddress: \"Phone\" set to $phoneNumber")
emailTextInput.setText(emailAddress)
Log.i(TAG, "fillAndSaveAddress: \"Email\" set to $emailAddress")
saveButton.click()
Log.i(TAG, "fillAndSaveAddress: Clicked \"Save\" button")
Log.i(TAG, "fillAndSaveAddress: Looking for \"Manage addressese\" button")
manageAddressesButton.waitForExists(waitingTime)
}
@ -384,6 +464,7 @@ class SettingsSubMenuAutofillRobot {
fun goBackToAutofillSettings(interact: SettingsSubMenuAutofillRobot.() -> Unit): SettingsSubMenuAutofillRobot.Transition {
navigateBackButton.click()
Log.i(TAG, "goBackToAutofillSettings: Clicked \"Navigate back\" toolbar button")
SettingsSubMenuAutofillRobot().interact()
return SettingsSubMenuAutofillRobot.Transition()
@ -398,6 +479,7 @@ class SettingsSubMenuAutofillRobot {
fun goBackToBrowser(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
mDevice.pressBack()
Log.i(TAG, "goBackToBrowser: Go back to browser view using device back button")
BrowserRobot().interact()
return BrowserRobot.Transition()
@ -405,6 +487,11 @@ class SettingsSubMenuAutofillRobot {
}
}
fun autofillScreen(interact: SettingsSubMenuAutofillRobot.() -> Unit): SettingsSubMenuAutofillRobot.Transition {
SettingsSubMenuAutofillRobot().interact()
return SettingsSubMenuAutofillRobot.Transition()
}
private val autofillToolbarTitle = itemContainingText(getStringResource(R.string.preferences_autofill))
private val addressesSectionTitle = itemContainingText(getStringResource(R.string.preferences_addresses))
private val manageAddressesToolbarTitle =

@ -31,6 +31,7 @@ import org.junit.Assert.assertTrue
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.Constants.TAG
import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource
import org.mozilla.fenix.helpers.MatcherHelper.assertCheckedItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemContainingTextExists
@ -196,8 +197,11 @@ class ThreeDotMenuMainRobot {
// such as the Pixel 2, we require two swipes to display the "Settings" menu item
// at the bottom. On larger devices, the second swipe is a no-op.
threeDotMenuRecyclerView().perform(swipeUp())
Log.i(TAG, "openSettings: Swiped up the main menu once")
threeDotMenuRecyclerView().perform(swipeUp())
Log.i(TAG, "openSettings: Swiped up the main menu twice")
settingsButton(localizedText).click()
Log.i(TAG, "openSettings: Clicked main menu $localizedText button")
SettingsRobot().interact()
return SettingsRobot.Transition()
@ -322,10 +326,10 @@ class ThreeDotMenuMainRobot {
fun refreshPage(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
refreshButton.also {
Log.i("MozTestLog", "refreshPage: Looking for refresh button")
Log.i(TAG, "refreshPage: Looking for refresh button")
it.waitForExists(waitingTime)
it.click()
Log.i("MozTestLog", "refreshPage: Clicked the refresh button")
Log.i(TAG, "refreshPage: Clicked the refresh button")
}
BrowserRobot().interact()

Loading…
Cancel
Save