Home | History | Annotate | Download | only in helpers
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.platform.test.helpers;
     18 
     19 import android.app.Instrumentation;
     20 import android.support.test.uiautomator.Direction;
     21 
     22 import java.util.List;
     23 
     24 public abstract class AbstractGmailHelper extends AbstractStandardAppHelper {
     25 
     26     public AbstractGmailHelper(Instrumentation instr) {
     27         super(instr);
     28     }
     29 
     30     /**
     31      * Setup expectations: Gmail is open and the navigation bar is visible.
     32      *
     33      * This method will navigate to the Inbox or Primary, depending on the name.
     34      */
     35     public abstract void goToInbox();
     36 
     37     /**
     38      * Alias method for AbstractGmailHelper#goToInbox
     39      */
     40     public void goToPrimary() {
     41         goToInbox();
     42     }
     43 
     44     /**
     45      * Setup expectations: Gmail is open on the Inbox or Primary page.
     46      *
     47      * This method will open a new e-mail to compose and block until complete.
     48      */
     49     public abstract void goToComposeEmail();
     50 
     51     /**
     52      * Checks if the current view is the compose email view.
     53      *
     54      * @return true if the current view is the compose email view, false otherwise.
     55      */
     56     public abstract boolean isInComposeEmail();
     57 
     58     /**
     59      * Checks if the app is open on the Inbox or Primary page.
     60      *
     61      * @return true if the current view is the Inbox or Primary page, false otherwise.
     62      */
     63     public abstract boolean isInPrimaryOrInbox();
     64 
     65     /**
     66      * Setup expectations: Gmail is open and on the Inbox or Primary page.
     67      *
     68      * This method will open the (index)'th visible e-mail in the list and block until the e-mail is
     69      * visible in the foreground. The top-most visible e-mail will always be labeled 0. To get the
     70      * number of visible e-mails, consult the getVisibleEmailCount() function.
     71      */
     72     public abstract void openEmailByIndex(int index);
     73 
     74     /**
     75      * Setup expectations: Gmail is open and on the Inbox or Primary page.
     76      *
     77      * This method will return the number of visible e-mails for use with the #openEmailByIndex
     78      * method.
     79      */
     80     public abstract int getVisibleEmailCount();
     81 
     82     /**
     83      * Setup expectations: Gmail is open and an e-mail is open in the foreground.
     84      *
     85      * This method will press reply, send a reply e-mail with the given parameters, and block until
     86      * the original message is in the foreground again.
     87      */
     88     public abstract void sendReplyEmail(String address, String body);
     89 
     90     /**
     91      * Setup expectations: Gmail is open and composing an e-mail.
     92      *
     93      * This method will set the e-mail's To address and block until complete.
     94      */
     95     public abstract void setEmailToAddress(String address);
     96 
     97     /**
     98      * Setup expectations: Gmail is open and composing an e-mail.
     99      *
    100      * This method will set the e-mail's subject and block until complete.
    101      */
    102     public abstract void setEmailSubject(String subject);
    103 
    104     /**
    105      * Setup expectations: Gmail is open and composing an e-mail.
    106      *
    107      * This method will set the e-mail's Body and block until complete. Focus will remain on the
    108      * e-mail body after completion.
    109      */
    110     public abstract void setEmailBody(String body);
    111 
    112     /**
    113      * Setup expectations: Gmail is open and composing an e-mail.
    114      *
    115      * This method will press send and block until the device is idle on the original e-mail.
    116      */
    117     public abstract void clickSendButton();
    118 
    119     /**
    120      * Setup expectations: Gmail is open and composing an e-mail.
    121      *
    122      * This method will get the e-mail's composition's body and block until complete.
    123      *
    124      * @return {String} the text contained in the email composition's body.
    125      */
    126     public abstract String getComposeEmailBody();
    127 
    128     /**
    129      * Setup expectations: Gmail is open and the navigation drawer is visible.
    130      *
    131      * This method will open the navigation drawer and block until complete.
    132      */
    133     public abstract void openNavigationDrawer();
    134 
    135     /**
    136      * Setup expectations: Gmail is open and the navigation drawer is open.
    137      *
    138      * This method will close the navigation drawer and returns true otherwise false
    139      */
    140     public abstract boolean closeNavigationDrawer();
    141 
    142     /**
    143      * Setup expectations: Gmail is open and the navigation drawer is open.
    144      *
    145      * This method will scroll the navigation drawer and block until idle. Only accepts UP and DOWN.
    146      */
    147     public abstract void scrollNavigationDrawer(Direction dir);
    148 
    149     /**
    150      * Setup expectations: Gmail is open and a mailbox is open.
    151      *
    152      * This method will scroll the mailbox view.
    153      *
    154      * @param direction     The direction to scroll, only accepts UP and DOWN.
    155      * @param amount        The amount to scroll
    156      * @param scrollToEnd   Whether or not to scroll to the end
    157      */
    158     public abstract void scrollMailbox(Direction direction, float amount, boolean scrollToEnd);
    159 
    160     /**
    161      * Setup expectations: Gmail is open and an email is open.
    162      *
    163      * This method will scroll the current email.
    164      *
    165      * @param direction     The direction to scroll, only accepts UP and DOWN.
    166      * @param amount        The amount to scroll
    167      * @param scrollToEnd   Whether or not to scroll to the end
    168      */
    169     public abstract void scrollEmail(Direction direction, float amount, boolean scrollToEnd);
    170 
    171     /**
    172      * Setup expectations: Gmail is open and the navigation drawer is open.
    173      *
    174      * This method will open the mailbox with the given name and block until emails in
    175      * that mailbox have loaded.
    176      *
    177      * @param mailboxName The case insensitive name of the mailbox to open
    178      */
    179     public abstract void openMailbox(String mailboxName);
    180 
    181     /**
    182      * Setup expectations: Gmail is open and an email is open.
    183      *
    184      * This method will return to the mailbox the current email was opened from.
    185      */
    186     public abstract void returnToMailbox();
    187 
    188     /**
    189      * Setup expectations: Gmail is open and an email is open.
    190      *
    191      * This method starts downloading the attachment at the specified index in the current email.
    192      * The download happens in the background. This method returns immediately after starting
    193      * the download and does not wait for the download to complete.
    194      *
    195      * @param index The index of the attachment to download
    196      */
    197     public abstract void downloadAttachment(int index);
    198 
    199     /**
    200      * Setup expectations: Gmail is open and an email is open.
    201      *
    202      * This method gets every link target in an open email by traversing the UI tree of the body
    203      * of the open message.
    204      *
    205      * @return an iterator over the links in the message
    206      */
    207     public abstract List<String> getEmailLinks();
    208 
    209     /**
    210      * Setup expectations: Gmail is open and an email is open.
    211      *
    212      * This method clicks the link in the open email with the given target.
    213      *
    214      * @param target the target of the link to click
    215      */
    216     public abstract void openEmailLink(String target);
    217 }
    218