For #26144 new verifySponsoredShortcutsListTest UI test

This commit is contained in:
AndiAJ 2022-08-12 15:44:44 +03:00 committed by mergify[bot]
parent 81dae89969
commit 96c8bde3fd
3 changed files with 92 additions and 1 deletions

View File

@ -238,4 +238,24 @@ class TopSitesTest {
verifyEmptyHistoryView()
}
}
@SmokeTest
@Test
fun verifySponsoredShortcutsListTest() {
homeScreen {
}.openThreeDotMenu {
}.openCustomizeHome {
verifySponsoredShortcutsCheckBox(true)
}.goBack {
verifyExistingSponsoredTopSitesTabs(2)
verifyExistingSponsoredTopSitesTabs(3)
}.openThreeDotMenu {
}.openCustomizeHome {
clickSponsoredShortcuts()
verifySponsoredShortcutsCheckBox(false)
}.goBack {
verifyNotExistingSponsoredTopSitesList()
}
}
}

View File

@ -26,6 +26,8 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withHint
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withParent
import androidx.test.espresso.matcher.ViewMatchers.withParentIndex
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiObject
@ -50,13 +52,13 @@ import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.helpers.TestHelper.appName
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
import org.mozilla.fenix.helpers.ext.waitNotNull
import org.mozilla.fenix.helpers.matchers.hasItem
import org.mozilla.fenix.helpers.withBitmapDrawable
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.ui.util.STRING_ONBOARDING_ACCOUNT_SIGN_IN_HEADER
import org.mozilla.fenix.ui.util.STRING_ONBOARDING_TOOLBAR_PLACEMENT_HEADER
import org.mozilla.fenix.ui.util.STRING_ONBOARDING_TRACKING_PROTECTION_HEADER
@ -137,7 +139,9 @@ class HomeScreenRobot {
fun verifyExistingTopSitesList() = assertExistingTopSitesList()
fun verifyNotExistingTopSitesList(title: String) = assertNotExistingTopSitesList(title)
fun verifyNotExistingSponsoredTopSitesList() = assertSponsoredTopSitesNotDisplayed()
fun verifyExistingTopSitesTabs(title: String) = assertExistingTopSitesTabs(title)
fun verifyExistingSponsoredTopSitesTabs(position: Int) = assertSponsoredTopSiteIsDisplayed(position)
fun verifyTopSiteContextMenuItems() = assertTopSiteContextMenuItems()
fun verifyJumpBackInSectionIsDisplayed() = assertJumpBackInSectionIsDisplayed()
@ -662,6 +666,21 @@ private fun assertExistingTopSitesTabs(title: String) {
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
private fun assertSponsoredTopSiteIsDisplayed(position: Int) {
mDevice.findObject(
UiSelector()
.resourceId("$packageName:id/top_site_subtitle")
.textContains(getStringResource(R.string.top_sites_sponsored_label))
).waitForExists(waitingTime)
onView(
allOf(
withText(R.string.top_sites_sponsored_label),
withParent(withParentIndex(position - 1))
)
).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
private fun assertNotExistingTopSitesList(title: String) {
mDevice.findObject(UiSelector().text(title))
.waitUntilGone(waitingTime)
@ -670,6 +689,16 @@ private fun assertNotExistingTopSitesList(title: String) {
.check(matches(not(hasItem(hasDescendant(withText(title))))))
}
private fun assertSponsoredTopSitesNotDisplayed() {
assertFalse(
mDevice.findObject(
UiSelector()
.resourceId("$packageName:id/top_site_subtitle")
.textContains(getStringResource(R.string.top_sites_sponsored_label))
).waitForExists(waitingTime)
)
}
private fun assertTopSiteContextMenuItems() {
mDevice.waitNotNull(
findObject(By.text("Open in private tab")),

View File

@ -8,12 +8,17 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
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.allOf
import org.hamcrest.CoreMatchers.endsWith
import org.junit.Assert.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
@ -37,6 +42,8 @@ class SettingsSubMenuHomepageRobot {
assertHomepageAfterFourHoursButton()
}
fun clickSponsoredShortcuts() = sponsoredShortcuts().click()
fun clickJumpBackInButton() = jumpBackInButton().click()
fun clickRecentBookmarksButton() = recentBookmarksButton().click()
@ -58,6 +65,38 @@ 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()
)
)
)
)
)
}
}
class Transition {
fun goBack(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
@ -81,6 +120,9 @@ class SettingsSubMenuHomepageRobot {
private fun mostVisitedTopSitesButton() =
onView(allOf(withText(R.string.top_sites_toggle_top_recent_sites_4)))
private fun sponsoredShortcuts() =
onView(allOf(withText(R.string.customize_toggle_contile)))
private fun jumpBackInButton() =
onView(allOf(withText(R.string.customize_toggle_jump_back_in)))