diff --git a/app/src/androidTest/assets/pages/lorem-ipsum.html b/app/src/androidTest/assets/pages/lorem-ipsum.html
new file mode 100644
index 000000000..7d5aee9ca
--- /dev/null
+++ b/app/src/androidTest/assets/pages/lorem-ipsum.html
@@ -0,0 +1,16 @@
+
+
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit,
+ sed do eiusmod tempor incididunt ut labore et dolore magna
+ aliqua. Ut enim ad minim veniam, quis nostrud exercitation
+ ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
+ aute irure dolor in reprehenderit in voluptate velit esse cillum
+ dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
+ non proident, sunt in culpa qui officia deserunt mollit anim id est
+ laborum.
+
+
+
+
diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/NavigationToolbarTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/NavigationToolbarTest.kt
index 4660da180..666884f54 100644
--- a/app/src/androidTest/java/org/mozilla/fenix/ui/NavigationToolbarTest.kt
+++ b/app/src/androidTest/java/org/mozilla/fenix/ui/NavigationToolbarTest.kt
@@ -17,12 +17,13 @@ import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.ui.robots.navigationToolbar
/**
- * Tests for verifying basic functionality of browser navigation
+ * Tests for verifying basic functionality of browser navigation and page related interactions
*
* Including:
* - Visiting a URL
* - Back and Forward navigation
* - Refresh
+ * - Find in page
*/
class NavigationToolbarTest {
@@ -63,6 +64,7 @@ class NavigationToolbarTest {
navigationToolbar {
}.openThreeDotMenu {
verifyThreeDotMenuExists()
+ verifyBackButton()
}.goBack {
verifyPageContent(defaultWebPage.content)
}
@@ -87,6 +89,7 @@ class NavigationToolbarTest {
navigationToolbar {
}.openThreeDotMenu {
verifyThreeDotMenuExists()
+ verifyForwardButton()
}.goForward {
verifyPageContent(nextWebPage.content)
}
@@ -104,6 +107,8 @@ class NavigationToolbarTest {
// Use refresh from the three-dot menu
navigationToolbar {
}.openThreeDotMenu {
+ verifyThreeDotMenuExists()
+ verifyRefreshButton()
}.refreshPage {
verifyPageContent("REFRESHED")
}
@@ -118,4 +123,37 @@ class NavigationToolbarTest {
verifyPageContent(defaultWebPage.content)
}
}
+
+ @Test
+ fun findInPageTest() {
+ val loremIpsumWebPage = TestAssetHelper.getLoremIpsumAsset(mockWebServer)
+
+ navigationToolbar {
+ }.enterURLAndEnterToBrowser(loremIpsumWebPage.url) {
+ verifyPageContent(loremIpsumWebPage.content)
+ }
+
+ navigationToolbar {
+ }.openThreeDotMenu {
+ verifyThreeDotMenuExists()
+ verifyFindInPageButton()
+ }.openFindInPage {
+ verifyFindInPageNextButton()
+ verifyFindInPagePrevButton()
+ verifyFindInPageCloseButton()
+ enterFindInPageQuery("lab")
+ verifyFindNextInPageResult("1/3")
+ verifyFindNextInPageResult("2/3")
+ verifyFindNextInPageResult("3/3")
+ verifyFindPrevInPageResult("1/3")
+ verifyFindPrevInPageResult("3/3")
+ verifyFindPrevInPageResult("2/3")
+ enterFindInPageQuery("in")
+ verifyFindNextInPageResult("3/7")
+ verifyFindNextInPageResult("4/7")
+ verifyFindNextInPageResult("5/7")
+ verifyFindNextInPageResult("6/7")
+ verifyFindNextInPageResult("7/7")
+ }.closeFindInPage { }
+ }
}
diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/FindInPageRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/FindInPageRobot.kt
new file mode 100644
index 000000000..f2008e56d
--- /dev/null
+++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/FindInPageRobot.kt
@@ -0,0 +1,73 @@
+/* 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
+import androidx.test.espresso.action.ViewActions.clearText
+import androidx.test.espresso.action.ViewActions.typeText
+import androidx.test.espresso.assertion.ViewAssertions.matches
+import androidx.test.espresso.matcher.ViewMatchers
+import androidx.test.espresso.matcher.ViewMatchers.withId
+import androidx.test.espresso.matcher.ViewMatchers.withText
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.uiautomator.By
+import androidx.test.uiautomator.UiDevice
+import androidx.test.uiautomator.Until
+import org.mozilla.fenix.R
+import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
+import org.mozilla.fenix.helpers.click
+
+/**
+ * Implementation of Robot Pattern for the find in page UI.
+ */
+class FindInPageRobot {
+
+ val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())!!
+
+ fun verifyFindInPageNextButton() = assertFindInPageNextButton()!!
+ fun verifyFindInPagePrevButton() = assertFindInPagePrevButton()!!
+ fun verifyFindInPageCloseButton() = assertFindInPageCloseButton()!!
+
+ fun enterFindInPageQuery(expectedText: String) {
+ mDevice.wait(Until.findObject(By.res("find_in_page_query_text")), waitingTimeShort)
+ findInPageQuery().perform(clearText(), typeText(expectedText))
+ }
+
+ fun verifyFindNextInPageResult(ratioCounter: String) {
+ mDevice.waitForIdle()
+ findInPageResult().check(matches(withText((ratioCounter))))
+ findInPageNextButton().click()
+ }
+
+ fun verifyFindPrevInPageResult(ratioCounter: String) {
+ mDevice.waitForIdle()
+ findInPageResult().check(matches(withText((ratioCounter))))
+ findInPagePrevButton().click()
+ }
+
+ class Transition {
+ fun closeFindInPage(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
+ mDevice.waitForIdle()
+ findInPageCloseButton().click()
+ BrowserRobot().interact()
+ return BrowserRobot.Transition()
+ }
+ }
+}
+
+private fun findInPageQuery() = onView(withId(R.id.find_in_page_query_text))
+private fun findInPageResult() = onView(withId(R.id.find_in_page_result_text))
+private fun findInPageNextButton() = onView(withId(R.id.find_in_page_next_btn))
+private fun findInPagePrevButton() = onView(withId(R.id.find_in_page_prev_btn))
+private fun findInPageCloseButton() = onView(withId(R.id.find_in_page_close_btn))
+
+private fun assertFindInPageNextButton() = findInPageNextButton()
+ .check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
+private fun assertFindInPagePrevButton() = findInPagePrevButton()
+ .check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
+private fun assertFindInPageCloseButton() = findInPageCloseButton()
+ .check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuRobot.kt
index fb1d39e60..8ac8f92e1 100644
--- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuRobot.kt
+++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ThreeDotMenuRobot.kt
@@ -35,6 +35,7 @@ class ThreeDotMenuRobot {
fun verifyCloseAllTabsButton() = assertCloseAllTabsButton()
fun verifyShareButton() = assertShareButton()
fun verifySaveCollection() = assertSaveCollectionButton()
+ fun verifyFindInPageButton() = assertFindInPageButton()
class Transition {
@@ -95,6 +96,14 @@ class ThreeDotMenuRobot {
HomeScreenRobot().interact()
return HomeScreenRobot.Transition()
}
+
+ fun openFindInPage(interact: FindInPageRobot.() -> Unit): FindInPageRobot.Transition {
+ mDevice.wait(Until.findObject(By.text("Find in page")), waitingTime)
+ findInPageButton().click()
+
+ FindInPageRobot().interact()
+ return FindInPageRobot.Transition()
+ }
}
}
private fun threeDotMenuRecyclerViewExists() {
@@ -135,3 +144,7 @@ private fun assertShareButton() = shareButton()
private fun saveCollectionButton() = onView(allOf(withText("Save to collection")))
private fun assertSaveCollectionButton() = saveCollectionButton()
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
+
+private fun findInPageButton() = onView(allOf(withText("Find in page")))
+private fun assertFindInPageButton() = findInPageButton()
+ .check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))