parent
a9bfb303f7
commit
6b639b1a32
|
@ -5,16 +5,11 @@
|
||||||
package org.mozilla.fenix.ui
|
package org.mozilla.fenix.ui
|
||||||
|
|
||||||
import androidx.test.uiautomator.UiDevice
|
import androidx.test.uiautomator.UiDevice
|
||||||
import okhttp3.mockwebserver.MockWebServer
|
|
||||||
import org.junit.After
|
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
|
||||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||||
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
|
||||||
import org.mozilla.fenix.ui.robots.homeScreen
|
import org.mozilla.fenix.ui.robots.homeScreen
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,38 +21,17 @@ class HomeScreenTest {
|
||||||
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
|
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
|
||||||
|
|
||||||
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||||
private lateinit var mockWebServer: MockWebServer
|
|
||||||
|
|
||||||
@get:Rule
|
@get:Rule
|
||||||
val activityTestRule = HomeActivityTestRule()
|
val activityTestRule = HomeActivityTestRule()
|
||||||
|
|
||||||
@Before
|
|
||||||
fun setUp() {
|
|
||||||
mockWebServer = MockWebServer().apply {
|
|
||||||
setDispatcher(AndroidAssetDispatcher())
|
|
||||||
start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
fun tearDown() {
|
|
||||||
mockWebServer.shutdown()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun homeScreenItemsTest() {
|
fun homeScreenItemsTest() {
|
||||||
|
homeScreen { }.dismissOnboarding()
|
||||||
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
|
|
||||||
|
|
||||||
// temp work-around until FIRST_RUN pref = false
|
|
||||||
// is added: https://github.com/mozilla-mobile/fenix/issues/3777
|
|
||||||
homeScreen {
|
|
||||||
verifyNavigationToolbar()
|
|
||||||
}.completeFirstRun(defaultWebPage.url) {
|
|
||||||
}
|
|
||||||
|
|
||||||
homeScreen {
|
homeScreen {
|
||||||
verifyHomeScreen()
|
verifyHomeScreen()
|
||||||
|
verifyNavigationToolbar()
|
||||||
verifyHomePrivateBrowsingButton()
|
verifyHomePrivateBrowsingButton()
|
||||||
verifyHomeMenu()
|
verifyHomeMenu()
|
||||||
verifyHomeWordmark()
|
verifyHomeWordmark()
|
||||||
|
@ -75,20 +49,21 @@ class HomeScreenTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun firstRunHomeScreenItemsTest() {
|
fun firstRunHomeScreenItemsTest() {
|
||||||
|
|
||||||
homeScreen {
|
homeScreen {
|
||||||
verifyHomeScreen()
|
verifyHomeScreen()
|
||||||
|
verifyNavigationToolbar()
|
||||||
verifyHomePrivateBrowsingButton()
|
verifyHomePrivateBrowsingButton()
|
||||||
verifyHomeMenu()
|
verifyHomeMenu()
|
||||||
verifyHomeWordmark()
|
verifyHomeWordmark()
|
||||||
|
|
||||||
verifyWelcomeHeader()
|
verifyWelcomeHeader()
|
||||||
|
|
||||||
verifyAlreadyHaveAnAccountHeader()
|
|
||||||
verifyGetTheMostHeader()
|
verifyGetTheMostHeader()
|
||||||
verifyAccountsSignInButton()
|
verifyAccountsSignInButton()
|
||||||
verifyGetToKnowHeader()
|
verifyGetToKnowHeader()
|
||||||
|
|
||||||
|
swipeUpToDismissFirstRun()
|
||||||
|
|
||||||
verifyChooseThemeHeader()
|
verifyChooseThemeHeader()
|
||||||
verifyChooseThemeText()
|
verifyChooseThemeText()
|
||||||
verifyLightThemeToggle()
|
verifyLightThemeToggle()
|
||||||
|
|
|
@ -30,3 +30,8 @@ class BrowserRobot {
|
||||||
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun browserScreen(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
||||||
|
BrowserRobot().interact()
|
||||||
|
return BrowserRobot.Transition()
|
||||||
|
}
|
||||||
|
|
|
@ -6,11 +6,8 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.ui.robots
|
package org.mozilla.fenix.ui.robots
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import androidx.test.espresso.Espresso.onView
|
import androidx.test.espresso.Espresso.onView
|
||||||
import androidx.test.espresso.action.ViewActions
|
|
||||||
import androidx.test.espresso.action.ViewActions.click
|
import androidx.test.espresso.action.ViewActions.click
|
||||||
import androidx.test.espresso.action.ViewActions.typeText
|
|
||||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||||
import androidx.test.espresso.matcher.ViewMatchers
|
import androidx.test.espresso.matcher.ViewMatchers
|
||||||
import androidx.test.espresso.matcher.ViewMatchers.Visibility
|
import androidx.test.espresso.matcher.ViewMatchers.Visibility
|
||||||
|
@ -18,12 +15,13 @@ import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import androidx.test.uiautomator.By
|
import androidx.test.uiautomator.By
|
||||||
import androidx.test.uiautomator.UiDevice
|
import androidx.test.uiautomator.UiDevice
|
||||||
|
import androidx.test.uiautomator.UiScrollable
|
||||||
|
import androidx.test.uiautomator.UiSelector
|
||||||
import androidx.test.uiautomator.Until
|
import androidx.test.uiautomator.Until
|
||||||
import org.hamcrest.CoreMatchers
|
import org.hamcrest.CoreMatchers
|
||||||
import org.hamcrest.Matchers.allOf
|
import org.hamcrest.Matchers.allOf
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
|
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
|
||||||
import org.mozilla.fenix.helpers.click
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of Robot Pattern for the home screen menu.
|
* Implementation of Robot Pattern for the home screen menu.
|
||||||
|
@ -46,7 +44,6 @@ class HomeScreenRobot {
|
||||||
|
|
||||||
// First Run elements
|
// First Run elements
|
||||||
fun verifyWelcomeHeader() = assertWelcomeHeader()
|
fun verifyWelcomeHeader() = assertWelcomeHeader()
|
||||||
fun verifyAlreadyHaveAnAccountHeader() = assertAlreadyHaveAnAccountHeader()
|
|
||||||
fun verifyGetTheMostHeader() = assertGetTheMostHeader()
|
fun verifyGetTheMostHeader() = assertGetTheMostHeader()
|
||||||
fun verifyAccountsSignInButton() = assertAccountsSignInButton()
|
fun verifyAccountsSignInButton() = assertAccountsSignInButton()
|
||||||
fun verifyGetToKnowHeader() = assertGetToKnowHeader()
|
fun verifyGetToKnowHeader() = assertGetToKnowHeader()
|
||||||
|
@ -69,8 +66,19 @@ class HomeScreenRobot {
|
||||||
fun verifyPrivacyNoticeButton() = assertPrivacyNoticeButton()
|
fun verifyPrivacyNoticeButton() = assertPrivacyNoticeButton()
|
||||||
fun verifyStartBrowsingButton() = assertStartBrowsingButton()
|
fun verifyStartBrowsingButton() = assertStartBrowsingButton()
|
||||||
|
|
||||||
class Transition {
|
private fun scrollToElementByText(text: String): UiScrollable {
|
||||||
|
mDevice.wait(Until.findObject(By.text(text)), waitingTime)
|
||||||
|
val matchedScrollableElement = mDevice.findObject(UiSelector().text(text))
|
||||||
|
val appView = UiScrollable(UiSelector().scrollable(true))
|
||||||
|
appView.scrollIntoView(matchedScrollableElement)
|
||||||
|
return appView
|
||||||
|
}
|
||||||
|
|
||||||
|
fun swipeUpToDismissFirstRun() {
|
||||||
|
scrollToElementByText("Start browsing")
|
||||||
|
}
|
||||||
|
|
||||||
|
class Transition {
|
||||||
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||||
|
|
||||||
fun openThreeDotMenu(interact: ThreeDotMenuRobot.() -> Unit): ThreeDotMenuRobot.Transition {
|
fun openThreeDotMenu(interact: ThreeDotMenuRobot.() -> Unit): ThreeDotMenuRobot.Transition {
|
||||||
|
@ -82,21 +90,8 @@ class HomeScreenRobot {
|
||||||
return ThreeDotMenuRobot.Transition()
|
return ThreeDotMenuRobot.Transition()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun completeFirstRun(url: Uri, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
fun dismissOnboarding() {
|
||||||
|
openThreeDotMenu { }.openSettings { }.goBack { }
|
||||||
mDevice.wait(Until.findObject(By.text("Search or enter address")), waitingTime)
|
|
||||||
navigationToolbar().perform(click())
|
|
||||||
|
|
||||||
browserToolbarEditView().perform(
|
|
||||||
typeText(url.toString()),
|
|
||||||
ViewActions.pressImeActionButton())
|
|
||||||
|
|
||||||
tabCounterText().click()
|
|
||||||
mDevice.wait(Until.findObject(By.res("close_tab_button")), waitingTime)
|
|
||||||
closeTabButton().click()
|
|
||||||
|
|
||||||
BrowserRobot().interact()
|
|
||||||
return BrowserRobot.Transition()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,15 +103,8 @@ fun homeScreen(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition
|
||||||
|
|
||||||
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||||
|
|
||||||
private fun navigationToolbar() = onView(CoreMatchers.allOf(ViewMatchers.withText("Search or enter address")))
|
|
||||||
|
|
||||||
private fun browserToolbarEditView() = onView(allOf(ViewMatchers.withId(R.id.mozac_browser_toolbar_edit_url_view)))
|
|
||||||
private fun closeTabButton() = onView(allOf(ViewMatchers.withId(R.id.close_tab_button)))
|
|
||||||
|
|
||||||
private fun assertNavigationToolbar() = onView(CoreMatchers.allOf(ViewMatchers.withText("Search or enter address")))
|
private fun assertNavigationToolbar() = onView(CoreMatchers.allOf(ViewMatchers.withText("Search or enter address")))
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||||
private fun tabCounterText() = onView(allOf(ViewMatchers.withId(R.id.counter_text)))
|
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
||||||
private fun assertHomeScreen() = onView(ViewMatchers.withResourceName("homeLayout"))
|
private fun assertHomeScreen() = onView(ViewMatchers.withResourceName("homeLayout"))
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||||
private fun assertHomeMenu() = onView(ViewMatchers.withResourceName("menuButton"))
|
private fun assertHomeMenu() = onView(ViewMatchers.withResourceName("menuButton"))
|
||||||
|
@ -155,10 +143,6 @@ private fun threeDotButton() = onView(allOf(ViewMatchers.withId(R.id.menuButton)
|
||||||
// First Run elements
|
// First Run elements
|
||||||
private fun assertWelcomeHeader() = onView(CoreMatchers.allOf(ViewMatchers.withText("Welcome to Firefox Preview!")))
|
private fun assertWelcomeHeader() = onView(CoreMatchers.allOf(ViewMatchers.withText("Welcome to Firefox Preview!")))
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||||
private fun assertAlreadyHaveAnAccountHeader() {
|
|
||||||
onView(CoreMatchers.allOf(ViewMatchers.withText("Already have an account?")))
|
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
||||||
}
|
|
||||||
private fun assertGetTheMostHeader() {
|
private fun assertGetTheMostHeader() {
|
||||||
mDevice.wait(Until.findObject(By.res("Get the most out of Firefox Preview")), waitingTime)
|
mDevice.wait(Until.findObject(By.res("Get the most out of Firefox Preview")), waitingTime)
|
||||||
}
|
}
|
||||||
|
@ -166,11 +150,13 @@ private fun assertAccountsSignInButton() = onView(ViewMatchers.withResourceName(
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||||
private fun assertGetToKnowHeader() = onView(CoreMatchers.allOf(ViewMatchers.withText("Get to know Firefox Preview")))
|
private fun assertGetToKnowHeader() = onView(CoreMatchers.allOf(ViewMatchers.withText("Get to know Firefox Preview")))
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||||
private fun assertChooseThemeHeader() = onView(CoreMatchers.allOf(ViewMatchers.withText("Choose your theme")))
|
private fun assertChooseThemeHeader() {
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Choose your theme")))
|
||||||
private fun assertChooseThemeText() {
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||||
mDevice.wait(Until.findObject(By.res("Try dark theme: easier on your battery and eyes")), waitingTime)
|
|
||||||
}
|
}
|
||||||
|
private fun assertChooseThemeText() =
|
||||||
|
mDevice.wait(Until.findObject(By.res("Try dark theme: easier on your battery and eyes")), waitingTime)
|
||||||
|
|
||||||
private fun assertLightThemeToggle() = onView(ViewMatchers.withResourceName("theme_light_radio_button"))
|
private fun assertLightThemeToggle() = onView(ViewMatchers.withResourceName("theme_light_radio_button"))
|
||||||
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
||||||
private fun assertLightThemeDescription() = onView(CoreMatchers.allOf(ViewMatchers.withText("Light theme")))
|
private fun assertLightThemeDescription() = onView(CoreMatchers.allOf(ViewMatchers.withText("Light theme")))
|
||||||
|
@ -200,7 +186,7 @@ private fun assertBrowsePrivatelyText() {
|
||||||
mDevice.wait(Until.findObject(By.text("private browsing is just a tap away.")), waitingTime)
|
mDevice.wait(Until.findObject(By.text("private browsing is just a tap away.")), waitingTime)
|
||||||
}
|
}
|
||||||
private fun assertYourPrivacyHeader() {
|
private fun assertYourPrivacyHeader() {
|
||||||
mDevice.wait(Until.findObject(By.text("your privacy")), waitingTime)
|
mDevice.wait(Until.findObject(By.text("Your privacy")), waitingTime)
|
||||||
}
|
}
|
||||||
private fun assertYourPrivacyText() {
|
private fun assertYourPrivacyText() {
|
||||||
val privacyText = "We've designed Firefox Preview to give you control"
|
val privacyText = "We've designed Firefox Preview to give you control"
|
||||||
|
|
Loading…
Reference in New Issue