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

Commit

Permalink
run #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Horvath committed Feb 23, 2022
1 parent 81d8c38 commit 9980a76
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 109 deletions.
16 changes: 16 additions & 0 deletions app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
Expand Down Expand Up @@ -142,4 +143,19 @@ class HomeScreenTest {
verifyWelcomeHeader()
}
}

@SmokeTest
@Test
fun tapLogoToChangeWallpaperTest() {
homeScreen {
clickFirefoxLogo()
verifyWallpaperImageApplied(true)
clickFirefoxLogo()
verifyWallpaperImageApplied(true)
clickFirefoxLogo()
verifyWallpaperImageApplied(true)
clickFirefoxLogo()
verifyWallpaperImageApplied(false)
}
}
}
105 changes: 1 addition & 104 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,25 @@
package org.mozilla.fenix.ui

import android.content.res.Configuration
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.FenixApplication
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.FeatureSettingsHelper
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
import org.mozilla.fenix.helpers.TestAssetHelper.getLoremIpsumAsset
import org.mozilla.fenix.helpers.TestHelper.restartApp
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.checkTextSizeOnWebsite
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar

/**
* Tests for verifying the main three dot menu options
* Tests for verifying the General section of the Settings menu
*
*/

class SettingsBasicsTest {
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.

private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private lateinit var mockWebServer: MockWebServer
private val featureSettingsHelper = FeatureSettingsHelper()

Expand Down Expand Up @@ -132,97 +122,4 @@ class SettingsBasicsTest {
verifyMenuItemsAreDisabled()
}
}

@SmokeTest
@Test
fun jumpBackInOptionTest() {
val genericURL = getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
mDevice.waitForIdle()
}.goToHomescreen {
verifyJumpBackInSectionIsDisplayed()
}.openThreeDotMenu {
}.openCustomizeHome {
clickJumpBackInButton()
}.goBack {
verifyJumpBackInSectionIsNotDisplayed()
}
}

@SmokeTest
@Test
fun recentBookmarksOptionTest() {
val genericURL = getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
mDevice.waitForIdle()
}.openThreeDotMenu {
}.bookmarkPage {
}.goToHomescreen {
verifyRecentBookmarksSectionIsDisplayed()
}.openThreeDotMenu {
}.openCustomizeHome {
clickRecentBookmarksButton()
}.goBack {
verifyRecentBookmarksSectionIsNotDisplayed()
}
}

@SmokeTest
@Test
fun startOnHomepageTest() {
val genericURL = getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
mDevice.waitForIdle()
}.openThreeDotMenu {
}.openSettings {
}.openHomepageSubMenu {
clickStartOnHomepageButton()
}

restartApp(activityIntentTestRule)

homeScreen {
verifyHomeScreen()
}
}

@SmokeTest
@Test
fun startOnLastTabTest() {
val firstWebPage = getGenericAsset(mockWebServer, 1)

homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openHomepageSubMenu {
clickStartOnHomepageButton()
}

restartApp(activityIntentTestRule)

homeScreen {
verifyHomeScreen()
}

navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
mDevice.waitForIdle()
}.goToHomescreen {
}.openThreeDotMenu {
}.openCustomizeHome {
clickStartOnLastTabButton()
}

restartApp(activityIntentTestRule)

browserScreen {
verifyUrl(firstWebPage.url.toString())
}
}
}
160 changes: 160 additions & 0 deletions app/src/androidTest/java/org/mozilla/fenix/ui/SettingsHomepageTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/* 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 okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.FeatureSettingsHelper
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
import org.mozilla.fenix.helpers.TestHelper.restartApp
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar

/**
* Tests for verifying the Homepage settings menu
*
*/
class SettingsHomepageTest {
private lateinit var mockWebServer: MockWebServer
private val featureSettingsHelper = FeatureSettingsHelper()

@get:Rule
val activityIntentTestRule = HomeActivityIntentTestRule()

@Before
fun setUp() {
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
featureSettingsHelper.setJumpBackCFREnabled(false)
}

@After
fun tearDown() {
mockWebServer.shutdown()

// resetting modified features enabled setting to default
featureSettingsHelper.resetAllFeatureFlags()
}

@SmokeTest
@Test
fun jumpBackInOptionTest() {
val genericURL = getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
}.goToHomescreen {
verifyJumpBackInSectionIsDisplayed()
}.openThreeDotMenu {
}.openCustomizeHome {
clickJumpBackInButton()
}.goBack {
verifyJumpBackInSectionIsNotDisplayed()
}
}

