| Index: clank/test/geppetto/clanktests/src/com/google/android/apps/chrome/uiautomator/utilities/PageHelper.java
|
| diff --git a/clank/test/geppetto/clanktests/src/com/google/android/apps/chrome/uiautomator/utilities/PageHelper.java b/clank/test/geppetto/clanktests/src/com/google/android/apps/chrome/uiautomator/utilities/PageHelper.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cc6dddfa5dd83c7871ae44f3d6fd63488190927f
|
| --- /dev/null
|
| +++ b/clank/test/geppetto/clanktests/src/com/google/android/apps/chrome/uiautomator/utilities/PageHelper.java
|
| @@ -0,0 +1,108 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package com.google.android.apps.chrome.uiautomator.utilities;
|
| +
|
| +import android.support.test.uiautomator.UiDevice;
|
| +import android.support.test.uiautomator.UiObject;
|
| +import android.support.test.uiautomator.UiObjectNotFoundException;
|
| +import android.support.test.uiautomator.UiSelector;
|
| +
|
| +import com.google.android.apps.uiautomator.utilities.Constants;
|
| +import com.google.android.apps.uiautomator.utilities.DeviceHelper;
|
| +import com.google.android.apps.uiautomator.utilities.HelperBase;
|
| +
|
| +import junit.framework.Assert;
|
| +
|
| +/**
|
| + * Helper for interacting with page on phone/tablet.
|
| + */
|
| +public class PageHelper extends HelperBase {
|
| + private final DeviceHelper mDeviceHelper;
|
| + private final OptionsMenuHelper mOptionsMenuHelper;
|
| + private final ToolbarHelper mToolbarHelper;
|
| +
|
| + private final UiObject mPageContent;
|
| +
|
| + public PageHelper(UiDevice uiDevice) {
|
| + super(uiDevice);
|
| +
|
| + mDeviceHelper = new DeviceHelper(getDevice());
|
| + mOptionsMenuHelper = new OptionsMenuHelper(getDevice());
|
| + mToolbarHelper = new ToolbarHelper(getDevice());
|
| +
|
| + mPageContent = getDevice().findObject(new UiSelector().resourceIdMatches(".*content"));
|
| + }
|
| +
|
| + /**
|
| + * Waits until the current tab has finished loading by waiting for the
|
| + * refresh button to appear.
|
| + */
|
| + public void waitForPageLoad() throws UiObjectNotFoundException {
|
| + if (!mDeviceHelper.isTablet()) {
|
| + mOptionsMenuHelper.open();
|
| + Assert.assertTrue("The page did not load.",
|
| + mToolbarHelper.getRefreshButton().waitForExists(Constants.PAGELOAD_TIMEOUT));
|
| + mOptionsMenuHelper.close();
|
| + } else {
|
| + Assert.assertTrue("The page did not load.",
|
| + mToolbarHelper.getRefreshButton().waitForExists(Constants.PAGELOAD_TIMEOUT));
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Verifies text on a web page.
|
| + *
|
| + * @param webContentText Expected Text to be searched.
|
| + */
|
| + public void verifyTextOnPage(String webContentText) {
|
| + UiObject textOnPage = getDevice().findObject(
|
| + new UiSelector().descriptionContains(webContentText)
|
| + .className("android.view.View"));
|
| + Assert.assertTrue(textOnPage.exists());
|
| + }
|
| +
|
| + /**
|
| + * Clicks on a button on a web page.
|
| + *
|
| + * @param buttonName Button to click.
|
| + */
|
| + public void clickOnButton(String buttonName) throws UiObjectNotFoundException {
|
| + UiObject formButton = getDevice().findObject(
|
| + new UiSelector().className(android.widget.Button.class)
|
| + .descriptionContains(buttonName));
|
| + Assert.assertTrue(formButton.isClickable());
|
| + formButton.click();
|
| + }
|
| +
|
| + /**
|
| + * Returns a UiObject that represents an element on the page with a particular content
|
| + * description.
|
| + *
|
| + * @param contentDescription The content description of the element on the page.
|
| + */
|
| + public UiObject getElementWithDescription(String contentDescription)
|
| + throws UiObjectNotFoundException {
|
| + return getDevice().findObject(new UiSelector().description(contentDescription));
|
| + }
|
| +
|
| + /**
|
| + * Returns a UiObject that represents the input box element associated with a particular label.
|
| + *
|
| + * @param fieldLabel The label associated with the input element.
|
| + */
|
| + public UiObject getFormInputElementWithLabel(String fieldLabel)
|
| + throws UiObjectNotFoundException {
|
| + return getElementWithDescription(fieldLabel).getFromParent(
|
| + new UiSelector().className(android.widget.EditText.class));
|
| + }
|
| +
|
| + /**
|
| + * Returns true if the element is visible on the displayed part of the page.
|
| + */
|
| + public boolean isVisibleOnPage(UiObject element)
|
| + throws UiObjectNotFoundException {
|
| + return mPageContent.getBounds().contains(element.getBounds());
|
| + }
|
| +}
|
|
|