diff options
Diffstat (limited to 'system_image_uitests/app/src/androidTest/java')
3 files changed, 75 insertions, 144 deletions
diff --git a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/NetworkIOTest.java b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/NetworkIOTest.java index 279a92bc..6e51ffed 100644 --- a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/NetworkIOTest.java +++ b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/NetworkIOTest.java @@ -21,6 +21,7 @@ import com.android.devtools.systemimage.uitest.common.Res; import com.android.devtools.systemimage.uitest.framework.SystemImageTestFramework; import com.android.devtools.systemimage.uitest.utils.AppLauncher; import com.android.devtools.systemimage.uitest.utils.NetworkUtil; +import com.android.devtools.systemimage.uitest.utils.SettingsUtil; import com.android.devtools.systemimage.uitest.utils.UiAutomatorPlus; import com.android.devtools.systemimage.uitest.utils.Wait; @@ -37,7 +38,7 @@ import android.support.test.uiautomator.By; import android.support.test.uiautomator.UiDevice; import android.support.test.uiautomator.UiObject; import android.support.test.uiautomator.UiObject2; -import android.support.test.uiautomator.UiScrollable; +import android.support.test.uiautomator.UiObjectNotFoundException; import android.support.test.uiautomator.UiSelector; import android.telephony.TelephonyManager; @@ -105,6 +106,19 @@ public class NetworkIOTest { } } + private UiObject2 navigateToDataSwitch(Instrumentation instrumentation) throws UiObjectNotFoundException { + String containerRes = (testFramework.getApi() >= 24) ? Res.NETWORK_SWITCHES_RECYCLER_VIEW_RES : + Res.NETWORK_SWITCHES_CONTAINER_RES; + + SettingsUtil.openItem(instrumentation, "Data usage"); + + return UiAutomatorPlus.findObjectByRelative( + instrumentation, + By.clazz("android.widget.Switch"), + By.text("Cellular data"), + By.res(containerRes)); + } + /** * Verifies cellular data can be toggled off. * <p> @@ -130,26 +144,19 @@ public class NetworkIOTest { final Instrumentation instrumentation = testFramework.getInstrumentation(); UiDevice device = UiDevice.getInstance(instrumentation); // TODO: Add a fixture method in AppLauncher class to launch a specified path. - if (testFramework.getApi() >= 23) { - AppLauncher.launch(instrumentation, "Settings"); - UiScrollable itemList = new UiScrollable( - new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES)); - itemList.setAsVerticalList(); - itemList.scrollToBeginning(100); - device.findObject(new UiSelector().textContains("Data usage")).click(); - - UiObject2 dataSwitch = UiAutomatorPlus.findObjectByRelative( - instrumentation, - By.clazz("android.widget.Switch"), - By.text("Cellular data"), - By.res(Res.NETWORK_SWITCHES_CONTAINER_RES)); + int api = testFramework.getApi(); + if (api >= 23) { + UiObject2 dataSwitch = navigateToDataSwitch(instrumentation); + // Test requires "Cellular data" switch widget to start in the on state. if (!dataSwitch.isChecked()) { dataSwitch.click(); } // Disable "Cellular data" option. dataSwitch.click(); - device.findObject(new UiSelector().text("OK")).click(); + if (api < 24) { + device.findObject(new UiSelector().text("OK")).click(); + } // Wait for data connection to turn off. new Wait().until(new Wait.ExpectedCondition() { @Override @@ -161,9 +168,9 @@ public class NetworkIOTest { assertFalse("Cellular data is enabled.", NetworkUtil.hasCellularNetworkConnection(instrumentation)); - if (device.findObject( - new UiSelector().textContains("Set cellular data limit")).exists()) { - assertTrue("Set cellular data limit text not visible.", false); + if (api < 24) { + assertFalse("Set cellular data limit text is visible.", device.findObject( + new UiSelector().textContains("Set cellular data limit")).exists()); } // Enable Cellular data. dataSwitch.click(); @@ -195,22 +202,16 @@ public class NetworkIOTest { final Instrumentation instrumentation = testFramework.getInstrumentation(); UiDevice device = UiDevice.getInstance(instrumentation); // TODO: Add a fixture method in AppLauncher class to launch a specified path. - if (testFramework.getApi() >= 23) { - AppLauncher.launch(instrumentation, "Settings"); - UiScrollable itemList = new UiScrollable( - new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES)); - itemList.setAsVerticalList(); - itemList.scrollToBeginning(100); - device.findObject(new UiSelector().textContains("Data usage")).click(); - - UiObject2 dataSwitch = UiAutomatorPlus.findObjectByRelative( - instrumentation, - By.clazz("android.widget.Switch"), - By.text("Cellular data"), - By.res(Res.NETWORK_SWITCHES_CONTAINER_RES)); + int api = testFramework.getApi(); + if (api >= 23) { + UiObject2 dataSwitch = navigateToDataSwitch(instrumentation); + // Test requires "Cellular data" switch widget to start in the off state. if (dataSwitch.isChecked()) { dataSwitch.click(); + if (api < 24) { + device.findObject(new UiSelector().text("OK")).click(); + } } // Enable Cellular data. dataSwitch.click(); @@ -225,9 +226,9 @@ public class NetworkIOTest { assertTrue("Cellular data is disabled.", NetworkUtil.hasCellularNetworkConnection(instrumentation)); - if (!device.findObject( - new UiSelector().textContains("Set cellular data limit")).exists()) { - assertTrue("Set cellular data limit text is visible.", false); + if (api < 24) { + assertTrue("Set cellular data limit text is not visible.", device.findObject( + new UiSelector().textContains("Set cellular data limit")).exists()); } } } diff --git a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/SettingsTest.java b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/SettingsTest.java index be689c96..9d0c2d80 100644 --- a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/SettingsTest.java +++ b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/SettingsTest.java @@ -19,8 +19,8 @@ package com.android.devtools.systemimage.uitest.smoke; import com.android.devtools.systemimage.uitest.annotations.TestInfo; import com.android.devtools.systemimage.uitest.common.Res; import com.android.devtools.systemimage.uitest.framework.SystemImageTestFramework; -import com.android.devtools.systemimage.uitest.utils.AppLauncher; import com.android.devtools.systemimage.uitest.utils.DeveloperOptionsManager; +import com.android.devtools.systemimage.uitest.utils.SettingsUtil; import com.android.devtools.systemimage.uitest.utils.UiAutomatorPlus; import com.android.devtools.systemimage.uitest.utils.Wait; @@ -33,17 +33,11 @@ import static org.junit.Assert.*; import android.app.Instrumentation; import android.support.test.runner.AndroidJUnit4; import android.support.test.uiautomator.By; -import android.support.test.uiautomator.BySelector; import android.support.test.uiautomator.UiDevice; -import android.support.test.uiautomator.UiObject; import android.support.test.uiautomator.UiObject2; import android.support.test.uiautomator.UiObjectNotFoundException; import android.support.test.uiautomator.UiScrollable; import android.support.test.uiautomator.UiSelector; -import android.support.test.uiautomator.Until; - -import java.util.List; -import java.util.concurrent.TimeUnit; /** @@ -84,12 +78,7 @@ public class SettingsTest { return; } - AppLauncher.launch(instrumentation, "Settings"); - UiScrollable itemList = new UiScrollable( - new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES)); - itemList.setAsVerticalList(); - itemList.scrollIntoView(new UiSelector().textContains("Google")); - device.findObject(new UiSelector().textContains("Google")).clickAndWaitForNewWindow(); + SettingsUtil.openItem(instrumentation, "Google"); device.findObject(new UiSelector().textContains("Location")).clickAndWaitForNewWindow(); assertTrue("Failed to find Location title.", new Wait().until(new Wait.ExpectedCondition() { @@ -125,15 +114,7 @@ public class SettingsTest { UiDevice device = UiDevice.getInstance(instrumentation); if (testFramework.getApi() >= 23) { - AppLauncher.launch(instrumentation, "Settings"); - UiScrollable settingsList = - new UiScrollable( - new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES) - ); - settingsList.setAsVerticalList(); - UiObject appsObject = settingsList.getChildByText( - new UiSelector().className("android.widget.TextView"), "Apps"); - appsObject.clickAndWaitForNewWindow(); + SettingsUtil.openItem(instrumentation, "Apps"); device.findObject(new UiSelector().resourceId(Res.SETTINGS_ADVANCED_OPTION_RES)) .clickAndWaitForNewWindow(); device.findObject(new UiSelector().textContains("App permissions")) @@ -149,6 +130,33 @@ public class SettingsTest { } /** + * Common code for finding a checkbox/switch in the Date & time settings. + */ + private UiObject2 navigateToDateTimeSwitch(String text) throws UiObjectNotFoundException { + final Instrumentation instrumentation = testFramework.getInstrumentation(); + SettingsUtil.openItem(instrumentation, "Date & time"); + + UiObject2 widget; + try { + final String listViewClass = ( + testFramework.getApi() >= 24) ? "android.support.v7.widget.RecyclerView" : + "android.widget.ListView"; + widget = UiAutomatorPlus.findObjectByRelative( + instrumentation, + By.clazz("android.widget.Switch"), + By.text(text), + By.clazz(listViewClass)); + } catch (UiObjectNotFoundException e) { + widget = UiAutomatorPlus.findObjectByRelative( + instrumentation, + By.clazz("android.widget.CheckBox"), + By.text(text), + By.clazz("android.widget.ListView")); + } + return widget; + } + + /** * Verifies set date and set time fields are editable. * <p> * This is run to qualify releases. Please involve the test team in substantial changes. @@ -170,33 +178,9 @@ public class SettingsTest { @TestInfo(id = "14581295") public void enableSetDateAndSetTime() throws Exception { int api = testFramework.getApi(); - Instrumentation instrumentation = testFramework.getInstrumentation(); final UiDevice device = testFramework.getDevice(); - AppLauncher.launch(instrumentation, "Settings"); - String scrollableRes = (api >= 24) ? Res.SETTINGS_RECYCLER_VIEW_RES : - Res.SETTINGS_LIST_CONTAINER_RES; - UiScrollable itemList = new UiScrollable( - new UiSelector().resourceIdMatches(scrollableRes)); - itemList.setAsVerticalList(); - itemList.scrollIntoView(new UiSelector().textContains("Date & time")); - device.findObject(new UiSelector().text("Date & time")).click(); + final UiObject2 widget = navigateToDateTimeSwitch("Automatic date & time"); - UiObject2 widget; - try { - String listViewClass = (api >= 24) ? "android.support.v7.widget.RecyclerView" : - "android.widget.ListView"; - widget = UiAutomatorPlus.findObjectByRelative( - instrumentation, - By.clazz("android.widget.Switch"), - By.text("Automatic date & time"), - By.clazz(listViewClass)); - } catch (UiObjectNotFoundException e) { - widget = UiAutomatorPlus.findObjectByRelative( - instrumentation, - By.clazz("android.widget.CheckBox"), - By.text("Automatic date & time"), - By.clazz("android.widget.ListView")); - } // Test requires "Automatic date & time" widget to start in the enabled state. if (!widget.isChecked()) { widget.click(); @@ -305,12 +289,7 @@ public class SettingsTest { return; } - AppLauncher.launch(instrumentation, "Settings"); - UiScrollable itemList = new UiScrollable( - new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES)); - itemList.setAsVerticalList(); - itemList.scrollIntoView(new UiSelector().textContains("Google")); - device.findObject(new UiSelector().text("Google")).click(); + SettingsUtil.openItem(instrumentation, "Google"); device.findObject(new UiSelector().text("Search & Now")).click(); device.findObject(new UiSelector().text("Now cards")).click(); @@ -353,30 +332,9 @@ public class SettingsTest { @Test @TestInfo(id = "14581409") public void enableTimeZone() throws Exception { - Instrumentation instrumentation = testFramework.getInstrumentation(); final UiDevice device = testFramework.getDevice(); - AppLauncher.launch(instrumentation, "Settings"); - UiScrollable itemList = - new UiScrollable( - new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES)); - itemList.setAsVerticalList(); - itemList.scrollIntoView(new UiSelector().textContains("Date & time")); - device.findObject(new UiSelector().text("Date & time")).click(); + final UiObject2 widget = navigateToDateTimeSwitch("Automatic time zone"); - UiObject2 widget; - try { - widget = UiAutomatorPlus.findObjectByRelative( - instrumentation, - By.clazz("android.widget.Switch"), - By.text("Automatic time zone"), - By.clazz("android.widget.ListView")); - } catch (UiObjectNotFoundException e) { - widget = UiAutomatorPlus.findObjectByRelative( - instrumentation, - By.clazz("android.widget.CheckBox"), - By.text("Automatic time zone"), - By.clazz("android.widget.ListView")); - } // Initialize automatic time zone option to enabled state. if (!widget.isChecked()) { widget.click(); @@ -432,30 +390,9 @@ public class SettingsTest { @Test @TestInfo(id = "14581410") public void enableTwentyFourHourFormat() throws Exception { - Instrumentation instrumentation = testFramework.getInstrumentation(); final UiDevice device = testFramework.getDevice(); - AppLauncher.launch(instrumentation, "Settings"); - UiScrollable itemList = - new UiScrollable( - new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES)); - itemList.setAsVerticalList(); - itemList.scrollIntoView(new UiSelector().textContains("Date & time")); - device.findObject(new UiSelector().text("Date & time")).click(); + final UiObject2 widget = navigateToDateTimeSwitch("Use 24-hour format"); - UiObject2 widget; - try { - widget = UiAutomatorPlus.findObjectByRelative( - instrumentation, - By.clazz("android.widget.Switch"), - By.text("Use 24-hour format"), - By.clazz("android.widget.ListView")); - } catch (UiObjectNotFoundException e) { - widget = UiAutomatorPlus.findObjectByRelative( - instrumentation, - By.clazz("android.widget.CheckBox"), - By.text("Use 24-hour format"), - By.clazz("android.widget.ListView")); - } // Initialize 24-hour format option to disabled state. if (widget.isChecked()) { widget.click(); diff --git a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/ShellUtilTest.java b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/ShellUtilTest.java index 7637156a..5f3b4798 100644 --- a/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/ShellUtilTest.java +++ b/system_image_uitests/app/src/androidTest/java/com/android/devtools/systemimage/uitest/smoke/ShellUtilTest.java @@ -17,16 +17,14 @@ package com.android.devtools.systemimage.uitest.smoke; import com.android.devtools.systemimage.uitest.annotations.TestInfo; -import com.android.devtools.systemimage.uitest.common.Res; import com.android.devtools.systemimage.uitest.framework.SystemImageTestFramework; +import com.android.devtools.systemimage.uitest.utils.SettingsUtil; import com.android.devtools.systemimage.uitest.utils.ShellUtil; -import com.android.devtools.systemimage.uitest.utils.AppLauncher; import com.android.devtools.systemimage.uitest.utils.DeveloperOptionsManager; import com.android.devtools.systemimage.uitest.utils.Wait; import org.hamcrest.Matchers; -import org.junit.After; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -37,7 +35,6 @@ import android.app.Instrumentation; import android.support.test.runner.AndroidJUnit4; import android.support.test.uiautomator.UiDevice; import android.support.test.uiautomator.UiObject; -import android.support.test.uiautomator.UiScrollable; import android.support.test.uiautomator.UiSelector; import android.util.Log; @@ -121,6 +118,7 @@ public class ShellUtilTest { public void createBugReport() throws Exception { Instrumentation instrumentation = testFramework.getInstrumentation(); final UiDevice device = UiDevice.getInstance(instrumentation); + if (testFramework.getApi() >= 21) { deleteBugReportFiles(); @@ -128,20 +126,15 @@ public class ShellUtilTest { DeveloperOptionsManager.enableDeveloperOptions(testFramework.getInstrumentation()); } - AppLauncher.launch(instrumentation, "Settings"); - UiScrollable itemList = new UiScrollable( - new UiSelector().resourceIdMatches(Res.SETTINGS_LIST_CONTAINER_RES)); - itemList.setAsVerticalList(); - UiObject item = itemList.getChildByText( - new UiSelector().className("android.widget.TextView"), "Developer options"); - item.click(); + SettingsUtil.openItem(instrumentation, "Developer options"); // Remove bug report files even if the test fails. try { device.findObject( new UiSelector().text("Take bug report")).clickAndWaitForNewWindow(); - if (device.findObject(new UiSelector().text("Report")).exists()) { - device.findObject(new UiSelector().text("Report")).click(); + UiObject reportButton = device.findObject(new UiSelector().text("Report")); + if (reportButton.exists()) { + reportButton.click(); } boolean gotPngAndZip = new Wait( TimeUnit.MILLISECONDS.convert(30L, TimeUnit.SECONDS)).until( |