1
0
Fork 0

for #9407: fixed and added collection tests (#10566)

master
Oana Horvath 2020-05-12 10:51:44 +03:00 committed by GitHub
parent d58c022619
commit 56e0dd8d6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 491 additions and 157 deletions

View File

@ -4,27 +4,19 @@
package org.mozilla.fenix.ui
import android.net.Uri
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import okhttp3.mockwebserver.MockWebServer
import org.junit.Ignore
import org.junit.Before
import org.junit.After
import org.junit.Test
import org.junit.Before
import org.junit.Rule
import org.mozilla.fenix.R
import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
@ -35,8 +27,11 @@ import org.mozilla.fenix.ui.robots.navigationToolbar
class CollectionTest {
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private lateinit var mockWebServer: MockWebServer
private val firstCollectionName = "testcollection_1"
private val secondCollectionName = "testcollection_2"
@get:Rule
val activityTestRule = HomeActivityTestRule()
@ -55,161 +50,299 @@ class CollectionTest {
}
@Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793")
// open a webpage, and add currently opened tab to existing collection
fun addTabToCollectionTest() {
fun verifyCreateFirstCollectionFlowItems() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
createCollection(firstWebPage.url, "testcollection_1")
// Close the open tab
homeScreen {
verifyHomeScreen()
}
onView(ViewMatchers.withId(R.id.close_tab_button)).click()
// On homeview, open another webpage
navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
}.openHomeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
verifyPageContent(secondWebPage.content)
}
// Save the current page to the testcollection_1
navigationToolbar {
}.openThreeDotMenu {
// click save to collection menu item, type collection name
clickBrowserViewSaveCollectionButton()
org.mozilla.fenix.ui.robots.mDevice.wait(
Until.findObject(By.text("testcollection_1")),
TestAssetHelper.waitingTime)
onView(ViewMatchers.withText("testcollection_1")).click()
mDevice.pressBack() // go to main page
}
// close currently opened tab
homeScreen {
verifyHomeScreen()
onView(ViewMatchers.withId(R.id.close_tab_button)).click()
org.mozilla.fenix.ui.robots.mDevice.wait(
Until.findObject(By.text("testcollection_1")),
TestAssetHelper.waitingTime)
// On homeview, expand the collection and open the first saved page
onView(ViewMatchers.withText("testcollection_1")).click()
onView(ViewMatchers.withText("Test_Page_1")).click()
}
// Page content: 1
browserScreen {
verifyPageContent("Page content: 1")
mDevice.pressBack() // go to main page
}
// tab_in_collection_item
homeScreen {
verifyHomeScreen()
onView(ViewMatchers.withId(R.id.close_tab_button)).click()
// On homeview, expand the collection and open the first saved page
org.mozilla.fenix.ui.robots.mDevice.wait(
Until.findObject(By.text("Test_Page_2")),
TestAssetHelper.waitingTime)
onView(ViewMatchers.withText("Test_Page_2")).click()
}
// Page content: 2
browserScreen {
verifyPageContent("Page content: 2")
}.openHomeScreen {
clickSaveCollectionButton()
verifySelectTabsView()
selectAllTabsForCollection()
verifyTabsSelectedCounterText(2)
deselectAllTabsForCollection()
verifyTabsSelectedCounterText(0)
selectTabForCollection(firstWebPage.title)
verifyTabsSelectedCounterText(1)
selectAllTabsForCollection()
saveTabsSelectedForCollection()
verifyNameCollectionView()
verifyDefaultCollectionName("Collection 1")
typeCollectionName(firstCollectionName)
verifySnackBarText("Tabs saved!")
verifyExistingOpenTabs(firstWebPage.title)
verifyExistingOpenTabs(secondWebPage.title)
}
}
@Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793")
// Rename Collection from the Homescreen
fun renameCollectionTest() {
// open a webpage, and add currently opened tab to existing collection
fun addTabToExistingCollectionTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
createCollection(firstCollectionName)
homeScreen {
verifyExistingTabList()
closeTab()
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
verifyPageContent(secondWebPage.content)
}.openThreeDotMenu {
clickBrowserViewSaveCollectionButton()
}.selectExistingCollection(firstCollectionName) {
verifySnackBarText("Tab saved!")
}.openHomeScreen {
verifyExistingTabList()
expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyItemInCollectionExists(secondWebPage.title)
}
}
@Test
fun collectionMenuAddTabButtonTest() {
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
createCollection(firstCollectionName)
homeScreen {
closeTab()
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
expandCollection(firstCollectionName)
clickCollectionThreeDotButton()
selectAddTabToCollection()
verifyTabsSelectedCounterText(1)
saveTabsSelectedForCollection()
verifySnackBarText("Tab saved!")
verifyItemInCollectionExists(secondWebPage.title)
}
}
@Test
fun collectionMenuOpenAllTabsTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
createCollection(firstWebPage.url, "testcollection_1")
createCollection(firstCollectionName)
homeScreen {
closeTab()
expandCollection(firstCollectionName)
clickCollectionThreeDotButton()
selectOpenTabs()
verifyExistingOpenTabs(firstWebPage.title)
}
}
@Test
fun renameCollectionTest() {
createCollection(firstCollectionName)
homeScreen {
// On homeview, tap the 3-dot button to expand, select rename, rename collection
expandCollection(firstCollectionName)
clickCollectionThreeDotButton()
selectRenameCollection()
typeCollectionName("renamed_collection")
mDevice.wait(Until.findObject(By.text("renamed_collection")), TestAssetHelper.waitingTime)
// Verify the new name is displayed on homeview
onView(ViewMatchers.withText("renamed_collection"))
.check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
verifyCollectionIsDisplayed("renamed_collection")
}
}
@Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793")
// Delete Collection from the Homescreen
fun deleteCollectionTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
createCollection(firstWebPage.url, "testcollection_1")
createCollection(firstCollectionName)
homeScreen {
// Choose delete collection from homeview, and confirm
expandCollection(firstCollectionName)
clickCollectionThreeDotButton()
selectDeleteCollection()
confirmDeleteCollection()
// Check for No collections caption
onView(ViewMatchers.withText("No collections"))
.check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
verifyNoCollectionsHeader()
}
}
@Test
@Ignore("Temp disable test - see: https://github.com/mozilla-mobile/fenix/issues/5793")
fun createCollectionTest() {
fun createCollectionFromTabTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
createCollection(firstWebPage.url, "testcollection_1")
createCollection(secondWebPage.url, "testcollection_2", false)
// On the main screen, swipe to bottom until the collections are shown
createCollection(firstCollectionName)
homeScreen {
// swipe to bottom until the collections are shown
verifyHomeScreen()
verifyExistingOpenTabs(firstWebPage.title)
try {
onView(ViewMatchers.withText("testcollection_1"))
.check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
verifyCollectionIsDisplayed(firstCollectionName)
} catch (e: NoMatchingViewException) {
scrollToElementByText("testcollection_1")
scrollToElementByText(firstCollectionName)
}
onView(ViewMatchers.withText("testcollection_2")).check(ViewAssertions
.matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}
}
private fun createCollection(url: Uri, collectionName: String, firstCollection: Boolean = true) {
@Test
fun verifyExpandedCollectionItemsTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
// Open a webpage and save to collection "testcollection_1"
navigationToolbar {
}.enterURLAndEnterToBrowser(url) {
verifyPageContent(firstWebPage.content)
createCollection(firstCollectionName)
homeScreen {
verifyCollectionIsDisplayed(firstCollectionName)
verifyCollectionIcon()
expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyCollectionItemLogo()
verifyCollectionItemUrl()
verifyShareCollectionButtonIsVisible(true)
verifyCollectionMenuIsVisible(true)
verifyCollectionItemRemoveButtonIsVisible(firstWebPage.title, true)
collapseCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title, false)
verifyShareCollectionButtonIsVisible(false)
verifyCollectionMenuIsVisible(false)
verifyCollectionItemRemoveButtonIsVisible(firstWebPage.title, false)
}
}
@Test
fun shareCollectionTest() {
createCollection(firstCollectionName)
homeScreen {
expandCollection(firstCollectionName)
clickShareCollectionButton()
verifyShareTabsOverlay()
}
}
@Test
fun removeTabFromCollectionTest() {
val webPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
createCollection(firstCollectionName)
homeScreen {
closeTab()
expandCollection(firstCollectionName)
removeTabFromCollection(webPage.title)
verifyItemInCollectionExists(webPage.title, false)
}
createCollection(firstCollectionName)
homeScreen {
closeTab()
expandCollection(firstCollectionName)
swipeCollectionItemLeft(webPage.title)
verifyItemInCollectionExists(webPage.title, false)
}
createCollection(firstCollectionName)
homeScreen {
closeTab()
expandCollection(firstCollectionName)
swipeCollectionItemRight(webPage.title)
verifyItemInCollectionExists(webPage.title, false)
}
}
@Test
fun selectTabOnLongTapTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
}.openHomeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
longTapSelectTab(firstWebPage.title)
verifySelectTabsView()
verifyTabsSelectedCounterText(1)
selectTabForCollection(secondWebPage.title)
verifyTabsSelectedCounterText(2)
saveTabsSelectedForCollection()
typeCollectionName(firstCollectionName)
verifySnackBarText("Tabs saved!")
closeTabViaXButton(firstWebPage.title)
closeTabViaXButton(secondWebPage.title)
expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyItemInCollectionExists(secondWebPage.title)
}
}
@Test
fun tabsOverflowMenuSaveCollectionTest() {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
}.openHomeScreen {
}.openNavigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
}.openTabsListThreeDotMenu {
verifySaveCollection()
}.clickOpenTabsMenuSaveCollection {
verifySelectTabsView()
verifyTabsSelectedCounterText(0)
selectAllTabsForCollection()
verifyTabsSelectedCounterText(2)
saveTabsSelectedForCollection()
typeCollectionName(firstCollectionName)
closeTabViaXButton(firstWebPage.title)
closeTabViaXButton(secondWebPage.title)
expandCollection(firstCollectionName)
verifyItemInCollectionExists(firstWebPage.title)
verifyItemInCollectionExists(secondWebPage.title)
}
}
@Test
fun navigateBackInCollectionFlowTest() {
val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2)
createCollection(firstCollectionName)
navigationToolbar {
}.enterURLAndEnterToBrowser(secondWebPage.url) {
}.openHomeScreen {
longTapSelectTab(secondWebPage.title)
verifySelectTabsView()
saveTabsSelectedForCollection()
verifySelectCollectionView()
clickAddNewCollection()
verifyNameCollectionView()
goBackCollectionFlow()
verifySelectCollectionView()
goBackCollectionFlow()
verifySelectTabsView()
goBackCollectionFlow()
verifyHomeComponent()
}
}
private fun createCollection(collectionName: String, firstCollection: Boolean = true) {
val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
verifyPageContent(firstWebPage.content)
}.openThreeDotMenu {
// click save to collection menu item, type collection name
clickBrowserViewSaveCollectionButton()
if (!firstCollection)
clickAddNewCollection()
}.typeCollectionName(collectionName) {}
mDevice.pressBack() // go to main page
org.mozilla.fenix.ui.robots.mDevice.wait(
Until.findObject(By.text(collectionName)),
TestAssetHelper.waitingTime)
}.typeCollectionName(collectionName) {
verifySnackBarText("Tab saved!")
}.openHomeScreen {
mDevice.wait(
Until.findObject(By.text(collectionName)),
TestAssetHelper.waitingTime
)
}
}
}

