From 2d52cd4ef0e4cf90c9734336c886c71cc8c9cfd4 Mon Sep 17 00:00:00 2001 From: Mincheng Date: Mon, 21 Oct 2024 15:22:01 +1100 Subject: [PATCH] Add UI Automator test for verifying 'Commons' app language option in system settings This commit introduces a UI Automator test in the 'AppLanguagesSystemTest.java' file under the 'fr.free.nrw.commons.ui' package. The test verifies the following: - Navigates through Android system settings. - Scrolls to and selects 'Languages & input'. - Opens 'App languages' and checks if the 'Commons' app appears in the list. The test uses UiScrollable and UiSelector to find and interact with system UI elements. --- .../commons/ui/AppLanguagesSystemTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 app/src/androidTest/java/fr/free/nrw/commons/ui/AppLanguagesSystemTest.java diff --git a/app/src/androidTest/java/fr/free/nrw/commons/ui/AppLanguagesSystemTest.java b/app/src/androidTest/java/fr/free/nrw/commons/ui/AppLanguagesSystemTest.java new file mode 100644 index 000000000..3abe28e36 --- /dev/null +++ b/app/src/androidTest/java/fr/free/nrw/commons/ui/AppLanguagesSystemTest.java @@ -0,0 +1,58 @@ +package fr.free.nrw.commons.ui; + +import androidx.test.uiautomator.UiScrollable; +import androidx.test.uiautomator.UiSelector; +import androidx.test.uiautomator.UiObject; +import androidx.test.uiautomator.UiDevice; +import androidx.test.platform.app.InstrumentationRegistry; +import android.content.Intent; +import android.provider.Settings; + +import org.junit.Before; +import org.junit.Test; + +public class AppLanguagesSystemTest { + + private UiDevice device; + + @Before + public void setUp() { + // Initiate UI Automator + device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + + // Use Intent to start system application + Intent intent = new Intent(Settings.ACTION_SETTINGS); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + InstrumentationRegistry.getInstrumentation().getContext().startActivity(intent); + + // wait Settings starting + device.waitForIdle(); + } + + @Test + public void testCommonsAppLanguageOptionExists() throws Exception { + // 1. Find and click "System" + UiScrollable settingsList = new UiScrollable(new UiSelector().scrollable(true)); + UiObject systemOption = settingsList.getChildByText(new UiSelector().text("System"), "System"); + systemOption.click(); + + // 2. scroll and find "Languages & input" + UiObject languagesInputOption = device.findObject(new UiSelector() + .className("android.widget.TextView") + .textContains("Gboard")); + languagesInputOption.clickAndWaitForNewWindow(); + + + + + // 3. detect "App languages" and click + UiObject appLanguagesOption = device.findObject(new UiSelector().text("App languages")); + appLanguagesOption.clickAndWaitForNewWindow(); + + // 4. detect "Commons" APP is there + UiScrollable appLanguagesList = new UiScrollable(new UiSelector().scrollable(true)); + UiObject commonsAppOption = appLanguagesList.getChildByText(new UiSelector().text("Commons"), "Commons"); + + assert(commonsAppOption.exists()); + } +}