aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinhui Wang <jinhuiw@google.com>2016-07-29 15:31:23 -0700
committerJinhui Wang <jinhuiw@google.com>2016-07-29 15:36:18 -0700
commit304b7180bec364db585c15017e772df0bb702395 (patch)
tree65b264810d3fe734bbdfc2249dad5b16e4f5d7c4
parent0084d9265dee1f3e79c721d1a29b2518951e4d0f (diff)
downloadAfwTestHarness-304b7180bec364db585c15017e772df0bb702395.tar.gz
Improve GoogleServicesPage
Use UiDevice.swipe() instead of UiScrollable Change-Id: Iec8fadcccc60967e1e921af36e5b91f441a7bca4
-rw-r--r--libs/UiAutomatorLib/src/com/android/afwtest/uiautomator/pages/gms/GoogleServicesPage.java16
-rw-r--r--libs/UiAutomatorLib/src/com/android/afwtest/uiautomator/utils/Device.java46
2 files changed, 55 insertions, 7 deletions
diff --git a/libs/UiAutomatorLib/src/com/android/afwtest/uiautomator/pages/gms/GoogleServicesPage.java b/libs/UiAutomatorLib/src/com/android/afwtest/uiautomator/pages/gms/GoogleServicesPage.java
index 4a832b3..75b8f75 100644
--- a/libs/UiAutomatorLib/src/com/android/afwtest/uiautomator/pages/gms/GoogleServicesPage.java
+++ b/libs/UiAutomatorLib/src/com/android/afwtest/uiautomator/pages/gms/GoogleServicesPage.java
@@ -23,12 +23,10 @@ import static com.android.afwtest.uiautomator.Constants.GMS_PKG_NAME;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.UiDevice;
-import android.support.test.uiautomator.UiScrollable;
-import android.support.test.uiautomator.UiSelector;
-import android.widget.ScrollView;
import com.android.afwtest.common.test.TestConfig;
import com.android.afwtest.uiautomator.pages.UiPage;
+import com.android.afwtest.uiautomator.utils.Device;
import com.android.afwtest.uiautomator.utils.WidgetUtils;
import java.io.IOException;
@@ -85,10 +83,14 @@ public final class GoogleServicesPage extends UiPage {
WidgetUtils.waitAndClick(getUiDevice(), GMS_CHECK_BOX_SELECTOR, DEFAULT_TIMEOUT_MS);
- // Scroll down
- UiScrollable page = new UiScrollable(
- new UiSelector().className(ScrollView.class.getName()));
- page.flingToEnd(5);
+ // Scroll up so that the Next button appears.
+ for (int i = 0; i < 5; ++i) {
+ Device.swipeUp(getUiDevice());
+ if (WidgetUtils.safeWait(getUiDevice(),
+ GMS_NEXT_BUTTON_RES_SELECTOR, TimeUnit.SECONDS.toMillis(3)) != null) {
+ break;
+ }
+ }
WidgetUtils.waitAndClick(getUiDevice(), GMS_NEXT_BUTTON_RES_SELECTOR, DEFAULT_TIMEOUT_MS);
}
diff --git a/libs/UiAutomatorLib/src/com/android/afwtest/uiautomator/utils/Device.java b/libs/UiAutomatorLib/src/com/android/afwtest/uiautomator/utils/Device.java
new file mode 100644
index 0000000..f462718
--- /dev/null
+++ b/libs/UiAutomatorLib/src/com/android/afwtest/uiautomator/utils/Device.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2016 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.afwtest.uiautomator.utils;
+
+import android.support.test.uiautomator.UiDevice;
+
+/**
+ * Device related util functions.
+ */
+public final class Device {
+ /**
+ * Swipes screen down for half page.
+ *
+ * @param uiDevice {@link UiDevice} object
+ */
+ public static void swipeDown(UiDevice device) {
+ int width = device.getDisplayWidth();
+ int height = device.getDisplayHeight();
+ device.swipe(width / 2, height / 4, width / 2, height * 3 / 4, 10);
+ }
+
+ /**
+ * Swipes screen up for half page.
+ *
+ * @param uiDevice {@link UiDevice} object
+ */
+ public static void swipeUp(UiDevice device) {
+ int width = device.getDisplayWidth();
+ int height = device.getDisplayHeight();
+ device.swipe(width / 2, height * 3 / 4, width / 2, height / 4, 10);
+ }
+} \ No newline at end of file