js-apis-uitest.md 113.1 KB
Newer Older
E
esterzhou 已提交
1
# @ohos.uitest
E
add doc  
ester.zhou 已提交
2

E
esterzhou 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15
The **UiTest** module provides APIs that you can use to simulate UI actions during testing, such as clicks, double-clicks, long-clicks, and swipes.

This module provides the following functions:

- [On<sup>9+</sup>](#on9): provides UI component feature description APIs for component filtering and matching.
- [Component<sup>9+</sup>](#component9): represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection.
- [Driver<sup>9+</sup>](#driver9): works as the entry class and provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot.
- [UiWindow<sup>9+</sup>](#uiwindow9): works as the entry class and provides APIs for obtaining window attributes, dragging windows, and adjusting window sizes.
- [By<sup>(deprecated)</sup>](#bydeprecated): provides UI component feature description APIs for component filtering and matching. This API is deprecated since API version 9. You are advised to use [On<sup>9+</sup>](#on9) instead.
- [UiComponent<sup>(deprecated)</sup>](#uicomponentdeprecated): represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection. This API is deprecated since API version 9. You are advised to use [Component<sup>9+</sup>](#component9) instead.
- [UiDriver<sup>(deprecated)</sup>](#uidriverdeprecated): works as the entry class and provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot. This API is deprecated since API version 9. You are advised to use [Driver<sup>9+</sup>](#driver9) instead.

>**NOTE**
E
add doc  
ester.zhou 已提交
16
>
E
esterzhou 已提交
17
>The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
E
add doc  
ester.zhou 已提交
18 19 20 21


## Modules to Import

E
esterzhou 已提交
22 23
```js
import {UiComponent, UiDriver, Component, Driver, UiWindow, ON, BY, MatchPattern, DisplayRotation, ResizeDirection, WindowMode, PointerMatrix} from '@ohos.uitest';
E
add doc  
ester.zhou 已提交
24 25
```

E
esterzhou 已提交
26
## MatchPattern
E
add doc  
ester.zhou 已提交
27

E
esterzhou 已提交
28
Enumerates the match patterns supported for component attributes.
E
add doc  
ester.zhou 已提交
29

E
esterzhou 已提交
30
**System capability**: SystemCapability.Test.UiTest
E
add doc  
ester.zhou 已提交
31

E
esterzhou 已提交
32 33 34 35 36 37
| Name       | Value  | Description          |
| ----------- | ---- | -------------- |
| EQUALS      | 0    | Equal to the given value.  |
| CONTAINS    | 1    | Contains the given value.  |
| STARTS_WITH | 2    | Starts with the given value.|
| ENDS_WITH   | 3    | Ends with the given value.|
E
add doc  
ester.zhou 已提交
38

E
esterzhou 已提交
39
## ResizeDirection<sup>9+</sup>
E
add doc  
ester.zhou 已提交
40

E
esterzhou 已提交
41
Enumerates the directions in which a window can be resized.
E
add doc  
ester.zhou 已提交
42 43 44

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
45 46 47 48 49 50 51 52 53 54
| Name      | Value  | Description    |
| ---------- | ---- | -------- |
| LEFT       | 0    | Left.  |
| RIGHT      | 1    | Right.  |
| UP         | 2    | Up.  |
| DOWN       | 3    | Down.  |
| LEFT_UP    | 4    | Upper left.|
| LEFT_DOWN  | 5    | Lower left.|
| RIGHT_UP   | 6    | Upper right.|
| RIGHT_DOWN | 7    | Lower right.|
E
add doc  
ester.zhou 已提交
55

E
esterzhou 已提交
56
## Point<sup>9+</sup>
E
add doc  
ester.zhou 已提交
57

E
esterzhou 已提交
58
Provides the coordinates of a point.
E
add doc  
ester.zhou 已提交
59

E
esterzhou 已提交
60
**System capability**: SystemCapability.Test.UiTest
E
add doc  
ester.zhou 已提交
61

E
esterzhou 已提交
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
| Name| Type  | Readable| Writable| Description            |
| ---- | ------ | ---- | ---- | ---------------- |
| X    | number | Yes  | No  | X-coordinate of a point.|
| Y    | number | Yes  | No  | Y-coordinate of a point.|

## Rect<sup>9+</sup>

Provides bounds information of a component.

**System capability**: SystemCapability.Test.UiTest

| Name   | Type  | Readable| Writable| Description                     |
| ------- | ------ | ---- | ---- | ------------------------- |
| leftX   | number | Yes  | No  | X-coordinate of the upper left corner of the component bounds.|
| topY    | number | Yes  | No  | Y-coordinate of the upper left corner of the component bounds.|
| rightX  | number | Yes  | No  | X-coordinate of the lower right corner of the component bounds.|
| bottomY | number | Yes  | No  | Y-coordinate of the lower right corner of the component bounds.|

## WindowMode<sup>9+</sup>

**System capability**: SystemCapability.Test.UiTest

Enumerates the window modes.

| Name      | Value  | Description      |
| ---------- | ---- | ---------- |
| FULLSCREEN | 0    | Full-screen mode.|
| PRIMARY    | 1    | Primary window mode.  |
| SECONDARY  | 2    | Secondary window mode.|
| FLOATING   | 3    | Floating window mode.|

## DisplayRotation<sup>9+</sup>

**System capability**: SystemCapability.Test.UiTest

Describes the display rotation of the device.

| Name        | Value  | Description                                    |
| ------------ | ---- | ---------------------------------------- |
| ROTATION_0   | 0    | The device display is not rotated and is in its original vertical orientation.    |
| ROTATION_90  | 1    | The device display rotates 90° clockwise and is in landscape orientation.     |
| ROTATION_180 | 2    | The device display rotates 180° clockwise and is in reverse vertical orientation.|
| ROTATION_270 | 3    | The device display rotates 270° clockwise and is in reverse landscape orientation.|

## WindowFilter<sup>9+</sup>

Provides the flag attributes of this window.

**System capability**: SystemCapability.Test.UiTest

| Name      | Type   | Readable| Writable| Description                      |
| ---------- | ------- | ---- | ---- | -------------------------- |
| bundleName | string  | Yes  | No  | Bundle name of the application to which the window belongs.      |
| title      | string  | Yes  | No  | Title of the window.          |
| focused    | boolean | Yes  | No  | Whether the window is in focused state.    |
| actived    | boolean | Yes  | No  | Whether the window is interacting with the user.|

## On<sup>9+</sup>

Since API version 9, the UiTest framework provides a wide range of UI component feature description APIs in the **On** class to filter and match components.
The API capabilities provided by the **On** class exhibit the following features: 1. Allow one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component. <br>2. Provide multiple match patterns for component attributes. <br>3. Support absolute positioning and relative positioning for components. APIs such as [ON.isBefore](#isbefore) and [ON.isAfter](#isafter) can be used to specify the features of adjacent components to assist positioning. <br>All APIs provided in the **On** class are synchronous. You are advised to use the static constructor **ON** to create an **On** object in chain mode.
E
add doc  
ester.zhou 已提交
123

E
ester.zhou 已提交
124
```js
E
esterzhou 已提交
125
ON.text('123').type('button');
E
add doc  
ester.zhou 已提交
126 127
```

E
esterzhou 已提交
128
### text<sup>9+</sup>
E
add doc  
ester.zhou 已提交
129

E
esterzhou 已提交
130
text(txt: string, pattern?: MatchPattern): On
E
add doc  
ester.zhou 已提交
131

E
esterzhou 已提交
132
Specifies the text attribute of the target component. Multiple match patterns are supported.
E
add doc  
ester.zhou 已提交
133 134 135 136 137

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
138 139 140 141
| Name | Type                         | Mandatory| Description                                               |
| ------- | ----------------------------- | ---- | --------------------------------------------------- |
| txt     | string                        | Yes  | Component text, used to match the target component.               |
| pattern | [MatchPattern](#matchpattern) | No  | Match pattern. The default value is [EQUALS](#matchpattern).|
E
add doc  
ester.zhou 已提交
142 143 144

**Return value**

E
esterzhou 已提交
145 146 147
| Type      | Description                              |
| ---------- | ---------------------------------- |
| [On](#on9) | **On** object that matches the text attribute of the target component.|
E
add doc  
ester.zhou 已提交
148 149 150

**Example**

E
ester.zhou 已提交
151
```js
E
esterzhou 已提交
152
let on = ON.text('123'); // Use the static constructor ON to create an On object and specify the text attribute of the target component.
E
add doc  
ester.zhou 已提交
153 154 155
```


E
esterzhou 已提交
156
### id<sup>9+</sup>
E
add doc  
ester.zhou 已提交
157

E
esterzhou 已提交
158
id(id: string): On
E
add doc  
ester.zhou 已提交
159

E
ester.zhou 已提交
160
Specifies the ID attribute of the target component.
E
add doc  
ester.zhou 已提交
161 162 163 164 165

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
ester.zhou 已提交
166 167
| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
E
esterzhou 已提交
168
| id     | string | Yes  | Component ID.|
E
add doc  
ester.zhou 已提交
169 170 171

**Return value**

E
esterzhou 已提交
172 173 174
| Type      | Description                            |
| ---------- | -------------------------------- |
| [On](#on9) | **On** object that matches the ID attribute of the target component.|
E
add doc  
ester.zhou 已提交
175 176 177

**Example**

E
ester.zhou 已提交
178
```js
E
esterzhou 已提交
179
let on = ON.id('123'); // Use the static constructor ON to create an On object and specify the ID attribute of the target component.
E
add doc  
ester.zhou 已提交
180 181 182
```


E
esterzhou 已提交
183
### type<sup>9+</sup>
E
add doc  
ester.zhou 已提交
184

E
esterzhou 已提交
185
type(tp: string): On
E
add doc  
ester.zhou 已提交
186

E
ester.zhou 已提交
187
Specifies the type attribute of the target component.
E
add doc  
ester.zhou 已提交
188 189 190 191 192

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
ester.zhou 已提交
193 194
| Name| Type  | Mandatory| Description          |
| ------ | ------ | ---- | -------------- |
E
add doc  
ester.zhou 已提交
195 196 197 198
| tp     | string | Yes  | Component type.|

**Return value**

E
esterzhou 已提交
199 200 201
| Type      | Description                                    |
| ---------- | ---------------------------------------- |
| [On](#on9) | **On** object that matches the type attribute of the target component.|
E
add doc  
ester.zhou 已提交
202 203 204

**Example**

E
ester.zhou 已提交
205
```js
E
esterzhou 已提交
206
let on = ON.type('button'); // Use the static constructor ON to create an On object and specify the type attribute of the target component.
E
add doc  
ester.zhou 已提交
207 208 209
```


E
esterzhou 已提交
210
### clickable<sup>9+</sup>
E
add doc  
ester.zhou 已提交
211

E
esterzhou 已提交
212
clickable(b?: boolean): On
E
add doc  
ester.zhou 已提交
213

E
esterzhou 已提交
214
Specifies the clickable status attribute of the target component.
E
add doc  
ester.zhou 已提交
215 216 217 218 219

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
220 221 222
| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| b      | boolean | No  | Clickable status of the target component.<br>**true**: clickable.<br>**false**: not clickable.<br> Default value: **true**|
E
add doc  
ester.zhou 已提交
223 224 225

**Return value**

E
esterzhou 已提交
226 227 228
| Type      | Description                                      |
| ---------- | ------------------------------------------ |
| [On](#on9) | **On** object that matches the clickable status attribute of the target component.|
E
add doc  
ester.zhou 已提交
229 230 231

**Example**

E
ester.zhou 已提交
232
```js
E
esterzhou 已提交
233
let on = ON.clickable(true); // Use the static constructor ON to create an On object and specify the clickable status attribute of the target component.
E
add doc  
ester.zhou 已提交
234
```
E
ester.zhou 已提交
235

E
esterzhou 已提交
236
### longClickable<sup>9+</sup>
E
ester.zhou 已提交
237

E
esterzhou 已提交
238
longClickable(b?: boolean): On
E
ester.zhou 已提交
239 240 241 242 243 244 245

Specifies the long-clickable status attribute of the target component.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
246 247 248
| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| b      | boolean | No  | Long-clickable status of the target component.<br>**true**: long-clickable.<br>**false**: not long-clickable.<br> Default value: **true**|
E
ester.zhou 已提交
249 250 251

**Return value**

E
esterzhou 已提交
252 253 254
| Type      | Description                                          |
| ---------- | ---------------------------------------------- |
| [On](#on9) | **On** object that matches the long-clickable status attribute of the target component.|
E
ester.zhou 已提交
255 256 257 258

**Example**

```js
E
esterzhou 已提交
259
let on = ON.longClickable(true); // Use the static constructor ON to create an On object and specify the long-clickable status attribute of the target component.
E
add doc  
ester.zhou 已提交
260 261 262
```


E
esterzhou 已提交
263
### scrollable<sup>9+</sup>
E
add doc  
ester.zhou 已提交
264

E
esterzhou 已提交
265
scrollable(b?: boolean): On
E
add doc  
ester.zhou 已提交
266

E
ester.zhou 已提交
267
Specifies the scrollable status attribute of the target component.
E
add doc  
ester.zhou 已提交
268 269 270 271 272

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
273 274 275
| Name| Type   | Mandatory| Description                                                       |
| ------ | ------- | ---- | ----------------------------------------------------------- |
| b      | boolean | No  | Scrollable status of the target component.<br>**true**: scrollable.<br>**false**: not scrollable.<br> Default value: **true**|
E
add doc  
ester.zhou 已提交
276 277 278

**Return value**

E
esterzhou 已提交
279 280 281
| Type      | Description                                      |
| ---------- | ------------------------------------------ |
| [On](#on9) | **On** object that matches the scrollable status attribute of the target component.|
E
add doc  
ester.zhou 已提交
282 283 284

**Example**

E
ester.zhou 已提交
285
```js
E
esterzhou 已提交
286
let on = ON.scrollable(true); // Use the static constructor ON to create an On object and specify the scrollable status attribute of the target component.
E
add doc  
ester.zhou 已提交
287 288
```

E
esterzhou 已提交
289
### enabled<sup>9+</sup>
E
add doc  
ester.zhou 已提交
290

E
esterzhou 已提交
291
enabled(b?: boolean): On
E
add doc  
ester.zhou 已提交
292

E
ester.zhou 已提交
293
Specifies the enabled status attribute of the target component.
E
add doc  
ester.zhou 已提交
294 295 296 297 298

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
299 300 301
| Name| Type   | Mandatory| Description                                                     |
| ------ | ------- | ---- | --------------------------------------------------------- |
| b      | boolean | No  | Enabled status of the target component.<br>**true**: enabled.<br>**false**: disabled.<br> Default value: **true**|
E
add doc  
ester.zhou 已提交
302 303 304

**Return value**

E
esterzhou 已提交
305 306 307
| Type      | Description                                    |
| ---------- | ---------------------------------------- |
| [On](#on9) | **On** object that matches the enabled status attribute of the target component.|
E
add doc  
ester.zhou 已提交
308 309 310

**Example**

E
ester.zhou 已提交
311
```js
E
esterzhou 已提交
312
let on = ON.enabled(true); // Use the static constructor ON to create an On object and specify the enabled status attribute of the target component.
E
add doc  
ester.zhou 已提交
313 314
```

E
esterzhou 已提交
315
### focused<sup>9+</sup>
E
add doc  
ester.zhou 已提交
316

E
esterzhou 已提交
317
focused(b?: boolean): On
E
add doc  
ester.zhou 已提交
318

E
ester.zhou 已提交
319
Specifies the focused status attribute of the target component.
E
add doc  
ester.zhou 已提交
320 321 322 323 324

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
325 326 327
| Name| Type   | Mandatory| Description                                                 |
| ------ | ------- | ---- | ----------------------------------------------------- |
| b      | boolean | No  | Focused status of the target component.<br>**true**: focused.<br>**false**: not focused.<br> Default value: **true**|
E
add doc  
ester.zhou 已提交
328 329 330

**Return value**

E
esterzhou 已提交
331 332 333
| Type      | Description                                    |
| ---------- | ---------------------------------------- |
| [On](#on9) | **On** object that matches the focused status attribute of the target component.|
E
add doc  
ester.zhou 已提交
334 335 336

**Example**

E
ester.zhou 已提交
337
```js
E
esterzhou 已提交
338
let on = ON.focused(true); // Use the static constructor ON to create an On object and specify the focused status attribute of the target component.
E
add doc  
ester.zhou 已提交
339 340
```

E
esterzhou 已提交
341
### selected<sup>9+</sup>
E
add doc  
ester.zhou 已提交
342

E
esterzhou 已提交
343
selected(b?: boolean): On
E
add doc  
ester.zhou 已提交
344

E
ester.zhou 已提交
345
Specifies the selected status attribute of the target component.
E
add doc  
ester.zhou 已提交
346 347 348 349 350

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
351 352 353
| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| b      | boolean | No  | Selected status of the target component.<br>**true**: selected.<br>**false**: not selected.<br> Default value: **true**|
E
add doc  
ester.zhou 已提交
354 355 356

**Return value**

E
esterzhou 已提交
357 358 359
| Type      | Description                                      |
| ---------- | ------------------------------------------ |
| [On](#on9) | **On** object that matches the selected status attribute of the target component.|
E
ester.zhou 已提交
360 361 362 363

**Example**

```js
E
esterzhou 已提交
364
let on = ON.selected(true); // Use the static constructor ON to create an On object and specify the selected status attribute of the target component.
E
ester.zhou 已提交
365 366
```

E
esterzhou 已提交
367
### checked<sup>9+</sup>
E
ester.zhou 已提交
368

E
esterzhou 已提交
369
checked(b?: boolean): On
E
ester.zhou 已提交
370 371 372 373 374 375 376

Specifies the checked status attribute of the target component.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
377 378 379
| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| b      | boolean | No  | Checked status of the target component.<br>**true**: checked.<br>**false**: not checked.<br> Default value: **false**|
E
ester.zhou 已提交
380 381 382

**Return value**

E
esterzhou 已提交
383 384 385
| Type      | Description                                      |
| ---------- | ------------------------------------------ |
| [On](#on9) | **On** object that matches the checked status attribute of the target component.|
E
add doc  
ester.zhou 已提交
386 387 388

**Example**

E
ester.zhou 已提交
389
```js
E
esterzhou 已提交
390
let on = ON.checked(true); // Use the static constructor ON to create an On object and specify the checked status attribute of the target component.
E
add doc  
ester.zhou 已提交
391
```
E
ester.zhou 已提交
392

E
esterzhou 已提交
393
### checkable<sup>9+</sup>
E
ester.zhou 已提交
394

E
esterzhou 已提交
395
checkable(b?: boolean): On
E
ester.zhou 已提交
396 397 398 399 400 401 402

Specifies the checkable status attribute of the target component.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
403 404 405
| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| b      | boolean | No  | Checkable status of the target component.<br>**true**: checkable.<br>**false**: not checkable.<br> Default value: **false**|
E
ester.zhou 已提交
406 407 408

**Return value**

E
esterzhou 已提交
409 410 411
| Type      | Description                                        |
| ---------- | -------------------------------------------- |
| [On](#on9) | **On** object that matches the checkable status attribute of the target component.|
E
ester.zhou 已提交
412 413 414 415

**Example**

```js
E
esterzhou 已提交
416
let on = ON.checkable(true); // Use the static constructor ON to create an On object and specify the checkable status attribute of the target component.
E
add doc  
ester.zhou 已提交
417 418
```

E
esterzhou 已提交
419
### isBefore<sup>9+</sup>
E
add doc  
ester.zhou 已提交
420

E
esterzhou 已提交
421
isBefore(on: On): On
E
add doc  
ester.zhou 已提交
422 423 424 425 426 427 428

Specifies the attributes of the component before which the target component is located.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
429 430 431
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | Yes  | Attributes of the component before which the target component is located.|
E
add doc  
ester.zhou 已提交
432 433 434

**Return value**

E
esterzhou 已提交
435 436 437
| Type      | Description                                                |
| ---------- | ---------------------------------------------------- |
| [On](#on9) | **On** object.|
E
add doc  
ester.zhou 已提交
438 439 440

**Example**

E
ester.zhou 已提交
441
```js
E
esterzhou 已提交
442
let on = ON.isBefore(ON.text('123')); // Use the static constructor ON to create an On object and specify the attributes of the component before which the target component is located.
E
add doc  
ester.zhou 已提交
443 444
```

E
esterzhou 已提交
445
### isAfter<sup>9+</sup>
E
add doc  
ester.zhou 已提交
446

E
esterzhou 已提交
447
isAfter(on: On): On
E
add doc  
ester.zhou 已提交
448 449 450 451 452 453 454

Specifies the attributes of the component after which the target component is located.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
455 456 457
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | Yes  | Attributes of the component after which the target component is located.|
E
add doc  
ester.zhou 已提交
458 459 460

**Return value**

E
esterzhou 已提交
461 462 463
| Type      | Description                                                |
| ---------- | ---------------------------------------------------- |
| [On](#on9) | **On** object.|
E
add doc  
ester.zhou 已提交
464 465 466

**Example**

E
ester.zhou 已提交
467
```js
E
esterzhou 已提交
468
let on = ON.isAfter(ON.text('123')); // Use the static constructor ON to create an On object and specify the attributes of the component after which the target component is located.
E
add doc  
ester.zhou 已提交
469 470
```

E
esterzhou 已提交
471
## Component<sup>9+</sup>
E
add doc  
ester.zhou 已提交
472

E
esterzhou 已提交
473
In **UiTest** of API version 9, the **Component** class represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection.
E
ester.zhou 已提交
474 475
All APIs provided in this class use a promise to return the result and must be invoked using **await**.

E
esterzhou 已提交
476
### click<sup>9+</sup>
E
add doc  
ester.zhou 已提交
477

E
ester.zhou 已提交
478
click(): Promise\<void>
E
add doc  
ester.zhou 已提交
479 480 481 482 483

Clicks this component.

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
484 485 486 487 488 489 490 491 492
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
add doc  
ester.zhou 已提交
493 494
**Example**

E
ester.zhou 已提交
495
```js
E
ester.zhou 已提交
496
async function demo() {
E
esterzhou 已提交
497 498 499
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    await button.click();
E
ester.zhou 已提交
500
}
E
add doc  
ester.zhou 已提交
501 502
```

E
esterzhou 已提交
503
### doubleClick<sup>9+</sup>
E
add doc  
ester.zhou 已提交
504

E
ester.zhou 已提交
505
doubleClick(): Promise\<void>
E
add doc  
ester.zhou 已提交
506 507 508 509 510

Double-clicks this component.

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
511 512 513 514 515 516 517 518 519
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
add doc  
ester.zhou 已提交
520 521
**Example**

E
ester.zhou 已提交
522
```js
E
ester.zhou 已提交
523
async function demo() {
E
esterzhou 已提交
524 525 526
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    await button.doubleClick();
E
ester.zhou 已提交
527
}
E
add doc  
ester.zhou 已提交
528 529
```

E
esterzhou 已提交
530
### longClick<sup>9+</sup>
E
add doc  
ester.zhou 已提交
531

E
ester.zhou 已提交
532
longClick(): Promise\<void>
E
add doc  
ester.zhou 已提交
533 534 535 536 537

Long-clicks this component.

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
538 539 540 541 542 543 544 545 546
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
add doc  
ester.zhou 已提交
547 548
**Example**

E
ester.zhou 已提交
549
```js
E
ester.zhou 已提交
550
async function demo() {
E
esterzhou 已提交
551 552 553
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    await button.longClick();
E
ester.zhou 已提交
554
}
E
add doc  
ester.zhou 已提交
555 556
```

E
esterzhou 已提交
557
### getId<sup>9+</sup>
E
add doc  
ester.zhou 已提交
558

E
esterzhou 已提交
559
getId(): Promise\<string>
E
add doc  
ester.zhou 已提交
560 561 562 563 564 565 566

Obtains the ID of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
ester.zhou 已提交
567 568
| Type            | Description                           |
| ---------------- | ------------------------------- |
E
esterzhou 已提交
569
| Promise\<string> | Promise used to return the ID of the component.|
E
add doc  
ester.zhou 已提交
570

E
esterzhou 已提交
571
**Error codes**
E
add doc  
ester.zhou 已提交
572

E
esterzhou 已提交
573
For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).
E
add doc  
ester.zhou 已提交
574

E
esterzhou 已提交
575 576 577 578
| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
579 580 581

**Example**

E
ester.zhou 已提交
582
```js
E
ester.zhou 已提交
583
async function demo() {
E
esterzhou 已提交
584 585 586
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let num = await button.getId();
E
ester.zhou 已提交
587
}
E
add doc  
ester.zhou 已提交
588 589
```

E
esterzhou 已提交
590
### getText<sup>9+</sup>
E
add doc  
ester.zhou 已提交
591

E
ester.zhou 已提交
592
getText(): Promise\<string>
E
add doc  
ester.zhou 已提交
593 594 595 596 597 598 599

Obtains the text information of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
ester.zhou 已提交
600 601 602
| Type            | Description                             |
| ---------------- | --------------------------------- |
| Promise\<string> | Promise used to return the text information of the component.|
E
add doc  
ester.zhou 已提交
603

E
esterzhou 已提交
604 605 606 607 608 609 610 611 612
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
add doc  
ester.zhou 已提交
613 614
**Example**

E
ester.zhou 已提交
615
```js
E
ester.zhou 已提交
616
async function demo() {
E
esterzhou 已提交
617 618 619
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let text = await button.getText();
E
ester.zhou 已提交
620
}
E
add doc  
ester.zhou 已提交
621 622
```

E
esterzhou 已提交
623
### getType<sup>9+</sup>
E
add doc  
ester.zhou 已提交
624

E
ester.zhou 已提交
625
getType(): Promise\<string>
E
add doc  
ester.zhou 已提交
626 627 628 629 630 631 632

Obtains the type of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
ester.zhou 已提交
633 634 635
| Type            | Description                         |
| ---------------- | ----------------------------- |
| Promise\<string> | Promise used to return the type of the component.|
E
add doc  
ester.zhou 已提交
636

E
esterzhou 已提交
637 638 639 640 641 642 643 644 645
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
add doc  
ester.zhou 已提交
646 647
**Example**

E
ester.zhou 已提交
648
```js
E
ester.zhou 已提交
649
async function demo() {
E
esterzhou 已提交
650 651 652
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let type = await button.getType();
E
ester.zhou 已提交
653
}
E
add doc  
ester.zhou 已提交
654 655
```

E
esterzhou 已提交
656
### getBounds<sup>9+</sup>
E
ester.zhou 已提交
657 658 659 660 661 662 663 664 665

getBounds(): Promise\<Rect>

Obtains the bounds of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
| Type                    | Description                                 |
| ------------------------ | ------------------------------------- |
| Promise\<[Rect](#rect9)> | Promise used to return the bounds of the component.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let rect = await button.getBounds();
}
```

### getBoundsCenter<sup>9+</sup>

getBoundsCenter(): Promise\<Point>

Obtains the information about the center of the bounding box around this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                      | Description                                           |
| -------------------------- | ----------------------------------------------- |
| Promise\<[Point](#point9)> | Promise used to return the information about the center of the bounding box around the component.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
ester.zhou 已提交
711 712 713 714 715

**Example**

```js
async function demo() {
E
esterzhou 已提交
716 717 718
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let point = await button.getBoundsCenter();
E
ester.zhou 已提交
719 720 721
}
```

E
esterzhou 已提交
722
### isClickable<sup>9+</sup>
E
add doc  
ester.zhou 已提交
723

E
esterzhou 已提交
724
isClickable(): Promise\<boolean>
E
add doc  
ester.zhou 已提交
725 726 727 728 729 730 731

Obtains the clickable status of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
732 733 734 735 736 737 738 739 740 741 742 743
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is clickable, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
744 745 746

**Example**

E
ester.zhou 已提交
747
```js
E
ester.zhou 已提交
748
async function demo() {
E
esterzhou 已提交
749 750
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
E
ester.zhou 已提交
751
    if(await button.isClickable()) {
E
esterzhou 已提交
752 753 754
        console.info('This button can be Clicked');
    } else {
        console.info('This button can not be Clicked');
E
ester.zhou 已提交
755 756
    }
}
E
add doc  
ester.zhou 已提交
757 758
```

E
esterzhou 已提交
759
### isLongClickable<sup>9+</sup>
E
add doc  
ester.zhou 已提交
760

E
esterzhou 已提交
761
isLongClickable(): Promise\<boolean> 
E
add doc  
ester.zhou 已提交
762

E
esterzhou 已提交
763
Obtains the long-clickable status of this component.
E
ester.zhou 已提交
764 765 766 767 768

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
769 770 771 772 773 774 775 776 777 778 779 780
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the long-clickable status of the component. The value **true** means that the component is long-clickable, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
ester.zhou 已提交
781 782 783 784 785

**Example**

```js
async function demo() {
E
esterzhou 已提交
786 787
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
E
ester.zhou 已提交
788
    if(await button.isLongClickable()) {
E
esterzhou 已提交
789 790 791
        console.info('This button can longClick');
    } else {
        console.info('This button can not longClick');
E
ester.zhou 已提交
792 793 794 795
    }
}
```

E
esterzhou 已提交
796
### isChecked<sup>9+</sup>
E
ester.zhou 已提交
797

E
esterzhou 已提交
798
isChecked(): Promise\<boolean>
E
add doc  
ester.zhou 已提交
799

E
ester.zhou 已提交
800
Obtains the checked status of this component.
E
add doc  
ester.zhou 已提交
801 802 803 804 805

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
806 807 808 809 810 811 812 813 814 815 816 817
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the checked status of the component. The value **true** means that the component is checked, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
818 819 820

**Example**

E
ester.zhou 已提交
821 822
```js
async function demo() {
E
esterzhou 已提交
823 824
    let driver = Driver.create();
    let checkBox = await driver.findComponent(ON.type('Checkbox'));
E
ester.zhou 已提交
825
    if(await checkBox.isChecked) {
E
esterzhou 已提交
826 827 828
        console.info('This checkBox is checked');
    } else {
        console.info('This checkBox is not checked');
E
ester.zhou 已提交
829 830
    }
}
E
add doc  
ester.zhou 已提交
831
```
E
ester.zhou 已提交
832

E
esterzhou 已提交
833
### isCheckable<sup>9+</sup>
E
ester.zhou 已提交
834

E
esterzhou 已提交
835
isCheckable(): Promise\<boolean>
E
ester.zhou 已提交
836

E
esterzhou 已提交
837
Obtains the checkable status of this component.
E
ester.zhou 已提交
838 839 840 841 842

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
843 844 845 846 847 848 849 850 851 852 853 854
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the checkable status of the component. The value **true** means that the component is checkable, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
ester.zhou 已提交
855 856 857 858 859

**Example**

```js
async function demo() {
E
esterzhou 已提交
860 861
    let driver = Driver.create();
    let checkBox = await driver.findComponent(ON.type('Checkbox'));
E
ester.zhou 已提交
862
    if(await checkBox.isCheckable) {
E
esterzhou 已提交
863 864 865
        console.info('This checkBox is checkable');
    } else {
        console.info('This checkBox is not checkable');
E
ester.zhou 已提交
866 867 868 869
    }
}
```

E
esterzhou 已提交
870
### isScrollable<sup>9+</sup>
E
ester.zhou 已提交
871

E
esterzhou 已提交
872
isScrollable(): Promise\<boolean>
E
ester.zhou 已提交
873 874 875 876 877 878 879

Obtains the scrollable status of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
880 881 882 883 884 885 886 887 888 889 890 891
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is scrollable, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
ester.zhou 已提交
892 893 894 895

**Example**

```js
E
ester.zhou 已提交
896
async function demo() {
E
esterzhou 已提交
897 898
    let driver = Driver.create();
    let scrollBar = await driver.findComponent(ON.scrollable(true));
E
ester.zhou 已提交
899
    if(await scrollBar.isScrollable()) {
E
esterzhou 已提交
900 901 902
        console.info('This scrollBar can be operated');
    } else {
        console.info('This scrollBar can not be operated');
E
ester.zhou 已提交
903 904
    }
}
E
add doc  
ester.zhou 已提交
905 906 907
```


E
esterzhou 已提交
908
### isEnabled<sup>9+</sup>
E
add doc  
ester.zhou 已提交
909

E
esterzhou 已提交
910
isEnabled(): Promise\<boolean>
E
add doc  
ester.zhou 已提交
911

E
ester.zhou 已提交
912
Obtains the enabled status of this component.
E
add doc  
ester.zhou 已提交
913 914 915 916 917

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
918 919 920 921 922 923 924 925 926 927 928 929
| Type             | Description                                                      |
| ----------------- | ---------------------------------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is enabled, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
930 931 932

**Example**

E
ester.zhou 已提交
933
```js
E
ester.zhou 已提交
934
async function demo() {
E
esterzhou 已提交
935 936
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
E
ester.zhou 已提交
937
    if(await button.isEnabled()) {
E
esterzhou 已提交
938 939 940
        console.info('This button can be operated');
    } else {
        console.info('This button can not be operated');
E
ester.zhou 已提交
941 942 943
    }
}

E
add doc  
ester.zhou 已提交
944 945
```

E
esterzhou 已提交
946
### isFocused<sup>9+</sup>
E
add doc  
ester.zhou 已提交
947

E
esterzhou 已提交
948
isFocused(): Promise\<boolean>
E
add doc  
ester.zhou 已提交
949 950 951 952 953 954 955

Obtains the focused status of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
956 957 958 959 960 961 962 963 964 965 966 967
| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the focused status of the component. The value **true** means that the component is focused, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
968 969 970

**Example**

E
ester.zhou 已提交
971
```js
E
ester.zhou 已提交
972
async function demo() {
E
esterzhou 已提交
973 974
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
E
ester.zhou 已提交
975
    if(await button.isFocused()) {
E
esterzhou 已提交
976 977 978
        console.info('This button is focused');
    } else {
        console.info('This button is not focused');
E
ester.zhou 已提交
979 980
	}
}
E
add doc  
ester.zhou 已提交
981 982
```

E
esterzhou 已提交
983
### isSelected<sup>9+</sup>
E
add doc  
ester.zhou 已提交
984

E
esterzhou 已提交
985
isSelected(): Promise\<boolean>
E
add doc  
ester.zhou 已提交
986 987 988 989 990 991 992

Obtains the selected status of this component.

**System capability**: SystemCapability.Test.UiTest

**Return value**

E
esterzhou 已提交
993 994 995 996 997 998 999 1000 1001 1002 1003 1004
| Type             | Description                                               |
| ----------------- | --------------------------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is selected, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1005 1006 1007

**Example**

E
ester.zhou 已提交
1008
```js
E
ester.zhou 已提交
1009
async function demo() {
E
esterzhou 已提交
1010 1011
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
E
ester.zhou 已提交
1012
    if(await button.isSelected()) {
E
esterzhou 已提交
1013 1014 1015
        console.info('This button is selected');
	} else {
        console.info('This button is not selected');
E
ester.zhou 已提交
1016 1017
    }
}
E
add doc  
ester.zhou 已提交
1018 1019
```

E
esterzhou 已提交
1020
### inputText<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1021

E
ester.zhou 已提交
1022
inputText(text: string): Promise\<void>
E
add doc  
ester.zhou 已提交
1023 1024 1025 1026 1027 1028 1029

Enters text into this component (available for text boxes).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
| Name| Type  | Mandatory| Description                                    |
| ------ | ------ | ---- | ---------------------------------------- |
| text   | string | Yes  | Text to enter, which can contain English and special characters.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1042 1043 1044

**Example**

E
ester.zhou 已提交
1045 1046
```js
async function demo() {
E
esterzhou 已提交
1047 1048 1049
    let driver = Driver.create();
    let text = await driver.findComponent(ON.text('hello world'));
    await text.inputText('123');
E
ester.zhou 已提交
1050
}
E
add doc  
ester.zhou 已提交
1051
```
E
ester.zhou 已提交
1052

E
esterzhou 已提交
1053
### clearText<sup>9+</sup>
E
ester.zhou 已提交
1054 1055 1056

clearText(): Promise\<void>

E
esterzhou 已提交
1057
Clears text in this component. This API is applicable to text boxes.
E
ester.zhou 已提交
1058 1059 1060

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
1061 1062 1063 1064 1065 1066 1067
**Error codes**

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
ester.zhou 已提交
1068 1069 1070
**Example**

```js
E
ester.zhou 已提交
1071
async function demo() {
E
esterzhou 已提交
1072 1073 1074
    let driver = Driver.create();
    let text = await driver.findComponent(ON.text('hello world'));
    await text.clearText();
E
ester.zhou 已提交
1075
}
E
add doc  
ester.zhou 已提交
1076 1077
```

E
esterzhou 已提交
1078
### scrollSearch<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1079

E
esterzhou 已提交
1080
scrollSearch(on: On): Promise\<Component>
E
add doc  
ester.zhou 已提交
1081

E
esterzhou 已提交
1082
Scrolls on this component to search for the target component. This API is applicable to components that support scrolling.
E
add doc  
ester.zhou 已提交
1083 1084 1085 1086 1087

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1088 1089 1090
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | Yes  | Attributes of the target component.|
E
add doc  
ester.zhou 已提交
1091 1092 1093

**Return value**

E
esterzhou 已提交
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
| Type                              | Description                                 |
| ---------------------------------- | ------------------------------------- |
| Promise\<[Component](#component9)> | Promise used to return the target component.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1106 1107 1108

**Example**

E
ester.zhou 已提交
1109
```js
E
ester.zhou 已提交
1110
async function demo() {
E
esterzhou 已提交
1111 1112 1113
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('Scroll'));
    let button = await scrollBar.scrollSearch(ON.text('next page'));
E
ester.zhou 已提交
1114
}
E
add doc  
ester.zhou 已提交
1115 1116
```

E
esterzhou 已提交
1117
### scrollToTop<sup>9+</sup>
E
ester.zhou 已提交
1118

E
esterzhou 已提交
1119
scrollToTop(speed?: number): Promise\<void>
E
ester.zhou 已提交
1120

E
esterzhou 已提交
1121
Scrolls to the top of this component. This API is applicable to components that support scrolling.
E
ester.zhou 已提交
1122 1123 1124

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| speed  | number | No  | Scroll speed, in pixel/s. The value ranges from 200 to 15000. If the set value is not in the range, the default value 600 is used.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
ester.zhou 已提交
1140 1141 1142 1143
**Example**

```js
async function demo() {
E
esterzhou 已提交
1144 1145 1146
    let driver = Driver.create();
    let scrollBar = await driver.findComponent(ON.type('Scroll'));
    await scrollBar.scrollToTop();
E
ester.zhou 已提交
1147 1148 1149
}
```

E
esterzhou 已提交
1150
### scrollToBottom<sup>9+</sup>
E
ester.zhou 已提交
1151

E
esterzhou 已提交
1152
scrollToBottom(speed?: number): Promise\<void>
E
ester.zhou 已提交
1153

E
esterzhou 已提交
1154
Scrolls to the bottom of this component. This API is applicable to components that support scrolling.
E
ester.zhou 已提交
1155 1156 1157

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| speed  | number | No  | Scroll speed, in pixel/s. The value ranges from 200 to 15000. If the set value is not in the range, the default value 600 is used.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

E
ester.zhou 已提交
1173 1174 1175 1176
**Example**

```js
async function demo() {
E
esterzhou 已提交
1177 1178 1179
    let driver = Driver.create();
    let scrollBar = await driver.findComponent(ON.type('Scroll'));
    await scrollBar.scrollToBottom();
E
ester.zhou 已提交
1180 1181 1182
}
```

E
esterzhou 已提交
1183
### dragTo<sup>9+</sup>
E
ester.zhou 已提交
1184

E
esterzhou 已提交
1185
dragTo(target: Component): Promise\<void>
E
ester.zhou 已提交
1186 1187 1188 1189 1190 1191 1192

Drags this component to the target component.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
| Name| Type                    | Mandatory| Description      |
| ------ | ------------------------ | ---- | ---------- |
| target | [Component](#component9) | Yes  | Target component.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
ester.zhou 已提交
1205 1206 1207 1208 1209

**Example**

```js
async function demo() {
E
esterzhou 已提交
1210 1211 1212 1213
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let text = await driver.findComponent(ON.text('hello world'));
    await button.dragTo(text);
E
ester.zhou 已提交
1214 1215 1216
    }
```

E
esterzhou 已提交
1217
### pinchOut<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1218

E
esterzhou 已提交
1219
pinchOut(scale: number): Promise\<void>
E
add doc  
ester.zhou 已提交
1220

E
esterzhou 已提交
1221
Pinches a component to scale it up to the specified ratio.
E
add doc  
ester.zhou 已提交
1222

E
esterzhou 已提交
1223
**System capability**: SystemCapability.Test.UiTest
E
add doc  
ester.zhou 已提交
1224

E
esterzhou 已提交
1225
**Parameters**
E
add doc  
ester.zhou 已提交
1226

E
esterzhou 已提交
1227 1228 1229
| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
| scale  | number | Yes  | Scale factor.|
E
add doc  
ester.zhou 已提交
1230

E
esterzhou 已提交
1231 1232 1233
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).
E
add doc  
ester.zhou 已提交
1234

E
esterzhou 已提交
1235 1236 1237 1238
| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1239 1240 1241

**Example**

E
ester.zhou 已提交
1242
```js
E
ester.zhou 已提交
1243
async function demo() {
E
esterzhou 已提交
1244 1245 1246 1247
    let driver = Driver.create();
    let image = await driver.findComponent(ON.type('image'));
    await image.pinchOut(1.5);
    }
E
add doc  
ester.zhou 已提交
1248 1249
```

E
esterzhou 已提交
1250
### pinchIn<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1251

E
esterzhou 已提交
1252
pinchIn(scale: number): Promise\<void>
E
add doc  
ester.zhou 已提交
1253

E
esterzhou 已提交
1254
Pinches a component to scale it down to the specified ratio.
E
add doc  
ester.zhou 已提交
1255 1256 1257 1258 1259

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
| scale  | number | Yes  | Scale factor.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
E
add doc  
ester.zhou 已提交
1272 1273 1274

**Example**

E
ester.zhou 已提交
1275
```js
E
ester.zhou 已提交
1276
async function demo() {
E
esterzhou 已提交
1277 1278 1279 1280
    let driver = Driver.create();
    let image = await driver.findComponent(ON.type('image'));
    await image.pinchIn(0.5);
    }
E
add doc  
ester.zhou 已提交
1281 1282
```

E
esterzhou 已提交
1283
## Driver<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1284

E
esterzhou 已提交
1285 1286
The **Driver** class is the main entry to the UiTest framework. It provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot.
All APIs provided by this class, except for **Driver.create()**, use a promise to return the result and must be invoked using **await**.
E
add doc  
ester.zhou 已提交
1287

E
esterzhou 已提交
1288
### create<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1289

E
esterzhou 已提交
1290
static create(): Driver
E
add doc  
ester.zhou 已提交
1291

E
esterzhou 已提交
1292
Creates a **Driver** object and returns the object created. This API is a static API.
E
add doc  
ester.zhou 已提交
1293

E
esterzhou 已提交
1294
**System capability**: SystemCapability.Test.UiTest
E
add doc  
ester.zhou 已提交
1295 1296 1297

**Return value**

E
esterzhou 已提交
1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
| Type| Description          |
| -------- | ---------------------- |
| Driver   | **Driver** object created.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message          |
| -------- | ------------------ |
| 17000001 | Initialize failed. |
E
add doc  
ester.zhou 已提交
1309 1310 1311

**Example**

E
ester.zhou 已提交
1312
```js
E
ester.zhou 已提交
1313
async function demo() {
E
esterzhou 已提交
1314
    let driver = Driver.create();
E
ester.zhou 已提交
1315
}
E
add doc  
ester.zhou 已提交
1316 1317
```

E
esterzhou 已提交
1318
### delayMs<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1319

E
esterzhou 已提交
1320
delayMs(duration: number): Promise\<void>
E
add doc  
ester.zhou 已提交
1321

E
esterzhou 已提交
1322
Delays this **Driver** object within the specified duration.
E
add doc  
ester.zhou 已提交
1323 1324 1325 1326 1327

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1328 1329 1330
| Name  | Type  | Mandatory| Description                  |
| -------- | ------ | ---- | ---------------------- |
| duration | number | Yes  | Duration of time, in ms.|
E
add doc  
ester.zhou 已提交
1331

E
esterzhou 已提交
1332 1333 1334
**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).
E
add doc  
ester.zhou 已提交
1335

E
esterzhou 已提交
1336 1337 1338
| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1339 1340 1341

**Example**

E
ester.zhou 已提交
1342
```js
E
ester.zhou 已提交
1343
async function demo() {
E
esterzhou 已提交
1344 1345
    let driver = Driver.create();
    await driver.delayMs(1000);
E
ester.zhou 已提交
1346
}
E
add doc  
ester.zhou 已提交
1347 1348
```

E
esterzhou 已提交
1349
### findComponent<sup>9+</sup>
E
ester.zhou 已提交
1350

E
esterzhou 已提交
1351
findComponent(on: On): Promise\<Component>
E
ester.zhou 已提交
1352

E
esterzhou 已提交
1353
Searches this **Driver** object for the target component that matches the given attributes.
E
ester.zhou 已提交
1354 1355 1356 1357 1358

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1359 1360 1361
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | Yes  | Attributes of the target component.|
E
ester.zhou 已提交
1362 1363 1364

**Return value**

E
esterzhou 已提交
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
| Type                              | Description                             |
| ---------------------------------- | --------------------------------- |
| Promise\<[Component](#component9)> | Promise used to return the found component.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
ester.zhou 已提交
1376 1377 1378 1379 1380

**Example**

```js
async function demo() {
E
esterzhou 已提交
1381 1382
    let driver = Driver.create();
    let button = await driver.findComponent(ON.text('next page'));
E
ester.zhou 已提交
1383 1384 1385
}
```

E
esterzhou 已提交
1386
### findComponents<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1387

E
esterzhou 已提交
1388
findComponents(on: On): Promise\<Array\<Component>>
E
add doc  
ester.zhou 已提交
1389

E
esterzhou 已提交
1390
Searches this **Driver** object for all components that match the given attributes.
E
add doc  
ester.zhou 已提交
1391 1392 1393 1394 1395

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1396 1397 1398
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | Yes  | Attributes of the target component.|
E
add doc  
ester.zhou 已提交
1399

E
esterzhou 已提交
1400
**Return value**
E
add doc  
ester.zhou 已提交
1401

E
esterzhou 已提交
1402 1403 1404
| Type                                      | Description                                   |
| ------------------------------------------ | --------------------------------------- |
| Promise\<Array\<[Component](#component9)>> | Promise used to return a list of found components.|
E
add doc  
ester.zhou 已提交
1405

E
esterzhou 已提交
1406
**Error codes**
E
add doc  
ester.zhou 已提交
1407

E
esterzhou 已提交
1408
For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).
E
add doc  
ester.zhou 已提交
1409

E
esterzhou 已提交
1410 1411 1412
| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1413 1414 1415

**Example**

E
ester.zhou 已提交
1416
```js
E
ester.zhou 已提交
1417
async function demo() {
E
esterzhou 已提交
1418 1419
    let driver = Driver.create();
    let buttonList = await driver.findComponents(ON.text('next page'));
E
ester.zhou 已提交
1420
}
E
add doc  
ester.zhou 已提交
1421 1422
```

E
esterzhou 已提交
1423
### findWindow<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1424

E
esterzhou 已提交
1425
findWindow(filter: WindowFilter): Promise\<UiWindow>
E
add doc  
ester.zhou 已提交
1426

E
esterzhou 已提交
1427
Searches for the window that matches the specified attributes.
E
add doc  
ester.zhou 已提交
1428 1429 1430 1431 1432

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449
| Name| Type                          | Mandatory| Description            |
| ------ | ------------------------------ | ---- | ---------------- |
| filter | [WindowFilter](#windowfilter9) | Yes  | Attributes of the target window.|

**Return value**

| Type                            | Description                                 |
| -------------------------------- | ------------------------------------- |
| Promise\<[UiWindow](#uiwindow9)> | Promise used to return the target window.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1450 1451 1452

**Example**

E
ester.zhou 已提交
1453
```js
E
ester.zhou 已提交
1454
async function demo() {
E
esterzhou 已提交
1455 1456
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
E
ester.zhou 已提交
1457
}
E
add doc  
ester.zhou 已提交
1458 1459
```

E
esterzhou 已提交
1460
### waitForComponent<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1461

E
esterzhou 已提交
1462
waitForComponent(on: On, time: number): Promise\<Component>
E
add doc  
ester.zhou 已提交
1463

E
esterzhou 已提交
1464
Searches this **Driver** object for the target component that matches the given attributes within the specified duration.
E
add doc  
ester.zhou 已提交
1465 1466 1467 1468 1469

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487
| Name| Type      | Mandatory| Description                            |
| ------ | ---------- | ---- | -------------------------------- |
| On     | [On](#on9) | Yes  | Attributes of the target component.            |
| time   | number     | Yes  | Duration for searching for the target component, in ms.|

**Return value**

| Type                             | Description                             |
| --------------------------------- | --------------------------------- |
| Promise\<[Component](#component)> | Promise used to return the found component.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1488 1489 1490

**Example**

E
ester.zhou 已提交
1491
```js
E
ester.zhou 已提交
1492
async function demo() {
E
esterzhou 已提交
1493 1494
    let driver = Driver.create();
    let button = await driver.waitForComponent(ON.text('next page'),500);
E
ester.zhou 已提交
1495
}
E
add doc  
ester.zhou 已提交
1496 1497
```

E
esterzhou 已提交
1498
### assertComponentExist<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1499

E
esterzhou 已提交
1500
assertComponentExist(on: On): Promise\<void>
E
add doc  
ester.zhou 已提交
1501

E
esterzhou 已提交
1502
Asserts that a component that matches the given attributes exists on the current page.
E
add doc  
ester.zhou 已提交
1503 1504 1505 1506 1507

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
esterzhou 已提交
1508 1509 1510
| Name| Type      | Mandatory| Description                |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | Yes  | Attributes of the target component.|
E
add doc  
ester.zhou 已提交
1511

E
esterzhou 已提交
1512
**Error codes**
E
add doc  
ester.zhou 已提交
1513

E
esterzhou 已提交
1514 1515 1516 1517 1518 1519 1520 1521 1522 1523
For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000003 | Component existence assertion failed.    |

**Example**

```js
E
ester.zhou 已提交
1524
async function demo() {
E
esterzhou 已提交
1525 1526
    let driver = Driver.create();
    await driver.assertComponentExist(ON.text('next page'));
E
ester.zhou 已提交
1527
}
E
add doc  
ester.zhou 已提交
1528 1529
```

E
esterzhou 已提交
1530
### pressBack<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1531

E
esterzhou 已提交
1532
pressBack(): Promise\<void>
E
add doc  
ester.zhou 已提交
1533

E
esterzhou 已提交
1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624
Presses the Back button on this **Driver** object.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.pressBack();
}
```

### triggerKey<sup>9+</sup>

triggerKey(keyCode: number): Promise\<void>

Triggers the key of this **Driver** object that matches the given key code.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type  | Mandatory| Description         |
| ------- | ------ | ---- | ------------- |
| keyCode | number | Yes  | Key code.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.triggerKey(123);
}
```

### triggerCombineKeys<sup>9+</sup>

triggerCombineKeys(key0: number, key1: number, key2?: number): Promise\<void>

Triggers a key combination based on the specified key values. For example, if the value of **Key** is (2072, 2019), the **Driver** object finds and clicks the key combination that matches the value, for example, **Ctrl+C**.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description               |
| ------ | ------ | ---- | ------------------- |
| key0   | number | Yes  | The first key value.|
| key1   | number | Yes  | The second key value.|
| key2   | number | No  | The third key value.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.triggerCombineKeys(2072, 2047, 2035);
}
```


### click<sup>9+</sup>

click(x: number, y: number): Promise\<void>

Clicks a specific point of this **Driver** object based on the given coordinates.
E
add doc  
ester.zhou 已提交
1625 1626 1627 1628 1629

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
ester.zhou 已提交
1630 1631
| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
E
esterzhou 已提交
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1642 1643 1644

**Example**

E
ester.zhou 已提交
1645
```js
E
ester.zhou 已提交
1646
async function demo() {
E
esterzhou 已提交
1647 1648
    let driver = Driver.create();
    await driver.click(100,100);
E
ester.zhou 已提交
1649
}
E
add doc  
ester.zhou 已提交
1650 1651
```

E
esterzhou 已提交
1652
### doubleClick<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1653

E
esterzhou 已提交
1654
doubleClick(x: number, y: number): Promise\<void>
E
add doc  
ester.zhou 已提交
1655

E
esterzhou 已提交
1656
Double-clicks a specific point of this **Driver** object based on the given coordinates.
E
add doc  
ester.zhou 已提交
1657 1658 1659 1660 1661

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
ester.zhou 已提交
1662 1663
| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
E
esterzhou 已提交
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
add doc  
ester.zhou 已提交
1674 1675 1676

**Example**

E
ester.zhou 已提交
1677
```js
E
ester.zhou 已提交
1678
async function demo() {
E
esterzhou 已提交
1679 1680
    let driver = Driver.create();
    await driver.doubleClick(100,100);
E
ester.zhou 已提交
1681
}
E
add doc  
ester.zhou 已提交
1682 1683
```

E
esterzhou 已提交
1684
### longClick<sup>9+</sup>
E
ester.zhou 已提交
1685

E
esterzhou 已提交
1686
longClick(x: number, y: number): Promise\<void>
E
ester.zhou 已提交
1687

E
esterzhou 已提交
1688
Long-clicks a specific point of this **Driver** object based on the given coordinates.
E
ester.zhou 已提交
1689 1690 1691 1692 1693 1694 1695

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
E
esterzhou 已提交
1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
ester.zhou 已提交
1706 1707 1708 1709 1710

**Example**

```js
async function demo() {
E
esterzhou 已提交
1711 1712
    let driver = Driver.create();
    await driver.longClick(100,100);
E
ester.zhou 已提交
1713 1714 1715
}
```

E
esterzhou 已提交
1716
### swipe<sup>9+</sup>
E
add doc  
ester.zhou 已提交
1717

E
esterzhou 已提交
1718
swipe(startx: number, starty: number, endx: number, endy: number, speed?: number): Promise\<void>
E
add doc  
ester.zhou 已提交
1719

E
esterzhou 已提交
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790
Swipes on this **Driver** object from the given start point to the given end point.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| startx | number | Yes  | X-coordinate of the start point.                      |
| starty | number | Yes  | Y-coordinate of the start point.                      |
| endx   | number | Yes  | X-coordinate of the end point.                      |
| endy   | number | Yes  | Y-coordinate of the end point.                      |
| speed  | number | No  | Scroll speed, in pixel/s. The value ranges from 200 to 15000. If the set value is not in the range, the default value 600 is used.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.swipe(100,100,200,200,600);
}
```

### drag<sup>9+</sup>

drag(startx: number, starty: number, endx: number, endy: number, speed?: number): Promise\<void>

Drags this **Driver** object from the given start point to the given end point.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| startx | number | Yes  | X-coordinate of the start point.                      |
| starty | number | Yes  | Y-coordinate of the start point.                      |
| endx   | number | Yes  | X-coordinate of the end point.                      |
| endy   | number | Yes  | Y-coordinate of the end point.                      |
| speed  | number | No  | Scroll speed, in pixel/s. The value ranges from 200 to 15000. If the set value is not in the range, the default value 600 is used.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.drag(100,100,200,200,600);
}
```

### screenCap<sup>9+</sup>

screenCap(savePath: string): Promise\<boolean>

Captures the current screen of this **Driver** object and saves it as a PNG image to the given save path.
E
add doc  
ester.zhou 已提交
1791 1792 1793 1794 1795

**System capability**: SystemCapability.Test.UiTest

**Parameters**

E
ester.zhou 已提交
1796 1797
| Name  | Type  | Mandatory| Description          |
| -------- | ------ | ---- | -------------- |
E
add doc  
ester.zhou 已提交
1798 1799
| savePath | string | Yes  | File save path.|

E
ester.zhou 已提交
1800 1801
**Return value**

E
esterzhou 已提交
1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812
| Type             | Description                                  |
| ----------------- | -------------------------------------- |
| Promise\<boolean> | Promise used to return the operation result. The value **true** means that the operation is successful.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
E
ester.zhou 已提交
1813

E
add doc  
ester.zhou 已提交
1814 1815
**Example**

E
ester.zhou 已提交
1816
```js
E
ester.zhou 已提交
1817
async function demo() {
E
esterzhou 已提交
1818 1819
    let driver = Driver.create();
    await driver.screenCap('/local/tmp/1.png');
E
ester.zhou 已提交
1820
}
E
add doc  
ester.zhou 已提交
1821
```
E
ester.zhou 已提交
1822

E
esterzhou 已提交
1823
### setDisplayRotation<sup>9+</sup>
E
ester.zhou 已提交
1824

E
esterzhou 已提交
1825 1826 1827
setDisplayRotation(rotation: DisplayRotation): Promise\<void>

Sets the display rotation of the device.
E
ester.zhou 已提交
1828 1829 1830

**System capability**: SystemCapability.Test.UiTest

E
esterzhou 已提交
1831 1832 1833 1834 1835 1836 1837 1838 1839
**Parameters**

| Name  | Type                                | Mandatory| Description            |
| -------- | ------------------------------------ | ---- | ---------------- |
| rotation | [DisplayRotation](#displayrotation9) | Yes  | Display rotation of the device.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).
E
ester.zhou 已提交
1840

E
esterzhou 已提交
1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678
| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.setDisplayRotation(DisplayRotation.ROTATION_180);
}
```

### getDisplayRotation<sup>9+</sup>

getDisplayRotation(): Promise\<DisplayRotation>

Obtains the display rotation of the current device.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                                          | Description                                   |
| ---------------------------------------------- | --------------------------------------- |
| Promise\<[DisplayRotation](#displayrotation9)> | Promise used to return the display rotation of the current device.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let rotation = await driver.getDisplayRotation();
}
```

### setDisplayRotationEnabled<sup>9+</sup>

setDisplayRotationEnabled(enabled: boolean): Promise\<void>

Enables or disables display rotation.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type   | Mandatory| Description                                                   |
| ------- | ------- | ---- | ------------------------------------------------------- |
| enabled | boolean | Yes  | Whether to enable display rotation. The value **true** means to enable display rotation, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.setDisplayRotationEnabled(false);
}
```

### getDisplaySize<sup>9+</sup>

getDisplaySize(): Promise\<Point>

Obtains the display size of the current device.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                      | Description                                   |
| -------------------------- | --------------------------------------- |
| Promise\<[Point](#point9)> | Promise used to return the display size of the current device.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let size = await driver.getDisplaySize();
}
```

### getDisplayDensity<sup>9+</sup>

getDisplayDensity(): Promise\<Point>

Obtains the display density of the current device.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                      | Description                                     |
| -------------------------- | ----------------------------------------- |
| Promise\<[Point](#point9)> | Promise used to return the display density of the current device.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let density = await driver.getDisplayDensity();
}
```

### wakeUpDisplay<sup>9+</sup>

wakeUpDisplay(): Promise\<void>

Wakes up the device display.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.wakeUpDisplay();
}
```

### pressHome<sup>9+</sup>

pressHome(): Promise\<void>

Returns to the home screen.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.pressHome();
}
```

### waitForIdle<sup>9+</sup>

waitForIdle(idleTime: number, timeout: number): Promise\<boolean>

Checks whether all components on the current page are idle.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name  | Type  | Mandatory| Description                                                        |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| idleTime | number | Yes  | Idle time threshold, in milliseconds. If the duration for which a component remains inactive reaches this threshold, it is considered as idle.|
| timeout  | number | Yes  | Maximum idle waiting time, in milliseconds.                            |

**Return value**

| Type             | Description                                               |
| ----------------- | --------------------------------------------------- |
| Promise\<boolean> | Promise used to return the result.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let idled = await driver.waitForIdle(4000,5000);
}
```

### fling<sup>9+</sup>

fling(from: Point, to: Point, stepLen: number, speed: number): Promise\<void>

Simulates a fling operation on the screen.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type            | Mandatory| Description                                                        |
| ------- | ---------------- | ---- | ------------------------------------------------------------ |
| from    | [Point](#point9) | Yes  | Coordinates of the point where the finger touches the screen.                                  |
| to      | [Point](#point9) | Yes  | Coordinates of the point where the finger leaves the screen.                                    |
| stepLen | number           | Yes  | Fling step length, in pixels.                                    |
| speed   | number           | Yes  | Scroll speed, in pixel/s. The value ranges from 200 to 15000. If the set value is not in the range, the default value 600 is used.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    await driver.fling({X: 500, Y: 480},{X: 450, Y: 480},5,600);
}
```

### injectMultiPointerAction<sup>9+</sup>

injectMultiPointerAction(pointers: PointerMatrix, speed?: number): Promise\<boolean>

Injects a multi-touch operation to the device.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name  | Type                            | Mandatory| Description                                                        |
| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
| pointers | [PointerMatrix](#pointermatrix9) | Yes  | Scroll trajectory, including the number of fingers and an array of coordinates along the trajectory.                  |
| speed    | number                           | No  | Scroll speed, in pixel/s. The value ranges from 200 to 15000. If the set value is not in the range, the default value 600 is used.|

**Return value**

| Type             | Description                                 |
| ----------------- | ------------------------------------- |
| Promise\<boolean> | Promise used to return the result.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let pointers = PointerMatrix.create(2,3);
    pointers.setPoint(0,0,{X:230,Y:480});
    pointers.setPoint(0,1,{X:250,Y:380});
    pointers.setPoint(0,2,{X:270,Y:280});
    pointers.setPoint(1,0,{X:230,Y:680});
    pointers.setPoint(1,1,{X:240,Y:580});
    pointers.setPoint(1,2,{X:250,Y:480});
    await driver.injectMultiPointerAction(pointers);
}
```

## PointerMatrix<sup>9+</sup>

Implements a **PointerMatrix** object that stores coordinates and behaviors of each action of each finger in a multi-touch operation.

### create<sup>9+</sup>

static create(fingers: number, steps: number): PointerMatrix

Creates a **PointerMatrix** object and returns the object created. This API is a static API.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type  | Mandatory| Description                                      |
| ------- | ------ | ---- | ------------------------------------------ |
| fingers | number | Yes  | Number of fingers in the multi-touch operation. Value range: [1,10].|
| steps   | number | Yes  | Number of steps operated by each finger. Value range: [1,1000].|

**Return value**

| Type                            | Description                         |
| -------------------------------- | ----------------------------- |
| [PointerMatrix](#pointermatrix9) | **PointerMatrix** object created.|

**Example**

```js
async function demo() {
    let pointerMatrix = PointerMatrix.create(2,3);
}
```

### setPoint<sup>9+</sup>

setPoint(finger: number, step: number, point: Point): void

Sets the coordinates for the action corresponding to the specified finger and step in the **PointerMatrix** object.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type            | Mandatory| Description            |
| ------ | ---------------- | ---- | ---------------- |
| finger | number           | Yes  | Sequence number of the finger.    |
| step   | number           | Yes  | Sequence number of the step.    |
| point  | [Point](#point9) | Yes  | Coordinates of the action.|

**Example**

```js
async function demo() {
    let pointers = PointerMatrix.create(2,3);
    pointers.setPoint(0,0,{X:230,Y:480});
    pointers.setPoint(0,1,{X:250,Y:380});
    pointers.setPoint(0,2,{X:270,Y:280});
    pointers.setPoint(1,0,{X:230,Y:680});
    pointers.setPoint(1,1,{X:240,Y:580});
    pointers.setPoint(1,2,{X:250,Y:480});
}
```

## UiWindow<sup>9+</sup>

The **UiWindow** class represents a window on the UI and provides APIs for obtaining window attributes, dragging a window, and adjusting the window size.
All APIs provided in this class use a promise to return the result and must be invoked using **await**.

### getBundleName<sup>9+</sup>

getBundleName(): Promise\<string>

Obtains the bundle name of the application to which this window belongs.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                                     |
| ---------------- | ----------------------------------------- |
| Promise\<string> | Promise used to return the bundle name.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let name = await window.getBundleName();
}
```

### getBounds<sup>9+</sup>

getBounds(): Promise\<Rect>

Obtains the bounds information of this window.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                    | Description                             |
| ------------------------ | --------------------------------- |
| Promise\<[Rect](#rect9)> | Promise used to return the bounds information of the window.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let rect = await window.getBounds();
}
```

### getTitle<sup>9+</sup>

getTitle(): Promise\<string>

Obtains the title of this window.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                             |
| ---------------- | --------------------------------- |
| Promise\<string> | Promise used to return the title of the window.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let rect = await window.getTitle();
}
```

### getWindowMode<sup>9+</sup>

getWindowMode(): Promise\<WindowMode>

Obtains the window mode of this window.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type                                | Description                                 |
| ------------------------------------ | ------------------------------------- |
| Promise\<[WindowMode](#windowmode9)> | Promise used to return the window mode of the window.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let mode = await window.getWindowMode();
}
```

### isFocused<sup>9+</sup>

isFocused(): Promise\<boolean>

Checks whether this window is in focused state.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the window is in focused state, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let focused = await window.isFocused();
}
```

### isActived<sup>9+</sup>

isActived(): Promise\<boolean>

Checks whether this window is active.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the window is active, and **false** means the opposite.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let focused = await window.isActived();
}
```

### focus<sup>9+</sup>

focus(): Promise\<void>

Moves the focus to this window.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.focus();
}
```

### moveTo<sup>9+</sup>

moveTo(x: number, y: number): Promise\<void>

Moves this window to the target point. This API is applicable to moveable windows.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.moveTo(100, 100);
}
```

### resize<sup>9+</sup>

resize(wide: number, height: number, direction: ResizeDirection): Promise\<void>

Resizes this window based on the specified width, height, and resize direction. This API is applicable to resizable windows.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name   | Type                                | Mandatory| Description                                                        |
| --------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| wide      | number                               | Yes  | Target width.                        |
| height    | number                               | Yes  | Target height.                        |
| direction | [ResizeDirection](#resizedirection9) | Yes  | Resize direction.|

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.resize(100, 100, ResizeDirection.LEFT);
}
```

### split<sup>9+</sup>

split(): Promise\<void>

Switches the window to split-screen mode. This API is applicable to windows that support screen splitting.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                                |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.split();
}
```

### maximize<sup>9+</sup>

maximize(): Promise\<void>

Maximizes this window. This API is applicable to windows that can be maximized.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.maximize();
}
```

### minimize<sup>9+</sup>

minimize(): Promise\<void>

Minimizes this window. This API is applicable to windows that can be minimized.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.minimize();
}
```

### resume<sup>9+</sup>

resume(): Promise\<void>

Restores this window to the previous window mode.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.resume();
}
```

### close<sup>9+</sup>

close(): Promise\<void>

Closes this window.

**System capability**: SystemCapability.Test.UiTest

**Error codes**

For details about the error codes, see [UiTest Error Codes](../errorcodes/errorcode-uitest.md).

| ID| Error Message                              |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |

**Example**

```js
async function demo() {
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.close();
}
```

## By<sup>(deprecated)</sup>

The UiTest framework provides a wide range of UI component feature description APIs in the **By** class to filter and match components.
The API capabilities provided by the **By** class exhibit the following features: <br>1. Allow one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component. <br>2. Provide multiple match patterns for component attributes. <br>3. Support absolute positioning and relative positioning for components. APIs such as [By.isBefore<sup>(deprecated)</sup>](#isbeforedeprecated) and [By.isAfter<sup>(deprecated)</sup>](#isafterdeprecated) can be used to specify the features of adjacent components to assist positioning. <br>All APIs provided in the **By** class are synchronous. You are advised to use the static constructor **BY** to create a **By** object in chain mode.

This API is deprecated since API version 9. You are advised to use [On<sup>9+</sup>](#on9) instead.

```js
BY.text('123').type('button');
```

### text<sup>(deprecated)</sup>

text(txt: string, pattern?: MatchPattern): By

Specifies the text attribute of the target component. Multiple match patterns are supported.

This API is deprecated since API version 9. You are advised to use [text<sup>9+</sup>](#text9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type                         | Mandatory| Description                                               |
| ------- | ----------------------------- | ---- | --------------------------------------------------- |
| txt     | string                        | Yes  | Component text, used to match the target component.               |
| pattern | [MatchPattern](#matchpattern) | No  | Match pattern. The default value is [EQUALS](#matchpattern).|

**Return value**

| Type               | Description                              |
| ------------------- | ---------------------------------- |
| [By](#bydeprecated) | **By** object that matches the text attribute of the target component.|

**Example**

```js
let by = BY.text('123'); // Use the static constructor BY to create a By object and specify the text attribute of the target component.
```


### key<sup>(deprecated)</sup>

key(key: string): By

Specifies the key attribute of the target component.

This API is deprecated since API version 9. You are advised to use [id<sup>9+</sup>](#id9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description             |
| ------ | ------ | ---- | ----------------- |
| key    | string | Yes  | Component key.|

**Return value**

| Type               | Description                               |
| ------------------- | ----------------------------------- |
| [By](#bydeprecated) | **By** object that matches the key attribute of the target component.|

**Example**

```js
let by = BY.key('123'); // Use the static constructor BY to create a By object and specify the key attribute of the target component.
```


### id<sup>(deprecated)</sup>

id(id: number): By

Specifies the ID attribute of the target component.

This API is deprecated since API version 9.

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
| id     | number | Yes  | Component ID.|

**Return value**

| Type               | Description                            |
| ------------------- | -------------------------------- |
| [By](#bydeprecated) | **By** object that matches the ID attribute of the target component.|

**Example**

```js
let by = BY.id(123); // Use the static constructor BY to create a By object and specify the ID attribute of the target component.
```


### type<sup>(deprecated)</sup>

type(tp: string): By

Specifies the type attribute of the target component.

This API is deprecated since API version 9. You are advised to use [type<sup>9+</sup>](#type9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description          |
| ------ | ------ | ---- | -------------- |
| tp     | string | Yes  | Component type.|

**Return value**

| Type               | Description                                    |
| ------------------- | ---------------------------------------- |
| [By](#bydeprecated) | **By** object that matches the type attribute of the target component.|

**Example**

```js
let by = BY.type('button'); // Use the static constructor BY to create a By object and specify the type attribute of the target component.
```


### clickable<sup>(deprecated)</sup>

clickable(b?: boolean): By

Specifies the clickable status attribute of the target component.

This API is deprecated since API version 9. You are advised to use [clickable<sup>9+</sup>](#clickable9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| b      | boolean | No  | Clickable status of the target component.<br>**true**: clickable.<br>**false**: not clickable.<br> Default value: **true**|

**Return value**

| Type               | Description                                      |
| ------------------- | ------------------------------------------ |
| [By](#bydeprecated) | **By** object that matches the clickable status attribute of the target component.|

**Example**

```js
let by = BY.clickable(true); // Use the static constructor BY to create a By object and specify the clickable status attribute of the target component.
```


### scrollable<sup>(deprecated)</sup>

scrollable(b?: boolean): By

Specifies the scrollable status attribute of the target component.

This API is deprecated since API version 9. You are advised to use [scrollable<sup>9+</sup>](#scrollable9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type   | Mandatory| Description                                                       |
| ------ | ------- | ---- | ----------------------------------------------------------- |
| b      | boolean | No  | Scrollable status of the target component.<br>**true**: scrollable.<br>**false**: not scrollable.<br> Default value: **true**|

**Return value**

| Type               | Description                                      |
| ------------------- | ------------------------------------------ |
| [By](#bydeprecated) | **By** object that matches the scrollable status attribute of the target component.|

**Example**

```js
let by = BY.scrollable(true); // Use the static constructor BY to create a By object and specify the scrollable status attribute of the target component.
```

### enabled<sup>(deprecated)</sup>

enabled(b?: boolean): By

Specifies the enabled status attribute of the target component.

This API is deprecated since API version 9. You are advised to use [enabled<sup>9+</sup>](#enabled9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type   | Mandatory| Description                                                     |
| ------ | ------- | ---- | --------------------------------------------------------- |
| b      | boolean | No  | Enabled status of the target component.<br>**true**: enabled.<br>**false**: not disabled.<br> Default value: **true**|

**Return value**

| Type               | Description                                    |
| ------------------- | ---------------------------------------- |
| [By](#bydeprecated) | **By** object that matches the enabled status attribute of the target component.|

**Example**

```js
let by = BY.enabled(true); // Use the static constructor BY to create a By object and specify the enabled status attribute of the target component.
```

### focused<sup>(deprecated)</sup>

focused(b?: boolean): By

Specifies the focused status attribute of the target component.

This API is deprecated since API version 9. You are advised to use [focused<sup>9+</sup>](#focused9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type   | Mandatory| Description                                                 |
| ------ | ------- | ---- | ----------------------------------------------------- |
| b      | boolean | No  | Focused status of the target component.<br>**true**: focused.<br>**false**: not focused.<br> Default value: **true**|

**Return value**

| Type               | Description                                    |
| ------------------- | ---------------------------------------- |
| [By](#bydeprecated) | **By** object that matches the focused status attribute of the target component.|

**Example**

```js
let by = BY.focused(true); // Use the static constructor BY to create a By object and specify the focused status attribute of the target component.
```

### selected<sup>(deprecated)</sup>

selected(b?: boolean): By

Specifies the selected status of the target component.

This API is deprecated since API version 9. You are advised to use [selected<sup>9+</sup>](#selected9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type   | Mandatory| Description                                                        |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| b      | boolean | No  | Selected status of the target component.<br>**true**: selected.<br>**false**: not selected.<br> Default value: **true**|

**Return value**

| Type               | Description                                      |
| ------------------- | ------------------------------------------ |
| [By](#bydeprecated) | **By** object that matches the selected status attribute of the target component.|

**Example**

```js
let by = BY.selected(true); // Use the static constructor BY to create a By object and specify the selected status attribute of the target component.
```

### isBefore<sup>(deprecated)</sup>

isBefore(by: By): By

Specifies the attributes of the component before which the target component is located.

This API is deprecated since API version 9. You are advised to use [isBefore<sup>9+</sup>](#isbefore9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description            |
| ------ | ------------------- | ---- | ---------------- |
| by     | [By](#bydeprecated) | Yes  | Attributes of the component before which the target component is located.|

**Return value**

| Type               | Description                                                |
| ------------------- | ---------------------------------------------------- |
| [By](#bydeprecated) | **By** object.|

**Example**

```js
let by = BY.isBefore(BY.text('123')); // Use the static constructor BY to create a By object and specify the attributes of the component before which the target component is located.
```

### isAfter<sup>(deprecated)</sup>

isAfter(by: By): By

Specifies the attributes of the component after which the target component is located.

This API is deprecated since API version 9. You are advised to use [isAfter<sup>9+</sup>](#isafter9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description            |
| ------ | ------------------- | ---- | ---------------- |
| by     | [By](#bydeprecated) | Yes  | Attributes of the component before which the target component is located.|

**Return value**

| Type               | Description                                                |
| ------------------- | ---------------------------------------------------- |
| [By](#bydeprecated) | **By** object.|

**Example**

```js
let by = BY.isAfter(BY.text('123')); // Use the static constructor BY to create a By object and specify the attributes of the component after which the target component is located.
```

## UiComponent<sup>(deprecated)</sup>

In **UiTest**, the **UiComponent** class represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection.
All APIs provided in this class use a promise to return the result and must be invoked using **await**.

This API is deprecated since API version 9. You are advised to use [Component<sup>9+</sup>](#component9) instead.

### click<sup>(deprecated)</sup>

click(): Promise\<void>

Clicks this component.

This API is deprecated since API version 9. You are advised to use [click<sup>9+</sup>](#click9).

**System capability**: SystemCapability.Test.UiTest

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    await button.click();
}
```

### doubleClick<sup>(deprecated)</sup>

doubleClick(): Promise\<void>

Double-clicks this component.

This API is deprecated since API version 9. You are advised to use [doubleClick<sup>9+</sup>](#doubleclick9).

**System capability**: SystemCapability.Test.UiTest

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    await button.doubleClick();
}
```

### longClick<sup>(deprecated)</sup>

longClick(): Promise\<void>

Long-clicks this component.

This API is deprecated since API version 9. You are advised to use [longClick<sup>9+</sup>](#longclick9).

**System capability**: SystemCapability.Test.UiTest

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    await button.longClick();
}
```

### getId<sup>(deprecated)</sup>

getId(): Promise\<number>

Obtains the ID of this component.

This API is deprecated since API version 9.

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                           |
| ---------------- | ------------------------------- |
| Promise\<number> | Promise used to return the ID of the component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let num = await button.getId();
}
```

### getKey<sup>(deprecated)</sup>

getKey(): Promise\<string>

Obtains the key of this component.

This API is deprecated since API version 9. You are advised to use [getId<sup>9+</sup>](#getid9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                          |
| ---------------- | ------------------------------ |
| Promise\<string> | Promise used to return the key of the component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let str_key = await button.getKey();
}
```

### getText<sup>(deprecated)</sup>

getText(): Promise\<string>

Obtains the text information of this component.

This API is deprecated since API version 9. You are advised to use [getText<sup>9+</sup>](#gettext9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                             |
| ---------------- | --------------------------------- |
| Promise\<string> | Promise used to return the text information of the component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let text = await button.getText();
}
```

### getType<sup>(deprecated)</sup>

getType(): Promise\<string>

Obtains the type of this component.

This API is deprecated since API version 9. You are advised to use [getType<sup>9+</sup>](#gettype9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type            | Description                         |
| ---------------- | ----------------------------- |
| Promise\<string> | Promise used to return the type of the component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let type = await button.getType();
}
```

### isClickable<sup>(deprecated)</sup>

isClickable(): Promise\<boolean>

Obtains the clickable status of this component.

This API is deprecated since API version 9. You are advised to use [isClickable<sup>9+</sup>](#isclickable9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is clickable, and **false** means the opposite.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    if(await button.isClickable()) {
        console.info('This button can be Clicked');
    } else {
        console.info('This button can not be Clicked');
    }
}
```

### isScrollable<sup>(deprecated)</sup>

isScrollable(): Promise\<boolean>

Obtains the scrollable status of this component.

This API is deprecated since API version 9. You are advised to use [isScrollable<sup>9+</sup>](#isscrollable9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is scrollable, and **false** means the opposite.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let scrollBar = await driver.findComponent(BY.scrollable(true));
    if(await scrollBar.isScrollable()) {
        console.info('This scrollBar can be operated');
    } else {
        console.info('This scrollBar can not be operated');
    }
}
```


### isEnabled<sup>(deprecated)</sup>

isEnabled(): Promise\<boolean>

Obtains the enabled status of this component.

This API is deprecated since API version 9. You are advised to use [isEnabled<sup>9+</sup>](#isenabled9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                      |
| ----------------- | ---------------------------------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is enabled, and **false** means the opposite.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    if(await button.isEnabled()) {
        console.info('This button can be operated');
    } else {
        console.info('This button can not be operated');
    }
}

```

### isFocused<sup>(deprecated)</sup>

isFocused(): Promise\<boolean>

Obtains the focused status of this component.

This API is deprecated since API version 9. You are advised to use [isFocused<sup>9+</sup>](#isfocused9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the target component is focused, and **false** means the opposite.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    if(await button.isFocused()) {
        console.info('This button is focused');
    } else {
        console.info('This button is not focused');
	}
}
```

### isSelected<sup>(deprecated)</sup>

isSelected(): Promise\<boolean>

Obtains the selected status of this component.

This API is deprecated since API version 9. You are advised to use [isSelected<sup>9+</sup>](#isselected9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type             | Description                                                 |
| ----------------- | ----------------------------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is selected, and **false** means the opposite.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    if(await button.isSelected()) {
        console.info('This button is selected');
    } else {
        console.info('This button is not selected');
    }
}
```

### inputText<sup>(deprecated)</sup>

inputText(text: string): Promise\<void>

Enters text into this component (available for text boxes).

This API is deprecated since API version 9. You are advised to use [inputText<sup>9+</sup>](#inputtext9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description            |
| ------ | ------ | ---- | ---------------- |
| text   | string | Yes  | Text to enter.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let text = await driver.findComponent(BY.text('hello world'));
    await text.inputText('123');
}
```

### scrollSearch<sup>(deprecated)</sup>

scrollSearch(by: By): Promise\<UiComponent>

Scrolls on this component to search for the target component (applicable to components that support scrolling, such as **\<List>**).

This API is deprecated since API version 9. You are advised to use [scrollSearch<sup>9+</sup>](#scrollsearch9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description                |
| ------ | ------------------- | ---- | -------------------- |
| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|

**Return value**

| Type                                           | Description                                 |
| ----------------------------------------------- | ------------------------------------- |
| Promise\<[UiComponent](#uicomponentdeprecated)> | Promise used to return the target component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let scrollBar = await driver.findComponent(BY.type('Scroll'));
    let button = await scrollBar.scrollSearch(BY.text('next page'));
}
```

## UiDriver<sup>(deprecated)</sup>

The **UiDriver** class is the main entry to the UiTest framework. It provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot.
All APIs provided by this class, except for **UiDriver.create()**, use a promise to return the result and must be invoked using **await**.

This API is deprecated since API version 9. You are advised to use [Driver<sup>9+</sup>](#driver9) instead.

### create<sup>(deprecated)</sup>

static create(): UiDriver

Creates a **UiDriver** object and returns the object created. This API is a static API.

This API is deprecated since API version 9. You are advised to use [create<sup>9+</sup>](#create9).

**System capability**: SystemCapability.Test.UiTest

**Return value**

| Type    | Description                    |
| -------- | ------------------------ |
| UiDriver | Returns the **UiDriver** object created.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
}
```

### delayMs<sup>(deprecated)</sup>

delayMs(duration: number): Promise\<void>

Delays this **UiDriver** object within the specified duration.

This API is deprecated since API version 9. You are advised to use [delayMs<sup>9+</sup>](#delayms9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name  | Type  | Mandatory| Description        |
| -------- | ------ | ---- | ------------ |
| duration | number | Yes  | Duration of time.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.delayMs(1000);
}
```

### findComponent<sup>(deprecated)</sup>

findComponent(by: By): Promise\<UiComponent>

Searches this **UiDriver** object for the target component that matches the given attributes.

This API is deprecated since API version 9. You are advised to use [findComponent<sup>9+</sup>](#findcomponent9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description                |
| ------ | ------------------- | ---- | -------------------- |
| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|

**Return value**

| Type                                           | Description                             |
| ----------------------------------------------- | --------------------------------- |
| Promise\<[UiComponent](#uicomponentdeprecated)> | Promise used to return the found component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.text('next page'));
}
```

### findComponents<sup>(deprecated)</sup>

findComponents(by: By): Promise\<Array\<UiComponent>>

Searches this **UiDriver** object for all components that match the given attributes.

This API is deprecated since API version 9. You are advised to use [findComponents<sup>9+</sup>](#findcomponents9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description                |
| ------ | ------------------- | ---- | -------------------- |
| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|

**Return value**

| Type                                                   | Description                                   |
| ------------------------------------------------------- | --------------------------------------- |
| Promise\<Array\<[UiComponent](#uicomponentdeprecated)>> | Promise used to return a list of found components.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    let buttonList = await driver.findComponents(BY.text('next page'));
}
```

### assertComponentExist<sup>(deprecated)</sup>

assertComponentExist(by: By): Promise\<void>

Asserts that a component that matches the given attributes exists on the current page. If the component does not exist, the API throws a JS exception, causing the current test case to fail.

This API is deprecated since API version 9. You are advised to use [assertComponentExist<sup>9+</sup>](#assertcomponentexist9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type               | Mandatory| Description                |
| ------ | ------------------- | ---- | -------------------- |
| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.assertComponentExist(BY.text('next page'));
}
```

### pressBack<sup>(deprecated)</sup>

pressBack(): Promise\<void>

Presses the Back button on this **UiDriver** object.

This API is deprecated since API version 9. You are advised to use [pressBack<sup>9+</sup>](#pressback9).

**System capability**: SystemCapability.Test.UiTest

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.pressBack();
}
```

### triggerKey<sup>(deprecated)</sup>

triggerKey(keyCode: number): Promise\<void>

Triggers the key of this **UiDriver** object that matches the given key code.

This API is deprecated since API version 9. You are advised to use [triggerKey<sup>9+</sup>](#triggerkey9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name | Type  | Mandatory| Description         |
| ------- | ------ | ---- | ------------- |
| keyCode | number | Yes  | Key code.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.triggerKey(123);
}
```


### click<sup>(deprecated)</sup>

click(x: number, y: number): Promise\<void>

Clicks a specific point of this **UiDriver** object based on the given coordinates.

This API is deprecated since API version 9. You are advised to use [click<sup>9+</sup>](#click9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.click(100,100);
}
```

### doubleClick<sup>(deprecated)</sup>

doubleClick(x: number, y: number): Promise\<void>

Double-clicks a specific point of this **UiDriver** object based on the given coordinates.

This API is deprecated since API version 9. You are advised to use [doubleClick<sup>9+</sup>](#doubleclick9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.doubleClick(100,100);
}
```

### longClick<sup>(deprecated)</sup>

longClick(x: number, y: number): Promise\<void>

Long-clicks a specific point of this **UiDriver** object based on the given coordinates.

This API is deprecated since API version 9. You are advised to use [longClick<sup>9+</sup>](#longclick9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | Yes  | X-coordinate of the target point.|
| y      | number | Yes  | Y-coordinate of the target point.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.longClick(100,100);
}
```

### swipe<sup>(deprecated)</sup>

swipe(startx: number, starty: number, endx: number, endy: number): Promise\<void>

Swipes on this **UiDriver** object from the start point to the end point based on the given coordinates.

This API is deprecated since API version 9. You are advised to use [swipe<sup>9+</sup>](#swipe9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
| startx | number | Yes  | X-coordinate of the start point.|
| starty | number | Yes  | Y-coordinate of the start point.|
| endx   | number | Yes  | X-coordinate of the end point.|
| endy   | number | Yes  | Y-coordinate of the end point.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.swipe(100,100,200,200);
}
```

### screenCap<sup>(deprecated)</sup>

screenCap(savePath: string): Promise\<boolean>

Captures the current screen of this **UiDriver** object and saves it as a PNG image to the given save path.

This API is deprecated since API version 9. You are advised to use [screenCap<sup>9+</sup>](#screencap9).

**System capability**: SystemCapability.Test.UiTest

**Parameters**

| Name  | Type  | Mandatory| Description          |
| -------- | ------ | ---- | -------------- |
| savePath | string | Yes  | File save path.|

**Return value**

| Type             | Description                                  |
| ----------------- | -------------------------------------- |
| Promise\<boolean> | Promise used to return the operation result. The value **true** means that the operation is successful.|

**Example**

```js
async function demo() {
    let driver = UiDriver.create();
    await driver.screenCap('/local/tmp/1.png');
}
```