summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanket Chinchalkar <schinchalkar@google.com>2020-01-24 12:26:43 -0800
committerSanket Chinchalkar <schinchalkar@google.com>2020-03-17 13:35:05 -0700
commitd94a01b72c4b15dd00216bea2959863732d8da7e (patch)
tree520066dfcbf357c18965ca8c0eb90ef63003c586
parent9514ec5bec3dace261bd5e8041f8e9815233e143 (diff)
downloadplatform_testing-d94a01b72c4b15dd00216bea2959863732d8da7e.tar.gz
DO NOT MERGE : Added launcher strategy for volvo
Bug: 151652125 Test: Test on Hawk devices Change-Id: Ic481b4979baf812b6a628bcb4f9678b64aa8cdb5 Enable Notification Tests for Volvo Test: Run NotificationHelperTests Bug: 148292255 Change-Id: I920372cdb708e5c8fc2ef26c74b7bb7e64dd4578
-rw-r--r--libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoMediaCenterHelper.java7
-rw-r--r--libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoMediaHelper.java20
-rw-r--r--libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoNotificationHelper.java34
-rw-r--r--libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoNotificationMockingHelper.java3
-rw-r--r--libraries/launcher-helper/src/android/support/test/launcherhelper/AutoLauncherStrategy.java36
-rw-r--r--libraries/launcher-helper/src/android/support/test/launcherhelper/IAutoLauncherStrategy.java13
-rw-r--r--libraries/launcher-helper/src/android/support/test/launcherhelper/LauncherStrategyFactory.java1
-rw-r--r--libraries/launcher-helper/src/android/support/test/launcherhelper/VolvoLauncherStrategy.java154
8 files changed, 258 insertions, 10 deletions
diff --git a/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoMediaCenterHelper.java b/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoMediaCenterHelper.java
index 9a59952ad..52caa07e5 100644
--- a/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoMediaCenterHelper.java
+++ b/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoMediaCenterHelper.java
@@ -78,4 +78,9 @@ public interface IAutoMediaCenterHelper extends IAppHelper {
*/
void search(String title);
-} \ No newline at end of file
+ /**
+ * This method is used to check if media is currently playing Returns true if media is playing
+ * else returns false
+ */
+ boolean isPlaying();
+}
diff --git a/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoMediaHelper.java b/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoMediaHelper.java
index 035d68fad..ada56e72f 100644
--- a/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoMediaHelper.java
+++ b/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoMediaHelper.java
@@ -93,4 +93,24 @@ public interface IAutoMediaHelper extends IAppHelper {
* @return to get current playing track name.
*/
String getMediaTrackName();
+
+ /**
+ * Setup expectations: on home screen.
+ *
+ * @return to get current playing track name from home screen.
+ */
+ String getMediaTrackNameFromHomeScreen();
+
+ /**
+ * Setup expectations: Media app is open. User navigates to sub-page of the Media Player
+ *
+ * <p>This method is to go back to the Media Player main page from any sub-page.
+ */
+ void goBackToMediaHomePage();
+
+ /**
+ * This method is used to check if media is currently playing Returns true if media is playing
+ * else returns false
+ */
+ boolean isPlaying();
}
diff --git a/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoNotificationHelper.java b/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoNotificationHelper.java
index ac18ada0d..b5fd0f72d 100644
--- a/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoNotificationHelper.java
+++ b/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoNotificationHelper.java
@@ -16,4 +16,36 @@
package android.platform.helpers;
-public interface IAutoNotificationHelper extends INotificationHelper, Scrollable {}
+public interface IAutoNotificationHelper extends INotificationHelper, Scrollable, IAppHelper {
+ /**
+ * Setup expectations: Notification app is open and scrolled to the bottom.
+ *
+ * <p>Tap clear all button if present.
+ */
+ void tapClearAllBtn();
+
+ /**
+ * Setup expectations: A notification is received.
+ *
+ * <p>Check whether notification has been posted.
+ *
+ * @param title of the notification to be checked.
+ */
+ boolean checkNotificationExists(String title);
+
+ /**
+ * Setup expectations: A notification is received.
+ *
+ * <p>Swipe away a received notification.
+ *
+ * @param title of the notification to be swiped.
+ */
+ void removeNotification(String title);
+
+ /**
+ * Setup expectations: None.
+ *
+ * <p>Swipe down from status bar to open notifications.
+ */
+ void openNotification();
+}
diff --git a/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoNotificationMockingHelper.java b/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoNotificationMockingHelper.java
new file mode 100644
index 000000000..9903832ba
--- /dev/null
+++ b/libraries/app-helpers/interfaces/auto/src/android/platform/helpers/IAutoNotificationMockingHelper.java
@@ -0,0 +1,3 @@
+package android.platform.helpers;
+
+public interface IAutoNotificationMockingHelper extends INotificationHelper, IAppHelper {}
diff --git a/libraries/launcher-helper/src/android/support/test/launcherhelper/AutoLauncherStrategy.java b/libraries/launcher-helper/src/android/support/test/launcherhelper/AutoLauncherStrategy.java
index c547f0d7f..869d87019 100644
--- a/libraries/launcher-helper/src/android/support/test/launcherhelper/AutoLauncherStrategy.java
+++ b/libraries/launcher-helper/src/android/support/test/launcherhelper/AutoLauncherStrategy.java
@@ -23,14 +23,14 @@ import android.support.test.uiautomator.Direction;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;
+import android.system.helpers.CommandsHelper;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
-import java.util.stream.Stream;
import java.util.stream.Collectors;
-
+import java.util.stream.Stream;
public class AutoLauncherStrategy implements IAutoLauncherStrategy {
private static final String LOG_TAG = AutoLauncherStrategy.class.getSimpleName();
@@ -88,6 +88,7 @@ public class AutoLauncherStrategy implements IAutoLauncherStrategy {
protected UiDevice mDevice;
private Instrumentation mInstrumentation;
+ private CommandsHelper mCommandsHelper;
/**
* {@inheritDoc}
@@ -111,6 +112,7 @@ public class AutoLauncherStrategy implements IAutoLauncherStrategy {
@Override
public void setInstrumentation(Instrumentation instrumentation) {
mInstrumentation = instrumentation;
+ mCommandsHelper = CommandsHelper.getInstance(mInstrumentation);
}
/**
@@ -201,9 +203,21 @@ public class AutoLauncherStrategy implements IAutoLauncherStrategy {
openFacet("Notification");
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
+ @Override
+ public void openNotifications() {
+ String cmd = "cmd statusbar expand-notifications";
+ mCommandsHelper.executeShellCommand(cmd);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void pressHome() {
+ String cmd = "input keyevent KEYCODE_HOME";
+ mCommandsHelper.executeShellCommand(cmd);
+ }
+
+ /** {@inheritDoc} */
@Override
public void openAssistantFacet() {
openFacet("Google Assistant");
@@ -326,6 +340,18 @@ public class AutoLauncherStrategy implements IAutoLauncherStrategy {
}
}
+ @Override
+ public void openBluetoothAudioApp() {
+ String appName = "Bluetooth Audio";
+ if (checkApplicationExists(appName)) {
+ UiObject2 app = mDevice.findObject(By.clickable(true).hasDescendant(By.text(appName)));
+ app.clickAndWait(Until.newWindow(), APP_LAUNCH_TIMEOUT);
+ mDevice.waitForIdle();
+ } else {
+ throw new RuntimeException(String.format("Application %s not found", appName));
+ }
+ }
+
private UiObject2 findApplication(String appName) {
BySelector appSelector = By.clickable(true).hasDescendant(By.text(appName));
if (mDevice.hasObject(SCROLLABLE_APP_LIST)) {
diff --git a/libraries/launcher-helper/src/android/support/test/launcherhelper/IAutoLauncherStrategy.java b/libraries/launcher-helper/src/android/support/test/launcherhelper/IAutoLauncherStrategy.java
index 8351b82a6..731d39cfa 100644
--- a/libraries/launcher-helper/src/android/support/test/launcherhelper/IAutoLauncherStrategy.java
+++ b/libraries/launcher-helper/src/android/support/test/launcherhelper/IAutoLauncherStrategy.java
@@ -65,9 +65,10 @@ public interface IAutoLauncherStrategy extends ILauncherStrategy {
*/
void openAssistantFacet();
- /**
- * Open Quick Settings.
- */
+ /** This method is to open Bluetooth Audio application */
+ void openBluetoothAudioApp();
+
+ /** Open Quick Settings. */
void openQuickSettings();
/**
@@ -95,4 +96,10 @@ public interface IAutoLauncherStrategy extends ILauncherStrategy {
* @param appName application to be opened.
*/
void openApp(String appName);
+
+ /** This method is to open notifications */
+ void openNotifications();
+
+ /** This method is to navigate to device home */
+ void pressHome();
}
diff --git a/libraries/launcher-helper/src/android/support/test/launcherhelper/LauncherStrategyFactory.java b/libraries/launcher-helper/src/android/support/test/launcherhelper/LauncherStrategyFactory.java
index f812b991f..8a3db419d 100644
--- a/libraries/launcher-helper/src/android/support/test/launcherhelper/LauncherStrategyFactory.java
+++ b/libraries/launcher-helper/src/android/support/test/launcherhelper/LauncherStrategyFactory.java
@@ -42,6 +42,7 @@ public class LauncherStrategyFactory {
mKnownLauncherStrategies = new HashSet<>();
registerLauncherStrategy(AospLauncherStrategy.class);
registerLauncherStrategy(AutoLauncherStrategy.class);
+ registerLauncherStrategy(VolvoLauncherStrategy.class);
registerLauncherStrategy(GoogleExperienceLauncherStrategy.class);
registerLauncherStrategy(Launcher3Strategy.class);
registerLauncherStrategy(NexusLauncherStrategy.class);
diff --git a/libraries/launcher-helper/src/android/support/test/launcherhelper/VolvoLauncherStrategy.java b/libraries/launcher-helper/src/android/support/test/launcherhelper/VolvoLauncherStrategy.java
new file mode 100644
index 000000000..695a9b26c
--- /dev/null
+++ b/libraries/launcher-helper/src/android/support/test/launcherhelper/VolvoLauncherStrategy.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2017 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 android.support.test.launcherhelper;
+
+import android.app.Instrumentation;
+import android.os.SystemClock;
+import android.support.test.uiautomator.By;
+import android.support.test.uiautomator.BySelector;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject2;
+import android.support.test.uiautomator.Until;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/** Implementation of {@link ILauncherStrategy} to support Volvo launcher */
+public class VolvoLauncherStrategy extends AutoLauncherStrategy {
+ private static final String VOLVO_LAUNCHER_PACKAGE = "com.volvocars.launcher";
+ private static final String SYSTEM_UI_PACKAGE = "com.android.systemui";
+
+ private static final Map<String, BySelector> FACET_MAP =
+ Stream.of(
+ new Object[][] {
+ {
+ "App Grid",
+ By.res(SYSTEM_UI_PACKAGE, "nav_bar_apps").clickable(true)
+ },
+ })
+ .collect(
+ Collectors.toMap(
+ data -> (String) data[0], data -> (BySelector) data[1]));
+
+ private static final Map<String, BySelector> APP_OPEN_VERIFIERS =
+ Stream.of(
+ new Object[][] {
+ {"App Grid", By.res(VOLVO_LAUNCHER_PACKAGE, "apps_pane")},
+ })
+ .collect(
+ Collectors.toMap(
+ data -> (String) data[0], data -> (BySelector) data[1]));
+
+ private static final long APP_LAUNCH_TIMEOUT_MS = 10000;
+ private static final long UI_WAIT_TIMEOUT_MS = 5000;
+ private static final long POLL_INTERVAL = 100;
+
+ protected UiDevice mDevice;
+ private Instrumentation mInstrumentation;
+
+ @Override
+ public String getSupportedLauncherPackage() {
+ return VOLVO_LAUNCHER_PACKAGE;
+ }
+
+ @Override
+ public void setUiDevice(UiDevice uiDevice) {
+ mDevice = uiDevice;
+ }
+
+ @Override
+ public void setInstrumentation(Instrumentation instrumentation) {
+ super.setInstrumentation(instrumentation);
+ mInstrumentation = instrumentation;
+ }
+
+ @Override
+ public void openApp(String appName) {
+ if (checkApplicationExists(appName)) {
+ UiObject2 app = mDevice.findObject(By.clickable(true).hasDescendant(By.text(appName)));
+ app.clickAndWait(Until.newWindow(), APP_LAUNCH_TIMEOUT_MS);
+ mDevice.waitForIdle();
+ } else {
+ throw new RuntimeException(String.format("Application %s not found", appName));
+ }
+ }
+
+ @Override
+ public void openBluetoothAudioApp() {
+ String appName = "Bluetooth Media Player";
+ if (checkApplicationExists(appName)) {
+ UiObject2 app = mDevice.findObject(By.clickable(true).hasDescendant(By.text(appName)));
+ app.clickAndWait(Until.newWindow(), APP_LAUNCH_TIMEOUT_MS);
+ mDevice.waitForIdle();
+ } else {
+ throw new RuntimeException(String.format("Application %s not found", appName));
+ }
+ }
+
+ @Override
+ public boolean checkApplicationExists(String appName) {
+ openAppGridFacet();
+ UiObject2 app = findApplication(appName);
+ return app != null;
+ }
+
+ @Override
+ public void openAppGridFacet() {
+ openFacet("App Grid");
+ }
+
+ @Override
+ public void openMapsFacet() {
+ // Volvo does not have Facet for Maps, so open Maps from App Grid
+ openApp("Maps");
+ }
+
+ private void openFacet(String facetName) {
+ BySelector facetSelector = FACET_MAP.get(facetName);
+ UiObject2 facet = mDevice.findObject(facetSelector);
+ if (facet != null) {
+ facet.click();
+ waitUntilAppOpen(facetName, APP_LAUNCH_TIMEOUT_MS);
+ } else {
+ throw new RuntimeException(String.format("Failed to find %s facet.", facetName));
+ }
+ }
+
+ private void waitUntilAppOpen(String appName, long timeout) {
+ SystemClock.sleep(timeout);
+ long startTime = SystemClock.uptimeMillis();
+ boolean isOpen = false;
+ do {
+ isOpen = mDevice.hasObject(APP_OPEN_VERIFIERS.get(appName));
+ if (isOpen) {
+ break;
+ }
+ SystemClock.sleep(POLL_INTERVAL);
+ } while ((SystemClock.uptimeMillis() - startTime) < timeout);
+ if (!isOpen) {
+ throw new IllegalStateException(
+ String.format(
+ "Did not find any app of %s in foreground after %d ms.",
+ appName, timeout));
+ }
+ }
+
+ private UiObject2 findApplication(String appName) {
+ BySelector appSelector = By.clickable(true).hasDescendant(By.text(appName));
+ return mDevice.findObject(appSelector);
+ }
+}