Skip to content

Commit

Permalink
Bug #2887 - Fix openFXATest UI test
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiAJ authored and mergify[bot] committed Jun 20, 2024
1 parent 37853f8 commit 0248d02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ object TestHelper {
fun itemWithResId(resourceId: String) =
mDevice.findObject(UiSelector().resourceId(resourceId))

fun itemWithText(itemText: String) =
mDevice.findObject(UiSelector().text(itemText))

fun itemWithResIdContainingText(resourceId: String, text: String) =
mDevice.findObject(UiSelector().resourceId(resourceId).textContains(text))

fun assertItemWithResIdExists(vararg appItems: UiObject, exists: Boolean = true) {
fun assertUIObjectExists(vararg appItems: UiObject, exists: Boolean = true) {
if (exists) {
for (appItem in appItems) {
assertTrue(appItem.waitForExists(waitingTime))
Expand All @@ -95,14 +98,6 @@ object TestHelper {
}
}
}
fun assertItemWithResIdAndTextExists(vararg appItems: UiObject, exists: Boolean = true) {
for (appItem in appItems) {
if (exists) {
assertTrue(appItem.waitForExists(waitingTime))
} else {
assertFalse(appItem.waitForExists(waitingTimeShort))
}
}
}

fun getStringResource(id: Int) = appContext.resources.getString(id, appName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import org.mozilla.reference.browser.R
import org.mozilla.reference.browser.ext.waitAndInteract
import org.mozilla.reference.browser.helpers.TestAssetHelper.waitingTime
import org.mozilla.reference.browser.helpers.TestAssetHelper.waitingTimeShort
import org.mozilla.reference.browser.helpers.TestHelper.assertItemWithResIdAndTextExists
import org.mozilla.reference.browser.helpers.TestHelper.assertItemWithResIdExists
import org.mozilla.reference.browser.helpers.TestHelper.assertUIObjectExists
import org.mozilla.reference.browser.helpers.TestHelper.getStringResource
import org.mozilla.reference.browser.helpers.TestHelper.itemWithResId
import org.mozilla.reference.browser.helpers.TestHelper.itemWithResIdContainingText
Expand All @@ -42,14 +41,14 @@ class AddonsManagerRobot {
fun verifyAddonsRecommendedView() {
assertTrue(mDevice.findObject(UiSelector().text("Recommended")).waitForExists(waitingTime))
// Check uBlock is displayed in the "Recommended" section
assertItemWithResIdAndTextExists(
assertUIObjectExists(
itemWithResIdContainingText("$packageName:id/add_on_name", "uBlock Origin"),
itemWithResIdContainingText(
"$packageName:id/add_on_description",
"Finally, an efficient wide-spectrum content blocker. Easy on CPU and memory.",
),
)
assertItemWithResIdExists(
assertUIObjectExists(
itemWithResId("$packageName:id/rating"),
itemWithResId("$packageName:id/review_count"),
itemWithResId("$packageName:id/add_button"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import org.mozilla.reference.browser.R
import org.mozilla.reference.browser.helpers.TestAssetHelper
import org.mozilla.reference.browser.helpers.TestAssetHelper.waitingTime
import org.mozilla.reference.browser.helpers.TestHelper
import org.mozilla.reference.browser.helpers.TestHelper.assertUIObjectExists
import org.mozilla.reference.browser.helpers.TestHelper.getStringResource
import org.mozilla.reference.browser.helpers.TestHelper.itemWithText
import org.mozilla.reference.browser.helpers.TestHelper.packageName
import org.mozilla.reference.browser.helpers.click
import org.mozilla.reference.browser.helpers.hasCousin
Expand Down Expand Up @@ -80,7 +83,7 @@ class SettingsViewRobot {
}

fun openFXASignin(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
syncSigninButton().click()
syncSignInButton().click()
BrowserRobot().interact()
return BrowserRobot.Transition()
}
Expand Down Expand Up @@ -132,7 +135,7 @@ private fun assertSettingsView() {
Espresso.onView(withText(R.string.preferences_about_page))
}

private fun syncSigninButton() = Espresso.onView(withText(R.string.sign_in))
private fun syncSignInButton() = itemWithText(getStringResource(R.string.sign_in))
private fun syncHistorySummary() = Espresso.onView(withText(R.string.preferences_sign_in_summary))
private fun syncQrCodeButton() = Espresso.onView(withText(R.string.pair_sign_in))
private fun syncQrSummary() = Espresso.onView(withText(R.string.preferences_pair_sign_in_summary))
Expand Down Expand Up @@ -162,8 +165,7 @@ private fun aboutReferenceBrowserButton() = Espresso.onView(withText(R.string.pr
private fun assertNavigateUpButton() {
mDevice.wait(Until.findObject(By.text("Navigate up")), TestAssetHelper.waitingTimeShort)
}
private fun assertSyncSigninButton() = syncSigninButton()
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun assertSyncSigninButton() = assertUIObjectExists(syncSignInButton())
private fun assertSyncHistorySummary() = syncHistorySummary()
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun assertSyncQrCodeButton() = syncQrCodeButton()
Expand Down

0 comments on commit 0248d02

Please sign in to comment.