Code cleanup in BookmarksRobot and BookmarksTest

upstream-sync
Oana Horvath 4 years ago
parent e1e21669b2
commit 095d07598a

@ -466,20 +466,12 @@ class BookmarksTest {
bookmarksListIdlingResource = bookmarksListIdlingResource =
RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list), 2) RecyclerViewIdlingResource(activityTestRule.activity.findViewById(R.id.bookmark_list), 2)
IdlingRegistry.getInstance().register(bookmarksListIdlingResource!!) IdlingRegistry.getInstance().register(bookmarksListIdlingResource!!)
}.openThreeDotMenu(defaultWebPage.url) {
IdlingRegistry.getInstance().unregister(bookmarksListIdlingResource!!)
}.clickEdit {
verifyEditBookmarksView()
changeBookmarkTitle(testBookmark.title)
saveEditBookmark()
IdlingRegistry.getInstance().register(bookmarksListIdlingResource!!)
createFolder(bookmarksFolderName) createFolder(bookmarksFolderName)
IdlingRegistry.getInstance().unregister(bookmarksListIdlingResource!!) IdlingRegistry.getInstance().unregister(bookmarksListIdlingResource!!)
}.openThreeDotMenu(testBookmark.title) { }.openThreeDotMenu(defaultWebPage.title) {
}.clickEdit { }.clickEdit {
clickParentFolderSelector() clickParentFolderSelector()
selectFolder(bookmarksFolderName) selectFolder(bookmarksFolderName)

@ -132,8 +132,6 @@ class BookmarksRobot {
addFolderButton().click() addFolderButton().click()
} }
fun clickdeleteBookmarkButton() = deleteBookmarkButton().click()
fun addNewFolderName(name: String) { fun addNewFolderName(name: String) {
addFolderTitleField() addFolderTitleField()
.click() .click()
@ -166,7 +164,7 @@ class BookmarksRobot {
fun saveEditBookmark() { fun saveEditBookmark() {
saveBookmarkButton().click() saveBookmarkButton().click()
mDevice.findObject(UiSelector().resourceId("R.id.bookmark_list")).waitForExists(waitingTime) mDevice.findObject(UiSelector().resourceId("org.mozilla.fenix.debug:id/bookmark_list")).waitForExists(waitingTime)
} }
fun clickParentFolderSelector() = bookmarkFolderSelector().click() fun clickParentFolderSelector() = bookmarkFolderSelector().click()
@ -190,31 +188,6 @@ class BookmarksRobot {
return Transition() return Transition()
} }
fun goBackToBrowser(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
closeButton().click()
BrowserRobot().interact()
return BrowserRobot.Transition()
}
fun confirmBookmarkFolderDeletionAndGoBackToBrowser(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
onView(withText(R.string.delete_browsing_data_prompt_allow))
.inRoot(RootMatchers.isDialog())
.check(matches(isDisplayed()))
.click()
BrowserRobot().interact()
return BrowserRobot.Transition()
}
fun openThreeDotMenu(interact: ThreeDotMenuBookmarksRobot.() -> Unit): ThreeDotMenuBookmarksRobot.Transition {
mDevice.waitNotNull(Until.findObject(res("org.mozilla.fenix.debug:id/overflow_menu")))
threeDotMenu().click()
ThreeDotMenuBookmarksRobot().interact()
return ThreeDotMenuBookmarksRobot.Transition()
}
fun openThreeDotMenu(bookmarkTitle: String, interact: ThreeDotMenuBookmarksRobot.() -> Unit): ThreeDotMenuBookmarksRobot.Transition { fun openThreeDotMenu(bookmarkTitle: String, interact: ThreeDotMenuBookmarksRobot.() -> Unit): ThreeDotMenuBookmarksRobot.Transition {
mDevice.waitNotNull(Until.findObject(res("org.mozilla.fenix.debug:id/overflow_menu"))) mDevice.waitNotNull(Until.findObject(res("org.mozilla.fenix.debug:id/overflow_menu")))
threeDotMenu(bookmarkTitle).click() threeDotMenu(bookmarkTitle).click()
@ -259,7 +232,7 @@ private fun bookmarkFavicon(url: String) = onView(
) )
) )
private fun bookmarkURL(url: String) = onView(allOf(withId(R.id.url), withText(url))) private fun bookmarkURL(url: String) = onView(allOf(withId(R.id.url), withText(containsString(url))))
private fun addFolderButton() = onView(withId(R.id.add_bookmark_folder)) private fun addFolderButton() = onView(withId(R.id.add_bookmark_folder))
@ -267,8 +240,6 @@ private fun addFolderTitleField() = onView(withId(R.id.bookmarkNameEdit))
private fun saveFolderButton() = onView(withId(R.id.confirm_add_folder_button)) private fun saveFolderButton() = onView(withId(R.id.confirm_add_folder_button))
private fun deleteBookmarkButton() = onView(withId(R.id.delete_bookmark_button))
private fun threeDotMenu(bookmarkUrl: Uri) = onView( private fun threeDotMenu(bookmarkUrl: Uri) = onView(
allOf( allOf(
withId(R.id.overflow_menu), withId(R.id.overflow_menu),
@ -283,8 +254,6 @@ private fun threeDotMenu(bookmarkTitle: String) = onView(
) )
) )
private fun threeDotMenu() = onView(withId(R.id.overflow_menu)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
private fun snackBarText() = onView(withId(R.id.snackbar_text)) private fun snackBarText() = onView(withId(R.id.snackbar_text))
private fun snackBarUndoButton() = onView(withId(R.id.snackbar_btn)) private fun snackBarUndoButton() = onView(withId(R.id.snackbar_btn))
@ -306,7 +275,7 @@ private fun assertBookmarksView() {
withParent(withId(R.id.navigationToolbar)) withParent(withId(R.id.navigationToolbar))
) )
) )
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) .check(matches(isDisplayed()))
} }
private fun assertEmptyBookmarksList() = private fun assertEmptyBookmarksList() =
@ -321,7 +290,7 @@ private fun assertBookmarkFavicon(forUrl: Uri) = bookmarkFavicon(forUrl.toString
) )
private fun assertBookmarkURL(expectedURL: String) = private fun assertBookmarkURL(expectedURL: String) =
mDevice.findObject(UiSelector().text(expectedURL)) bookmarkURL(expectedURL).check(matches(isDisplayed()))
private fun assertFolderTitle(expectedTitle: String) = private fun assertFolderTitle(expectedTitle: String) =
onView(withText(expectedTitle)).check(matches(isDisplayed())) onView(withText(expectedTitle)).check(matches(isDisplayed()))
@ -359,13 +328,13 @@ private fun assertKeyboardVisibility(isExpectedToBeVisible: Boolean) =
) )
private fun assertShareOverlay() = private fun assertShareOverlay() =
onView(withId(R.id.shareWrapper)).check(matches(ViewMatchers.isDisplayed())) onView(withId(R.id.shareWrapper)).check(matches(isDisplayed()))
private fun assertShareBookmarkTitle() = private fun assertShareBookmarkTitle() =
onView(withId(R.id.share_tab_title)).check(matches(ViewMatchers.isDisplayed())) onView(withId(R.id.share_tab_title)).check(matches(isDisplayed()))
private fun assertShareBookmarkFavicon() = private fun assertShareBookmarkFavicon() =
onView(withId(R.id.share_tab_favicon)).check(matches(ViewMatchers.isDisplayed())) onView(withId(R.id.share_tab_favicon)).check(matches(isDisplayed()))
private fun assertShareBookmarkUrl() = private fun assertShareBookmarkUrl() =
onView(withId(R.id.share_tab_url)).check(matches(isDisplayed())) onView(withId(R.id.share_tab_url)).check(matches(isDisplayed()))

