• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.platform.systemui_tapl.ui
18 
19 import android.platform.systemui_tapl.utils.DeviceUtils.androidResSelector
20 import android.platform.systemui_tapl.utils.DeviceUtils.sysuiResSelector
21 import android.platform.systemui_tapl.utils.UserUtils.runThenWaitUntilSwitchCompleted
22 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible
23 import android.platform.uiautomatorhelpers.DeviceHelpers.waitForObj
24 import java.util.regex.Pattern
25 
26 /**
27  * System UI test automation object representing the panel for adding the new user.
28  * https://hsv.googleplex.com/6238141703782400
29  */
30 class AddUserPanel internal constructor() {
31 
32     init {
<lambda>null33         TITLE_SELECTOR.assertVisible { "Add user panel is not visible" }
34     }
35 
36     /** Clicks on the OK button. */
OKnull37     fun OK() {
38         runThenWaitUntilSwitchCompleted {
39             waitForObj(OK_SELECTOR) { "OK Button not found" }.click()
40         }
41     }
42 
43     /** Clicks on the cancel button. */
cancelnull44     fun cancel() {
45         waitForObj(CANCEL_SELECTOR) { "Cancel button not found" }.click()
46     }
47 
48     /** Sets the user name. */
setUserNamenull49     fun setUserName(userName: String) {
50         val editNameField = waitForObj(EDIT_NAME_SELECTOR) { "Name edit field not found" }
51         editNameField.click()
52         editNameField.text = userName
53     }
54 
55     companion object {
56         // https://hsv.googleplex.com/6238141703782400?node=7
57         private val TITLE_SELECTOR =
58             androidResSelector("alertTitle")
59                 .text(Pattern.compile("Add user", Pattern.CASE_INSENSITIVE))
60 
61         // https://hsv.googleplex.com/6238141703782400?node=18
62         private val OK_SELECTOR =
63             androidResSelector("button1").text(Pattern.compile("OK", Pattern.CASE_INSENSITIVE))
64 
65         // https://hsv.googleplex.com/6238141703782400?node=17
66         private val CANCEL_SELECTOR =
67             androidResSelector("button2").text(Pattern.compile("Cancel", Pattern.CASE_INSENSITIVE))
68 
69         // https://hsv.googleplex.com/6238141703782400?node=17
70         private val EDIT_NAME_SELECTOR = sysuiResSelector("user_name")
71     }
72 }
73