Loading TEST_MAPPING +8 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,14 @@ } ] }, { "name": "SettingsUITests", "options": [ { "exclude-annotation": "org.junit.Ignore" } ] }, { "name": "SettingsPerfTests" } Loading tests/uitests/src/com/android/settings/biometrics2/utils/LockScreenUtil.java +1 −1 Original line number Diff line number Diff line Loading @@ -22,10 +22,10 @@ import static java.lang.String.format; import android.app.KeyguardManager; import android.content.Context; import android.os.SystemClock; import android.support.test.uiautomator.UiDevice; import android.util.Log; import androidx.test.InstrumentationRegistry; import androidx.test.uiautomator.UiDevice; import org.junit.Assert; Loading tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.kt +4 −53 Original line number Diff line number Diff line Loading @@ -19,13 +19,9 @@ package com.android.settings.ui import android.provider.Settings import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import androidx.test.uiautomator.By import androidx.test.uiautomator.Direction import androidx.test.uiautomator.UiDevice import com.android.settings.ui.testutils.SettingsTestUtils.SETTINGS_PACKAGE import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen import com.android.settings.ui.testutils.SettingsTestUtils.waitObject import com.google.common.truth.Truth.assertWithMessage import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -43,56 +39,11 @@ class AboutPhoneSettingsTests { @Test fun testAllMenuEntriesExist() { searchForItemsAndTakeAction(device) device.assertHasTexts(ON_SCREEN_TEXTS) } /** * Removes items found in the view and optionally takes some action. */ private fun removeItemsAndTakeAction(device: UiDevice, itemsLeftToFind: MutableList<String>) { val iterator = itemsLeftToFind.iterator() while (iterator.hasNext()) { val itemText = iterator.next() val item = device.waitObject(By.text(itemText)) if (item != null) { iterator.remove() } } } /** * Searches for UI elements in the current view and optionally takes some action. * * * Will scroll down the screen until it has found all elements or reached the bottom. * This allows elements to be found and acted on even if they change order. */ private fun searchForItemsAndTakeAction(device: UiDevice) { val itemsLeftToFind = resourceTexts.toMutableList() assertWithMessage("There must be at least one item to search for on the screen!") .that(itemsLeftToFind) .isNotEmpty() var canScrollDown = true while (canScrollDown && itemsLeftToFind.isNotEmpty()) { removeItemsAndTakeAction(device, itemsLeftToFind) // when we've finished searching the current view, scroll down val view = device.waitObject(By.res("$SETTINGS_PACKAGE:id/main_content")) canScrollDown = view?.scroll(Direction.DOWN, 1.0f) ?: false } // check the last items once we have reached the bottom of the view removeItemsAndTakeAction(device, itemsLeftToFind) assertWithMessage( "The following items were not found on the screen: " + itemsLeftToFind.joinToString(", ") ) .that(itemsLeftToFind) .isEmpty() } companion object { // TODO: retrieve using name/ids from com.android.settings package private val resourceTexts = listOf( private companion object { val ON_SCREEN_TEXTS = listOf( "Device name", "Legal information", "Regulatory labels" Loading tests/uitests/src/com/android/settings/ui/AppsSettingsTests.kt +4 −11 Original line number Diff line number Diff line Loading @@ -18,9 +18,8 @@ package com.android.settings.ui import android.provider.Settings import androidx.test.uiautomator.By import androidx.test.uiautomator.Direction import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.Until import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts import com.android.settings.ui.testutils.SettingsTestUtils.clickObject import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen import com.android.settings.ui.testutils.SettingsTestUtils.waitObject Loading @@ -42,13 +41,7 @@ class AppsSettingsTests { @Test fun testAppSettingsListForCalculator() { device.clickObject(By.text("Calculator")) val scrollableObj = device.findObject(By.scrollable(true)) for (setting in resourceTexts) { scrollableObj.scrollUntil(Direction.DOWN, Until.findObject(By.text(setting))) val appSetting = device.waitObject(By.text(setting)) assertWithMessage("Missing setting for Calculator: $setting") .that(appSetting).isNotNull() } device.assertHasTexts(ON_SCREEN_TEXTS) } @Test Loading @@ -61,8 +54,8 @@ class AppsSettingsTests { assertWithMessage("App not enabled successfully").that(disableButton).isNotNull() } companion object { private val resourceTexts = arrayOf( private companion object { val ON_SCREEN_TEXTS = listOf( "Notifications", "Permissions", "Storage & cache", Loading tests/uitests/src/com/android/settings/ui/BatterySettingsTest.kt 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.ui import android.content.Intent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.uiautomator.UiDevice import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class BatterySettingsTest { private lateinit var device: UiDevice @Before fun setUp() { device = startMainActivityFromHomeScreen(Intent.ACTION_POWER_USAGE_SUMMARY) } @Test fun hasTexts() { device.assertHasTexts(ON_SCREEN_TEXTS) } private companion object { // Items we really want to always show val ON_SCREEN_TEXTS = listOf( "Battery usage", "Battery Saver", "Battery percentage", "Remaining battery life is approximate and can change based on usage" ) } } Loading
TEST_MAPPING +8 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,14 @@ } ] }, { "name": "SettingsUITests", "options": [ { "exclude-annotation": "org.junit.Ignore" } ] }, { "name": "SettingsPerfTests" } Loading
tests/uitests/src/com/android/settings/biometrics2/utils/LockScreenUtil.java +1 −1 Original line number Diff line number Diff line Loading @@ -22,10 +22,10 @@ import static java.lang.String.format; import android.app.KeyguardManager; import android.content.Context; import android.os.SystemClock; import android.support.test.uiautomator.UiDevice; import android.util.Log; import androidx.test.InstrumentationRegistry; import androidx.test.uiautomator.UiDevice; import org.junit.Assert; Loading
tests/uitests/src/com/android/settings/ui/AboutPhoneSettingsTests.kt +4 −53 Original line number Diff line number Diff line Loading @@ -19,13 +19,9 @@ package com.android.settings.ui import android.provider.Settings import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import androidx.test.uiautomator.By import androidx.test.uiautomator.Direction import androidx.test.uiautomator.UiDevice import com.android.settings.ui.testutils.SettingsTestUtils.SETTINGS_PACKAGE import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen import com.android.settings.ui.testutils.SettingsTestUtils.waitObject import com.google.common.truth.Truth.assertWithMessage import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -43,56 +39,11 @@ class AboutPhoneSettingsTests { @Test fun testAllMenuEntriesExist() { searchForItemsAndTakeAction(device) device.assertHasTexts(ON_SCREEN_TEXTS) } /** * Removes items found in the view and optionally takes some action. */ private fun removeItemsAndTakeAction(device: UiDevice, itemsLeftToFind: MutableList<String>) { val iterator = itemsLeftToFind.iterator() while (iterator.hasNext()) { val itemText = iterator.next() val item = device.waitObject(By.text(itemText)) if (item != null) { iterator.remove() } } } /** * Searches for UI elements in the current view and optionally takes some action. * * * Will scroll down the screen until it has found all elements or reached the bottom. * This allows elements to be found and acted on even if they change order. */ private fun searchForItemsAndTakeAction(device: UiDevice) { val itemsLeftToFind = resourceTexts.toMutableList() assertWithMessage("There must be at least one item to search for on the screen!") .that(itemsLeftToFind) .isNotEmpty() var canScrollDown = true while (canScrollDown && itemsLeftToFind.isNotEmpty()) { removeItemsAndTakeAction(device, itemsLeftToFind) // when we've finished searching the current view, scroll down val view = device.waitObject(By.res("$SETTINGS_PACKAGE:id/main_content")) canScrollDown = view?.scroll(Direction.DOWN, 1.0f) ?: false } // check the last items once we have reached the bottom of the view removeItemsAndTakeAction(device, itemsLeftToFind) assertWithMessage( "The following items were not found on the screen: " + itemsLeftToFind.joinToString(", ") ) .that(itemsLeftToFind) .isEmpty() } companion object { // TODO: retrieve using name/ids from com.android.settings package private val resourceTexts = listOf( private companion object { val ON_SCREEN_TEXTS = listOf( "Device name", "Legal information", "Regulatory labels" Loading
tests/uitests/src/com/android/settings/ui/AppsSettingsTests.kt +4 −11 Original line number Diff line number Diff line Loading @@ -18,9 +18,8 @@ package com.android.settings.ui import android.provider.Settings import androidx.test.uiautomator.By import androidx.test.uiautomator.Direction import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.Until import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts import com.android.settings.ui.testutils.SettingsTestUtils.clickObject import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen import com.android.settings.ui.testutils.SettingsTestUtils.waitObject Loading @@ -42,13 +41,7 @@ class AppsSettingsTests { @Test fun testAppSettingsListForCalculator() { device.clickObject(By.text("Calculator")) val scrollableObj = device.findObject(By.scrollable(true)) for (setting in resourceTexts) { scrollableObj.scrollUntil(Direction.DOWN, Until.findObject(By.text(setting))) val appSetting = device.waitObject(By.text(setting)) assertWithMessage("Missing setting for Calculator: $setting") .that(appSetting).isNotNull() } device.assertHasTexts(ON_SCREEN_TEXTS) } @Test Loading @@ -61,8 +54,8 @@ class AppsSettingsTests { assertWithMessage("App not enabled successfully").that(disableButton).isNotNull() } companion object { private val resourceTexts = arrayOf( private companion object { val ON_SCREEN_TEXTS = listOf( "Notifications", "Permissions", "Storage & cache", Loading
tests/uitests/src/com/android/settings/ui/BatterySettingsTest.kt 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.ui import android.content.Intent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.uiautomator.UiDevice import com.android.settings.ui.testutils.SettingsTestUtils.assertHasTexts import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class BatterySettingsTest { private lateinit var device: UiDevice @Before fun setUp() { device = startMainActivityFromHomeScreen(Intent.ACTION_POWER_USAGE_SUMMARY) } @Test fun hasTexts() { device.assertHasTexts(ON_SCREEN_TEXTS) } private companion object { // Items we really want to always show val ON_SCREEN_TEXTS = listOf( "Battery usage", "Battery Saver", "Battery percentage", "Remaining battery life is approximate and can change based on usage" ) } }