1/* 2 * Copyright (C) 2015 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 17package com.android.tv.testing.uihelper; 18 19import android.content.res.Resources; 20import android.support.test.uiautomator.By; 21import android.support.test.uiautomator.BySelector; 22import android.support.test.uiautomator.Direction; 23import android.support.test.uiautomator.UiDevice; 24import android.support.test.uiautomator.UiObject2; 25 26import com.android.tv.R; 27import com.android.tv.ui.sidepanel.SideFragment; 28 29import junit.framework.Assert; 30 31/** 32 * Helper for testing {@link SideFragment}s. 33 */ 34public class SidePanelHelper extends BaseUiDeviceHelper { 35 36 public SidePanelHelper(UiDevice uiDevice, Resources targetResources) { 37 super(uiDevice, targetResources); 38 } 39 40 public BySelector bySidePanelTitled(int titleResId) { 41 return By.copy(Constants.SIDE_PANEL) 42 .hasDescendant(ByResource.text(mTargetResources, titleResId)); 43 } 44 45 public BySelector byViewText(int textResId) { 46 return By.hasDescendant(ByResource.text(mTargetResources, textResId)); 47 } 48 49 public UiObject2 assertNavigateToItem(int resId) { 50 String title = mTargetResources.getString(resId); 51 return assertNavigateToItem(title); 52 } 53 54 public UiObject2 assertNavigateToItem(String title) { 55 BySelector sidePanelSelector = ByResource.id(mTargetResources, R.id.side_panel_list); 56 UiObject2 sidePanelList = mUiDevice.findObject(sidePanelSelector); 57 Assert.assertNotNull(sidePanelSelector + " not found", sidePanelList); 58 59 return UiDeviceAsserts 60 .assertNavigateTo(mUiDevice, sidePanelList, By.hasDescendant(By.text(title)), 61 Direction.DOWN); 62 } 63} 64