summaryrefslogtreecommitdiff
path: root/library/core-src/com/android/uiautomator/core/Configurator.java
blob: 55ed3e786d6d361396c604f243218a46fd4f8e0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.uiautomator.core;

/**
 * The Configurator allows for modification of some key framework parameters.
 * New settings take effect immediately and can be changed any time during a test run.
 *
 * Can be obtained by calling {@link #getInstance()}
 * @since API Level 18
 */
public final class Configurator {
    private long mWaitForIdleTimeout = 10 * 1000;
    private long mWaitForSelector = 10 * 1000;
    private long mWaitForActionAcknowledgment = 3 * 1000;

    // The events for a scroll typically complete even before touchUp occurs.
    // This short timeout to make sure we get the very last in cases where the above isn't true.
    private long mScrollEventWaitTimeout = 200; // ms

    // Default is inject as fast as we can
    private long mKeyInjectionDelay = 0; // ms

    // reference to self
    private static Configurator sConfigurator;

    private Configurator() {
        /* hide constructor */
    }

    /**
     * Retrieves a singleton instance of Configurator
     *
     * @return Configurator instance
     * @since API Level 18
     */
    public static Configurator getInstance() {
        if (sConfigurator == null) {
            sConfigurator = new Configurator();
        }
        return sConfigurator;
    }

    /**
     * Sets the timeout used to wait for user interface idle before an automation action.
     *
     * All automation APIs, except {@link UiDevice}, perform this wait for idle before looking for
     * the widget specified by the object's {@link UiSelector}. Once idle is detected, a
     * wait for selector will begin. See {@link #setWaitForSelectorTimeout(long)}
     *
     * @param timeout Timeout value in milliseconds
     * @return self
     * @since API Level 18
     */
    public Configurator setWaitForIdleTimeout(long timeout) {
        mWaitForIdleTimeout = timeout;
        return this;
    }

    /**
     * Gets the timeout used to wait for user interface idle before an automation action.
     *
     * All automation APIs, except {@link UiDevice}, perform this wait for idle before looking for
     * the widget specified by the object's {@link UiSelector}. Once idle is detected, a
     * wait for selector will begin. See {@link #setWaitForSelectorTimeout(long)}
     *
     * @return current timeout in milliseconds
     * @since API Level 18
     */
    public long getWaitForIdleTimeout() {
        return mWaitForIdleTimeout;
    }

    /**
     * Sets the timeout used to wait for a widget matching a selector to become visible
     * in user interface.
     *
     * The user interface content is dynamic and sometimes the specific widget to be
     * automated may not yet be visible. This wait allows the framework to keep looking
     * for a matching widget to the object's {@link UiSelector}, up until the timeout.
     *
     * @param timeout Timeout value in milliseconds.
     * @return self
     * @since API Level 18
     */
    public Configurator setWaitForSelectorTimeout(long timeout) {
        mWaitForSelector = timeout;
        return this;
    }

    /**
     * Gets the timeout used to wait for a widget matching a selector to become visible
     * in user interface.
     *
     * The user interface content is dynamic and sometimes the specific widget to be
     * automated, may not yet be visible. This wait allows the framework to keep looking
     * for a matching widget to the object's {@link UiSelector}, up until the timeout.
     *
     * @return current timeout in milliseconds
     * @since API Level 18
     */
    public long getWaitForSelectorTimeout() {
        return mWaitForSelector;
    }

    /**
     * Sets the timeout used to wait for acknowledgment events caused by automation scroll
     * swipe action.
     *
     * The acknowledgment event is an accessibility event, corresponding to the scroll action.
     * This acknowledgment helps the framework determine if the requested action was successful.
     * Changing this timeout value should only be made in very rare cases and in general use,
     * should not be modified.
     *
     * @param timeout Timeout value in milliseconds
     * @return self
     * @since API Level 18
     */
    public Configurator setScrollAcknowledgmentTimeout(long timeout) {
        mScrollEventWaitTimeout = timeout;
        return this;
    }

    /**
     * Gets the timeout used to wait for acknowledgment events caused by automation scroll
     * swipe action.
     *
     * The acknowledgment event is an accessibility event, corresponding to the scroll action.
     * This acknowledgment helps the framework determine if the requested action was successful.
     * Changing this timeout value should only be made in very rare cases and in general use,
     * should not be modified.
     *
     * @return current timeout in milliseconds
     * @since API Level 18
     */
    public long getScrollAcknowledgmentTimeout() {
        return mScrollEventWaitTimeout;
    }

    /**
     * Sets the timeout used to wait for acknowledgment events caused by generic automation
     * actions such as clicks, setText, pressMenu etc...
     *
     * The acknowledgment event is an accessibility event, corresponding to an action, that the
     * framework looks for after an action is performed. This acknowledgment helps the
     * framework determine if the requested action was successful. Changing this timeout
     * value should only be made in very rare cases and in general use, should not be modified.
     *
     * @param timeout Timeout value in milliseconds
     * @return self
     * @since API Level 18
     */
    public Configurator setActionAcknowledgmentTimeout(long timeout) {
        mWaitForActionAcknowledgment = timeout;
        return this;
    }

    /**
     * Gets the timeout used to wait for acknowledgment events caused by generic automation
     * actions such as clicks, setText, pressMenu etc...
     *
     * The acknowledgment event is an accessibility event, corresponding to an action, that the
     * framework looks for after an action is performed. This acknowledgment helps the
     * framework determine if the requested action was successful. Changing this timeout
     * value should only be made in very rare cases and in general use, should not be modified.
     *
     * @return current timeout in milliseconds
     * @since API Level 18
     */
    public long getActionAcknowledgmentTimeout() {
        return mWaitForActionAcknowledgment;
    }

    /**
     * Sets a delay between key presses when sending text.
     *
     * @param delay Delay value in milliseconds
     * @return self
     * @since API Level 18
     */
    public Configurator setKeyInjectionDelay(long delay) {
        mKeyInjectionDelay = delay;
        return this;
    }

    /**
     * Gets the delay between key presses when sending text.
     *
     * @return current delay in milliseconds
     * @since API Level 18
     */
    public long getKeyInjectionDelay() {
        return mKeyInjectionDelay;
    }
}