Fix more SettingsUITests
Also add SettingsUITests to postsubmit. Bug: 290381395 Test: ui test Change-Id: Ib1dd35bf7823290bf77deb31366e9cb6ae9f65f7
This commit is contained in:
@@ -27,6 +27,14 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "SettingsUITests",
|
||||
"options": [
|
||||
{
|
||||
"exclude-annotation": "org.junit.Ignore"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "SettingsPerfTests"
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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
|
||||
@@ -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"
|
||||
|
@@ -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
|
||||
@@ -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
|
||||
@@ -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",
|
||||
|
@@ -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"
|
||||
)
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -35,9 +35,11 @@ import androidx.test.uiautomator.Until;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@Ignore
|
||||
@MediumTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ConnectedDeviceTests {
|
||||
|
@@ -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()
|
||||
}
|
||||
}
|
@@ -26,6 +26,9 @@ import androidx.test.uiautomator.By;
|
||||
import androidx.test.uiautomator.UiDevice;
|
||||
import androidx.test.uiautomator.Until;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
public class DataUsageSettingsTests extends InstrumentationTestCase {
|
||||
|
||||
private static final String SETTINGS_PACKAGE = "com.android.settings";
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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",
|
||||
)
|
||||
}
|
||||
}
|
@@ -29,7 +29,9 @@ import androidx.test.uiautomator.UiDevice;
|
||||
import androidx.test.uiautomator.UiObject2;
|
||||
import androidx.test.uiautomator.Until;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
@Ignore
|
||||
public class LocationSettingsTests extends InstrumentationTestCase {
|
||||
|
||||
private static final String SETTINGS_PACKAGE = "com.android.settings";
|
||||
|
@@ -35,9 +35,12 @@ import androidx.test.uiautomator.UiDevice;
|
||||
import androidx.test.uiautomator.UiObject2;
|
||||
import androidx.test.uiautomator.Until;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
/**
|
||||
* Additional tests for Wifi Settings.
|
||||
*/
|
||||
@Ignore
|
||||
public class MoreWirelessSettingsTest2 extends InstrumentationTestCase {
|
||||
// These back button presses are performed in tearDown() to exit Wifi
|
||||
// Settings sub-menus that a test might finish in. This number should be
|
||||
|
@@ -33,8 +33,11 @@ import androidx.test.uiautomator.UiDevice;
|
||||
import androidx.test.uiautomator.UiObject2;
|
||||
import androidx.test.uiautomator.Until;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
/** Verifies that you can get to the notification app listing page from the apps & notifications
|
||||
* page */
|
||||
@Ignore
|
||||
public class NotificationSettingsTests extends InstrumentationTestCase {
|
||||
private static final boolean LOCAL_LOGV = false;
|
||||
private static final String TAG = "NotifiSettingsTests";
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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",
|
||||
)
|
||||
}
|
||||
}
|
@@ -30,8 +30,11 @@ import androidx.test.uiautomator.UiDevice;
|
||||
import androidx.test.uiautomator.UiObject2;
|
||||
import androidx.test.uiautomator.Until;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Ignore
|
||||
public class SoundSettingsTest extends InstrumentationTestCase {
|
||||
private static final String PAGE = Settings.ACTION_SOUND_SETTINGS;
|
||||
private static final int TIMEOUT = 2000;
|
||||
|
@@ -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",
|
||||
)
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -32,6 +32,7 @@ import androidx.test.uiautomator.Until;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
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
|
||||
* testing on all devices, regardless of physical SD card support.
|
||||
*/
|
||||
@Ignore
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class StorageWizardTest {
|
||||
private static final String ANDROID_PACKAGE = "android";
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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")
|
||||
}
|
||||
}
|
@@ -37,12 +37,14 @@ import androidx.test.uiautomator.Until;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Core tests for Wifi Settings.
|
||||
*/
|
||||
@Ignore
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@MediumTest
|
||||
public class WirelessNetworkSettingsTests {
|
||||
|
@@ -43,11 +43,13 @@ import androidx.test.uiautomator.Until;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
||||
@Ignore
|
||||
@MediumTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ZonePickerSettingsTest {
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -28,7 +28,7 @@ import androidx.test.uiautomator.UiDevice
|
||||
import androidx.test.uiautomator.UiObject2
|
||||
import androidx.test.uiautomator.Until
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Assert.fail
|
||||
import com.google.common.truth.Truth.assertWithMessage
|
||||
|
||||
object SettingsTestUtils {
|
||||
const val SETTINGS_PACKAGE = "com.android.settings"
|
||||
@@ -66,18 +66,11 @@ object SettingsTestUtils {
|
||||
return device
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun assertTitleMatch(device: UiDevice, title: String) {
|
||||
var maxAttempt = 5
|
||||
while (maxAttempt-- > 0 &&
|
||||
device.wait(
|
||||
Until.findObject(By.res("android:id/title").text(title)),
|
||||
TIMEOUT
|
||||
) == null
|
||||
) {
|
||||
device.waitObject(By.res(SETTINGS_PACKAGE, "main_content"))
|
||||
?.scroll(Direction.DOWN, 1.0f)
|
||||
fun UiDevice.assertHasTexts(texts: List<String>) {
|
||||
val scrollableObj = findObject(By.scrollable(true))
|
||||
for (text in texts) {
|
||||
scrollableObj.scrollUntil(Direction.DOWN, Until.findObject(By.text(text)))
|
||||
assertWithMessage("Missing text: $text").that(waitObject(By.text(text))).isNotNull()
|
||||
}
|
||||
fail("$title in Setting has not been loaded correctly")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user