1 /* 2 * Copyright (C) 2018 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 androidx.test.uiautomator.Direction; 20 import androidx.test.uiautomator.UiObject2; 21 22 public interface IGoogleHelper extends IAppHelper { 23 24 public enum NavigationTab { 25 DISCOVER("Discover"), 26 SNAPSHOT("Snapshot"), 27 SEARCH("Search"), 28 COLLECTIONS("Collections"), 29 MORE("More"); 30 31 private final String text; 32 NavigationTab(String text)33 NavigationTab(String text) { 34 this.text = text; 35 } 36 37 @Override toString()38 public String toString() { 39 return text; 40 } 41 }; 42 43 public enum SearchResultTab { 44 ALL("All"), 45 IMAGES("Images"), 46 VIDEOS("Videos"), 47 NEWS("News"), 48 MAPS("Maps"), 49 BOOKS("Books"), 50 SHOPPING("Shopping"), 51 FLIGHTS("Flights"); 52 53 private final String mDisplayName; 54 SearchResultTab(String displayName)55 SearchResultTab(String displayName) { 56 mDisplayName = displayName; 57 } 58 59 @Override toString()60 public String toString() { 61 return mDisplayName; 62 } 63 } 64 65 /** 66 * Setup expectations: Google app open 67 * 68 * <p>This method will start a voice search 69 * 70 * @return true if the search is started, false otherwise 71 */ doVoiceSearch()72 public boolean doVoiceSearch(); 73 74 /** 75 * Setup expectations: Google app open to a search result 76 * 77 * <p>This method will return the query from the search 78 */ getSearchQuery()79 public String getSearchQuery(); 80 81 /** 82 * Setup expectations: Google app open. 83 * 84 * <p>This method goes to the specified tab, such as Discover, Search, Collections. 85 */ navigateToTab(NavigationTab tab)86 public void navigateToTab(NavigationTab tab); 87 88 /** 89 * Setup expectations: In home and with search bar. 90 * 91 * <p>This method starts search from the search bar in home. 92 */ startSearch()93 public default void startSearch() { 94 throw new UnsupportedOperationException("Not yet implemented."); 95 } 96 97 /** 98 * Setup expectations: Google app open. 99 * 100 * <p>This method inputs keyword in search box. 101 * 102 * @param query The keyword to search. 103 */ inputSearch(String query)104 public default void inputSearch(String query) { 105 throw new UnsupportedOperationException("Not yet implemented."); 106 } 107 108 /** 109 * Setup expectations: Google app open and a search keyword input. 110 * 111 * <p>This method clicks the search button and waits for the results. 112 */ clickSearchButtonAndWaitForResults()113 public default void clickSearchButtonAndWaitForResults() { 114 throw new UnsupportedOperationException("Not yet implemented."); 115 } 116 117 /** 118 * Setup expectations: Google app open to a search result. 119 * 120 * <p>This method flings the search results. 121 * 122 * @param dir The direction of the fling, must be UP or DOWN. 123 */ flingSearchResults(Direction dir)124 public default void flingSearchResults(Direction dir) { 125 throw new UnsupportedOperationException("Not yet implemented."); 126 } 127 128 /** 129 * Setup expectations: Google app open to a search result. 130 * 131 * <p>This method scroll the search results. 132 * 133 * @param dir The direction of the fling, must be UP or DOWN. 134 */ scrollSearchResults(Direction dir)135 public default void scrollSearchResults(Direction dir) { 136 throw new UnsupportedOperationException("Not yet implemented."); 137 } 138 139 /** 140 * Setup expectations: In home. 141 * 142 * <p>This method flings right to Google Feed. 143 */ openFeed()144 public default void openFeed() { 145 throw new UnsupportedOperationException("Not yet implemented."); 146 } 147 148 /** 149 * Setup expectations: Feed open. 150 * 151 * <p>This method flings the feed. 152 * 153 * @param dir The direction of the fling, must be UP or DOWN. 154 */ flingFeed(Direction dir)155 public default void flingFeed(Direction dir) { 156 throw new UnsupportedOperationException("Not yet implemented."); 157 } 158 159 /** 160 * Setup expectations: Feed open. 161 * 162 * <p>Get the UiObject2 of feed container. 163 */ getFeedContainer()164 public UiObject2 getFeedContainer(); 165 166 /** 167 * Setup expectations: Feed open. 168 * 169 * <p>This method flings the feed. 170 * 171 * @param container The container with scrollable elements. 172 * @param dir The direction of the fling, must be UP or DOWN. 173 */ flingFeed(UiObject2 container, Direction dir)174 public void flingFeed(UiObject2 container, Direction dir); 175 176 /** 177 * Setup expectations: Feed open. 178 * 179 * <p>This method scrolls the feed with speed. 180 * 181 * @param container The container with scrollable elements. 182 * @param dir The direction of the scroll, must be UP or DOWN. 183 * @param speed The speed of scroll. 184 */ scrollFeed(UiObject2 container, Direction dir, int speed)185 public void scrollFeed(UiObject2 container, Direction dir, int speed); 186 187 /** 188 * Setup expectations: Google app open and has done a search. 189 * 190 * <p>This method will go to the specified search result tab. 191 * 192 * @param tab one of the tabs of the search result page. 193 */ openSearchResultTab(IGoogleHelper.SearchResultTab tab)194 public abstract void openSearchResultTab(IGoogleHelper.SearchResultTab tab); 195 196 /** 197 * Setup expectations: In home. 198 * 199 * <p>This method clear search result. 200 */ clearSearchResult()201 public default boolean clearSearchResult() { 202 throw new UnsupportedOperationException("Not yet implemented."); 203 } 204 } 205