View File

@ -237,13 +237,6 @@ class BrowserRobot {
menuSaveImage.click()
}
fun waitForCollectionSavedPopup() {
mDevice.wait(
Until.findObject(text("Tab saved!")),
waitingTime
)
}
fun createBookmark(url: Uri) {
navigationToolbar {
}.enterURLAndEnterToBrowser(url) {

View File

@ -9,8 +9,12 @@ package org.mozilla.fenix.ui.robots
import android.graphics.Bitmap
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.longClick
import androidx.test.espresso.action.ViewActions.swipeLeft
import androidx.test.espresso.action.ViewActions.swipeRight
import androidx.test.espresso.assertion.ViewAssertions.doesNotExist
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
@ -18,6 +22,7 @@ import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
@ -125,40 +130,193 @@ class HomeScreenRobot {
// Collections element
fun clickCollectionThreeDotButton() {
collectionThreeDotButton().click()
mDevice.waitNotNull(Until.findObject(By.text("Delete collection")), waitingTime)
mDevice.waitNotNull(findObject(text("Delete collection")), waitingTime)
}
fun selectOpenTabs() {
onView(allOf(withText("Open tabs"))).click()
}
fun selectRenameCollection() {
onView(allOf(ViewMatchers.withText("Rename collection"))).click()
mDevice.waitNotNull(Until.findObject(By.res("name_collection_edittext")))
onView(allOf(withText("Rename collection"))).click()
mDevice.waitNotNull(findObject(text("Rename collection")))
}
fun selectAddTabToCollection() {
onView(allOf(withText("Add tab"))).click()
mDevice.waitNotNull(findObject(text("Select Tabs")))
}
fun selectDeleteCollection() {
onView(allOf(ViewMatchers.withText("Delete collection"))).click()
mDevice.waitNotNull(Until.findObject(By.res("message")), waitingTime)
onView(allOf(withText("Delete collection"))).click()
mDevice.waitNotNull(findObject(By.res("android:id/message")), waitingTime)
}
fun confirmDeleteCollection() {
onView(allOf(ViewMatchers.withText("DELETE"))).click()
mDevice.waitNotNull(Until.findObject(By.res("collections_header")), waitingTime)
onView(allOf(withText("DELETE"))).click()
mDevice.waitNotNull(findObject(By.res("org.mozilla.fenix.debug:id/collections_header")), waitingTime)
}
fun typeCollectionName(name: String) {
mDevice.wait(Until.findObject(By.res("name_collection_edittext")), waitingTime)
mDevice.wait(findObject(By.res("org.mozilla.fenix.debug:id/name_collection_edittext")), waitingTime)
collectionNameTextField().perform(ViewActions.replaceText(name))
collectionNameTextField().perform(ViewActions.pressImeActionButton())
mDevice.waitNotNull(Until.gone(text("Name collection")))
}
fun saveTabsSelectedForCollection() = onView(withId(R.id.save_button)).click()
fun verifyCollectionIsDisplayed(title: String) {
mDevice.wait(findObject(text(title)), waitingTime)
collectionTitle(title).check(matches(isDisplayed()))
}
fun verifyCollectionIcon() =
onView(withId(R.id.collection_icon)).check(matches(isDisplayed()))
fun expandCollection(title: String) {
try {
mDevice.waitNotNull(findObject(text(title)), waitingTime)
collectionTitle(title).click()
} catch (e: NoMatchingViewException) {
scrollToElementByText(title)
}
}
fun collapseCollection(title: String) {
try {
mDevice.waitNotNull(findObject(text(title)), waitingTime)
onView(allOf(withId(R.id.chevron), hasSibling(withText(title)))).click()
} catch (e: NoMatchingViewException) {
scrollToElementByText(title)
}
}
fun clickSaveCollectionButton() = saveCollectionButton().click()
fun verifyItemInCollectionExists(title: String, visible: Boolean = true) {
try {
collectionItem(title)
.check(
if (visible) matches(isDisplayed()) else doesNotExist()
)
} catch (e: NoMatchingViewException) {
scrollToElementByText(title)
}
}
fun verifyCollectionItemLogo() =
onView(withId(R.id.list_item_favicon)).check(matches(isDisplayed()))
fun verifyCollectionItemUrl() =
onView(withId(R.id.list_item_url)).check(matches(isDisplayed()))
fun verifyShareCollectionButtonIsVisible(visible: Boolean) {
shareCollectionButton()
.check(
if (visible) matches(withEffectiveVisibility(Visibility.VISIBLE))
else matches(withEffectiveVisibility(Visibility.GONE))
)
}
fun verifyCollectionMenuIsVisible(visible: Boolean) {
collectionThreeDotButton()
.check(
if (visible) matches(withEffectiveVisibility(Visibility.VISIBLE))
else matches(withEffectiveVisibility(Visibility.GONE))
)
}
fun verifyCollectionItemRemoveButtonIsVisible(title: String, visible: Boolean) {
removeTabFromCollectionButton(title)
.check(
if (visible) matches(withEffectiveVisibility(Visibility.VISIBLE))
else doesNotExist()
)
}
fun verifySelectTabsView(vararg tabTitles: String) {
onView(allOf(withId(R.id.back_button), withText("Select Tabs")))
.check(matches(isDisplayed()))
for (title in tabTitles)
onView(withId(R.id.tab_list)).check(matches(hasItem(withText(title))))
}
fun verifyTabsSelectedCounterText(tabsSelected: Int) {
when (tabsSelected) {
0 -> onView(withId(R.id.bottom_bar_text)).check(matches(withText("Select tabs to save")))
1 -> onView(withId(R.id.bottom_bar_text)).check(matches(withText("1 tab selected")))
else -> onView(withId(R.id.bottom_bar_text)).check(matches(withText("$tabsSelected tabs selected")))
}
}
fun selectAllTabsForCollection() {
onView(withId(R.id.select_all_button))
.check(matches(withText("Select All")))
.click()
}
fun deselectAllTabsForCollection() {
onView(withId(R.id.select_all_button))
.check(matches(withText("Deselect All")))
.click()
}
fun selectTabForCollection(title: String) {
tab(title).click()
}
fun clickAddNewCollection() =
onView(allOf(withText("Add new collection"))).click()
fun verifyNameCollectionView() {
onView(allOf(withId(R.id.back_button), withText("Name collection")))
.check(matches(isDisplayed()))
}
fun verifyDefaultCollectionName(name: String) =
onView(withId(R.id.name_collection_edittext)).check(matches(withText(name)))
fun verifySelectCollectionView() {
onView(allOf(withId(R.id.back_button), withText("Select collection")))
.check(matches(isDisplayed()))
}
fun verifyShareTabsOverlay() = assertShareTabsOverlay()
fun clickShareCollectionButton() = onView(withId(R.id.collection_share_button)).click()
fun removeTabFromCollection(title: String) = removeTabFromCollectionButton(title).click()
fun swipeCollectionItemRight(title: String) {
try {
collectionItem(title).perform(swipeRight())
} catch (e: NoMatchingViewException) {
scrollToElementByText(title)
}
}
fun swipeCollectionItemLeft(title: String) {
try {
collectionItem(title).perform(swipeLeft())
} catch (e: NoMatchingViewException) {
scrollToElementByText(title)
}
}
fun longTapSelectTab(title: String) {
tab(title).perform(longClick())
}
fun goBackCollectionFlow() = collectionFlowBackButton().click()
fun scrollToElementByText(text: String): UiScrollable {
val appView = UiScrollable(UiSelector().scrollable(true))
appView.scrollTextIntoView(text)
return appView
}
fun swipeUpToDismissFirstRun() {
scrollToElementByText("Start browsing")
}
fun closeTab() {
closeTabButton().click()
}
@ -174,16 +332,16 @@ class HomeScreenRobot {
onView(withId(R.id.sessionControlRecyclerView)).perform(ViewActions.swipeDown())
fun swipeTabRight(title: String) =
onView(allOf(withId(R.id.tab_title), withText(title))).perform(ViewActions.swipeRight())
tab(title).perform(ViewActions.swipeRight())
fun swipeTabLeft(title: String) =
onView(allOf(withId(R.id.tab_title), withText(title))).perform(ViewActions.swipeLeft())
tab(title).perform(ViewActions.swipeLeft())
fun closeTabViaXButton(title: String) = closeTabViaX(title)
fun verifySnackBarText(expectedText: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.text(expectedText)), TestAssetHelper.waitingTime)
mDevice.waitNotNull(findObject(By.text(expectedText)), TestAssetHelper.waitingTime)
}
fun snackBarButtonClick(expectedText: String) {
@ -228,10 +386,6 @@ class HomeScreenRobot {
openThreeDotMenu { }.openSettings { }.goBack { }
}
fun addNewTab() {
openSearch { }.openBrowser { }.openHomeScreen { }
}
fun togglePrivateBrowsingMode() {
onView(ViewMatchers.withResourceName("privateBrowsingButton"))
.perform(click())
@ -315,12 +469,7 @@ class HomeScreenRobot {
fun openTab(title: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
mDevice.waitNotNull(findObject(text(title)))
onView(
allOf(
withId(R.id.tab_title),
withText(title)
)
).click()
tab(title).click()
BrowserRobot().interact()
return BrowserRobot.Transition()
@ -582,12 +731,20 @@ private fun assertExistingTabList() =
onView(allOf(withId(R.id.item_tab)))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertExistingOpenTabs(title: String) =
onView(withId(R.id.sessionControlRecyclerView)).perform(
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
ViewMatchers.hasDescendant(withText(title))
)
).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun assertExistingOpenTabs(title: String) {
try {
tab(title).check(matches(isDisplayed()))
} catch (e: NoMatchingViewException) {
onView(withId(R.id.sessionControlRecyclerView)).perform(
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
allOf(
withId(R.id.tab_title),
withText(title)
)
)
).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}
}
private fun tabsListThreeDotButton() = onView(allOf(withId(R.id.tabs_overflow_button)))
@ -597,6 +754,9 @@ private fun collectionThreeDotButton() =
private fun collectionNameTextField() =
onView(allOf(ViewMatchers.withResourceName("name_collection_edittext")))
private fun collectionTitle(title: String) =
onView(allOf(withId(R.id.collection_title), withText(title)))
private fun closeTabViaX(title: String) {
val closeButton = onView(
allOf(
@ -626,13 +786,45 @@ private fun assertTopSiteContextMenuItems() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(
Until.findObject(By.text("Open in private tab")),
findObject(By.text("Open in private tab")),
waitingTime
)
mDevice.waitNotNull(
Until.findObject(By.text("Remove")),
findObject(By.text("Remove")),
waitingTime
)
}
private fun assertShareTabsOverlay() {
onView(withId(R.id.shared_site_list)).check(matches(isDisplayed()))
onView(withId(R.id.share_tab_title)).check(matches(isDisplayed()))
onView(withId(R.id.share_tab_favicon)).check(matches(isDisplayed()))
onView(withId(R.id.share_tab_url)).check(matches(isDisplayed()))
}
private fun tabMediaControlButton() = onView(withId(R.id.play_pause_button))
private fun collectionItem(title: String) =
onView(allOf(withId(R.id.list_element_title), withText(title)))
private fun saveCollectionButton() = onView(withId(R.id.save_tab_group_button))
private fun shareCollectionButton() = onView(withId(R.id.collection_share_button))
private fun removeTabFromCollectionButton(title: String) =
onView(
allOf(
withId(R.id.list_item_action_button),
hasSibling(withText(title))
)
)
private fun collectionFlowBackButton() = onView(withId(R.id.back_button))
private fun tab(title: String) =
onView(
allOf(
withId(R.id.tab_title),
withText(title)
)
)

View File

@ -15,7 +15,6 @@ import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.hasFocus
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
@ -57,6 +56,7 @@ class ThreeDotMenuMainRobot {
fun verifyShareTabButton() = assertShareTabButton()
fun verifySaveCollection() = assertSaveCollectionButton()
fun clickBrowserViewSaveCollectionButton() {
browserViewSaveCollectionButton().click()
}
@ -198,11 +198,12 @@ class ThreeDotMenuMainRobot {
waitingTime
)
collectionNameTextField().check(matches(hasFocus()))
collectionNameTextField().perform(
ViewActions.replaceText(name),
ViewActions.pressImeActionButton()
)
// wait for the collection creation wrapper to be dismissed
mDevice.waitNotNull(Until.gone(By.res("org.mozilla.fenix.debug:id/createCollectionWrapper")))
BrowserRobot().interact()
return BrowserRobot.Transition()
@ -236,6 +237,21 @@ class ThreeDotMenuMainRobot {
AddToHomeScreenRobot().interact()
return AddToHomeScreenRobot.Transition()
}
fun selectExistingCollection(title: String, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
mDevice.waitNotNull(Until.findObject(By.text(title)), waitingTime)
onView(withText(title)).click()
BrowserRobot().interact()
return BrowserRobot.Transition()
}
fun clickOpenTabsMenuSaveCollection(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
saveCollectionButton().click()
HomeScreenRobot().interact()
return HomeScreenRobot.Transition()
}
}
}