mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
[fenix] No issue: Refactor web page items long clicks
This commit is contained in:
parent
39d8566832
commit
3cf57466d4
@ -72,7 +72,7 @@ class ContextMenusTest {
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(pageLinks.url) {
|
||||
mDevice.waitForIdle()
|
||||
longClickMatchingText("Link 1")
|
||||
longClickLink("Link 1")
|
||||
verifyLinkContextMenuItems(genericURL.url)
|
||||
clickContextOpenLinkInNewTab()
|
||||
verifySnackBarText("New tab opened")
|
||||
@ -96,7 +96,7 @@ class ContextMenusTest {
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(pageLinks.url) {
|
||||
mDevice.waitForIdle()
|
||||
longClickMatchingText("Link 2")
|
||||
longClickLink("Link 2")
|
||||
verifyLinkContextMenuItems(genericURL.url)
|
||||
clickContextOpenLinkInPrivateTab()
|
||||
verifySnackBarText("New private tab opened")
|
||||
@ -118,7 +118,7 @@ class ContextMenusTest {
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(pageLinks.url) {
|
||||
mDevice.waitForIdle()
|
||||
longClickMatchingText("Link 3")
|
||||
longClickLink("Link 3")
|
||||
verifyLinkContextMenuItems(genericURL.url)
|
||||
clickContextCopyLink()
|
||||
verifySnackBarText("Link copied to clipboard")
|
||||
@ -138,7 +138,7 @@ class ContextMenusTest {
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(pageLinks.url) {
|
||||
mDevice.waitForIdle()
|
||||
longClickMatchingText("Link 1")
|
||||
longClickLink("Link 1")
|
||||
verifyLinkContextMenuItems(genericURL.url)
|
||||
clickContextShareLink(genericURL.url) // verify share intent is matched with associated URL
|
||||
}
|
||||
@ -154,7 +154,7 @@ class ContextMenusTest {
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(pageLinks.url) {
|
||||
mDevice.waitForIdle()
|
||||
longClickMatchingText("test_link_image")
|
||||
longClickLink("test_link_image")
|
||||
verifyLinkImageContextMenuItems(imageResource.url)
|
||||
clickContextOpenImageNewTab()
|
||||
verifySnackBarText("New tab opened")
|
||||
@ -173,7 +173,7 @@ class ContextMenusTest {
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(pageLinks.url) {
|
||||
mDevice.waitForIdle()
|
||||
longClickMatchingText("test_link_image")
|
||||
longClickLink("test_link_image")
|
||||
verifyLinkImageContextMenuItems(imageResource.url)
|
||||
clickContextCopyImageLocation()
|
||||
verifySnackBarText("Link copied to clipboard")
|
||||
@ -193,7 +193,7 @@ class ContextMenusTest {
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(pageLinks.url) {
|
||||
mDevice.waitForIdle()
|
||||
longClickMatchingText("test_link_image")
|
||||
longClickLink("test_link_image")
|
||||
verifyLinkImageContextMenuItems(imageResource.url)
|
||||
clickContextSaveImage()
|
||||
}
|
||||
@ -218,13 +218,13 @@ class ContextMenusTest {
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(pageLinks.url) {
|
||||
mDevice.waitForIdle()
|
||||
longClickMatchingText("Link 1")
|
||||
longClickLink("Link 1")
|
||||
verifyLinkContextMenuItems(genericURL.url)
|
||||
dismissContentContextMenu(genericURL.url)
|
||||
longClickMatchingText("test_link_image")
|
||||
longClickLink("test_link_image")
|
||||
verifyLinkImageContextMenuItems(imageResource.url)
|
||||
dismissContentContextMenu(imageResource.url)
|
||||
longClickMatchingText("test_no_link_image")
|
||||
longClickLink("test_no_link_image")
|
||||
verifyNoLinkImageContextMenuItems(imageResource.url)
|
||||
}
|
||||
}
|
||||
@ -236,7 +236,7 @@ class ContextMenusTest {
|
||||
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(genericURL.url) {
|
||||
longClickMatchingText(genericURL.content)
|
||||
longClickLink(genericURL.content)
|
||||
}.clickShareSelectedText {
|
||||
verifyAndroidShareLayout()
|
||||
}
|
||||
|
@ -186,9 +186,9 @@ class SearchTest {
|
||||
homeScreen {
|
||||
}.openSearch {
|
||||
}.submitQuery("test search") {
|
||||
longClickMatchingText("Link 1")
|
||||
longClickLink("Link 1")
|
||||
clickContextOpenLinkInNewTab()
|
||||
longClickMatchingText("Link 2")
|
||||
longClickLink("Link 2")
|
||||
clickContextOpenLinkInNewTab()
|
||||
}.goToHomescreen {
|
||||
verifyJumpBackInSectionIsDisplayed()
|
||||
@ -221,9 +221,9 @@ class SearchTest {
|
||||
homeScreen {
|
||||
}.openSearch {
|
||||
}.submitQuery("test search") {
|
||||
longClickMatchingText("Link 1")
|
||||
longClickLink("Link 1")
|
||||
clickContextOpenLinkInPrivateTab()
|
||||
longClickMatchingText("Link 2")
|
||||
longClickLink("Link 2")
|
||||
clickContextOpenLinkInPrivateTab()
|
||||
}.goToHomescreen {
|
||||
verifyCurrentSearchGroupIsDisplayed(false, "test search", 3)
|
||||
@ -254,9 +254,9 @@ class SearchTest {
|
||||
homeScreen {
|
||||
}.openSearch {
|
||||
}.submitQuery("test search") {
|
||||
longClickMatchingText("Link 1")
|
||||
longClickLink("Link 1")
|
||||
clickContextOpenLinkInPrivateTab()
|
||||
longClickMatchingText("Link 2")
|
||||
longClickLink("Link 2")
|
||||
clickContextOpenLinkInPrivateTab()
|
||||
}.openTabDrawer {
|
||||
}.openTab(firstPage) {
|
||||
@ -290,9 +290,9 @@ class SearchTest {
|
||||
homeScreen {
|
||||
}.openSearch {
|
||||
}.submitQuery("test search") {
|
||||
longClickMatchingText("Link 1")
|
||||
longClickLink("Link 1")
|
||||
clickContextOpenLinkInNewTab()
|
||||
longClickMatchingText("Link 2")
|
||||
longClickLink("Link 2")
|
||||
clickContextOpenLinkInNewTab()
|
||||
}.openTabDrawer {
|
||||
}.openTabFromGroup(firstPage) {
|
||||
|
@ -347,43 +347,14 @@ class BrowserRobot {
|
||||
fun clickLinkMatchingText(expectedText: String) =
|
||||
clickPageObject(webPageItemContainingText(expectedText))
|
||||
|
||||
fun longClickMatchingText(expectedText: String) {
|
||||
try {
|
||||
mDevice.waitForWindowUpdate(packageName, waitingTime)
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/engineView"))
|
||||
.waitForExists(waitingTime)
|
||||
mDevice.findObject(UiSelector().textContains(expectedText)).waitForExists(waitingTime)
|
||||
val link = mDevice.findObject(By.textContains(expectedText))
|
||||
link.click(LONG_CLICK_DURATION)
|
||||
} catch (e: NullPointerException) {
|
||||
println(e)
|
||||
fun longClickLink(expectedText: String) =
|
||||
longClickPageObject(webPageItemWithText(expectedText))
|
||||
|
||||
// Refresh the page in case the first long click didn't succeed
|
||||
navigationToolbar {
|
||||
}.openThreeDotMenu {
|
||||
}.refreshPage {
|
||||
mDevice.waitForIdle()
|
||||
}
|
||||
|
||||
// Long click again the desired text
|
||||
mDevice.waitForWindowUpdate(packageName, waitingTime)
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/engineView"))
|
||||
.waitForExists(waitingTime)
|
||||
mDevice.findObject(UiSelector().textContains(expectedText)).waitForExists(waitingTime)
|
||||
val link = mDevice.findObject(By.textContains(expectedText))
|
||||
link.click(LONG_CLICK_DURATION)
|
||||
}
|
||||
}
|
||||
fun longClickMatchingText(expectedText: String) =
|
||||
longClickPageObject(webPageItemContainingText(expectedText))
|
||||
|
||||
fun longClickAndCopyText(expectedText: String, selectAll: Boolean = false) {
|
||||
try {
|
||||
// Long click desired text
|
||||
mDevice.waitForWindowUpdate(packageName, waitingTime)
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/engineView"))
|
||||
.waitForExists(waitingTime)
|
||||
mDevice.findObject(UiSelector().textContains(expectedText)).waitForExists(waitingTime)
|
||||
val link = mDevice.findObject(By.textContains(expectedText))
|
||||
link.click(LONG_CLICK_DURATION)
|
||||
longClickPageObject(webPageItemContainingText(expectedText))
|
||||
|
||||
// Click Select all from the text selection toolbar
|
||||
if (selectAll) {
|
||||
@ -396,67 +367,15 @@ class BrowserRobot {
|
||||
mDevice.findObject(UiSelector().textContains("Copy")).waitForExists(waitingTime)
|
||||
val copyText = mDevice.findObject(By.textContains("Copy"))
|
||||
copyText.click()
|
||||
} catch (e: NullPointerException) {
|
||||
println("Failed to long click desired text: ${e.localizedMessage}")
|
||||
|
||||
// Refresh the page in case the first long click didn't succeed
|
||||
navigationToolbar {
|
||||
}.openThreeDotMenu {
|
||||
}.refreshPage {
|
||||
mDevice.waitForIdle()
|
||||
}
|
||||
|
||||
// Long click again the desired text
|
||||
mDevice.waitForWindowUpdate(packageName, waitingTime)
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/engineView"))
|
||||
.waitForExists(waitingTime)
|
||||
mDevice.findObject(UiSelector().textContains(expectedText)).waitForExists(waitingTime)
|
||||
val link = mDevice.findObject(By.textContains(expectedText))
|
||||
link.click(LONG_CLICK_DURATION)
|
||||
|
||||
// Click again Select all from the text selection toolbar
|
||||
if (selectAll) {
|
||||
mDevice.findObject(UiSelector().textContains("Select all")).waitForExists(waitingTime)
|
||||
val selectAllText = mDevice.findObject(By.textContains("Select all"))
|
||||
selectAllText.click()
|
||||
}
|
||||
|
||||
// Click again Copy from the text selection toolbar
|
||||
mDevice.findObject(UiSelector().textContains("Copy")).waitForExists(waitingTime)
|
||||
val copyText = mDevice.findObject(By.textContains("Copy"))
|
||||
copyText.click()
|
||||
}
|
||||
}
|
||||
|
||||
fun longClickAndSearchText(searchButton: String, expectedText: String) {
|
||||
var currentTries = 0
|
||||
while (currentTries++ < 3) {
|
||||
try {
|
||||
// Long click desired text
|
||||
mDevice.waitForWindowUpdate(packageName, waitingTime)
|
||||
mDevice.findObject(UiSelector().resourceId("$packageName:id/engineView"))
|
||||
.waitForExists(waitingTime)
|
||||
mDevice.findObject(UiSelector().textContains(expectedText)).waitForExists(waitingTime)
|
||||
val link = mDevice.findObject(By.textContains(expectedText))
|
||||
link.click(LONG_CLICK_DURATION)
|
||||
longClickPageObject(webPageItemContainingText(expectedText))
|
||||
|
||||
// Click search from the text selection toolbar
|
||||
mDevice.findObject(UiSelector().textContains(searchButton)).waitForExists(waitingTime)
|
||||
val searchText = mDevice.findObject(By.textContains(searchButton))
|
||||
searchText.click()
|
||||
|
||||
break
|
||||
} catch (e: NullPointerException) {
|
||||
println("Failed to long click desired text: ${e.localizedMessage}")
|
||||
|
||||
// Refresh the page in case the first long click didn't succeed
|
||||
navigationToolbar {
|
||||
}.openThreeDotMenu {
|
||||
}.refreshPage {
|
||||
mDevice.waitForIdle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun snackBarButtonClick() {
|
||||
@ -985,6 +904,29 @@ private fun clickPageObject(webPageItem: UiObject) {
|
||||
}
|
||||
}
|
||||
|
||||
fun longClickPageObject(webPageItem: UiObject) {
|
||||
for (i in 1..RETRY_COUNT) {
|
||||
try {
|
||||
webPageItem.also {
|
||||
it.waitForExists(waitingTime)
|
||||
it.longClick()
|
||||
}
|
||||
|
||||
break
|
||||
} catch (e: UiObjectNotFoundException) {
|
||||
if (i == RETRY_COUNT) {
|
||||
throw e
|
||||
} else {
|
||||
browserScreen {
|
||||
}.openThreeDotMenu {
|
||||
}.refreshPage {
|
||||
}
|
||||
progressBar.waitUntilGone(waitingTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun webPageItemContainingText(itemText: String) =
|
||||
mDevice.findObject(UiSelector().textContains(itemText))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user