No issue: Change hardcoded package and app name in tests

upstream-sync
Oana Horvath 3 years ago
parent 63eec5dfec
commit f3e3f86388

@ -9,7 +9,7 @@ import androidx.navigation.NavController
import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.request.RequestInterceptor
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ui.robots.appContext
import org.mozilla.fenix.helpers.TestHelper.appContext
import java.lang.ref.WeakReference
/**

@ -11,8 +11,8 @@ import androidx.test.rule.ActivityTestRule
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.onboarding.FenixOnboarding
import org.mozilla.fenix.ui.robots.appContext
/**
* A [org.junit.Rule] to handle shared test set up for tests on [HomeActivity].

@ -30,6 +30,7 @@ import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import kotlinx.coroutines.runBlocking
import mozilla.components.support.ktx.android.content.appName
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.allOf
import org.mozilla.fenix.R
@ -41,7 +42,9 @@ import java.io.File
object TestHelper {
val packageName = InstrumentationRegistry.getInstrumentation().targetContext.packageName
val appContext: Context = InstrumentationRegistry.getInstrumentation().targetContext
val packageName: String = appContext.packageName
val appName = appContext.appName
fun scrollToElementByText(text: String): UiScrollable {
val appView = UiScrollable(UiSelector().scrollable(true))

@ -194,16 +194,4 @@ class SettingsBasicsTest {
verifyMenuItemsAreDisabled()
}
}
@Test
fun changeDefaultBrowserSetting() {
// Opens settings and toggles the default browser setting to on. The device settings open and allows the user to set a default browser.
homeScreen {
}.openThreeDotMenu {
}.openSettings {
verifyDefaultBrowserIsDisaled()
clickDefaultBrowserSwitch()
verifyAndroidDefaultAppsMenuAppears()
}
}
}

@ -30,6 +30,7 @@ import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.RecyclerViewIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.createCustomTabIntent
import org.mozilla.fenix.helpers.TestHelper.deleteDownloadFromStorage
import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText
@ -1132,8 +1133,7 @@ class SmokeTest {
verifyAddPrivateBrowsingShortcutButton()
clickAddPrivateBrowsingShortcutButton()
clickAddAutomaticallyButton()
}.openHomeScreenShortcut("Private Firefox Preview") {
}
}.openHomeScreenShortcut("Private $appName") {}
}
@Test

@ -11,9 +11,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.UiSelector
import junit.framework.TestCase.assertTrue
import mozilla.components.support.ktx.android.content.appName
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.appName
/**
* Implementation of the robot pattern for Custom tabs
@ -29,7 +29,7 @@ class CustomTabRobot {
}
fun verifyPoweredByTextIsDisplayed() {
mDevice.findObject(UiSelector().textContains("POWERED BY ${appContext.appName}"))
mDevice.findObject(UiSelector().textContains("POWERED BY $appName"))
}
fun verifyOpenInBrowserButtonExists() {
@ -75,7 +75,7 @@ private fun desktopSiteButton() = onView(withId(R.id.switch_widget))
private fun findInPageButton() = onView(withText("Find in page"))
private fun openInBrowserButton() = onView(withText("Open in ${appContext.appName}"))
private fun openInBrowserButton() = onView(withText("Open in $appName"))
private fun refreshButton() = mDevice.findObject(UiSelector().description("Refresh"))

@ -12,10 +12,10 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
@ -24,13 +24,13 @@ import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_APPS_PHOTOS
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.helpers.ext.waitNotNull
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_APPS_PHOTOS
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.packageName
/**
* Implementation of Robot Pattern for download UI handling.
@ -52,13 +52,13 @@ class DownloadRobot {
fun verifyDownloadedFileIcon() = assertDownloadedFileIcon()
fun verifyEmptyDownloadsList() {
mDevice.findObject(UiSelector().resourceId("org.mozilla.fenix.debug:id/download_empty_view"))
mDevice.findObject(UiSelector().resourceId("$packageName:id/download_empty_view"))
.waitForExists(waitingTime)
onView(withText("No downloaded files")).check(matches(isDisplayed()))
}
fun waitForDownloadsListToExist() =
assertTrue(mDevice.findObject(UiSelector().resourceId("org.mozilla.fenix.debug:id/download_list"))
assertTrue(mDevice.findObject(UiSelector().resourceId("$packageName:id/download_list"))
.waitForExists(waitingTime))
class Transition {

@ -38,7 +38,6 @@ import androidx.test.uiautomator.Until
import androidx.test.uiautomator.Until.findObject
import junit.framework.TestCase.assertTrue
import mozilla.components.browser.state.state.searchEngines
import mozilla.components.support.ktx.android.content.appName
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.CoreMatchers.instanceOf
@ -48,6 +47,8 @@ import org.junit.Assert
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText
import org.mozilla.fenix.helpers.click
@ -63,7 +64,7 @@ import org.mozilla.fenix.ui.util.STRING_ONBOARDING_TRACKING_PROTECTION_HEADER
*/
class HomeScreenRobot {
val privateSessionMessage =
"${appContext.appName} clears your search and browsing history from private tabs when you close them" +
"$appName clears your search and browsing history from private tabs when you close them" +
" or quit the app. While this doesnt make you anonymous to websites or your internet" +
" service provider, it makes it easier to keep what you do online private from anyone" +
" else who uses this device."
@ -424,7 +425,6 @@ fun homeScreen(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition
}
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
private fun homeScreenList() =
UiScrollable(
@ -510,7 +510,7 @@ private fun verifySearchEngineIcon(searchEngineName: String) {
// First Run elements
private fun assertWelcomeHeader() =
onView(allOf(withText("Welcome to ${appContext.appName}!")))
onView(allOf(withText("Welcome to $appName!")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertStartSyncHeader() {
@ -597,7 +597,7 @@ private fun assertYourPrivacyText() {
onView(
allOf(
withText(
"Weve designed ${appContext.appName} to give you control over what you share online and what you share with us."
"Weve designed $appName to give you control over what you share online and what you share with us."
)
)
)

@ -18,6 +18,7 @@ import org.hamcrest.Matchers
import org.hamcrest.Matchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.click
/**
@ -27,7 +28,7 @@ import org.mozilla.fenix.helpers.click
class RecentlyClosedTabsRobot {
fun waitForListToExist() =
mDevice.findObject(UiSelector().resourceId("org.mozilla.fenix.debug:id/recently_closed_list"))
mDevice.findObject(UiSelector().resourceId("$packageName:id/recently_closed_list"))
.waitForExists(
TestAssetHelper.waitingTime
)

@ -33,6 +33,7 @@ import org.hamcrest.CoreMatchers
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_PLAY_SERVICES
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText
import org.mozilla.fenix.helpers.assertIsEnabled
import org.mozilla.fenix.helpers.click
@ -475,8 +476,8 @@ private fun assertRateOnGooglePlay(): ViewInteraction {
private fun assertAboutFirefoxPreview(): ViewInteraction {
onView(withId(R.id.recycler_view))
.perform(RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(hasDescendant(withText("About Firefox Preview"))))
return onView(withText("About Firefox Preview"))
.perform(RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(hasDescendant(withText("About $appName"))))
return onView(withText("About $appName"))
.check(matches(isDisplayed()))
}

@ -28,6 +28,7 @@ import org.hamcrest.CoreMatchers.containsString
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.isVisibleForUser
import org.mozilla.fenix.settings.SupportUtils
import java.text.SimpleDateFormat
@ -108,7 +109,7 @@ private fun assertVersionNumber() {
private fun assertProductCompany() {
onView(withId(R.id.about_content))
.check(matches(withText(containsString("Firefox Preview is produced by Mozilla."))))
.check(matches(withText(containsString("$appName is produced by Mozilla."))))
}
private fun assertCurrentTimestamp() {
@ -122,11 +123,11 @@ private fun assertCurrentTimestamp() {
private fun assertWhatIsNewInFirefoxPreview() {
if (!onView(withText("Whats new in Firefox Preview")).isVisibleForUser()) {
if (!onView(withText("Whats new in $appName")).isVisibleForUser()) {
onView(withId(R.id.about_layout)).perform(ViewActions.swipeUp())
}
onView(withText("Whats new in Firefox Preview"))
onView(withText("Whats new in $appName"))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.perform(click())
@ -222,7 +223,7 @@ private fun assertLibrariesUsed() {
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
.perform(click())
onView(withId(R.id.navigationToolbar)).check(matches(hasDescendant(withText(containsString("Firefox Preview | OSS Libraries")))))
onView(withId(R.id.navigationToolbar)).check(matches(hasDescendant(withText(containsString("$appName | OSS Libraries")))))
Espresso.pressBack()
}

@ -4,17 +4,17 @@ import android.widget.RelativeLayout
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withParent
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers.allOf
@ -27,6 +27,7 @@ import org.mozilla.fenix.helpers.IdlingResourceHelper.registerAddonInstallingIdl
import org.mozilla.fenix.helpers.IdlingResourceHelper.unregisterAddonInstallingIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.helpers.ext.waitNotNull
@ -132,7 +133,7 @@ class SettingsSubMenuAddonsManagerRobot {
allOf(
withText("Okay, Got it"),
withParent(instanceOf(RelativeLayout::class.java)),
hasSibling(withText("$addonName has been added to Firefox Preview")),
hasSibling(withText("$addonName has been added to $appName")),
hasSibling(withText("Open it in the menu")),
hasSibling(withText("Allow in private browsing"))
)

@ -16,6 +16,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.hamcrest.CoreMatchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.assertIsEnabled
import org.mozilla.fenix.helpers.click
@ -68,7 +69,7 @@ private fun assertDataCollectionOptions() {
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
val usageAndTechnicalDataText =
"Shares performance, usage, hardware and customization data about your browser with Mozilla to help us make Firefox Preview better"
"Shares performance, usage, hardware and customization data about your browser with Mozilla to help us make $appName better"
onView(withText(usageAndTechnicalDataText))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

@ -21,9 +21,10 @@ import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers.allOf
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.assertIsChecked
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.helpers.TestAssetHelper
/**
* Implementation of Robot Pattern for the settings Delete Browsing Data sub menu.
@ -104,7 +105,7 @@ private fun cancelButton() =
mDevice.findObject(UiSelector().textStartsWith("CANCEL"))
private fun assertMessageInDialogBox() =
onView(withText("Firefox Preview will delete the selected browsing data."))
onView(withText("$appName will delete the selected browsing data."))
.inRoot(isDialog())
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

@ -10,9 +10,9 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withChild
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
@ -26,6 +26,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.not
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText
import org.mozilla.fenix.helpers.assertIsChecked
import org.mozilla.fenix.helpers.click
@ -122,7 +123,7 @@ private fun assertEnhancedTrackingProtectionHeader() {
private fun assertEnhancedTrackingProtectionHeaderDescription() {
onView(allOf(withParent(withParentIndex(0)),
withText("Keep your data to yourself. Firefox Preview protects you from many of the most common trackers that follow what you do online.")))
withText("Keep your data to yourself. $appName protects you from many of the most common trackers that follow what you do online.")))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

@ -25,6 +25,7 @@ import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.helpers.isEnabled
@ -104,7 +105,7 @@ private fun goBackButton() = onView(withContentDescription("Navigate up"))
private fun addAutomaticallyButton() =
mDevice.findObject(UiSelector().textStartsWith("add automatically"))
private fun privateBrowsingShortcutIcon() = mDevice.findObject(text("Private Firefox Preview"))
private fun privateBrowsingShortcutIcon() = mDevice.findObject(text("Private $appName"))
private fun assertAddPrivateBrowsingShortcutButton() {
mDevice.wait(
@ -130,6 +131,6 @@ private fun assertOpenLinksInPrivateTabOff() {
}
private fun assertPrivateBrowsingShortcutIcon() {
mDevice.wait(Until.findObject(text("Private Firefox Preview")), waitingTime)
assertTrue(mDevice.hasObject(text("Private Firefox Preview")))
mDevice.wait(Until.findObject(text("Private $appName")), waitingTime)
assertTrue(mDevice.hasObject(text("Private $appName")))
}

@ -24,6 +24,7 @@ import androidx.test.uiautomator.UiSelector
import org.hamcrest.CoreMatchers
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.click
/**
@ -53,7 +54,7 @@ class SettingsSubMenuSearchRobot {
fun saveNewSearchEngine() {
addSearchEngineSaveButton().click()
mDevice.findObject(
UiSelector().resourceId("org.mozilla.fenix.debug:id/recycler_view")
UiSelector().resourceId("$packageName:id/recycler_view")
).waitForExists(waitingTime)
}

@ -60,7 +60,7 @@ class TabDrawerRobot {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(
Until.findObject(By.res("org.mozilla.fenix.debug:id/mozac_browser_tabstray_url")),
Until.findObject(By.res("$packageName:id/mozac_browser_tabstray_url")),
waitingTime
)
onView(withId(R.id.mozac_browser_tabstray_url))
@ -88,7 +88,7 @@ class TabDrawerRobot {
fun closeTab() {
mDevice.findObject(
UiSelector().resourceId("org.mozilla.fenix.debug:id/mozac_browser_tabstray_close")
UiSelector().resourceId("$packageName:id/mozac_browser_tabstray_close")
).waitForExists(waitingTime)
var retries = 0 // number of retries before failing, will stop at 2
@ -96,7 +96,7 @@ class TabDrawerRobot {
closeTabButton().click()
retries++
} while (mDevice.findObject(
UiSelector().resourceId("org.mozilla.fenix.debug:id/mozac_browser_tabstray_close")
UiSelector().resourceId("$packageName:id/mozac_browser_tabstray_close")
).exists() && retries < 3
)
}
@ -150,7 +150,7 @@ class TabDrawerRobot {
mDevice.waitNotNull(
findObject(
By
.res("org.mozilla.fenix.debug:id/play_pause_button")
.res("$packageName:id/play_pause_button")
.desc(action)
),
waitingTime

@ -33,6 +33,7 @@ import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.helpers.ext.waitNotNull
import org.mozilla.fenix.share.ShareFragment
@ -179,7 +180,7 @@ class ThreeDotMenuMainRobot {
mDevice.waitNotNull(Until.findObject(By.text("Bookmarks")), waitingTime)
bookmarksButton().click()
assertTrue(mDevice.findObject(UiSelector().resourceId("org.mozilla.fenix.debug:id/bookmark_list")).waitForExists(waitingTime))
assertTrue(mDevice.findObject(UiSelector().resourceId("$packageName:id/bookmark_list")).waitForExists(waitingTime))
BookmarksRobot().interact()
return BookmarksRobot.Transition()
@ -301,7 +302,7 @@ class ThreeDotMenuMainRobot {
interact: BrowserRobot.() -> Unit
): BrowserRobot.Transition {
mDevice.wait(
Until.findObject(By.res("org.mozilla.fenix.debug:id/name_collection_edittext")),
Until.findObject(By.res("$packageName:id/name_collection_edittext")),
waitingTime
)
@ -310,7 +311,7 @@ class ThreeDotMenuMainRobot {
ViewActions.pressImeActionButton()
)
// wait for the collection creation wrapper to be dismissed
mDevice.waitNotNull(Until.gone(By.res("org.mozilla.fenix.debug:id/createCollectionWrapper")))
mDevice.waitNotNull(Until.gone(By.res("$packageName:id/createCollectionWrapper")))
BrowserRobot().interact()
return BrowserRobot.Transition()

Loading…
Cancel
Save