@SmokeTest
@Test
fun recentBookmarksOptionTest() {
val genericURL = getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
}.openThreeDotMenu {
}.bookmarkPage {
}.goToHomescreen {
verifyRecentBookmarksSectionIsDisplayed()
}.openThreeDotMenu {
}.openCustomizeHome {
clickRecentBookmarksButton()
}.goBack {
verifyRecentBookmarksSectionIsNotDisplayed()
}
}

@SmokeTest
@Test
fun startOnHomepageTest() {
val genericURL = getGenericAsset(mockWebServer, 1)

navigationToolbar {
}.enterURLAndEnterToBrowser(genericURL.url) {
}.openThreeDotMenu {
}.openSettings {
}.openHomepageSubMenu {
clickStartOnHomepageButton()
}

restartApp(activityIntentTestRule)

homeScreen {
verifyHomeScreen()
}
}

@SmokeTest
@Test
fun startOnLastTabTest() {
val firstWebPage = getGenericAsset(mockWebServer, 1)

homeScreen {
}.openThreeDotMenu {
}.openSettings {
}.openHomepageSubMenu {
clickStartOnHomepageButton()
}

restartApp(activityIntentTestRule)

homeScreen {
verifyHomeScreen()
}

navigationToolbar {
}.enterURLAndEnterToBrowser(firstWebPage.url) {
}.goToHomescreen {
}.openThreeDotMenu {
}.openCustomizeHome {
clickStartOnLastTabButton()
}

restartApp(activityIntentTestRule)

browserScreen {
verifyUrl(firstWebPage.url.toString())
}
}

@SmokeTest
@Test
fun setWallpaperTest() {
val wallpapers = listOf(
"Wallpaper Item: amethyst",
"Wallpaper Item: cerulean",
"Wallpaper Item: sunrise"
)

for (wallpaper in wallpapers) {
homeScreen {
}.openThreeDotMenu {
}.openCustomizeHome {
openWallpapersMenu()
selectWallpaper(wallpaper)
verifySnackBarText("Wallpaper updated!")
}.clickSnackBarViewButton {
verifyWallpaperImageApplied(true)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ import org.hamcrest.CoreMatchers.instanceOf
import org.hamcrest.CoreMatchers.not
import org.hamcrest.Matchers
import org.junit.Assert
import org.junit.Assert.assertFalse
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTimeShort
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.packageName
Expand Down Expand Up @@ -81,6 +83,24 @@ class HomeScreenRobot {
fun verifyNoTabsOpened() = assertNoTabsOpened()
fun verifyKeyboardVisible() = assertKeyboardVisibility(isExpectedToBeVisible = true)

fun verifyWallpaperImageApplied(isEnabled: Boolean) {
if (isEnabled) {
assertTrue(
mDevice.findObject(
UiSelector().resourceId("$packageName:id/wallpaperImageView")
).waitForExists(waitingTimeShort)
)
} else {
assertFalse(
mDevice.findObject(
UiSelector().resourceId("$packageName:id/wallpaperImageView")
).waitForExists(waitingTimeShort)
)
}

mDevice.findObject(UiSelector())
}

// First Run elements
fun verifyWelcomeHeader() = assertWelcomeHeader()

Expand Down Expand Up @@ -159,6 +179,8 @@ class HomeScreenRobot {
).click()
}

fun clickFirefoxLogo() = homepageWordmark.click()

class Transition {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

Expand Down Expand Up @@ -390,8 +412,9 @@ private fun assertHomePrivateBrowsingButton() =
privateBrowsingButton()
.check(matches(isDisplayed()))

private fun assertHomeWordmark() = onView(ViewMatchers.withResourceName("wordmark"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private val homepageWordmark = onView(ViewMatchers.withResourceName("wordmark"))
private fun assertHomeWordmark() =
homepageWordmark.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

private fun assertHomeToolbar() = onView(ViewMatchers.withResourceName("toolbar"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
Expand Down Expand Up @@ -649,3 +672,4 @@ val deleteFromHistory =
withText(R.string.delete_from_history)
)
).inRoot(RootMatchers.isPlatformPopup())

Loading

0 comments on commit 9980a76

Please sign in to comment.