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.system.helpers; 18 19 import android.content.Context; 20 import android.content.pm.PackageManager; 21 import android.support.test.uiautomator.By; 22 import android.support.test.uiautomator.UiDevice; 23 import android.support.test.uiautomator.UiObject2; 24 import android.support.test.uiautomator.Until; 25 26 import androidx.test.InstrumentationRegistry; 27 28 import junit.framework.Assert; 29 30 /** 31 * Implement common helper methods for Hotseat. 32 */ 33 public class HotseatHelper { 34 private static final int TIMEOUT = 3000; 35 private UiDevice mDevice = null; 36 private PackageManager mPkgManger = null; 37 private Context mContext = null; 38 public static HotseatHelper sInstance = null; 39 HotseatHelper()40 private HotseatHelper() { 41 mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 42 mContext = InstrumentationRegistry.getTargetContext(); 43 } 44 getInstance()45 public static HotseatHelper getInstance() { 46 if (sInstance == null) { 47 sInstance = new HotseatHelper(); 48 } 49 return sInstance; 50 } 51 52 /** 53 * Launch app from hotseat 54 * @param textAppName 55 * @param appPackage 56 */ launchAppFromHotseat(String textAppName, String appPackage)57 public void launchAppFromHotseat(String textAppName, String appPackage) { 58 mDevice.pressHome(); 59 UiObject2 appOnHotseat = mDevice.findObject(By.clazz("android.widget.TextView") 60 .desc(textAppName)); 61 Assert.assertNotNull(textAppName + " app couldn't be found on hotseat", appOnHotseat); 62 appOnHotseat.click(); 63 UiObject2 appLoaded = mDevice.wait(Until.findObject(By.pkg(appPackage)), TIMEOUT * 2); 64 Assert.assertNotNull(textAppName + "app did not load on tapping from hotseat", appLoaded); 65 } 66 }