Home | History | Annotate | Download | only in bots
      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 
     17 package com.android.documentsui.bots;
     18 
     19 import static junit.framework.Assert.assertTrue;
     20 import static junit.framework.Assert.assertFalse;
     21 
     22 import android.content.Context;
     23 import android.support.test.uiautomator.By;
     24 import android.support.test.uiautomator.UiDevice;
     25 import android.support.test.uiautomator.UiObjectNotFoundException;
     26 
     27 import java.util.Map;
     28 
     29 /**
     30  * A test helper class that provides support for controlling menu items.
     31  */
     32 public class MenuBot extends Bots.BaseBot {
     33 
     34     public MenuBot(
     35             UiDevice device, Context context, int timeout) {
     36         super(device, context, timeout);
     37     }
     38 
     39     public boolean hasMenuItem(String menuLabel) throws UiObjectNotFoundException {
     40         return mDevice.findObject(By.text(menuLabel)) != null;
     41     }
     42 
     43     public void assertPresentMenuItems(Map<String, Boolean> menuStates) throws Exception {
     44         for (String key : menuStates.keySet()) {
     45             if (menuStates.get(key)) {
     46                 assertTrue(key + " expected to be shown", hasMenuItem(key));
     47             } else {
     48                 assertFalse(key + " expected not to be shown", hasMenuItem(key));
     49             }
     50         }
     51     }
     52 }
     53