Fix more SettingsUITests

Also add SettingsUITests to postsubmit.

Bug: 290381395
Test: ui test
Change-Id: Ib1dd35bf7823290bf77deb31366e9cb6ae9f65f7
This commit is contained in:
Chaohui Wang
2023-09-08 21:26:59 +08:00
parent f1a1439d2b
commit a35c6bc139
26 changed files with 346 additions and 549 deletions

View File

@@ -27,6 +27,14 @@
} }
] ]
}, },
{
"name": "SettingsUITests",
"options": [
{
"exclude-annotation": "org.junit.Ignore"
}
]
},
{ {
"name": "SettingsPerfTests" "name": "SettingsPerfTests"
} }

View File

@@ -22,10 +22,10 @@ import static java.lang.String.format;
import android.app.KeyguardManager; import android.app.KeyguardManager;
import android.content.Context; import android.content.Context;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.test.uiautomator.UiDevice;
import android.util.Log; import android.util.Log;
import androidx.test.InstrumentationRegistry; import androidx.test.InstrumentationRegistry;
import androidx.test.uiautomator.UiDevice;
import org.junit.Assert; import org.junit.Assert;

View File

@@ -19,13 +19,9 @@ package com.android.settings.ui
import android.provider.Settings import android.provider.Settings
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import androidx.test.uiautomator.UiDevice 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.startMainActivityFromHomeScreen
import com.android.settings.ui.testutils.SettingsTestUtils.waitObject
import com.google.common.truth.Truth.assertWithMessage
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@@ -43,56 +39,11 @@ class AboutPhoneSettingsTests {
@Test @Test
fun testAllMenuEntriesExist() { fun testAllMenuEntriesExist() {
searchForItemsAndTakeAction(device) device.assertHasTexts(ON_SCREEN_TEXTS)
} }
/** private companion object {
* Removes items found in the view and optionally takes some action. val ON_SCREEN_TEXTS = listOf(
*/
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(
"Device name", "Device name",
"Legal information", "Legal information",
"Regulatory labels" "Regulatory labels"

View File

@@ -18,9 +18,8 @@ package com.android.settings.ui
import android.provider.Settings import android.provider.Settings
import androidx.test.uiautomator.By import androidx.test.uiautomator.By
import androidx.test.uiautomator.Direction
import androidx.test.uiautomator.UiDevice 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.clickObject
import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
import com.android.settings.ui.testutils.SettingsTestUtils.waitObject import com.android.settings.ui.testutils.SettingsTestUtils.waitObject
@@ -42,13 +41,7 @@ class AppsSettingsTests {
@Test @Test
fun testAppSettingsListForCalculator() { fun testAppSettingsListForCalculator() {
device.clickObject(By.text("Calculator")) device.clickObject(By.text("Calculator"))
val scrollableObj = device.findObject(By.scrollable(true)) device.assertHasTexts(ON_SCREEN_TEXTS)
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()
}
} }
@Test @Test
@@ -61,8 +54,8 @@ class AppsSettingsTests {
assertWithMessage("App not enabled successfully").that(disableButton).isNotNull() assertWithMessage("App not enabled successfully").that(disableButton).isNotNull()
} }
companion object { private companion object {
private val resourceTexts = arrayOf( val ON_SCREEN_TEXTS = listOf(
"Notifications", "Notifications",
"Permissions", "Permissions",
"Storage & cache", "Storage & cache",

View File

@@ -0,0 +1,51 @@
/*
* 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"
)
}
}

View File

@@ -1,75 +0,0 @@
/*
* Copyright (C) 2018 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 android.os.RemoteException;
import android.system.helpers.SettingsHelper;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.UiDevice;
import com.android.settings.ui.testutils.SettingsTestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class BatterySettingsUITest {
// Items we really want to always show
private static final String[] CATEGORIES = new String[] {
"Battery Saver",
"Battery percentage",
"Battery usage data is approximate and can change based on usage",
};
private UiDevice mDevice;
private SettingsHelper mHelper;
@Before
public void setUp() throws Exception {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mHelper = SettingsHelper.getInstance();
try {
mDevice.setOrientationNatural();
} catch (RemoteException e) {
throw new RuntimeException("failed to freeze device orientaion", e);
}
}
@After
public void tearDown() throws Exception {
// Go back to home for next test.
mDevice.pressHome();
}
@Test
public void launchSecuritySettings() throws Exception {
// Launch Settings
SettingsHelper.launchSettingsPage(
InstrumentationRegistry.getTargetContext(), Intent.ACTION_POWER_USAGE_SUMMARY);
mHelper.scrollVert(false);
for (String category : CATEGORIES) {
SettingsTestUtils.assertTitleMatch(mDevice, category);
}
}
}

View File

@@ -35,9 +35,11 @@ import androidx.test.uiautomator.Until;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@Ignore
@MediumTest @MediumTest
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class ConnectedDeviceTests { public class ConnectedDeviceTests {

View File

@@ -0,0 +1,43 @@
/*
* 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.provider.Settings
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import com.android.settings.ui.testutils.SettingsTestUtils.startMainActivityFromHomeScreen
import com.android.settings.ui.testutils.SettingsTestUtils.waitObject
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class DataSaverSettingsTest {
private lateinit var device: UiDevice
@Before
fun setUp() {
device = startMainActivityFromHomeScreen(Settings.ACTION_DATA_SAVER_SETTINGS)
}
@Test
fun hasSwitchBar() {
assertThat(device.waitObject(By.text("Use Data Saver"))).isNotNull()
}
}

View File

@@ -26,6 +26,9 @@ import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice; import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.Until; import androidx.test.uiautomator.Until;
import org.junit.Ignore;
@Ignore
public class DataUsageSettingsTests extends InstrumentationTestCase { public class DataUsageSettingsTests extends InstrumentationTestCase {
private static final String SETTINGS_PACKAGE = "com.android.settings"; private static final String SETTINGS_PACKAGE = "com.android.settings";

View File

@@ -1,99 +0,0 @@
/*
* Copyright (C) 2018 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 static com.android.settings.ui.testutils.SettingsTestUtils.SETTINGS_PACKAGE;
import static com.android.settings.ui.testutils.SettingsTestUtils.TIMEOUT;
import android.os.RemoteException;
import android.platform.test.annotations.Presubmit;
import android.provider.Settings;
import android.system.helpers.SettingsHelper;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.Direction;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;
import com.android.settings.ui.testutils.SettingsTestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class HomepageDisplayTests {
private static final String[] HOMEPAGE_ITEMS = {
"Network & internet",
"Connected devices",
"Apps & notifications",
"Battery",
"Display",
"Sound",
"Storage",
"Security",
"Location",
"Privacy",
"Accounts",
"Accessibility",
"System"
};
private UiDevice mDevice;
@Before
public void setUp() throws Exception {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
try {
mDevice.setOrientationNatural();
} catch (RemoteException e) {
throw new RuntimeException("failed to freeze device orientaion", e);
}
}
@After
public void tearDown() throws Exception {
// Need to finish settings activity
mDevice.pressHome();
}
@Presubmit
@Test
public void testHomepageCategory() throws Exception {
// Launch Settings
SettingsHelper.launchSettingsPage(
InstrumentationRegistry.getContext(), Settings.ACTION_SETTINGS);
// Scroll to top
final UiObject2 view = mDevice.wait(
Until.findObject(By.res(SETTINGS_PACKAGE, "main_content")),
TIMEOUT);
view.scroll(Direction.UP, 100f);
// Inspect each item
for (String item : HOMEPAGE_ITEMS) {
SettingsTestUtils.assertTitleMatch(mDevice, item);
}
}
}

View File

@@ -0,0 +1,59 @@
/*
* 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.provider.Settings
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 HomepageDisplayTests {
private lateinit var device: UiDevice
@Before
fun setUp() {
device = startMainActivityFromHomeScreen(Settings.ACTION_SETTINGS)
}
@Test
fun hasHomepageItems() {
device.assertHasTexts(HOMEPAGE_ITEMS)
}
private companion object {
val HOMEPAGE_ITEMS = listOf(
"Network & internet",
"Connected devices",
"Apps",
"Notifications",
"Battery",
"Storage",
"Sound & vibration",
"Display",
"Accessibility",
"Security & privacy",
"Location",
"Passwords & accounts",
"System",
)
}
}

View File

@@ -29,7 +29,9 @@ import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until; import androidx.test.uiautomator.Until;
import org.junit.Ignore;
@Ignore
public class LocationSettingsTests extends InstrumentationTestCase { public class LocationSettingsTests extends InstrumentationTestCase {
private static final String SETTINGS_PACKAGE = "com.android.settings"; private static final String SETTINGS_PACKAGE = "com.android.settings";

View File

@@ -35,9 +35,12 @@ import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until; import androidx.test.uiautomator.Until;
import org.junit.Ignore;
/** /**
* Additional tests for Wifi Settings. * Additional tests for Wifi Settings.
*/ */
@Ignore
public class MoreWirelessSettingsTest2 extends InstrumentationTestCase { public class MoreWirelessSettingsTest2 extends InstrumentationTestCase {
// These back button presses are performed in tearDown() to exit Wifi // These back button presses are performed in tearDown() to exit Wifi
// Settings sub-menus that a test might finish in. This number should be // Settings sub-menus that a test might finish in. This number should be

View File

@@ -33,8 +33,11 @@ import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until; import androidx.test.uiautomator.Until;
import org.junit.Ignore;
/** Verifies that you can get to the notification app listing page from the apps & notifications /** Verifies that you can get to the notification app listing page from the apps & notifications
* page */ * page */
@Ignore
public class NotificationSettingsTests extends InstrumentationTestCase { public class NotificationSettingsTests extends InstrumentationTestCase {
private static final boolean LOCAL_LOGV = false; private static final boolean LOCAL_LOGV = false;
private static final String TAG = "NotifiSettingsTests"; private static final String TAG = "NotifiSettingsTests";

View File

@@ -1,76 +0,0 @@
/*
* Copyright (C) 2018 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.os.RemoteException;
import android.provider.Settings;
import android.system.helpers.SettingsHelper;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.UiDevice;
import com.android.settings.ui.testutils.SettingsTestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class SecuritySettingsLaunchTest {
// Items we really want to always show
private static final String[] CATEGORIES = new String[]{
"Security status",
"Device security",
"Privacy",
};
private UiDevice mDevice;
private SettingsHelper mHelper;
@Before
public void setUp() throws Exception {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mHelper = SettingsHelper.getInstance();
try {
mDevice.setOrientationNatural();
} catch (RemoteException e) {
throw new RuntimeException("failed to freeze device orientaion", e);
}
}
@After
public void tearDown() throws Exception {
// Go back to home for next test.
mDevice.pressHome();
}
@Test
public void launchSecuritySettings() throws Exception {
// Launch Settings
SettingsHelper.launchSettingsPage(
InstrumentationRegistry.getTargetContext(), Settings.ACTION_SECURITY_SETTINGS);
mHelper.scrollVert(false);
for (String category : CATEGORIES) {
SettingsTestUtils.assertTitleMatch(mDevice, category);
}
}
}

View File

@@ -0,0 +1,50 @@
/*
* 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.provider.Settings
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 SecuritySettingsTest {
private lateinit var device: UiDevice
@Before
fun setUp() {
device = startMainActivityFromHomeScreen(Settings.ACTION_SECURITY_SETTINGS)
}
@Test
fun hasTexts() {
device.assertHasTexts(ON_SCREEN_TEXTS)
}
private companion object {
// Items we really want to always show
val ON_SCREEN_TEXTS = listOf(
"Device unlock",
"Privacy",
"More security & privacy",
)
}
}

View File

@@ -30,8 +30,11 @@ import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until; import androidx.test.uiautomator.Until;
import org.junit.Ignore;
import java.util.Map; import java.util.Map;
@Ignore
public class SoundSettingsTest extends InstrumentationTestCase { public class SoundSettingsTest extends InstrumentationTestCase {
private static final String PAGE = Settings.ACTION_SOUND_SETTINGS; private static final String PAGE = Settings.ACTION_SOUND_SETTINGS;
private static final int TIMEOUT = 2000; private static final int TIMEOUT = 2000;

View File

@@ -0,0 +1,53 @@
/*
* 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.provider.Settings
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 StorageSettingsTest {
private lateinit var device: UiDevice
@Before
fun setUp() {
device = startMainActivityFromHomeScreen(Settings.ACTION_INTERNAL_STORAGE_SETTINGS)
}
@Test
fun hasTexts() {
device.assertHasTexts(ON_SCREEN_TEXTS)
}
private companion object {
val ON_SCREEN_TEXTS = listOf(
"System",
"Documents & other",
"Games",
"Apps",
"Audio",
"Videos",
"Images",
)
}
}

View File

@@ -1,80 +0,0 @@
/*
* Copyright (C) 2018 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.os.RemoteException;
import android.provider.Settings;
import android.system.helpers.SettingsHelper;
import android.test.suitebuilder.annotation.MediumTest;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.UiDevice;
import com.android.settings.ui.testutils.SettingsTestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class StorageSettingsUITest {
private static final String[] TITLES = {
"Photos & videos",
"Music & audio",
"Games",
"Movie & TV apps",
"Other apps",
"Files",
"System",
};
private UiDevice mDevice;
private SettingsHelper mHelper;
@Before
public void setUp() throws Exception {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mHelper = SettingsHelper.getInstance();
try {
mDevice.setOrientationNatural();
} catch (RemoteException e) {
throw new RuntimeException("failed to freeze device orientation", e);
}
}
@After
public void tearDown() {
mDevice.pressHome();
}
@Test
public void launchStorageSettings() throws Exception {
// Launch Settings
SettingsHelper.launchSettingsPage(
InstrumentationRegistry.getTargetContext(),
Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
mHelper.scrollVert(false);
for (String category : TITLES) {
SettingsTestUtils.assertTitleMatch(mDevice, category);
}
}
}

View File

@@ -32,6 +32,7 @@ import androidx.test.uiautomator.Until;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -42,6 +43,7 @@ import java.util.regex.Pattern;
* Verify storage wizard flows. Temporarily enables a virtual disk which enables * Verify storage wizard flows. Temporarily enables a virtual disk which enables
* testing on all devices, regardless of physical SD card support. * testing on all devices, regardless of physical SD card support.
*/ */
@Ignore
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class StorageWizardTest { public class StorageWizardTest {
private static final String ANDROID_PACKAGE = "android"; private static final String ANDROID_PACKAGE = "android";

View File

@@ -1,71 +0,0 @@
/*
* Copyright (C) 2018 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 static junit.framework.Assert.assertTrue;
import android.os.RemoteException;
import android.provider.Settings;
import android.system.helpers.SettingsHelper;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@MediumTest
@RunWith(AndroidJUnit4.class)
public class SyncSettingsTest {
private static final int TIMEOUT = 2000;
private UiDevice mDevice;
@Before
public void setUp() throws Exception {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
try {
mDevice.setOrientationNatural();
} catch (RemoteException e) {
throw new RuntimeException("failed to freeze device orientaion", e);
}
}
@After
public void tearDown() throws Exception {
// Need to finish settings activity
mDevice.pressHome();
}
@Test
public void syncPageShouldHaveAddAccountButton() throws Exception {
// Launch Settings
SettingsHelper.launchSettingsPage(
InstrumentationRegistry.getContext(), Settings.ACTION_SYNC_SETTINGS);
UiObject2 addAccount = mDevice.wait(
Until.findObject(By.text("Add account")), TIMEOUT);
assertTrue(addAccount != null);
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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.provider.Settings
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 SyncSettingsTest {
private lateinit var device: UiDevice
@Before
fun setUp() {
device = startMainActivityFromHomeScreen(Settings.ACTION_SYNC_SETTINGS)
}
@Test
fun hasTexts() {
device.assertHasTexts(ON_SCREEN_TEXTS)
}
private companion object {
val ON_SCREEN_TEXTS = listOf("Add account")
}
}

View File

@@ -37,12 +37,14 @@ import androidx.test.uiautomator.Until;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
* Core tests for Wifi Settings. * Core tests for Wifi Settings.
*/ */
@Ignore
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@MediumTest @MediumTest
public class WirelessNetworkSettingsTests { public class WirelessNetworkSettingsTests {

View File

@@ -43,11 +43,13 @@ import androidx.test.uiautomator.Until;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import java.util.TimeZone; import java.util.TimeZone;
@Ignore
@MediumTest @MediumTest
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class ZonePickerSettingsTest { public class ZonePickerSettingsTest {

View File

@@ -1,70 +0,0 @@
/*
* Copyright (C) 2018 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.inputmethods;
import static com.android.settings.ui.testutils.SettingsTestUtils.TIMEOUT;
import static com.google.common.truth.Truth.assertThat;
import android.app.Instrumentation;
import android.content.Intent;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.Until;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class DataSaverSummaryUITest {
private Instrumentation mInstrumentation;
private Intent mIntent;
private UiDevice mUiDevice;
@Before
public void setUp() {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mUiDevice = UiDevice.getInstance(mInstrumentation);
mIntent = new Intent().setClassName("com.android.settings",
"com.android.settings.Settings$DataUsageSummaryActivity")
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
@Test
public void launchSettings_hasSwitchBar() throws Exception {
launchDataSaverSettings();
final UiObject2 switchBar =
mUiDevice.wait(Until.findObject(By.text("Use Data Saver")), TIMEOUT);
assertThat(switchBar).isNotNull();
}
private void launchDataSaverSettings() throws InterruptedException {
mInstrumentation.getContext().startActivity(mIntent);
final UiObject2 prefDataSaver =
mUiDevice.wait(Until.findObject(By.text("Data Saver")), TIMEOUT);
assertThat(prefDataSaver).isNotNull();
prefDataSaver.click();
Thread.sleep(TIMEOUT * 2);
}
}

View File

@@ -28,7 +28,7 @@ import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject2 import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until import androidx.test.uiautomator.Until
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import org.junit.Assert.fail import com.google.common.truth.Truth.assertWithMessage
object SettingsTestUtils { object SettingsTestUtils {
const val SETTINGS_PACKAGE = "com.android.settings" const val SETTINGS_PACKAGE = "com.android.settings"
@@ -66,18 +66,11 @@ object SettingsTestUtils {
return device return device
} }
@JvmStatic fun UiDevice.assertHasTexts(texts: List<String>) {
fun assertTitleMatch(device: UiDevice, title: String) { val scrollableObj = findObject(By.scrollable(true))
var maxAttempt = 5 for (text in texts) {
while (maxAttempt-- > 0 && scrollableObj.scrollUntil(Direction.DOWN, Until.findObject(By.text(text)))
device.wait( assertWithMessage("Missing text: $text").that(waitObject(By.text(text))).isNotNull()
Until.findObject(By.res("android:id/title").text(title)),
TIMEOUT
) == null
) {
device.waitObject(By.res(SETTINGS_PACKAGE, "main_content"))
?.scroll(Direction.DOWN, 1.0f)
} }
fail("$title in Setting has not been loaded correctly")
} }
} }