1 /* 2 * Copyright (C) 2022 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 package android.platform.systemui_tapl.ui 17 18 import android.platform.systemui_tapl.utils.DeviceUtils.androidResSelector 19 import android.platform.uiautomatorhelpers.DeviceHelpers.assertInvisible 20 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisibility 21 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible 22 import android.platform.uiautomatorhelpers.DeviceHelpers.uiDevice 23 import com.android.launcher3.tapl.LauncherInstrumentation 24 25 /** System UI test automation object representing an alert dialog. */ 26 class AlertDialog internal constructor() { 27 28 init { 29 UI_DIALOG_TITLE.assertVisible() 30 } 31 32 /** Asserts visibility of the 'negative' button in the dialog */ assertNegativeButtonVisibilitynull33 fun assertNegativeButtonVisibility(visible: Boolean) { 34 uiDevice.assertVisibility(androidResSelector(UI_ALERT_DIALOG_NEGATIVE_BUTTON_ID), visible) 35 } 36 37 /* Dismisses the dialog by the Back gesture */ dismissnull38 fun dismiss() { 39 // Press back to dismiss the dialog 40 LauncherInstrumentation().pressBack() 41 UI_DIALOG_TITLE.assertInvisible() 42 } 43 44 companion object { 45 private const val UI_DIALOG_TITLE_ID = "alertTitle" 46 private const val UI_ALERT_DIALOG_NEGATIVE_BUTTON_ID = "button2" 47 private val UI_DIALOG_TITLE = androidResSelector(UI_DIALOG_TITLE_ID) 48 } 49 } 50