@ -37,6 +37,7 @@ import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until import androidx.test.uiautomator.Until
import org.hamcrest.Matcher import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf import org.hamcrest.Matchers.allOf
import org.junit.Assert.assertTrue
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 import org.mozilla.fenix.helpers.click
@ -160,9 +161,11 @@ class ThreeDotMenuMainRobot {
} }
fun openBookmarks(interact: BookmarksRobot.() -> Unit): BookmarksRobot.Transition { fun openBookmarks(interact: BookmarksRobot.() -> Unit): BookmarksRobot.Transition {
onView(withId(R.id.mozac_browser_menu_recyclerView)).perform(ViewActions.swipeDown()) onView(withId(R.id.mozac_browser_menu_recyclerView)).perform(swipeDown())
mDevice.findObject(UiSelector().resourceId("R.id.bookmark_list")).waitForExists(waitingTime) mDevice.waitNotNull(Until.findObject(By.text("Bookmarks")), waitingTime)
bookmarksButton().click() bookmarksButton().click()
assertTrue(mDevice.findObject(UiSelector().resourceId("org.mozilla.fenix.debug:id/bookmark_list")).waitForExists(waitingTime))
BookmarksRobot().interact() BookmarksRobot().interact()
return BookmarksRobot.Transition() return BookmarksRobot.Transition()

Loading…
Cancel
Save