1 /* 2 * Copyright (C) 2023 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 com.google.android.mobly.snippet.bundled; 18 19 import android.platform.helpers.HelperAccessor; 20 import android.platform.helpers.IAutoGeneralUIHelper; 21 22 import com.google.android.mobly.snippet.Snippet; 23 import com.google.android.mobly.snippet.rpc.Rpc; 24 25 /** Snippet class for general access to UI elements on Android devices */ 26 public class UISnippet implements Snippet { 27 28 private final HelperAccessor<IAutoGeneralUIHelper> mUIHelper; 29 UISnippet()30 public UISnippet() { 31 mUIHelper = new HelperAccessor<IAutoGeneralUIHelper>(IAutoGeneralUIHelper.class); 32 } 33 34 /** 35 * @param text - The text field on the element to click. 36 */ 37 @Rpc(description = "Attempt to click a UI Element that contains a particular text field.") clickUIElementWithText(String text)38 public void clickUIElementWithText(String text) { 39 mUIHelper.get().clickElementWithText(text); 40 } 41 42 /** 43 * @param text - The text field on the element to search for. 44 * @return - True if a UIElement with a text field holding the given text is on screen. False 45 * otherwise. 46 */ 47 @Rpc(description = "Attempt to find a UI Element that contains a particular text field.") hasUIElementWithText(String text)48 public boolean hasUIElementWithText(String text) { 49 return mUIHelper.get().hasElementWithText(text); 50 } 51 52 53 54 } 55