This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #3977: Add basic navigational UI tests
- Adds UI tests (and assets) for basic navigation fix: review changes fix: linter cleanup fix: detekt cleanup fix: adjust wait approaches
- Loading branch information
Showing
9 changed files
with
322 additions
and
6 deletions.
There are no files selected for viewing
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,7 @@ | ||
<html> | ||
<body> | ||
<h1> | ||
<p id="testContent">Page content: 1</p> | ||
</h1> | ||
</body> | ||
</html> |
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,7 @@ | ||
<html> | ||
<body> | ||
<h1> | ||
<p id="testContent">Page content: 2</p> | ||
</h1> | ||
</body> | ||
</html> |
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,7 @@ | ||
<html> | ||
<body> | ||
<h1> | ||
<p id="testContent">Page content: 3</p> | ||
</h1> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
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,45 @@ | ||
|
||
<html> | ||
<script src="jquery-3.4.1.slim.min.js"></script> | ||
<script> | ||
|
||
function setCookie(newVal){ | ||
window.document.cookie = "pageStatus = " + newVal + ";"; | ||
} | ||
|
||
|
||
function readCookie(name) { | ||
var nameEQ = name + "="; | ||
var ca = document.cookie.split(';'); | ||
for(var i=0;i < ca.length;i++) { | ||
var c = ca[i]; | ||
while (c.charAt(0)==' ') c = c.substring(1,c.length); | ||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); | ||
} | ||
return null; | ||
} | ||
|
||
function valSwap(){ | ||
currentCookie = readCookie("pageStatus"); | ||
if(currentCookie == null) { | ||
setCookie("DEFAULT"); | ||
} | ||
|
||
if (currentCookie.localeCompare("REFRESHED") == 0) { | ||
setCookie("DEFAULT"); | ||
return "My little test page - DEFAULT"; | ||
} else { | ||
setCookie("REFRESHED"); | ||
return "My little test page - REFRESHED!"; | ||
} | ||
} | ||
|
||
var textToShow = valSwap(); | ||
window.addEventListener('DOMContentLoaded', (event) => { | ||
document.querySelector('h1').innerHTML = textToShow; | ||
}); | ||
</script> | ||
<body> | ||
<h1>My little test page - DEFAULT</h1> | ||
</body> | ||
</html> |
121 changes: 121 additions & 0 deletions
121
app/src/androidTest/java/org/mozilla/fenix/ui/NavigationToolbarTest.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,121 @@ | ||
/* 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 androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.uiautomator.UiDevice | ||
import okhttp3.mockwebserver.MockWebServer | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher | ||
import org.mozilla.fenix.helpers.HomeActivityTestRule | ||
import org.mozilla.fenix.helpers.TestAssetHelper | ||
import org.mozilla.fenix.ui.robots.navigationToolbar | ||
|
||
/** | ||
* Tests for verifying basic functionality of browser navigation | ||
* | ||
* Including: | ||
* - Visiting a URL | ||
* - Back and Forward navigation | ||
* - Refresh | ||
*/ | ||
|
||
class NavigationToolbarTest { | ||
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) | ||
private lateinit var mockWebServer: MockWebServer | ||
|
||
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping. | ||
@get:Rule | ||
val activityTestRule = HomeActivityTestRule() | ||
|
||
@Before | ||
fun setUp() { | ||
mockWebServer = MockWebServer().apply { | ||
setDispatcher(AndroidAssetDispatcher()) | ||
start() | ||
} | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
mockWebServer.shutdown() | ||
} | ||
|
||
@Test | ||
fun goBackTest() { | ||
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) | ||
val nextWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2) | ||
|
||
navigationToolbar { | ||
}.enterURLAndEnterToBrowser(defaultWebPage.url) { | ||
verifyPageContent(defaultWebPage.content) | ||
}.openNavigationToolbar { | ||
}.enterURLAndEnterToBrowser(nextWebPage.url) { | ||
verifyPageContent(nextWebPage.content) | ||
} | ||
|
||
// Re-open the three-dot menu for verification | ||
navigationToolbar { | ||
}.openThreeDotMenu { | ||
verifyThreeDotMenuExists() | ||
}.goBack { | ||
verifyPageContent(defaultWebPage.content) | ||
} | ||
} | ||
|
||
@Test | ||
fun goForwardTest() { | ||
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) | ||
val nextWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2) | ||
|
||
navigationToolbar { | ||
}.enterURLAndEnterToBrowser(defaultWebPage.url) { | ||
verifyPageContent(defaultWebPage.content) | ||
}.openNavigationToolbar { | ||
}.enterURLAndEnterToBrowser(nextWebPage.url) { | ||
verifyPageContent(nextWebPage.content) | ||
mDevice.pressBack() | ||
verifyPageContent(defaultWebPage.content) | ||
} | ||
|
||
// Re-open the three-dot menu for verification | ||
navigationToolbar { | ||
}.openThreeDotMenu { | ||
verifyThreeDotMenuExists() | ||
}.goForward { | ||
verifyPageContent(nextWebPage.content) | ||
} | ||
} | ||
|
||
@Test | ||
fun refreshPageTest() { | ||
val refreshWebPage = TestAssetHelper.getRefreshAsset(mockWebServer) | ||
|
||
navigationToolbar { | ||
}.enterURLAndEnterToBrowser(refreshWebPage.url) { | ||
verifyPageContent("DEFAULT") | ||
} | ||
|
||
// Use refresh from the three-dot menu | ||
navigationToolbar { | ||
}.openThreeDotMenu { | ||
}.refreshPage { | ||
verifyPageContent("REFRESHED") | ||
} | ||
} | ||
|
||
@Test | ||
fun visitURLTest() { | ||
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) | ||
|
||
navigationToolbar { | ||
}.enterURLAndEnterToBrowser(defaultWebPage.url) { | ||
verifyPageContent(defaultWebPage.content) | ||
} | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
app/src/androidTest/java/org/mozilla/fenix/ui/robots/NavigationToolbarRobot.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,57 @@ | ||
/* 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 android.net.Uri | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.action.ViewActions.pressImeActionButton | ||
import androidx.test.espresso.action.ViewActions.replaceText | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
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.waitingTime | ||
import org.mozilla.fenix.helpers.click | ||
|
||
/** | ||
* Implementation of Robot Pattern for the URL toolbar. | ||
*/ | ||
class NavigationToolbarRobot { | ||
class Transition { | ||
|
||
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) | ||
|
||
fun enterURLAndEnterToBrowser(url: Uri, interact: BrowserRobot.() -> Unit): BrowserRobot.Transition { | ||
mDevice.wait(Until.findObject(By.text("Search or enter address")), waitingTime) | ||
urlBar().click() | ||
awesomeBar().perform(replaceText(url.toString()), pressImeActionButton()) | ||
|
||
BrowserRobot().interact() | ||
return BrowserRobot.Transition() | ||
} | ||
|
||
fun openThreeDotMenu(interact: ThreeDotMenuRobot.() -> Unit): ThreeDotMenuRobot.Transition { | ||
mDevice.wait(Until.findObject(By.text("Menu")), waitingTime) | ||
threeDotButton().click() | ||
|
||
ThreeDotMenuRobot().interact() | ||
return ThreeDotMenuRobot.Transition() | ||
} | ||
} | ||
} | ||
|
||
fun navigationToolbar(interact: NavigationToolbarRobot.() -> Unit): NavigationToolbarRobot.Transition { | ||
NavigationToolbarRobot().interact() | ||
return NavigationToolbarRobot.Transition() | ||
} | ||
|
||
private fun urlBar() = onView(ViewMatchers.withId(R.id.toolbar)) | ||
private fun awesomeBar() = onView(ViewMatchers.withId(R.id.mozac_browser_toolbar_edit_url_view)) | ||
private fun threeDotButton() = onView(ViewMatchers.withContentDescription("Menu")) |
Oops, something went wrong.