2019-05-16 02:32:25 +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-07-16 22:02:12 +02:00
|
|
|
import androidx.test.espresso.assertion.ViewAssertions.matches
|
2019-05-16 02:32:25 +02:00
|
|
|
import androidx.test.espresso.matcher.ViewMatchers
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.withText
|
2019-09-10 21:03:47 +02:00
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.withId
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
|
|
|
import androidx.test.espresso.matcher.ViewMatchers.withResourceName
|
2019-05-16 02:32:25 +02:00
|
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
2019-07-16 22:02:12 +02:00
|
|
|
import androidx.test.uiautomator.By
|
2019-05-16 02:32:25 +02:00
|
|
|
import androidx.test.uiautomator.UiDevice
|
2019-07-16 22:02:12 +02:00
|
|
|
import androidx.test.uiautomator.Until
|
2019-05-16 02:32:25 +02:00
|
|
|
import org.hamcrest.Matchers.allOf
|
|
|
|
import org.mozilla.fenix.R
|
2019-07-16 22:02:12 +02:00
|
|
|
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
|
2019-05-16 02:32:25 +02:00
|
|
|
import org.mozilla.fenix.helpers.click
|
2019-09-26 23:25:34 +02:00
|
|
|
import org.mozilla.fenix.share.ShareFragment
|
2019-05-16 02:32:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of Robot Pattern for the three dot (main) menu.
|
|
|
|
*/
|
|
|
|
class ThreeDotMenuRobot {
|
|
|
|
fun verifySettingsButton() = assertSettingsButton()
|
|
|
|
fun verifyLibraryButton() = assertLibraryButton()
|
|
|
|
fun verifyHelpButton() = assertHelpButton()
|
2019-07-16 22:02:12 +02:00
|
|
|
fun verifyThreeDotMenuExists() = threeDotMenuRecyclerViewExists()
|
|
|
|
fun verifyForwardButton() = assertForwardButton()
|
|
|
|
fun verifyBackButton() = assertBackButton()
|
|
|
|
fun verifyRefreshButton() = assertRefreshButton()
|
2019-08-27 19:56:12 +02:00
|
|
|
fun verifyCloseAllTabsButton() = assertCloseAllTabsButton()
|
|
|
|
fun verifyShareButton() = assertShareButton()
|
2019-09-10 21:03:47 +02:00
|
|
|
fun clickShareButton() {
|
|
|
|
shareButton().click()
|
|
|
|
mDevice.wait(Until.findObject(By.text("SHARE A LINK")), waitingTime)
|
|
|
|
}
|
2019-09-26 23:25:34 +02:00
|
|
|
|
2019-09-13 00:56:36 +02:00
|
|
|
fun verifyShareTabButton() = assertShareTabButton()
|
2019-08-27 19:56:12 +02:00
|
|
|
fun verifySaveCollection() = assertSaveCollectionButton()
|
2019-09-09 20:16:47 +02:00
|
|
|
fun verifyFindInPageButton() = assertFindInPageButton()
|
2019-09-26 23:25:34 +02:00
|
|
|
fun verifyShareScrim() = assertShareScrim()
|
2019-09-10 21:03:47 +02:00
|
|
|
fun verifySendToDeviceTitle() = assertSendToDeviceTitle()
|
|
|
|
fun verifyShareALinkTitle() = assertShareALinkTitle()
|
2019-09-11 17:41:05 +02:00
|
|
|
fun verifyWhatsNewButton() = assertWhatsNewButton()
|
2019-05-16 02:32:25 +02:00
|
|
|
|
|
|
|
class Transition {
|
|
|
|
|
2019-07-16 22:02:12 +02:00
|
|
|
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
2019-05-16 02:32:25 +02:00
|
|
|
|
|
|
|
fun openSettings(interact: SettingsRobot.() -> Unit): SettingsRobot.Transition {
|
2019-07-22 18:58:53 +02:00
|
|
|
mDevice.wait(Until.findObject(By.text("R.string.settings")), waitingTime)
|
2019-05-16 02:32:25 +02:00
|
|
|
settingsButton().click()
|
|
|
|
|
|
|
|
SettingsRobot().interact()
|
|
|
|
return SettingsRobot.Transition()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun openLibrary(interact: LibraryRobot.() -> Unit): LibraryRobot.Transition {
|
2019-07-22 18:58:53 +02:00
|
|
|
mDevice.wait(Until.findObject(By.text("R.string.Library")), waitingTime)
|
2019-05-16 02:32:25 +02:00
|
|
|
libraryButton().click()
|
|
|
|
|
|
|
|
LibraryRobot().interact()
|
|
|
|
return LibraryRobot.Transition()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun openHelp(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
2019-07-16 22:02:12 +02:00
|
|
|
mDevice.wait(Until.findObject(By.text("Help")), waitingTime)
|
2019-05-16 02:32:25 +02:00
|
|
|
helpButton().click()
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
}
|
2019-07-16 22:02:12 +02:00
|
|
|
|
|
|
|
fun goForward(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
|
|
|
mDevice.wait(Until.findObject(By.desc("Forward")), waitingTime)
|
|
|
|
forwardButton().click()
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun goBack(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
|
|
|
mDevice.wait(Until.findObject(By.desc("Back")), waitingTime)
|
|
|
|
backButton().click()
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun refreshPage(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
|
|
|
mDevice.wait(Until.findObject(By.desc("Refresh")), waitingTime)
|
|
|
|
refreshButton().click()
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
}
|
2019-08-27 19:56:12 +02:00
|
|
|
|
|
|
|
fun closeAllTabs(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
|
|
|
|
mDevice.wait(Until.findObject(By.text("Close all tabs")), waitingTime)
|
|
|
|
closeAllTabsButton().click()
|
|
|
|
|
|
|
|
HomeScreenRobot().interact()
|
|
|
|
return HomeScreenRobot.Transition()
|
|
|
|
}
|
2019-09-09 20:16:47 +02:00
|
|
|
|
|
|
|
fun openFindInPage(interact: FindInPageRobot.() -> Unit): FindInPageRobot.Transition {
|
|
|
|
mDevice.wait(Until.findObject(By.text("Find in page")), waitingTime)
|
|
|
|
findInPageButton().click()
|
|
|
|
|
|
|
|
FindInPageRobot().interact()
|
|
|
|
return FindInPageRobot.Transition()
|
|
|
|
}
|
2019-09-11 17:41:05 +02:00
|
|
|
|
|
|
|
fun openWhatsNew(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
|
|
|
mDevice.wait(Until.findObject(By.text("What's New")), waitingTime)
|
|
|
|
whatsNewButton().click()
|
|
|
|
|
|
|
|
BrowserRobot().interact()
|
|
|
|
return BrowserRobot.Transition()
|
|
|
|
}
|
2019-05-16 02:32:25 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-10 21:03:47 +02:00
|
|
|
|
2019-07-16 22:02:12 +02:00
|
|
|
private fun threeDotMenuRecyclerViewExists() {
|
|
|
|
onView(withId(R.id.mozac_browser_menu_recyclerView)).check(matches(isDisplayed()))
|
|
|
|
}
|
2019-09-26 23:25:34 +02:00
|
|
|
|
2019-07-22 18:58:53 +02:00
|
|
|
private fun settingsButton() = onView(allOf(withText(R.string.settings)))
|
2019-05-16 02:32:25 +02:00
|
|
|
private fun assertSettingsButton() = settingsButton()
|
2019-08-27 19:56:12 +02:00
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
2019-05-16 02:32:25 +02:00
|
|
|
|
|
|
|
private fun libraryButton() = onView(allOf(withText(R.string.browser_menu_your_library)))
|
|
|
|
private fun assertLibraryButton() = libraryButton()
|
2019-08-27 19:56:12 +02:00
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
2019-05-16 02:32:25 +02:00
|
|
|
|
|
|
|
private fun helpButton() = onView(allOf(withText(R.string.browser_menu_help)))
|
|
|
|
private fun assertHelpButton() = helpButton()
|
2019-08-27 19:56:12 +02:00
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
2019-07-16 22:02:12 +02:00
|
|
|
|
|
|
|
private fun forwardButton() = onView(ViewMatchers.withContentDescription("Forward"))
|
|
|
|
private fun assertForwardButton() = forwardButton()
|
2019-08-27 19:56:12 +02:00
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
2019-07-16 22:02:12 +02:00
|
|
|
|
|
|
|
private fun backButton() = onView(ViewMatchers.withContentDescription("Back"))
|
|
|
|
private fun assertBackButton() = backButton()
|
2019-08-27 19:56:12 +02:00
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
2019-07-16 22:02:12 +02:00
|
|
|
|
|
|
|
private fun refreshButton() = onView(ViewMatchers.withContentDescription("Refresh"))
|
|
|
|
private fun assertRefreshButton() = refreshButton()
|
2019-08-27 19:56:12 +02:00
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
private fun closeAllTabsButton() = onView(allOf(withText("Close all tabs")))
|
|
|
|
private fun assertCloseAllTabsButton() = closeAllTabsButton()
|
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
|
|
|
|
2019-09-13 00:56:36 +02:00
|
|
|
private fun shareTabButton() = onView(allOf(withText("Share tabs")))
|
|
|
|
private fun assertShareTabButton() = shareTabButton()
|
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
2019-09-26 23:25:34 +02:00
|
|
|
|
2019-09-10 21:03:47 +02:00
|
|
|
private fun shareButton() = onView(allOf(withText("Share")))
|
2019-08-27 19:56:12 +02:00
|
|
|
private fun assertShareButton() = shareButton()
|
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
|
|
|
|
|
|
|
private fun saveCollectionButton() = onView(allOf(withText("Save to collection")))
|
|
|
|
private fun assertSaveCollectionButton() = saveCollectionButton()
|
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
2019-09-09 20:16:47 +02:00
|
|
|
|
|
|
|
private fun findInPageButton() = onView(allOf(withText("Find in page")))
|
|
|
|
private fun assertFindInPageButton() = findInPageButton()
|
2019-09-10 21:03:47 +02:00
|
|
|
|
2019-09-26 23:25:34 +02:00
|
|
|
private fun shareScrim() = onView(withResourceName("closeSharingScrim"))
|
|
|
|
private fun assertShareScrim() =
|
|
|
|
shareScrim().check(matches(ViewMatchers.withAlpha(ShareFragment.SHOW_PAGE_ALPHA)))
|
|
|
|
|
|
|
|
private fun SendToDeviceTitle() =
|
|
|
|
onView(allOf(withText("SEND TO DEVICE"), withResourceName("accountHeaderText")))
|
|
|
|
|
2019-09-10 21:03:47 +02:00
|
|
|
private fun assertSendToDeviceTitle() = SendToDeviceTitle()
|
2019-09-09 20:16:47 +02:00
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|
2019-09-10 21:03:47 +02:00
|
|
|
|
2019-09-26 23:25:34 +02:00
|
|
|
private fun ShareALinkTitle() =
|
|
|
|
onView(allOf(withText("SHARE A LINK"), withResourceName("link_header")))
|
|
|
|
|
2019-09-10 21:03:47 +02:00
|
|
|
private fun assertShareALinkTitle() = ShareALinkTitle()
|
2019-09-11 17:41:05 +02:00
|
|
|
|
|
|
|
private fun whatsNewButton() = onView(allOf(withText("What's New")))
|
|
|
|
private fun assertWhatsNewButton() = whatsNewButton()
|
|
|
|
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
|