2019-04-10 18:59:38 +02:00
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
@file:Suppress("TooManyFunctions")
|
|
|
|
|
|
|
|
|
|
package org.mozilla.fenix.ui.robots
|
|
|
|
|
|
|
|
|
|
import androidx.test.espresso.Espresso.onView
|
2019-05-16 02:32:25 +02:00
|
|
|
|
import androidx.test.espresso.action.ViewActions.click
|
2019-04-10 18:59:38 +02:00
|
|
|
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers
|
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.Visibility
|
2019-05-16 02:32:25 +02:00
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
|
|
|
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
|
|
|
|
import androidx.test.uiautomator.UiDevice
|
2019-07-13 01:19:08 +02:00
|
|
|
|
import androidx.test.uiautomator.UiScrollable
|
|
|
|
|
import androidx.test.uiautomator.UiSelector
|
2019-07-05 19:38:09 +02:00
|
|
|
|
import org.hamcrest.CoreMatchers
|
2019-05-16 02:32:25 +02:00
|
|
|
|
import org.hamcrest.Matchers.allOf
|
2019-07-16 00:02:55 +02:00
|
|
|
|
import org.hamcrest.Matchers.containsString
|
2019-05-16 02:32:25 +02:00
|
|
|
|
import org.mozilla.fenix.R
|
2019-04-10 18:59:38 +02:00
|
|
|
|
|
2019-05-16 02:32:25 +02:00
|
|
|
|
/**
|
|
|
|
|
* Implementation of Robot Pattern for the home screen menu.
|
|
|
|
|
*/
|
2019-04-10 18:59:38 +02:00
|
|
|
|
class HomeScreenRobot {
|
2019-07-05 19:38:09 +02:00
|
|
|
|
fun verifyNavigationToolbar() = assertNavigationToolbar()
|
2019-05-16 02:32:25 +02:00
|
|
|
|
fun verifyHomeScreen() = assertHomeScreen()
|
|
|
|
|
fun verifyHomePrivateBrowsingButton() = assertHomePrivateBrowsingButton()
|
|
|
|
|
fun verifyHomeMenu() = assertHomeMenu()
|
2019-07-05 19:38:09 +02:00
|
|
|
|
fun verifyOpenTabsHeader() = assertOpenTabsHeader()
|
|
|
|
|
fun verifyAddTabButton() = assertAddTabButton()
|
|
|
|
|
fun verifyNoTabsOpenedText() = assertNoTabsOpenedText()
|
|
|
|
|
fun verifyCollectionsHeader() = assertCollectionsHeader()
|
|
|
|
|
fun verifyNoCollectionsHeader() = assertNoCollectionsHeader()
|
|
|
|
|
fun verifyNoCollectionsText() = assertNoCollectionsText()
|
|
|
|
|
fun verifyNoTabsOpenedHeader() = assertNoTabsOpenedHeader()
|
2019-05-16 02:32:25 +02:00
|
|
|
|
fun verifyHomeWordmark() = assertHomeWordmark()
|
|
|
|
|
fun verifyHomeToolbar() = assertHomeToolbar()
|
|
|
|
|
fun verifyHomeComponent() = assertHomeComponent()
|
|
|
|
|
|
2019-07-09 23:52:15 +02:00
|
|
|
|
// First Run elements
|
|
|
|
|
fun verifyWelcomeHeader() = assertWelcomeHeader()
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-07-09 23:52:15 +02:00
|
|
|
|
fun verifyGetTheMostHeader() = assertGetTheMostHeader()
|
|
|
|
|
fun verifyAccountsSignInButton() = assertAccountsSignInButton()
|
|
|
|
|
fun verifyGetToKnowHeader() = assertGetToKnowHeader()
|
|
|
|
|
fun verifyChooseThemeHeader() = assertChooseThemeHeader()
|
|
|
|
|
fun verifyChooseThemeText() = assertChooseThemeText()
|
|
|
|
|
fun verifyLightThemeToggle() = assertLightThemeToggle()
|
|
|
|
|
fun verifyLightThemeDescription() = assertLightThemeDescription()
|
|
|
|
|
fun verifyDarkThemeToggle() = assertDarkThemeToggle()
|
|
|
|
|
fun verifyDarkThemeDescription() = assertDarkThemeDescription()
|
|
|
|
|
fun verifyAutomaticThemeToggle() = assertAutomaticThemeToggle()
|
|
|
|
|
fun verifyAutomaticThemeDescription() = assertAutomaticThemeDescription()
|
|
|
|
|
fun verifyProtectYourselfHeader() = assertProtectYourselfHeader()
|
|
|
|
|
fun verifyTrackingProtectionToggle() = assertTrackingProtectionToggle()
|
|
|
|
|
fun verifyProtectYourselfText() = assertProtectYourselfText()
|
|
|
|
|
|
|
|
|
|
fun verifyBrowsePrivatelyHeader() = assertBrowsePrivatelyHeader()
|
|
|
|
|
fun verifyBrowsePrivatelyText() = assertBrowsePrivatelyText()
|
|
|
|
|
fun verifyYourPrivacyHeader() = assertYourPrivacyHeader()
|
|
|
|
|
fun verifyYourPrivacyText() = assertYourPrivacyText()
|
|
|
|
|
fun verifyPrivacyNoticeButton() = assertPrivacyNoticeButton()
|
|
|
|
|
fun verifyStartBrowsingButton() = assertStartBrowsingButton()
|
|
|
|
|
|
2019-07-13 01:19:08 +02:00
|
|
|
|
private fun scrollToElementByText(text: String): UiScrollable {
|
|
|
|
|
val appView = UiScrollable(UiSelector().scrollable(true))
|
2019-07-16 00:02:55 +02:00
|
|
|
|
appView.scrollTextIntoView(text)
|
2019-07-13 01:19:08 +02:00
|
|
|
|
return appView
|
|
|
|
|
}
|
2019-05-16 02:32:25 +02:00
|
|
|
|
|
2019-07-13 01:19:08 +02:00
|
|
|
|
fun swipeUpToDismissFirstRun() {
|
|
|
|
|
scrollToElementByText("Start browsing")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Transition {
|
2019-05-16 02:32:25 +02:00
|
|
|
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
|
|
|
|
|
|
|
|
|
fun openThreeDotMenu(interact: ThreeDotMenuRobot.() -> Unit): ThreeDotMenuRobot.Transition {
|
|
|
|
|
mDevice.waitForIdle()
|
|
|
|
|
threeDotButton().perform(click())
|
|
|
|
|
|
|
|
|
|
ThreeDotMenuRobot().interact()
|
|
|
|
|
return ThreeDotMenuRobot.Transition()
|
|
|
|
|
}
|
2019-07-05 19:38:09 +02:00
|
|
|
|
|
2019-07-15 23:25:31 +02:00
|
|
|
|
fun openSearch(interact: SearchRobot.() -> Unit): SearchRobot.Transition {
|
|
|
|
|
mDevice.waitForIdle()
|
|
|
|
|
navigationToolbar().perform(click())
|
|
|
|
|
|
|
|
|
|
SearchRobot().interact()
|
|
|
|
|
return SearchRobot.Transition()
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-13 01:19:08 +02:00
|
|
|
|
fun dismissOnboarding() {
|
|
|
|
|
openThreeDotMenu { }.openSettings { }.goBack { }
|
2019-07-05 19:38:09 +02:00
|
|
|
|
}
|
2019-05-16 02:32:25 +02:00
|
|
|
|
}
|
2019-04-10 18:59:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-16 02:32:25 +02:00
|
|
|
|
fun homeScreen(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
|
2019-04-10 18:59:38 +02:00
|
|
|
|
HomeScreenRobot().interact()
|
2019-05-16 02:32:25 +02:00
|
|
|
|
return HomeScreenRobot.Transition()
|
2019-04-10 18:59:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 19:38:09 +02:00
|
|
|
|
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
|
|
|
|
|
2019-08-14 22:36:50 +02:00
|
|
|
|
private fun navigationToolbar() =
|
|
|
|
|
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)))
|
2019-07-15 23:25:31 +02:00
|
|
|
|
|
2019-05-16 02:32:25 +02:00
|
|
|
|
private fun assertHomeScreen() = onView(ViewMatchers.withResourceName("homeLayout"))
|
2019-04-10 18:59:38 +02:00
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-05-16 02:32:25 +02:00
|
|
|
|
private fun assertHomeMenu() = onView(ViewMatchers.withResourceName("menuButton"))
|
2019-04-10 18:59:38 +02:00
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
|
|
|
|
private fun assertHomePrivateBrowsingButton() =
|
|
|
|
|
onView(ViewMatchers.withResourceName("privateBrowsingButton"))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
2019-05-16 02:32:25 +02:00
|
|
|
|
private fun assertHomeWordmark() = onView(ViewMatchers.withResourceName("wordmark"))
|
2019-04-10 18:59:38 +02:00
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-05-16 02:32:25 +02:00
|
|
|
|
private fun assertHomeToolbar() = onView(ViewMatchers.withResourceName("toolbar"))
|
2019-08-02 18:10:35 +02:00
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-07-16 00:02:55 +02:00
|
|
|
|
private fun assertOpenTabsHeader() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Open tabs")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
|
|
private fun assertAddTabButton() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withResourceName("add_tab_button")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
|
|
private fun assertNoTabsOpenedHeader() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("No tabs opened")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
2019-07-05 19:38:09 +02:00
|
|
|
|
private fun assertNoTabsOpenedText() {
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Your open tabs will be shown here.")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
}
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
|
|
|
|
private fun assertCollectionsHeader() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Collections")))
|
2019-07-05 19:38:09 +02:00
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
|
|
|
|
private fun assertNoCollectionsHeader() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("No collections")))
|
2019-07-05 19:38:09 +02:00
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-07-05 19:38:09 +02:00
|
|
|
|
private fun assertNoCollectionsText() =
|
2019-08-14 22:36:50 +02:00
|
|
|
|
onView(
|
|
|
|
|
CoreMatchers.allOf(
|
|
|
|
|
ViewMatchers
|
|
|
|
|
.withText("Collect the things that matter to you. To start, save open tabs to a new collection.")
|
|
|
|
|
)
|
|
|
|
|
)
|
2019-07-05 19:38:09 +02:00
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-05-16 02:32:25 +02:00
|
|
|
|
private fun assertHomeComponent() = onView(ViewMatchers.withResourceName("home_component"))
|
2019-04-10 18:59:38 +02:00
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-05-16 02:32:25 +02:00
|
|
|
|
|
|
|
|
|
private fun threeDotButton() = onView(allOf(ViewMatchers.withId(R.id.menuButton)))
|
2019-07-09 23:52:15 +02:00
|
|
|
|
|
|
|
|
|
// First Run elements
|
2019-08-14 22:36:50 +02:00
|
|
|
|
private fun assertWelcomeHeader() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Welcome to Firefox Preview!")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
2019-07-16 00:02:55 +02:00
|
|
|
|
private fun assertGetTheMostHeader() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Get the most out of Firefox Preview.")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
|
|
|
|
private fun assertAccountsSignInButton() =
|
|
|
|
|
onView(ViewMatchers.withResourceName("turn_on_sync_button"))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
|
|
private fun assertGetToKnowHeader() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Get to know Firefox Preview")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-07-16 00:02:55 +02:00
|
|
|
|
|
|
|
|
|
private fun assertChooseThemeHeader() =
|
2019-07-13 01:19:08 +02:00
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Choose your theme")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-07-16 00:02:55 +02:00
|
|
|
|
|
2019-07-13 01:19:08 +02:00
|
|
|
|
private fun assertChooseThemeText() =
|
2019-07-16 00:02:55 +02:00
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Try dark theme: easier on your battery and your eyes.")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-07-13 01:19:08 +02:00
|
|
|
|
|
2019-08-14 22:36:50 +02:00
|
|
|
|
private fun assertLightThemeToggle() =
|
|
|
|
|
onView(ViewMatchers.withResourceName("theme_light_radio_button"))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
|
|
private fun assertLightThemeDescription() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Light theme")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
|
|
private fun assertDarkThemeToggle() =
|
|
|
|
|
onView(ViewMatchers.withResourceName("theme_dark_radio_button"))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
|
|
private fun assertDarkThemeDescription() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Dark theme")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
|
|
private fun assertAutomaticThemeToggle() =
|
|
|
|
|
onView(ViewMatchers.withResourceName("theme_automatic_radio_button"))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
|
|
private fun assertAutomaticThemeDescription() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Automatic")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-07-16 00:02:55 +02:00
|
|
|
|
|
|
|
|
|
private fun assertProtectYourselfHeader() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Protect yourself")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-07-16 00:02:55 +02:00
|
|
|
|
private fun assertTrackingProtectionToggle() = onView(
|
2019-08-14 22:36:50 +02:00
|
|
|
|
CoreMatchers.allOf(ViewMatchers.withResourceName("tracking_protection_toggle"))
|
|
|
|
|
)
|
2019-07-16 00:02:55 +02:00
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-07-09 23:52:15 +02:00
|
|
|
|
private fun assertProtectYourselfText() {
|
2019-08-14 22:36:50 +02:00
|
|
|
|
onView(
|
|
|
|
|
CoreMatchers.allOf(
|
|
|
|
|
ViewMatchers.withText(
|
|
|
|
|
"Firefox Preview blocks ad trackers that follow you around the web."
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
2019-07-16 00:02:55 +02:00
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-07-09 23:52:15 +02:00
|
|
|
|
}
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-07-16 00:02:55 +02:00
|
|
|
|
private fun assertBrowsePrivatelyHeader() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Browse privately")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-07-16 00:02:55 +02:00
|
|
|
|
private fun assertBrowsePrivatelyText() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText(containsString("private browsing is just a tap away."))))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
|
|
private fun assertYourPrivacyHeader() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Your privacy")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-07-16 00:02:55 +02:00
|
|
|
|
private fun assertYourPrivacyText() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText(
|
|
|
|
|
"We’ve designed Firefox Preview to give you control over what you share online and what you share with us.")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
2019-08-14 22:36:50 +02:00
|
|
|
|
|
2019-07-16 00:02:55 +02:00
|
|
|
|
private fun assertPrivacyNoticeButton() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Read our privacy notice")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
|
|
private fun assertStartBrowsingButton() =
|
|
|
|
|
onView(CoreMatchers.allOf(ViewMatchers.withText("Start browsing")))
|
|
|
|
|
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
|