For #26286 new homepage settings UI tests

This commit is contained in:
AndiAJ 2022-09-15 17:04:44 +03:00 committed by mergify[bot]
parent de14a20fae
commit 400a2a60d1
3 changed files with 343 additions and 51 deletions

View File

@ -55,6 +55,74 @@ class SettingsHomepageTest {
featureSettingsHelper.resetAllFeatureFlags()
}
@Test
fun verifyHomepageSettingsTest() {
homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openHomepageSubMenu {
verifyHomePageView()
}
}
@Test
fun verifyShortcutOptionTest() {
// en-US defaults
val defaultTopSites = arrayOf(
"Top Articles",
"Wikipedia",
"Google",
)
homeScreen {
defaultTopSites.forEach { item ->
verifyExistingTopSitesTabs(item)
}
}.openThreeDotMenu {
}.openCustomizeHome {
clickShortcutsButton()
}.goBack {
defaultTopSites.forEach { item ->
verifyNotExistingTopSitesList(item)
}
}
}
@Test
fun verifyRecentlyVisitedOptionTest() {
featureSettingsHelper.setRecentTabsFeatureEnabled(false)
val genericURL = getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
}.goToHomescreen {
verifyRecentlyVisitedSectionIsDisplayed()
}.openThreeDotMenu {
}.openCustomizeHome {
clickRecentlyVisited()
}.goBack {
verifyRecentlyVisitedSectionIsNotDisplayed()
}
}
@Test
fun verifyPocketOptionTest() {
featureSettingsHelper.setRecentTabsFeatureEnabled(false)
featureSettingsHelper.setRecentlyVisitedFeatureEnabled(false)
val genericURL = getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
}.goToHomescreen {
verifyPocketSectionIsDisplayed()
}.openThreeDotMenu {
}.openCustomizeHome {
clickPocketButton()
}.goBack {
verifyPocketSectionIsNotDisplayed()
}
}
@SmokeTest
@Test
fun jumpBackInOptionTest() {

View File

@ -37,7 +37,6 @@ import mozilla.components.browser.state.state.searchEngines
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.CoreMatchers.instanceOf
import org.hamcrest.CoreMatchers.not
import org.hamcrest.Matchers
import org.junit.Assert
import org.junit.Assert.assertFalse
@ -56,7 +55,6 @@ 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
import org.mozilla.fenix.helpers.matchers.hasItem
import org.mozilla.fenix.helpers.withBitmapDrawable
import org.mozilla.fenix.ui.util.STRING_ONBOARDING_ACCOUNT_SIGN_IN_HEADER
import org.mozilla.fenix.ui.util.STRING_ONBOARDING_TOOLBAR_PLACEMENT_HEADER
@ -145,8 +143,12 @@ class HomeScreenRobot {
fun verifyJumpBackInSectionIsDisplayed() = assertJumpBackInSectionIsDisplayed()
fun verifyJumpBackInSectionIsNotDisplayed() = assertJumpBackInSectionIsNotDisplayed()
fun verifyRecentlyVisitedSectionIsDisplayed() = assertRecentlyVisitedSectionIsDisplayed()
fun verifyRecentlyVisitedSectionIsNotDisplayed() = assertRecentlyVisitedSectionIsNotDisplayed()
fun verifyRecentBookmarksSectionIsDisplayed() = assertRecentBookmarksSectionIsDisplayed()
fun verifyRecentBookmarksSectionIsNotDisplayed() = assertRecentBookmarksSectionIsNotDisplayed()
fun verifyPocketSectionIsDisplayed() = assertPocketSectionIsDisplayed()
fun verifyPocketSectionIsNotDisplayed() = assertPocketSectionIsNotDisplayed()
fun verifyRecentlyVisitedSearchGroupDisplayed(shouldBeDisplayed: Boolean, searchTerm: String, groupSize: Int) {
// checks if the search group exists in the Recently visited section
@ -820,11 +822,15 @@ private fun assertSponsoredShortcutTitle(sponsoredShortcutTitle: String, positio
}
private fun assertNotExistingTopSitesList(title: String) {
mDevice.findObject(UiSelector().text(title))
.waitUntilGone(waitingTime)
mDevice.findObject(UiSelector().text(title)).waitUntilGone(waitingTime)
onView(allOf(withId(R.id.top_sites_list)))
.check(matches(not(hasItem(hasDescendant(withText(title))))))
assertFalse(
mDevice.findObject(
UiSelector()
.resourceId("$packageName:id/top_site_title")
.textContains(title),
).waitForExists(waitingTime),
)
}
private fun assertSponsoredTopSitesNotDisplayed() {
@ -852,12 +858,20 @@ private fun assertJumpBackInSectionIsDisplayed() = assertTrue(jumpBackInSection(
private fun assertJumpBackInSectionIsNotDisplayed() = assertFalse(jumpBackInSection().waitForExists(waitingTimeShort))
private fun assertRecentlyVisitedSectionIsDisplayed() = assertTrue(recentlyVisitedSection().waitForExists(waitingTime))
private fun assertRecentlyVisitedSectionIsNotDisplayed() = assertFalse(recentlyVisitedSection().waitForExists(waitingTime))
private fun assertRecentBookmarksSectionIsDisplayed() =
assertTrue(recentBookmarksSection().waitForExists(waitingTime))
private fun assertRecentBookmarksSectionIsNotDisplayed() =
assertFalse(recentBookmarksSection().waitForExists(waitingTimeShort))
private fun assertPocketSectionIsDisplayed() = assertTrue(pocketSection().waitForExists(waitingTime))
private fun assertPocketSectionIsNotDisplayed() = assertFalse(pocketSection().waitForExists(waitingTime))
private fun privateBrowsingButton() = onView(withId(R.id.privateBrowsingButton))
private fun saveTabsToCollectionButton() = onView(withId(R.id.add_tabs_to_collections_button))
@ -867,9 +881,15 @@ private fun tabsCounter() = onView(withId(R.id.tab_button))
private fun jumpBackInSection() =
mDevice.findObject(UiSelector().textContains(getStringResource(R.string.recent_tabs_header)))
private fun recentlyVisitedSection() =
mDevice.findObject(UiSelector().textContains(getStringResource(R.string.history_metadata_header_2)))
private fun recentBookmarksSection() =
mDevice.findObject(UiSelector().textContains(getStringResource(R.string.recently_saved_title)))
private fun pocketSection() =
mDevice.findObject(UiSelector().textContains(getStringResource(R.string.pocket_stories_header_1)))
private fun startBrowsingButton(): UiObject {
val startBrowsingButton = mDevice.findObject(UiSelector().resourceId("$packageName:id/finish_button"))
homeScreenList()

View File

@ -6,22 +6,24 @@ package org.mozilla.fenix.ui.robots
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.isChecked
import androidx.test.espresso.matcher.ViewMatchers.isNotChecked
import androidx.test.espresso.matcher.ViewMatchers.withChild
import androidx.test.espresso.matcher.ViewMatchers.withClassName
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
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.endsWith
import org.hamcrest.Matchers
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.click
@ -30,25 +32,46 @@ import org.mozilla.fenix.helpers.click
*/
class SettingsSubMenuHomepageRobot {
fun verifyHomePageView() {
assertMostVisitedTopSitesButton()
fun verifyHomePageView(
shortcutsSwitchEnabled: Boolean = true,
sponsoredShortcutsCheckBox: Boolean = true,
jumpBackInSwitchEnabled: Boolean = true,
recentBookmarksSwitchEnabled: Boolean = true,
recentlyVisitedSwitchEnabled: Boolean = true,
pocketSwitchEnabled: Boolean = true,
sponsoredStoriesCheckBox: Boolean = true,
) {
assertShortcutsButton()
assertShortcutsSwitchState(shortcutsSwitchEnabled)
assertSponsoredShortcutsButton()
assertSponsoredShortcutsCheckBox(sponsoredShortcutsCheckBox)
assertJumpBackInButton()
assertJumpBackInSwitchState(jumpBackInSwitchEnabled)
assertRecentBookmarksButton()
assertRecentSearchesButton()
assertRecentBookmarksSwitchState(recentBookmarksSwitchEnabled)
assertRecentlyVisitedButton()
assertRecentlyVisitedSwitchState(recentlyVisitedSwitchEnabled)
assertPocketButton()
assertPocketSwitchState(pocketSwitchEnabled)
assertSponsoredStoriesButton()
assertSponsoredStoriesCheckBox(sponsoredStoriesCheckBox)
assertOpeningScreenHeading()
assertHomepageButton()
assertLastTabButton()
assertHomepageAfterFourHoursButton()
}
fun clickSponsoredShortcuts() = sponsoredShortcuts().click()
fun clickShortcutsButton() = shortcutsButton().click()
fun clickSponsoredShortcuts() = sponsoredShortcutsButton().click()
fun clickJumpBackInButton() = jumpBackInButton().click()
fun clickRecentlyVisited() = recentlyVisitedButton().click()
fun clickRecentBookmarksButton() = recentBookmarksButton().click()
fun clickRecentSearchesButton() = recentSearchesButton().click()
fun clickRecentSearchesButton() = recentlyVisitedButton().click()
fun clickPocketButton() = pocketButton().click()
@ -69,37 +92,7 @@ class SettingsSubMenuHomepageRobot {
).waitForExists(waitingTimeShort),
)
fun verifySponsoredShortcutsCheckBox(checked: Boolean) {
if (checked) {
sponsoredShortcuts()
.check(
matches(
hasSibling(
withChild(
allOf(
withClassName(endsWith("CheckBox")),
isChecked(),
),
),
),
),
)
} else {
sponsoredShortcuts()
.check(
matches(
hasSibling(
withChild(
allOf(
withClassName(endsWith("CheckBox")),
isNotChecked(),
),
),
),
),
)
}
}
fun verifySponsoredShortcutsCheckBox(checked: Boolean) = assertSponsoredShortcutsCheckBox(checked)
class Transition {
@ -121,10 +114,10 @@ class SettingsSubMenuHomepageRobot {
}
}
private fun mostVisitedTopSitesButton() =
private fun shortcutsButton() =
onView(allOf(withText(R.string.top_sites_toggle_top_recent_sites_4)))
private fun sponsoredShortcuts() =
private fun sponsoredShortcutsButton() =
onView(allOf(withText(R.string.customize_toggle_contile)))
private fun jumpBackInButton() =
@ -133,12 +126,15 @@ private fun jumpBackInButton() =
private fun recentBookmarksButton() =
onView(allOf(withText(R.string.customize_toggle_recent_bookmarks)))
private fun recentSearchesButton() =
private fun recentlyVisitedButton() =
onView(allOf(withText(R.string.customize_toggle_recently_visited)))
private fun pocketButton() =
onView(allOf(withText(R.string.customize_toggle_pocket)))
private fun sponsoredStoriesButton() =
onView(allOf(withText(R.string.customize_toggle_pocket_sponsored)))
private fun openingScreenHeading() = onView(withText(R.string.preferences_opening_screen))
private fun homepageButton() =
@ -170,16 +166,20 @@ private fun homepageAfterFourHoursButton() =
private fun goBackButton() = onView(allOf(withContentDescription(R.string.action_bar_up_description)))
private fun assertMostVisitedTopSitesButton() =
mostVisitedTopSitesButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertShortcutsButton() =
shortcutsButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertSponsoredShortcutsButton() =
sponsoredShortcutsButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertJumpBackInButton() =
jumpBackInButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertRecentBookmarksButton() =
recentBookmarksButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertRecentSearchesButton() =
recentSearchesButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertRecentlyVisitedButton() =
recentlyVisitedButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertPocketButton() =
pocketButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertSponsoredStoriesButton() =
sponsoredStoriesButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertOpeningScreenHeading() =
openingScreenHeading().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertHomepageButton() =
@ -189,4 +189,208 @@ private fun assertLastTabButton() =
private fun assertHomepageAfterFourHoursButton() =
homepageAfterFourHoursButton().check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
fun assertShortcutsSwitchState(enabled: Boolean) {
if (enabled) {
shortcutsButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isChecked(),
),
),
),
)
} else {
shortcutsButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isNotChecked(),
),
),
),
)
}
}
fun assertSponsoredShortcutsCheckBox(checked: Boolean) {
if (checked) {
sponsoredShortcutsButton()
.check(
matches(
hasSibling(
ViewMatchers.withChild(
allOf(
withClassName(CoreMatchers.endsWith("CheckBox")),
isChecked(),
),
),
),
),
)
} else {
sponsoredShortcutsButton()
.check(
matches(
hasSibling(
ViewMatchers.withChild(
allOf(
withClassName(CoreMatchers.endsWith("CheckBox")),
isNotChecked(),
),
),
),
),
)
}
}
fun assertJumpBackInSwitchState(enabled: Boolean) {
if (enabled) {
jumpBackInButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isChecked(),
),
),
),
)
} else {
jumpBackInButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isNotChecked(),
),
),
),
)
}
}
fun assertRecentBookmarksSwitchState(enabled: Boolean) {
if (enabled) {
recentBookmarksButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isChecked(),
),
),
),
)
} else {
recentBookmarksButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isNotChecked(),
),
),
),
)
}
}
fun assertRecentlyVisitedSwitchState(enabled: Boolean) {
if (enabled) {
recentlyVisitedButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isChecked(),
),
),
),
)
} else {
recentlyVisitedButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isNotChecked(),
),
),
),
)
}
}
fun assertPocketSwitchState(enabled: Boolean) {
if (enabled) {
pocketButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isChecked(),
),
),
),
)
} else {
pocketButton()
.check(
matches(
TestHelper.hasCousin(
Matchers.allOf(
withClassName(Matchers.endsWith("Switch")),
isNotChecked(),
),
),
),
)
}
}
fun assertSponsoredStoriesCheckBox(checked: Boolean) {
if (checked) {
sponsoredStoriesButton()
.check(
matches(
hasSibling(
ViewMatchers.withChild(
allOf(
withClassName(CoreMatchers.endsWith("CheckBox")),
isChecked(),
),
),
),
),
)
} else {
sponsoredStoriesButton()
.check(
matches(
hasSibling(
ViewMatchers.withChild(
allOf(
withClassName(CoreMatchers.endsWith("CheckBox")),
isNotChecked(),
),
),
),
),
)
}
}
private val wallpapersMenuButton = onView(withText("Wallpapers"))