Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Text selection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiAJ authored and Mugurell committed Jun 15, 2021
1 parent 82e2367 commit 78edf06
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 1 deletion.
39 changes: 39 additions & 0 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import org.mozilla.fenix.ui.robots.enhancedTrackingProtection
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
import org.mozilla.fenix.ui.robots.notificationShade
import org.mozilla.fenix.ui.robots.openEditURLView
import org.mozilla.fenix.ui.robots.searchScreen
import org.mozilla.fenix.ui.robots.tabDrawer
import org.mozilla.fenix.ui.util.STRING_ONBOARDING_TRACKING_PROTECTION_HEADER
Expand Down Expand Up @@ -1336,4 +1337,42 @@ class SmokeTest {
verifyAndroidDefaultAppsMenuAppears()
}
}

@Test
fun copyTextTest() {
val genericURL = TestAssetHelper.getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
longClickAndCopyText("content")
}.openNavigationToolbar {
openEditURLView()
}

searchScreen {
clickClearButton()
longClickToolbar()
clickPasteText()
verifyPastedToolbarText("content")
}
}

@Test
fun selectAllAndCopyTextTest() {
val genericURL = TestAssetHelper.getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
longClickAndCopyText("content", true)
}.openNavigationToolbar {
openEditURLView()
}

searchScreen {
clickClearButton()
longClickToolbar()
clickPasteText()
verifyPastedToolbarText("Page content: 1")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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")
@file:Suppress("TooManyFunctions", "TooGenericExceptionCaught")

package org.mozilla.fenix.ui.robots

Expand Down Expand Up @@ -334,6 +334,59 @@ class BrowserRobot {
element.click(LONG_CLICK_DURATION)
}

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)

// Click 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 Copy from the text selection toolbar
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 snackBarButtonClick(expectedText: String) {
onView(allOf(withId(R.id.snackbar_btn), withText(expectedText))).check(
matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withSubstring
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
Expand All @@ -35,6 +36,7 @@ import org.hamcrest.CoreMatchers.startsWith
import org.hamcrest.Matchers
import org.junit.Assert.assertEquals
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.LONG_CLICK_DURATION
import org.mozilla.fenix.helpers.SessionLoadedIdlingResource
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
Expand Down Expand Up @@ -126,6 +128,24 @@ class SearchRobot {
clearButton().perform(click())
}

fun longClickToolbar() {
mDevice.waitForWindowUpdate(packageName, waitingTime)
mDevice.findObject(UiSelector().resourceId("$packageName:id/awesomeBar"))
.waitForExists(waitingTime)
mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))
.waitForExists(waitingTime)
val toolbar = mDevice.findObject(By.res("$packageName:id/toolbar"))
toolbar.click(LONG_CLICK_DURATION)
}

fun clickPasteText() {
mDevice.findObject(UiSelector().textContains("Paste")).waitForExists(waitingTime)
val pasteText = mDevice.findObject(By.textContains("Paste"))
pasteText.click()
}

fun verifyPastedToolbarText(expectedText: String) = assertPastedToolbarText(expectedText)

class Transition {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private lateinit var sessionLoadedIdlingResource: SessionLoadedIdlingResource
Expand Down Expand Up @@ -295,4 +315,17 @@ private fun assertDefaultSearchEngine(expectedText: String) {
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
}

private fun assertPastedToolbarText(expectedText: String) {
mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))
.waitForExists(waitingTime)
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_url_view"))
.waitForExists(waitingTime)
onView(
allOf(
withSubstring(expectedText),
withId(R.id.mozac_browser_toolbar_edit_url_view)
)
).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
}

private fun goBackButton() = onView(allOf(withContentDescription("Navigate up")))

0 comments on commit 78edf06

Please sign in to comment.