From d3593a435f029edcb8f7a7178e695bbef94cd4a1 Mon Sep 17 00:00:00 2001 From: "oana.horvath" Date: Fri, 2 Dec 2022 16:22:00 +0200 Subject: [PATCH] [fenix] No issue: RTL nav bar UI tests --- .../org/mozilla/fenix/helpers/TestHelper.kt | 34 ++++++++++----- .../mozilla/fenix/ui/NavigationToolbarTest.kt | 43 +++++++++++++++++++ .../mozilla/fenix/ui/SettingsBasicsTest.kt | 1 + .../java/org/mozilla/fenix/ui/SmokeTest.kt | 18 -------- 4 files changed, 68 insertions(+), 28 deletions(-) diff --git a/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt b/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt index 81e4d522a6..6d92826350 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt @@ -6,6 +6,7 @@ package org.mozilla.fenix.helpers +import android.Manifest import android.app.ActivityManager import android.app.PendingIntent import android.content.ActivityNotFoundException @@ -42,6 +43,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withParent import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.ActivityTestRule +import androidx.test.runner.permission.PermissionRequester import androidx.test.uiautomator.By import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.UiObject @@ -57,6 +59,7 @@ import org.hamcrest.Matcher import org.junit.Assert import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue +import org.mozilla.fenix.Config import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.customtabs.ExternalAppBrowserActivity @@ -389,20 +392,31 @@ object TestHelper { /** * Changes the default language of the entire device, not just the app. + * Runs on Debug variant as we don't want to adjust Release permission manifests * Runs the test in its testBlock. - * Cleans up and sets the default locale after it's are done. + * Cleans up and sets the default locale after it's done. */ fun runWithSystemLocaleChanged(locale: Locale, testRule: ActivityTestRule, testBlock: () -> Unit) { - val defaultLocale = Locale.getDefault() + if (Config.channel.isDebug) { + /* Sets permission to change device language */ + PermissionRequester().apply { + addPermissions( + Manifest.permission.CHANGE_CONFIGURATION, + ) + requestPermissions() + } - try { - setSystemLocale(locale) - testBlock() - ThreadUtils.runOnUiThread { testRule.activity.recreate() } - } catch (e: Exception) { - e.printStackTrace() - } finally { - setSystemLocale(defaultLocale) + val defaultLocale = Locale.getDefault() + + try { + setSystemLocale(locale) + testBlock() + ThreadUtils.runOnUiThread { testRule.activity.recreate() } + } catch (e: Exception) { + e.printStackTrace() + } finally { + setSystemLocale(defaultLocale) + } } } 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 d0629660af..3f602610f6 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/NavigationToolbarTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/NavigationToolbarTest.kt @@ -12,11 +12,14 @@ 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.HomeActivityTestRule import org.mozilla.fenix.helpers.TestAssetHelper +import org.mozilla.fenix.helpers.TestHelper.runWithSystemLocaleChanged import org.mozilla.fenix.ui.robots.homeScreen import org.mozilla.fenix.ui.robots.navigationToolbar +import java.util.Locale /** * Tests for verifying basic functionality of browser navigation and page related interactions @@ -95,6 +98,46 @@ class NavigationToolbarTest { } } + // Swipes the nav bar left/right to switch between tabs + @SmokeTest + @Test + fun swipeToSwitchTabTest() { + val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) + val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2) + + navigationToolbar { + }.enterURLAndEnterToBrowser(firstWebPage.url) { + }.openTabDrawer { + }.openNewTab { + }.submitQuery(secondWebPage.url.toString()) { + swipeNavBarRight(secondWebPage.url.toString()) + verifyUrl(firstWebPage.url.toString()) + swipeNavBarLeft(firstWebPage.url.toString()) + verifyUrl(secondWebPage.url.toString()) + } + } + + // Because it requires changing system prefs, this test will run only on Debug builds + @Test + fun swipeToSwitchTabInRTLTest() { + val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) + val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2) + val arabicLocale = Locale("ar", "AR") + + runWithSystemLocaleChanged(arabicLocale, activityTestRule) { + navigationToolbar { + }.enterURLAndEnterToBrowser(firstWebPage.url) { + }.openTabDrawer { + }.openNewTab { + }.submitQuery(secondWebPage.url.toString()) { + swipeNavBarLeft(secondWebPage.url.toString()) + verifyUrl(firstWebPage.url.toString()) + swipeNavBarRight(firstWebPage.url.toString()) + verifyUrl(secondWebPage.url.toString()) + } + } + } + // Test running on beta/release builds in CI: // caution when making changes to it, so they don't block the builds @Test diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt index 24a6fc292f..77d550ac6e 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SettingsBasicsTest.kt @@ -302,6 +302,7 @@ class SettingsBasicsTest { } } + // Because it requires changing system prefs, this test will run only on Debug builds @Ignore("Failing due to app translation bug, see: https://github.com/mozilla-mobile/fenix/issues/26729") @Test fun frenchSystemLocaleTest() { diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt index c0be137641..9b789c9fdf 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/SmokeTest.kt @@ -421,24 +421,6 @@ class SmokeTest { } } - // Swipes the nav bar left/right to switch between tabs - @Test - fun swipeToSwitchTabTest() { - val firstWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) - val secondWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 2) - - navigationToolbar { - }.enterURLAndEnterToBrowser(firstWebPage.url) { - }.openTabDrawer { - }.openNewTab { - }.submitQuery(secondWebPage.url.toString()) { - swipeNavBarRight(secondWebPage.url.toString()) - verifyUrl(firstWebPage.url.toString()) - swipeNavBarLeft(firstWebPage.url.toString()) - verifyUrl(secondWebPage.url.toString()) - } - } - // Saves a login, then changes it and verifies the update @Test fun updateSavedLoginTest() {