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.helpers; 18 19 import android.content.pm.PackageManager.NameNotFoundException; 20 21 import android.support.test.uiautomator.UiWatcher; 22 import java.io.IOException; 23 24 public interface IAppHelper { 25 26 /** 27 * Setup expectation: On the launcher home screen. 28 * 29 * Launches the desired application. 30 */ open()31 abstract void open(); 32 33 /** 34 * Setup expectation: None 35 * <p> 36 * Presses back until the launcher package is visible, i.e. the home screen. This can be 37 * overriden for custom functionality, however consider and document the exit state if doing so. 38 */ exit()39 abstract void exit(); 40 41 /** 42 * Setup expectations: This application is on the initial launch screen. 43 * <p> 44 * Dismiss all visible relevant dialogs and block until this process is complete. 45 */ dismissInitialDialogs()46 abstract void dismissInitialDialogs(); 47 48 /** 49 * Setup expectations: None 50 * <p> 51 * Get the target application's component package. 52 * @return the package name for this helper's application. 53 */ getPackage()54 abstract String getPackage(); 55 56 /** 57 * Setup expectations: None. 58 * <p> 59 * Get the target application's launcher name. 60 * @return the name of this application's launcher. 61 */ getLauncherName()62 abstract String getLauncherName(); 63 64 /** 65 * Setup expectations: None 66 * <p> 67 * Get the target application's version String. 68 * @return the version code 69 * @throws NameNotFoundException if {@code getPackage} is not found 70 */ getVersion()71 abstract String getVersion() throws NameNotFoundException; 72 73 /** 74 * Setup expectations: None 75 * @return true, if this app's package is the root (depth 0), and false otherwise 76 */ isAppInForeground()77 abstract boolean isAppInForeground(); 78 79 /** 80 * Setup expectations: None 81 * <p> 82 * Captures a screenshot and UI XML with the supplied name. 83 * @param name the screenshot prefix 84 * @throws IOException if there is a capture failure 85 * @throws RuntimeException if creating the screenshot directory fails. 86 */ captureScreenshot(String name)87 abstract boolean captureScreenshot(String name) throws IOException; 88 89 /** 90 * Sends text events to the device through key codes. 91 * <p> 92 * Note: use this only when text accessibility is not supported. 93 * @param text the text to input as events 94 * @param delay the delay between each event 95 * @return true if successful, false otherwise 96 */ sendTextEvents(String text, long delay)97 abstract boolean sendTextEvents(String text, long delay); 98 99 /** 100 * Setup expectations: None 101 * <p> 102 * Registers a UiWatcher. 103 * @param name the name of the UiWatcher to register 104 * @param watcher the UiWatcher to register 105 */ registerWatcher(String name, UiWatcher watcher)106 abstract void registerWatcher(String name, UiWatcher watcher); 107 108 /** 109 * Setup expectations: None 110 * <p> 111 * Removes a previously registered UiWatcher. 112 * @param name the name of the UiWatcher to register 113 */ removeWatcher(String name)114 abstract void removeWatcher(String name); 115 } 116