2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/16615: UI Smoke Tests for No history in PB and Add to home screen

This commit is contained in:
AndiAJ 2021-01-19 09:40:36 +02:00 committed by Oana Horvath
parent 2042857a3c
commit b6a6e4ae41
3 changed files with 84 additions and 20 deletions

View File

@ -279,16 +279,25 @@ class SmokeTest {
@Test
// Verifies the Add to home screen option in a tab's 3 dot menu
fun mainMenuAddToHomeScreenTest() {
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val website = TestAssetHelper.getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
homeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(website.url) {
}.openThreeDotMenu {
}.openAddToHomeScreen {
verifyShortcutNameField(defaultWebPage.title)
clickCancelShortcutButton()
}
browserScreen {
}.openThreeDotMenu {
}.openAddToHomeScreen {
verifyShortcutNameField("Test_Page_1")
addShortcutName("Test Page")
clickAddShortcutButton()
clickAddAutomaticallyButton()
}.openHomeScreenShortcut(defaultWebPage.title) {}
}.openHomeScreenShortcut("Test Page") {
}
}
@Test
@ -1058,4 +1067,36 @@ class SmokeTest {
verifyNewTabButton()
}
}
@Test
fun noHistoryInPrivateBrowsingTest() {
val website = TestAssetHelper.getGenericAsset(mockWebServer, 1)
homeScreen {
}.togglePrivateBrowsingMode()
homeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(website.url) {
mDevice.waitForIdle()
}.openThreeDotMenu {
}.openHistory {
verifyEmptyHistoryView()
}
}
@Test
fun addPrivateBrowsingShortcutTest() {
homeScreen {
}.dismissOnboarding()
homeScreen {
}.triggerPrivateBrowsingShortcutPrompt {
verifyNoThanksPrivateBrowsingShortcutButton()
verifyAddPrivateBrowsingShortcutButton()
clickAddPrivateBrowsingShortcutButton()
clickAddAutomaticallyButton()
}.openHomeScreenShortcut("Private Firefox Preview") {
}
}
}

View File

@ -9,18 +9,16 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.clearText
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.By
import androidx.test.uiautomator.By.text
import androidx.test.uiautomator.By.textContains
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.anyOf
import org.junit.Assert
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.click
@ -31,7 +29,11 @@ import org.mozilla.fenix.helpers.ext.waitNotNull
*/
class AddToHomeScreenRobot {
fun verifyShortcutIcon() = assertShortcutIcon()
fun verifyAddPrivateBrowsingShortcutButton() = assertAddPrivateBrowsingShortcutButton()
fun verifyNoThanksPrivateBrowsingShortcutButton() = assertNoThanksPrivateBrowsingShortcutButton()
fun clickAddPrivateBrowsingShortcutButton() = addPrivateBrowsingShortcutButton().click()
fun addShortcutName(title: String) {
mDevice.waitNotNull(Until.findObject(By.text("Add to Home screen")), waitingTime)
@ -44,6 +46,8 @@ class AddToHomeScreenRobot {
fun clickAddShortcutButton() = addButton().click()
fun clickCancelShortcutButton() = cancelAddToHomeScreenButton().click()
fun clickAddAutomaticallyButton() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mDevice.wait(Until.findObject(textContains("add automatically")), waitingTime)
@ -92,15 +96,19 @@ private fun assertShortcutNameField(expectedText: String) {
.check(matches(isCompletelyDisplayed()))
}
private fun addButton() = onView(anyOf(withText("ADD")))
private fun addButton() = onView((withText("ADD")))
private fun cancelAddToHomeScreenButton() = onView((withText("CANCEL")))
private fun addAutomaticallyButton() =
mDevice.findObject(UiSelector().textContains("add automatically"))
private fun assertShortcutIcon() {
mDevice.wait(
Until.findObject(text("Firefox Preview")),
waitingTime
)
Assert.assertTrue(mDevice.hasObject(By.text("Firefox Preview")))
}
private fun addPrivateBrowsingShortcutButton() = onView(withId(R.id.cfr_pos_button))
private fun assertAddPrivateBrowsingShortcutButton() = addPrivateBrowsingShortcutButton()
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun noThanksPrivateBrowsingShortcutButton() = onView(withId(R.id.cfr_neg_button))
private fun assertNoThanksPrivateBrowsingShortcutButton() = noThanksPrivateBrowsingShortcutButton()
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))

View File

@ -37,8 +37,8 @@ import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import androidx.test.uiautomator.Until.findObject
import mozilla.components.support.ktx.android.content.appName
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
@ -47,7 +47,6 @@ import org.hamcrest.Matchers
import org.junit.Assert
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestHelper.scrollToElementByText
@ -268,7 +267,7 @@ class HomeScreenRobot {
fun verifySnackBarText(expectedText: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(findObject(By.text(expectedText)), TestAssetHelper.waitingTime)
mDevice.waitNotNull(findObject(By.text(expectedText)), waitingTime)
}
fun snackBarButtonClick(expectedText: String) {
@ -340,6 +339,22 @@ class HomeScreenRobot {
.perform(click())
}
fun triggerPrivateBrowsingShortcutPrompt(interact: AddToHomeScreenRobot.() -> Unit): AddToHomeScreenRobot.Transition {
// Loop to press the PB icon for 5 times to display the Add the Private Browsing Shortcut CFR
for (i in 1..5) {
mDevice.findObject(UiSelector().resourceId("$packageName:id/privateBrowsingButton"))
.waitForExists(
waitingTime
)
onView(ViewMatchers.withResourceName("privateBrowsingButton"))
.perform(click())
}
AddToHomeScreenRobot().interact()
return AddToHomeScreenRobot.Transition()
}
fun pressBack() {
onView(ViewMatchers.isRoot()).perform(ViewActions.pressBack())
}