Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Bug 1880064 - Add logs to ReaderViewRobot #5583

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ object AppAndSystemHelper {
* @return Boolean value that helps us know if the current activity supports custom tabs or PWAs.
*/
fun isExternalAppBrowserActivityInCurrentTask(): Boolean {
Log.i(TAG, "Trying to verify that the latest activity of the application is used for custom tabs or PWAs")
val activityManager = TestHelper.appContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager

mDevice.waitForIdle(TestAssetHelper.waitingTimeShort)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@

package org.mozilla.fenix.ui.robots

import android.util.Log
import androidx.test.uiautomator.UiSelector
import org.junit.Assert.assertTrue
import org.mozilla.fenix.helpers.AppAndSystemHelper.isExternalAppBrowserActivityInCurrentTask
import org.mozilla.fenix.helpers.Constants
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName

class PwaRobot {
fun verifyCustomTabToolbarIsNotDisplayed() = assertUIObjectExists(customTabToolbar(), exists = false)
fun verifyPwaActivityInCurrentTask() = assertTrue(isExternalAppBrowserActivityInCurrentTask())
fun verifyCustomTabToolbarIsNotDisplayed() = assertUIObjectExists(itemWithResId("$packageName:id/toolbar"), exists = false)
fun verifyPwaActivityInCurrentTask() {
assertTrue("$TAG: The latest activity of the application is not used for custom tabs or PWAs", isExternalAppBrowserActivityInCurrentTask())
}

class Transition
}

fun pwaScreen(interact: PwaRobot.() -> Unit): PwaRobot.Transition {
Log.i(TAG, "pwaScreen: Trying to find the engine view")
mDevice.findObject(UiSelector().resourceId("$packageName:id/engineView"))
Log.i(Constants.TAG, "pwaScreen: Found the engine view")
PwaRobot().interact()
return PwaRobot.Transition()
}

private fun customTabToolbar() = mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
package org.mozilla.fenix.ui.robots

import android.content.Context
import android.util.Log
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.click

Expand All @@ -24,34 +25,98 @@ import org.mozilla.fenix.helpers.click
*/
class ReaderViewRobot {

fun verifyAppearanceFontGroup(visible: Boolean = false): ViewInteraction =
assertAppearanceFontGroup(visible)
fun verifyAppearanceFontGroup(visible: Boolean = false) {
Log.i(TAG, "verifyAppearanceFontGroup: Trying to verify that the font group buttons are visible: $visible")
onView(
withId(R.id.mozac_feature_readerview_font_group),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)
Log.i(TAG, "verifyAppearanceFontGroup: Verified that the font group buttons are visible: $visible")
}

fun verifyAppearanceFontSansSerif(visible: Boolean = false): ViewInteraction =
assertAppearanceFontSansSerif(visible)
fun verifyAppearanceFontSansSerif(visible: Boolean = false) {
Log.i(TAG, "verifyAppearanceFontSansSerif: Trying to verify that the sans serif font button is visible: $visible")
onView(
withId(R.id.mozac_feature_readerview_font_sans_serif),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)
Log.i(TAG, "verifyAppearanceFontSansSerif: Verified that the sans serif font button is visible: $visible")
}

fun verifyAppearanceFontSerif(visible: Boolean = false): ViewInteraction =
assertAppearanceFontSerif(visible)
fun verifyAppearanceFontSerif(visible: Boolean = false) {
Log.i(TAG, "verifyAppearanceFontSerif: Trying to verify that the serif font button is visible: $visible")
onView(
withId(R.id.mozac_feature_readerview_font_serif),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)
Log.i(TAG, "verifyAppearanceFontSerif: Verified that the serif font button is visible: $visible")
}

fun verifyAppearanceFontDecrease(visible: Boolean = false): ViewInteraction =
assertAppearanceFontDecrease(visible)
fun verifyAppearanceFontDecrease(visible: Boolean = false) {
Log.i(TAG, "verifyAppearanceFontDecrease: Trying to verify that the decrease font button is visible: $visible")
onView(
withId(R.id.mozac_feature_readerview_font_size_decrease),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)
Log.i(TAG, "verifyAppearanceFontDecrease: Verified that the decrease font button is visible: $visible")
}

fun verifyAppearanceFontIncrease(visible: Boolean = false): ViewInteraction =
assertAppearanceFontIncrease(visible)
fun verifyAppearanceFontIncrease(visible: Boolean = false) {
Log.i(TAG, "verifyAppearanceFontIncrease: Trying to verify that the increase font button is visible: $visible")
onView(
withId(R.id.mozac_feature_readerview_font_size_increase),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)
Log.i(TAG, "verifyAppearanceFontIncrease: Verified that the increase font button is visible: $visible")
}

fun verifyAppearanceColorGroup(visible: Boolean = false): ViewInteraction =
assertAppearanceColorGroup(visible)
fun verifyAppearanceColorGroup(visible: Boolean = false) {
Log.i(TAG, "verifyAppearanceColorGroup: Trying to verify that the color group buttons are visible: $visible")
onView(
withId(R.id.mozac_feature_readerview_color_scheme_group),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)
Log.i(TAG, "verifyAppearanceColorGroup: Verified that the color group buttons are visible: $visible")
}

fun verifyAppearanceColorSepia(visible: Boolean = false): ViewInteraction =
assertAppearanceColorSepia(visible)
fun verifyAppearanceColorSepia(visible: Boolean = false) {
Log.i(TAG, "verifyAppearanceColorSepia: Trying to verify that the sepia color button is visible: $visible")
onView(
withId(R.id.mozac_feature_readerview_color_sepia),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)
Log.i(TAG, "verifyAppearanceColorSepia: Verified that the sepia color button is visible: $visible")
}

fun verifyAppearanceColorDark(visible: Boolean = false): ViewInteraction =
assertAppearanceColorDark(visible)
fun verifyAppearanceColorDark(visible: Boolean = false) {
Log.i(TAG, "verifyAppearanceColorDark: Trying to verify that the dark color button is visible: $visible")
onView(
withId(R.id.mozac_feature_readerview_color_dark),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)
Log.i(TAG, "verifyAppearanceColorDark: Verified that the dark color button is visible: $visible")
}

fun verifyAppearanceColorLight(visible: Boolean = false): ViewInteraction =
assertAppearanceColorLight(visible)
fun verifyAppearanceColorLight(visible: Boolean = false) {
Log.i(TAG, "verifyAppearanceColorLight: Trying to verify that the light color button is visible: $visible")
onView(
withId(R.id.mozac_feature_readerview_color_light),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)
Log.i(TAG, "verifyAppearanceColorLight: Verified that the light color button is visible: $visible")
}

fun verifyAppearanceFontIsActive(fontType: String) {
Log.i(TAG, "verifyAppearanceFontIsActive: Trying to verify that the font type is: $fontType")
val fontTypeKey: String = "mozac-readerview-fonttype"

val prefs = InstrumentationRegistry.getInstrumentation()
Expand All @@ -61,9 +126,11 @@ class ReaderViewRobot {
)

assertEquals(fontType, prefs.getString(fontTypeKey, ""))
Log.i(TAG, "verifyAppearanceFontIsActive: Verified that the font type is: $fontType")
}

fun verifyAppearanceFontSize(expectedFontSize: Int) {
Log.i(TAG, "verifyAppearanceFontSize: Trying to verify that the font size is: $expectedFontSize")
val fontSizeKey: String = "mozac-readerview-fontsize"

val prefs = InstrumentationRegistry.getInstrumentation()
Expand All @@ -75,9 +142,11 @@ class ReaderViewRobot {
val fontSizeKeyValue = prefs.getInt(fontSizeKey, 3)

assertEquals(expectedFontSize, fontSizeKeyValue)
Log.i(TAG, "verifyAppearanceFontSize: Verified that the font size is: $expectedFontSize")
}

fun verifyAppearanceColorSchemeChange(expectedColorScheme: String) {
Log.i(TAG, "verifyAppearanceColorSchemeChange: Trying to verify that the color scheme is: $expectedColorScheme")
val colorSchemeKey: String = "mozac-readerview-colorscheme"

val prefs = InstrumentationRegistry.getInstrumentation()
Expand All @@ -87,12 +156,15 @@ class ReaderViewRobot {
)

assertEquals(expectedColorScheme, prefs.getString(colorSchemeKey, ""))
Log.i(TAG, "verifyAppearanceColorSchemeChange: Verified that the color scheme is: $expectedColorScheme")
}

class Transition {

fun closeAppearanceMenu(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
Log.i(TAG, "closeAppearanceMenu: Trying to click device back button")
mDevice.pressBack()
Log.i(TAG, "closeAppearanceMenu: Clicked device back button")

BrowserRobot().interact()
return BrowserRobot.Transition()
Expand All @@ -103,8 +175,9 @@ class ReaderViewRobot {
onView(
withId(R.id.mozac_feature_readerview_font_sans_serif),
)

Log.i(TAG, "toggleSansSerif: Trying to click sans serif button")
sansSerifButton().click()
Log.i(TAG, "toggleSansSerif: Clicked sans serif button")

ReaderViewRobot().interact()
return Transition()
Expand All @@ -115,8 +188,9 @@ class ReaderViewRobot {
onView(
withId(R.id.mozac_feature_readerview_font_serif),
)

Log.i(TAG, "toggleSerif: Trying to click serif button")
serifButton().click()
Log.i(TAG, "toggleSerif: Clicked serif button")

ReaderViewRobot().interact()
return Transition()
Expand All @@ -127,8 +201,9 @@ class ReaderViewRobot {
onView(
withId(R.id.mozac_feature_readerview_font_size_decrease),
)

Log.i(TAG, "toggleFontSizeDecrease: Trying to click the decrease font button")
fontSizeDecrease().click()
Log.i(TAG, "toggleFontSizeDecrease: Clicked the decrease font button")

ReaderViewRobot().interact()
return Transition()
Expand All @@ -139,8 +214,9 @@ class ReaderViewRobot {
onView(
withId(R.id.mozac_feature_readerview_font_size_increase),
)

Log.i(TAG, "toggleFontSizeIncrease: Trying to click the increase font button")
fontSizeIncrease().click()
Log.i(TAG, "toggleFontSizeIncrease: Clicked the increase font button")

ReaderViewRobot().interact()
return Transition()
Expand All @@ -151,8 +227,9 @@ class ReaderViewRobot {
onView(
withId(R.id.mozac_feature_readerview_color_light),
)

Log.i(TAG, "toggleColorSchemeChangeLight: Trying to click the light color button")
toggleLightColorSchemeButton().click()
Log.i(TAG, "toggleColorSchemeChangeLight: Clicked the light color button")

ReaderViewRobot().interact()
return Transition()
Expand All @@ -163,8 +240,9 @@ class ReaderViewRobot {
onView(
withId(R.id.mozac_feature_readerview_color_dark),
)

Log.i(TAG, "toggleColorSchemeChangeDark: Trying to click the dark color button")
toggleDarkColorSchemeButton().click()
Log.i(TAG, "toggleColorSchemeChangeDark: Clicked the dark color button")

ReaderViewRobot().interact()
return Transition()
Expand All @@ -175,82 +253,15 @@ class ReaderViewRobot {
onView(
withId(R.id.mozac_feature_readerview_color_sepia),
)

Log.i(TAG, "toggleColorSchemeChangeSepia: Trying to click the sepia color button")
toggleSepiaColorSchemeButton().click()
Log.i(TAG, "toggleColorSchemeChangeSepia: Clicked the sepia color button")

ReaderViewRobot().interact()
return Transition()
}
}
}

fun readerViewRobot(interact: ReaderViewRobot.() -> Unit): ReaderViewRobot.Transition {
ReaderViewRobot().interact()
return ReaderViewRobot.Transition()
}

private fun assertAppearanceFontGroup(visible: Boolean) =
onView(
withId(R.id.mozac_feature_readerview_font_group),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)

private fun assertAppearanceFontSansSerif(visible: Boolean) =
onView(
withId(R.id.mozac_feature_readerview_font_sans_serif),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)

private fun assertAppearanceFontSerif(visible: Boolean) =
onView(
withId(R.id.mozac_feature_readerview_font_serif),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)

private fun assertAppearanceFontDecrease(visible: Boolean) =
onView(
withId(R.id.mozac_feature_readerview_font_size_decrease),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)

private fun assertAppearanceFontIncrease(visible: Boolean) =
onView(
withId(R.id.mozac_feature_readerview_font_size_increase),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)

private fun assertAppearanceColorDark(visible: Boolean) =
onView(
withId(R.id.mozac_feature_readerview_color_dark),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)

private fun assertAppearanceColorLight(visible: Boolean) =
onView(
withId(R.id.mozac_feature_readerview_color_light),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)

private fun assertAppearanceColorSepia(visible: Boolean) =
onView(
withId(R.id.mozac_feature_readerview_color_sepia),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)

private fun assertAppearanceColorGroup(visible: Boolean) =
onView(
withId(R.id.mozac_feature_readerview_color_scheme_group),
).check(
matches(withEffectiveVisibility(visibleOrGone(visible))),
)

private fun visibleOrGone(visibility: Boolean) =
if (visibility) ViewMatchers.Visibility.VISIBLE else ViewMatchers.Visibility.GONE
Loading