forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#4027: Adds search fragment UI tests
- Loading branch information
Showing
3 changed files
with
247 additions
and
1 deletion.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
app/src/androidTest/java/org/mozilla/fenix/ui/SearchTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* 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/. */ | ||
|
||
package org.mozilla.fenix.ui | ||
|
||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.mozilla.fenix.helpers.HomeActivityTestRule | ||
import org.mozilla.fenix.ui.robots.homeScreen | ||
|
||
/** | ||
* Tests for verifying the search fragment | ||
* | ||
* Including: | ||
* - Verify the toolbar, awesomebar, and shortcut bar are displayed | ||
* - Select shortcut button | ||
* - Select scan button | ||
* | ||
*/ | ||
|
||
class SearchTest { | ||
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping. | ||
@get:Rule | ||
val activityTestRule = HomeActivityTestRule() | ||
|
||
@Test | ||
fun searchScreenItemsTest() { | ||
homeScreen { }.dismissOnboarding() | ||
|
||
homeScreen { | ||
}.openSearch { | ||
verifySearchView() | ||
verifyBrowserToolbar() | ||
verifyScanButton() | ||
verifyShortcutsButton() | ||
} | ||
} | ||
|
||
@Test | ||
fun scanButtonTest() { | ||
homeScreen { }.dismissOnboarding() | ||
|
||
homeScreen { | ||
}.openSearch { | ||
clickScanButton() | ||
verifyScanPrompt() | ||
clickDenyPermission() | ||
clickScanButton() | ||
clickAllowPermission() | ||
} | ||
} | ||
|
||
@Test | ||
fun shortcutButtonTest() { | ||
homeScreen { }.dismissOnboarding() | ||
|
||
homeScreen { | ||
}.openSearch { | ||
clickShortcutsButton() | ||
verifySearchWithText() | ||
clickDuckDuckGoEngineButton() | ||
typeSearch() | ||
verifyDuckDuckGoResults() | ||
clickDuckDuckGoResult() | ||
verifyDuckDuckGoURL() | ||
} | ||
} | ||
|
||
@Test | ||
fun shortcutSearchEngineSettingsTest() { | ||
homeScreen { }.dismissOnboarding() | ||
|
||
homeScreen { | ||
}.openSearch { | ||
clickShortcutsButton() | ||
scrollToSearchEngineSettings() | ||
clickSearchEngineSettings() | ||
verifySearchEngineSettings() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
app/src/androidTest/java/org/mozilla/fenix/ui/robots/SearchRobot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* 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.recyclerview.widget.RecyclerView | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.ViewInteraction | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.action.ViewActions.typeText | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.contrib.RecyclerViewActions | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription | ||
import androidx.test.espresso.matcher.ViewMatchers.withId | ||
import androidx.test.espresso.matcher.ViewMatchers.withText | ||
import androidx.test.uiautomator.UiDevice | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.uiautomator.By | ||
import androidx.test.uiautomator.UiObject | ||
import androidx.test.uiautomator.UiScrollable | ||
import androidx.test.uiautomator.Until | ||
import org.hamcrest.CoreMatchers.allOf | ||
import org.hamcrest.Matchers | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.helpers.TestAssetHelper | ||
import androidx.test.uiautomator.UiSelector | ||
|
||
/** | ||
* Implementation of Robot Pattern for the search fragment. | ||
*/ | ||
class SearchRobot { | ||
fun verifySearchView() = assertSearchView() | ||
fun verifyBrowserToolbar() = assertBrowserToolbarEditView() | ||
fun verifyScanButton() = assertScanButton() | ||
fun verifyScanPrompt() = assertScanPrompt() | ||
fun verifyShortcutsButton() = assertShortcutsButton() | ||
fun verifySearchWithText() = assertSearchWithText() | ||
fun verifyDuckDuckGoResults() = assertDuckDuckGoResults() | ||
fun verifyDuckDuckGoURL() = assertDuckDuckGoURL() | ||
fun verifySearchEngineSettings() = assertSearchEngineSettings() | ||
|
||
fun clickScanButton() { | ||
scanButton().perform(click()) | ||
} | ||
|
||
fun clickDenyPermission() { | ||
denyPermissionButton().click() | ||
} | ||
|
||
fun clickAllowPermission() { | ||
allowPermissionButton().click() | ||
} | ||
|
||
fun clickShortcutsButton() { | ||
shortcutsButton().perform(click()) | ||
} | ||
|
||
fun typeSearch() { | ||
browserToolbarEditView().perform(typeText("Mozilla")) | ||
} | ||
|
||
fun clickDuckDuckGoEngineButton() { | ||
duckDuckGoEngineButton().perform(click()) | ||
} | ||
|
||
fun clickDuckDuckGoResult() { | ||
mDevice.wait(Until.findObjects(By.text("DuckDuckGo")), TestAssetHelper.waitingTime) | ||
awesomeBar().perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click())) | ||
} | ||
|
||
fun scrollToSearchEngineSettings(): UiScrollable { | ||
val appView = UiScrollable(UiSelector().scrollable(true)) | ||
appView.scrollTextIntoView("Search engine settings") | ||
return appView | ||
} | ||
|
||
fun clickSearchEngineSettings() { | ||
onView(withText("Search engine settings")).perform(click()) | ||
} | ||
|
||
class Transition { | ||
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) | ||
} | ||
} | ||
|
||
private fun awesomeBar() = onView(withId(R.id.awesomeBar)) | ||
|
||
private fun browserToolbarEditView() = onView(Matchers.allOf(withId(R.id.mozac_browser_toolbar_edit_url_view))) | ||
|
||
private fun duckDuckGoEngineButton(): ViewInteraction { | ||
mDevice.wait(Until.findObject(By.text("DuckDuckGo")), TestAssetHelper.waitingTime) | ||
return onView(Matchers.allOf(withText("DuckDuckGo"))) | ||
} | ||
|
||
private fun denyPermissionButton(): UiObject { | ||
mDevice.wait(Until.findObjects(By.text("Deny")), TestAssetHelper.waitingTime) | ||
return mDevice.findObject(UiSelector().text("Deny")) | ||
} | ||
|
||
private fun allowPermissionButton(): UiObject { | ||
mDevice.wait(Until.findObjects(By.text("Allow")), TestAssetHelper.waitingTime) | ||
return mDevice.findObject(UiSelector().text("Allow")) | ||
} | ||
|
||
private fun scanButton() = onView(allOf(withId(R.id.search_scan_button))) | ||
|
||
private fun shortcutsButton() = onView(withId(R.id.search_shortcuts_button)) | ||
|
||
private fun assertDuckDuckGoURL() { | ||
mDevice.wait(Until.findObjects(By.textStartsWith("https://duckduckgo.com")), TestAssetHelper.waitingTime) | ||
} | ||
|
||
private fun assertDuckDuckGoResults() { | ||
val count = mDevice.wait(Until.findObjects(By.text(("DuckDuckGo"))), TestAssetHelper.waitingTime) | ||
assert(count.size > 1) | ||
} | ||
|
||
private fun assertSearchView() { | ||
onView(allOf(withId(R.id.search_layout))) | ||
} | ||
|
||
private fun assertBrowserToolbarEditView() = | ||
onView(Matchers.allOf(withId(R.id.mozac_browser_toolbar_edit_url_view))) | ||
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) | ||
|
||
private fun assertScanPrompt() = | ||
mDevice.wait( | ||
Until.findObjects(By.text("Allow Firefox Preview to take pictures and record video?")), | ||
TestAssetHelper.waitingTime | ||
) | ||
|
||
private fun assertScanButton() = | ||
onView(allOf(withText("Scan"))) | ||
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) | ||
|
||
private fun assertShortcutsButton() = | ||
onView(allOf(withText("Shortcuts"))) | ||
.check(matches(ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) | ||
|
||
private fun assertSearchWithText() = | ||
mDevice.wait(Until.findObject(By.text("SEARCH WITH")), TestAssetHelper.waitingTime) | ||
|
||
private fun assertSearchEngineSettings() = | ||
mDevice.wait(Until.findObject(By.text("Search engine")), TestAssetHelper.waitingTime) | ||
|
||
fun searchScreen(interact: SearchRobot.() -> Unit): SearchRobot.Transition { | ||
SearchRobot().interact() | ||
return SearchRobot.Transition() | ||
} | ||
|
||
private fun goBackButton() = onView(allOf(withContentDescription("Navigate up"))) |