1# @ohos.UiTest
2
3The **UiTest** module provides APIs that you can use to simulate UI actions during testing, such as clicks, double-clicks, long-clicks, and swipes.
4
5This module provides the following functions:
6
7- [On<sup>9+</sup>](#on9): provides UI component feature description APIs for component filtering and matching.
8- [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.
9- [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.
10- [UiWindow<sup>9+</sup>](#uiwindow9): works as the entry class and provides APIs for obtaining window attributes, dragging windows, and adjusting window sizes.
11- [By<sup>(deprecated)</sup>](#bydeprecated): provides UI component feature description APIs for component filtering and matching. This class is deprecated since API version 9. You are advised to use [On<sup>9+</sup>](#on9) instead.
12- [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 class is deprecated since API version 9. You are advised to use [Component<sup>9+</sup>](#component9) instead.
13- [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 class is deprecated since API version 9. You are advised to use [Driver<sup>9+</sup>](#driver9) instead.
14
15> **NOTE**
16> - 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.
17> - The APIs of this module can be used only in <!--RP1-->[arkxtest](../../application-test/arkxtest-guidelines.md)<!--RP1End-->.
18> - The APIs of this module do not support concurrent calls.
19
20
21## Modules to Import
22
23```ts
24import { UiComponent, UiDriver, Component, Driver, UiWindow, ON, BY, MatchPattern, DisplayRotation, ResizeDirection, WindowMode, PointerMatrix, UiDirection, MouseButton, UIElementInfo, UIEventObserver } from '@kit.TestKit';
25```
26
27## MatchPattern
28
29Enumerates the match patterns supported for component attributes.
30
31**Atomic service API**: This API can be used in atomic services since API version 11.
32
33**System capability**: SystemCapability.Test.UiTest
34
35| Name       | Value  | Description          |
36| ----------- | ---- | -------------- |
37| EQUALS      | 0    | Equals the given value.  |
38| CONTAINS    | 1    | Contains the given value.  |
39| STARTS_WITH | 2    | Starts with the given value.|
40| ENDS_WITH   | 3    | Ends with the given value.|
41
42## ResizeDirection<sup>9+</sup>
43
44Enumerates the directions in which a window can be resized.
45
46**Atomic service API**: This API can be used in atomic services since API version 11.
47
48**System capability**: SystemCapability.Test.UiTest
49
50| Name      | Value  | Description    |
51| ---------- | ---- | -------- |
52| LEFT       | 0    | Left.  |
53| RIGHT      | 1    | Right.  |
54| UP         | 2    | Up.  |
55| DOWN       | 3    | Down.  |
56| LEFT_UP    | 4    | Upper left.|
57| LEFT_DOWN  | 5    | Lower left.|
58| RIGHT_UP   | 6    | Upper right.|
59| RIGHT_DOWN | 7    | Lower right.|
60
61## Point<sup>9+</sup>
62
63Provides the coordinates of a point.
64
65**Atomic service API**: This API can be used in atomic services since API version 11.
66
67**System capability**: SystemCapability.Test.UiTest
68
69| Name| Type  | Readable| Writable| Description            |
70| ---- | ------ | ---- | ---- | ---------------- |
71| x    | number | Yes  | No  | X coordinate of a point.|
72| y    | number | Yes  | No  | Y coordinate of a point.|
73
74## Rect<sup>9+</sup>
75
76Provides bounds information of a component.
77
78**Atomic service API**: This API can be used in atomic services since API version 11.
79
80**System capability**: SystemCapability.Test.UiTest
81
82| Name  | Type  | Readable| Writable| Description                     |
83| ------ | ------ | ---- | ---- | ------------------------- |
84| left   | number | Yes  | No  | X coordinate of the upper left corner of the component bounds.|
85| top    | number | Yes  | No  | Y coordinate of the upper left corner of the component bounds.|
86| right  | number | Yes  | No  | X coordinate of the lower right corner of the component bounds.|
87| bottom | number | Yes  | No  | Y coordinate of the lower right corner of the component bounds.|
88
89## WindowMode<sup>9+</sup>
90
91Enumerates the window modes.
92
93**Atomic service API**: This API can be used in atomic services since API version 11.
94
95**System capability**: SystemCapability.Test.UiTest
96
97| Name      | Value  | Description      |
98| ---------- | ---- | ---------- |
99| FULLSCREEN | 0    | Full-screen mode.|
100| PRIMARY    | 1    | Primary window mode.  |
101| SECONDARY  | 2    | Secondary window mode.|
102| FLOATING   | 3    | Floating window mode.|
103
104## DisplayRotation<sup>9+</sup>
105
106Describes the display rotation of the device.
107
108**Atomic service API**: This API can be used in atomic services since API version 11.
109
110**System capability**: SystemCapability.Test.UiTest
111
112| Name        | Value  | Description                                    |
113| ------------ | ---- | ---------------------------------------- |
114| ROTATION_0   | 0    | The device display is not rotated and is in its original vertical orientation.    |
115| ROTATION_90  | 1    | The device display rotates 90° clockwise and is in landscape orientation.     |
116| ROTATION_180 | 2    | The device display rotates 180° clockwise and is in reverse vertical orientation.|
117| ROTATION_270 | 3    | The device display rotates 270° clockwise and is in reverse landscape orientation.|
118
119## WindowFilter<sup>9+</sup>
120
121Provides the flag attributes of this window.
122
123**System capability**: SystemCapability.Test.UiTest
124
125| Name                | Type   | Readable| Writable| Description                                                        |
126| -------------------- | ------- | ---- | ---- | ------------------------------------------------------------ |
127| bundleName           | string  | Yes  | No  | Bundle name of the application to which the window belongs.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
128| title                | string  | Yes  | No  | Title of the window.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
129| focused              | boolean | Yes  | No  | Whether the window is in focused state.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
130| actived(deprecated)  | boolean | Yes  | No  | Whether the window is interacting with the user.<br>Since API version 11, this parameter is renamed **active**.|
131| active<sup>11+</sup> | boolean | Yes  | No  | Whether the window is interacting with the user.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
132
133## UiDirection<sup>10+</sup>
134
135Describes the direction of a UI operation such as fling.
136
137**Atomic service API**: This API can be used in atomic services since API version 11.
138
139**System capability**: SystemCapability.Test.UiTest
140
141| Name | Value  | Description  |
142| ----- | ---- | ------ |
143| LEFT  | 0    | Leftward.|
144| RIGHT | 1    | Rightward.|
145| UP    | 2    | Upward.|
146| DOWN  | 3    | Downward.|
147
148## MouseButton<sup>10+</sup>
149
150Describes the injected simulated mouse button.
151
152**Atomic service API**: This API can be used in atomic services since API version 11.
153
154**System capability**: SystemCapability.Test.UiTest
155
156| Name               | Value  | Description        |
157| ------------------- | ---- | ------------ |
158| MOUSE_BUTTON_LEFT   | 0    | Left button on the mouse.  |
159| MOUSE_BUTTON_RIGHT  | 1    | Right button on the mouse.  |
160| MOUSE_BUTTON_MIDDLE | 2    | Middle button on the mouse.|
161
162## UIElementInfo<sup>10+</sup>
163
164Provides information about the UI event.
165
166**Atomic service API**: This API can be used in atomic services since API version 11.
167
168**System capability**: SystemCapability.Test.UiTest
169
170| Name      | Type  | Readable| Writable| Description                 |
171| ---------- | ------ | ---- | ---- | --------------------- |
172| bundleName | string | Yes  | No  | Bundle name of the home application.     |
173| type       | string | Yes  | No  | Component or window type.      |
174| text       | string | Yes  | No  | Text information of the component or window.|
175
176## On<sup>9+</sup>
177
178Since 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.<br>
179The APIs provided by the **On** 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 [ON.isBefore](#isbefore9) and [ON.isAfter](#isafter9) 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.
180
181```ts
182import { ON } from '@kit.TestKit';
183ON.text('123').type('Button');
184```
185
186### text<sup>9+</sup>
187
188text(txt: string, pattern?: MatchPattern): On
189
190Specifies the text attribute of the target component. Multiple match patterns are supported.
191
192**Atomic service API**: This API can be used in atomic services since API version 11.
193
194**System capability**: SystemCapability.Test.UiTest
195
196**Parameters**
197
198| Name | Type                         | Mandatory| Description                                               |
199| ------- | ----------------------------- | ---- | --------------------------------------------------- |
200| txt     | string                        | Yes  | Component text, used to match the target component.               |
201| pattern | [MatchPattern](#matchpattern) | No  | Match pattern. The default value is [EQUALS](#matchpattern).|
202
203**Return value**
204
205| Type      | Description                              |
206| ---------- | ---------------------------------- |
207| [On](#on9) | **On** object that matches the text attribute of the target component.|
208
209**Error codes**
210
211For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
212
213| ID| Error Message                                                    |
214| -------- | ------------------------------------------------------------ |
215| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
216
217**Example**
218
219```ts
220import { On, ON } from '@kit.TestKit';
221let on:On = ON.text('123'); // Use the static constructor ON to create an On object and specify the text attribute of the target component.
222```
223
224### id<sup>9+</sup>
225
226id(id: string): On
227
228Specifies the ID attribute of the target component.
229
230**Atomic service API**: This API can be used in atomic services since API version 11.
231
232**System capability**: SystemCapability.Test.UiTest
233
234**Parameters**
235
236| Name| Type  | Mandatory| Description            |
237| ------ | ------ | ---- | ---------------- |
238| id     | string | Yes  | Component ID.|
239
240**Return value**
241
242| Type      | Description                            |
243| ---------- | -------------------------------- |
244| [On](#on9) | **On** object that matches the ID attribute of the target component.|
245
246**Error codes**
247
248For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
249
250| ID| Error Message                                                    |
251| -------- | ------------------------------------------------------------ |
252| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
253
254**Example**
255
256```ts
257import { On, ON } from '@kit.TestKit';
258let on:On = ON.id('123'); // Use the static constructor ON to create an On object and specify the id attribute of the target component.
259```
260
261
262### type<sup>9+</sup>
263
264type(tp: string): On
265
266Specifies the type attribute of the target component.
267
268>**NOTE**
269>
270>You can define the type of the component. In addition, you can use [DevEco Testing](https://developer.huawei.com/consumer/cn/download) to query the type information of the component.
271
272**Atomic service API**: This API can be used in atomic services since API version 11.
273
274**System capability**: SystemCapability.Test.UiTest
275
276**Parameters**
277
278| Name| Type  | Mandatory| Description          |
279| ------ | ------ | ---- | -------------- |
280| tp     | string | Yes  | Component type.|
281
282**Return value**
283
284| Type      | Description                                    |
285| ---------- | ---------------------------------------- |
286| [On](#on9) | **On** object that matches the type attribute of the target component.|
287
288**Error codes**
289
290For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
291
292| ID| Error Message                                                    |
293| -------- | ------------------------------------------------------------ |
294| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
295
296**Example**
297
298```ts
299import { On, ON } from '@kit.TestKit';
300let on:On = ON.type('Button'); // Use the static constructor ON to create an On object and specify the type attribute of the target component.
301```
302
303
304### clickable<sup>9+</sup>
305
306clickable(b?: boolean): On
307
308Specifies the clickable attribute of the target component.
309
310**Atomic service API**: This API can be used in atomic services since API version 11.
311
312**System capability**: SystemCapability.Test.UiTest
313
314**Parameters**
315
316| Name| Type   | Mandatory| Description                                                        |
317| ------ | ------- | ---- | ------------------------------------------------------------ |
318| b      | boolean | No  | Clickable status of the target component.<br>**true**: clickable.<br>**false**: not clickable.<br> Default value: **true**|
319
320**Return value**
321
322| Type      | Description                                      |
323| ---------- | ------------------------------------------ |
324| [On](#on9) | **On** object that matches the clickable attribute of the target component.|
325
326**Error codes**
327
328For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
329
330| ID| Error Message                                                    |
331| -------- | ------------------------------------------------------------ |
332| 401      | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.|
333
334**Example**
335
336```ts
337import { On, ON } from '@kit.TestKit';
338let on:On = ON.clickable(true); // Use the static constructor ON to create an On object and specify the clickable attribute of the target component.
339```
340
341### longClickable<sup>9+</sup>
342
343longClickable(b?: boolean): On
344
345Specifies the long-clickable attribute of the target component.
346
347**Atomic service API**: This API can be used in atomic services since API version 11.
348
349**System capability**: SystemCapability.Test.UiTest
350
351**Parameters**
352
353| Name| Type   | Mandatory| Description                                                        |
354| ------ | ------- | ---- | ------------------------------------------------------------ |
355| b      | boolean | No  | Long-clickable status of the target component.<br>**true**: long-clickable.<br>**false**: not long-clickable.<br> Default value: **true**|
356
357**Return value**
358
359| Type      | Description                                          |
360| ---------- | ---------------------------------------------- |
361| [On](#on9) | **On** object that matches the long-clickable attribute of the target component.|
362
363**Error codes**
364
365For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
366
367| ID| Error Message                                                    |
368| -------- | ------------------------------------------------------------ |
369| 401      | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.|
370
371**Example**
372
373```ts
374import { On, ON } from '@kit.TestKit';
375let on:On = ON.longClickable(true); // Use the static constructor ON to create an On object and specify the longClickable attribute of the target component.
376```
377
378
379### scrollable<sup>9+</sup>
380
381scrollable(b?: boolean): On
382
383Specifies the scrollable attribute of the target component.
384
385**Atomic service API**: This API can be used in atomic services since API version 11.
386
387**System capability**: SystemCapability.Test.UiTest
388
389**Parameters**
390
391| Name| Type   | Mandatory| Description                                                       |
392| ------ | ------- | ---- | ----------------------------------------------------------- |
393| b      | boolean | No  | Scrollable status of the target component.<br>**true**: scrollable.<br>**false**: not scrollable.<br> Default value: **true**|
394
395**Return value**
396
397| Type      | Description                                      |
398| ---------- | ------------------------------------------ |
399| [On](#on9) | **On** object that matches the scrollable attribute of the target component.|
400
401**Error codes**
402
403For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
404
405| ID| Error Message                                                    |
406| -------- | ------------------------------------------------------------ |
407| 401      | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.|
408
409**Example**
410
411```ts
412import { On, ON } from '@kit.TestKit';
413let on:On = ON.scrollable(true); // Use the static constructor ON to create an On object and specify the scrollable attribute of the target component.
414```
415
416### enabled<sup>9+</sup>
417
418enabled(b?: boolean): On
419
420Specifies the enabled attribute of the target component.
421
422**Atomic service API**: This API can be used in atomic services since API version 11.
423
424**System capability**: SystemCapability.Test.UiTest
425
426**Parameters**
427
428| Name| Type   | Mandatory| Description                                                     |
429| ------ | ------- | ---- | --------------------------------------------------------- |
430| b      | boolean | No  | Enabled status of the target component.<br>**true**: enabled.<br>**false**: not enabled.<br> Default value: **true**|
431
432**Return value**
433
434| Type      | Description                                    |
435| ---------- | ---------------------------------------- |
436| [On](#on9) | **On** object that matches the enabled attribute of the target component.|
437
438**Error codes**
439
440For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
441
442| ID| Error Message                                                    |
443| -------- | ------------------------------------------------------------ |
444| 401      | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.|
445
446**Example**
447
448```ts
449import { On, ON } from '@kit.TestKit';
450let on:On = ON.enabled(true); // Use the static constructor ON to create an On object and specify the enabled attribute of the target component.
451```
452
453### focused<sup>9+</sup>
454
455focused(b?: boolean): On
456
457Specifies the focused attribute of the target component.
458
459**Atomic service API**: This API can be used in atomic services since API version 11.
460
461**System capability**: SystemCapability.Test.UiTest
462
463**Parameters**
464
465| Name| Type   | Mandatory| Description                                                 |
466| ------ | ------- | ---- | ----------------------------------------------------- |
467| b      | boolean | No  | Focused status of the target component.<br>**true**: focused.<br>**false**: not focused.<br> Default value: **true**|
468
469**Return value**
470
471| Type      | Description                                    |
472| ---------- | ---------------------------------------- |
473| [On](#on9) | **On** object that matches the focused attribute of the target component.|
474
475**Error codes**
476
477For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
478
479| ID| Error Message                                                    |
480| -------- | ------------------------------------------------------------ |
481| 401      | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.|
482
483**Example**
484
485```ts
486import { On, ON } from '@kit.TestKit';
487let on:On = ON.focused(true); // Use the static constructor ON to create an On object and specify the focused attribute of the target component.
488```
489
490### selected<sup>9+</sup>
491
492selected(b?: boolean): On
493
494Specifies the selected attribute of the target component.
495
496**Atomic service API**: This API can be used in atomic services since API version 11.
497
498**System capability**: SystemCapability.Test.UiTest
499
500**Parameters**
501
502| Name| Type   | Mandatory| Description                                                        |
503| ------ | ------- | ---- | ------------------------------------------------------------ |
504| b      | boolean | No  | Selected status of the target component.<br>**true**: selected.<br>**false**: not selected.<br> Default value: **true**|
505
506**Return value**
507
508| Type      | Description                                      |
509| ---------- | ------------------------------------------ |
510| [On](#on9) | **On** object that matches the selected attribute of the target component.|
511
512**Error codes**
513
514For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
515
516| ID| Error Message                                                    |
517| -------- | ------------------------------------------------------------ |
518| 401      | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.|
519
520**Example**
521
522```ts
523import { On, ON } from '@kit.TestKit';
524let on:On = ON.selected(true); // Use the static constructor ON to create an On object and specify the selected attribute of the target component.
525```
526
527### checked<sup>9+</sup>
528
529checked(b?: boolean): On
530
531Specifies the checked attribute of the target component.
532
533**Atomic service API**: This API can be used in atomic services since API version 11.
534
535**System capability**: SystemCapability.Test.UiTest
536
537**Parameters**
538
539| Name| Type   | Mandatory| Description                                                        |
540| ------ | ------- | ---- | ------------------------------------------------------------ |
541| b      | boolean | No  | Checked status of the target component.<br>**true**: checked.<br>**false**: not checked.<br> Default value: **false**|
542
543**Return value**
544
545| Type      | Description                                      |
546| ---------- | ------------------------------------------ |
547| [On](#on9) | **On** object that matches the checked attribute of the target component.|
548
549**Error codes**
550
551For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
552
553| ID| Error Message                                                    |
554| -------- | ------------------------------------------------------------ |
555| 401      | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.|
556
557**Example**
558
559```ts
560import { On, ON } from '@kit.TestKit';
561let on:On = ON.checked(true); // Use the static constructor ON to create an On object and specify the checked attribute of the target component.
562```
563
564### checkable<sup>9+</sup>
565
566checkable(b?: boolean): On
567
568Specifies the checkable attribute of the target component.
569
570**Atomic service API**: This API can be used in atomic services since API version 11.
571
572**System capability**: SystemCapability.Test.UiTest
573
574**Parameters**
575
576| Name| Type   | Mandatory| Description                                                        |
577| ------ | ------- | ---- | ------------------------------------------------------------ |
578| b      | boolean | No  | Checkable status of the target component.<br>**true**: checkable.<br>**false**: not checkable.<br> Default value: **false**|
579
580**Return value**
581
582| Type      | Description                                        |
583| ---------- | -------------------------------------------- |
584| [On](#on9) | **On** object that matches the checkable attribute of the target component.|
585
586**Error codes**
587
588For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
589
590| ID| Error Message                                                    |
591| -------- | ------------------------------------------------------------ |
592| 401      | Parameter error. 1. Incorrect parameter types; 2. Parameter verification failed. |
593
594**Example**
595
596```ts
597import { On, ON } from '@kit.TestKit';
598let on:On = ON.checkable(true); // Use the static constructor ON to create an On object and specify the checkable attribute of the target component.
599```
600
601### isBefore<sup>9+</sup>
602
603isBefore(on: On): On
604
605Specifies that the target component is located before the given attribute component.
606
607**Atomic service API**: This API can be used in atomic services since API version 11.
608
609**System capability**: SystemCapability.Test.UiTest
610
611**Parameters**
612
613| Name| Type      | Mandatory| Description                |
614| ------ | ---------- | ---- | -------------------- |
615| on     | [On](#on9) | Yes  | Information about the attribute component.|
616
617**Return value**
618
619| Type      | Description                                                |
620| ---------- | ---------------------------------------------------- |
621| [On](#on9) | **On** object.|
622
623**Error codes**
624
625For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
626
627| ID| Error Message                                                    |
628| -------- | ------------------------------------------------------------ |
629| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
630
631**Example**
632
633```ts
634import { On, ON } from '@kit.TestKit';
635
636// Use the static constructor ON to create an On object and specify that the target component is located before the given attribute component.
637let on:On = ON.type('Button').isBefore(ON.text('123')); // Search for the first <Button> component located before the component whose text is 123.
638```
639
640### isAfter<sup>9+</sup>
641
642isAfter(on: On): On
643
644Specifies that the target component is located after the given attribute component.
645
646**Atomic service API**: This API can be used in atomic services since API version 11.
647
648**System capability**: SystemCapability.Test.UiTest
649
650**Parameters**
651
652| Name| Type      | Mandatory| Description                |
653| ------ | ---------- | ---- | -------------------- |
654| on     | [On](#on9) | Yes  | Information about the attribute component.|
655
656**Return value**
657
658| Type      | Description                                                |
659| ---------- | ---------------------------------------------------- |
660| [On](#on9) | **On** object.|
661
662**Error codes**
663
664For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
665
666| ID| Error Message                                                    |
667| -------- | ------------------------------------------------------------ |
668| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
669
670**Example**
671
672```ts
673import { On, ON } from '@kit.TestKit';
674
675// Use the static constructor ON to create an On object and specify that the target component is located after the given attribute component.
676let on:On = ON.type('Text').isAfter(ON.text('123'))  // Search for the first <Text> component located after the component whose text is 123.
677```
678
679### within<sup>10+</sup>
680
681within(on: On): On
682
683Specifies that the target component is located within the given attribute component.
684
685**Atomic service API**: This API can be used in atomic services since API version 11.
686
687**System capability**: SystemCapability.Test.UiTest
688
689**Parameters**
690
691| Name| Type      | Mandatory| Description                |
692| ------ | ---------- | ---- | -------------------- |
693| on     | [On](#on9) | Yes  | Information about the attribute component.|
694
695**Return value**
696
697| Type      | Description                                              |
698| ---------- | -------------------------------------------------- |
699| [On](#on9) | **On** object.|
700
701**Error codes**
702
703For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
704
705| ID| Error Message                                                    |
706| -------- | ------------------------------------------------------------ |
707| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
708
709**Example**
710
711```ts
712import { On, ON } from '@kit.TestKit';
713// Use the static constructor ON to create an On object and specify that the target component is located within the given attribute component.
714let on:On = ON.text('java').within(ON.type('Scroll'));  // Search for the child component whose text is java within the <Scroller> component.
715```
716
717### inWindow<sup>10+</sup>
718
719inWindow(bundleName: string): On;
720
721Specifies that the target component is located within the given application window.
722
723**Atomic service API**: This API can be used in atomic services since API version 11.
724
725**System capability**: SystemCapability.Test.UiTest
726
727**Parameters**
728
729| Name    | Type  | Mandatory| Description            |
730| ---------- | ------ | ---- | ---------------- |
731| bundleName | string | Yes  | Bundle name of the application window.|
732
733**Return value**
734
735| Type      | Description                                          |
736| ---------- | ---------------------------------------------- |
737| [On](#on9) | **On** object.|
738
739**Error codes**
740
741For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
742
743| ID| Error Message                                                    |
744| -------- | ------------------------------------------------------------ |
745| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
746
747**Example**
748
749```ts
750import { On, ON } from '@kit.TestKit';
751let on:On = ON.inWindow('com.uitestScene.acts'); // Use the static constructor ON to create an On object and specify that the target component is located within the given application window.
752```
753
754### description<sup>11+</sup>
755
756description(val: string, pattern?: MatchPattern): On
757
758Specifies the description of the target component. Multiple match patterns are supported.
759
760**Atomic service API**: This API can be used in atomic services since API version 11.
761
762**System capability**: SystemCapability.Test.UiTest
763
764**Parameters**
765
766| Name | Type                         | Mandatory| Description                                               |
767| ------- | ----------------------------- | ---- | --------------------------------------------------- |
768| val     | string                        | Yes  | Description of the component.                                   |
769| pattern | [MatchPattern](#matchpattern) | No  | Match pattern. The default value is [EQUALS](#matchpattern).|
770
771**Return value**
772
773| Type      | Description                                     |
774| ---------- | ----------------------------------------- |
775| [On](#on9) | **On** object.|
776
777**Error codes**
778
779For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
780
781| ID| Error Message                                                    |
782| -------- | ------------------------------------------------------------ |
783| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
784
785**Example**
786
787```ts
788import { On, ON } from '@kit.TestKit';
789let on:On = ON.description('123'); // Use the static constructor ON to create an On object and specify the description attribute of the target component.
790```
791
792## Component<sup>9+</sup>
793
794Represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection.
795All APIs provided in this class use a promise to return the result and must be invoked using **await**.
796
797### click<sup>9+</sup>
798
799click(): Promise\<void>
800
801Clicks this component.
802
803**Atomic service API**: This API can be used in atomic services since API version 11.
804
805**System capability**: SystemCapability.Test.UiTest
806
807**Error codes**
808
809For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
810
811| ID| Error Message                                |
812| -------- | ---------------------------------------- |
813| 17000002 | The async function is not called with await. |
814| 17000004 | The window or component is invisible or destroyed.           |
815
816**Example**
817
818```ts
819import { Driver, ON, Component } from '@kit.TestKit';
820async function demo() {
821  let driver:Driver = Driver.create();
822  let button: Component = await driver.findComponent(ON.type('Button'));
823  await button.click();
824}
825```
826
827### doubleClick<sup>9+</sup>
828
829doubleClick(): Promise\<void>
830
831Double-clicks this component.
832
833**Atomic service API**: This API can be used in atomic services since API version 11.
834
835**System capability**: SystemCapability.Test.UiTest
836
837**Error codes**
838
839For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
840
841| ID| Error Message                                |
842| -------- | ---------------------------------------- |
843| 17000002 | The async function is not called with await. |
844| 17000004 | The window or component is invisible or destroyed.           |
845
846**Example**
847
848```ts
849import {Component, Driver, ON } from '@kit.TestKit';
850async function demo() {
851  let driver: Driver = Driver.create();
852  let button: Component = await driver.findComponent(ON.type('Button'));
853  await button.doubleClick();
854}
855```
856
857### longClick<sup>9+</sup>
858
859longClick(): Promise\<void>
860
861Long-clicks this component.
862
863**Atomic service API**: This API can be used in atomic services since API version 11.
864
865**System capability**: SystemCapability.Test.UiTest
866
867**Error codes**
868
869For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
870
871| ID| Error Message                                |
872| -------- | ---------------------------------------- |
873| 17000002 | The async function is not called with await. |
874| 17000004 | The window or component is invisible or destroyed.           |
875
876**Example**
877
878```ts
879import { Component, Driver, ON } from '@kit.TestKit';
880async function demo() {
881  let driver: Driver = Driver.create();
882  let button: Component = await driver.findComponent(ON.type('Button'));
883  await button.longClick();
884}
885```
886
887### getId<sup>9+</sup>
888
889getId(): Promise\<string>
890
891Obtains the ID of this component.
892
893**Atomic service API**: This API can be used in atomic services since API version 11.
894
895**System capability**: SystemCapability.Test.UiTest
896
897**Return value**
898
899| Type            | Description                           |
900| ---------------- | ------------------------------- |
901| Promise\<string> | Promise used to return the ID of the component.|
902
903**Error codes**
904
905For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
906
907| ID| Error Message                                |
908| -------- | ---------------------------------------- |
909| 17000002 | The async function is not called with await. |
910| 17000004 | The window or component is invisible or destroyed.           |
911
912**Example**
913
914```ts
915import { Component, Driver, ON } from '@kit.TestKit';
916async function demo() {
917  let driver: Driver = Driver.create();
918  let button: Component = await driver.findComponent(ON.type('Button'));
919  let id = await button.getId();
920}
921```
922
923### getText<sup>9+</sup>
924
925getText(): Promise\<string>
926
927Obtains the text information of this component.
928
929**Atomic service API**: This API can be used in atomic services since API version 11.
930
931**System capability**: SystemCapability.Test.UiTest
932
933**Return value**
934
935| Type            | Description                             |
936| ---------------- | --------------------------------- |
937| Promise\<string> | Promise used to return the text information of the component.|
938
939**Error codes**
940
941For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
942
943| ID| Error Message                              |
944| -------- | ---------------------------------------- |
945| 17000002 | The async function is not called with await. |
946| 17000004 | The window or component is invisible or destroyed.           |
947
948**Example**
949
950```ts
951import { Component, Driver, ON } from '@kit.TestKit';
952async function demo() {
953  let driver: Driver = Driver.create();
954  let button: Component = await driver.findComponent(ON.type('Button'));
955  let text = await button.getText();
956}
957```
958
959### getType<sup>9+</sup>
960
961getType(): Promise\<string>
962
963Obtains the type of this component.
964
965**Atomic service API**: This API can be used in atomic services since API version 11.
966
967**System capability**: SystemCapability.Test.UiTest
968
969**Return value**
970
971| Type            | Description                         |
972| ---------------- | ----------------------------- |
973| Promise\<string> | Promise used to return the type of the component.|
974
975**Error codes**
976
977For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
978
979| ID| Error Message                              |
980| -------- | ---------------------------------------- |
981| 17000002 | The async function is not called with await. |
982| 17000004 | The window or component is invisible or destroyed.           |
983
984**Example**
985
986```ts
987import { Component, Driver, ON } from '@kit.TestKit';
988async function demo() {
989  let driver: Driver = Driver.create();
990  let button: Component = await driver.findComponent(ON.type('Button'));
991  let type = await button.getType();
992}
993```
994
995### getBounds<sup>9+</sup>
996
997getBounds(): Promise\<Rect>
998
999Obtains the bounds of this component.
1000
1001**Atomic service API**: This API can be used in atomic services since API version 11.
1002
1003**System capability**: SystemCapability.Test.UiTest
1004
1005**Return value**
1006
1007| Type                    | Description                                 |
1008| ------------------------ | ------------------------------------- |
1009| Promise\<[Rect](#rect9)> | Promise used to return the bounds of the component.|
1010
1011**Error codes**
1012
1013For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1014
1015| ID| Error Message                              |
1016| -------- | ---------------------------------------- |
1017| 17000002 | The async function is not called with await. |
1018| 17000004 | The window or component is invisible or destroyed.           |
1019
1020**Example**
1021
1022```ts
1023import { Component, Driver, ON } from '@kit.TestKit';
1024async function demo() {
1025  let driver: Driver = Driver.create();
1026  let button: Component = await driver.findComponent(ON.type('Button'));
1027  let rect = await button.getBounds();
1028}
1029```
1030
1031### getBoundsCenter<sup>9+</sup>
1032
1033getBoundsCenter(): Promise\<Point>
1034
1035Obtains the information about the center of the bounding box around this component.
1036
1037**Atomic service API**: This API can be used in atomic services since API version 11.
1038
1039**System capability**: SystemCapability.Test.UiTest
1040
1041**Return value**
1042
1043| Type                      | Description                                           |
1044| -------------------------- | ----------------------------------------------- |
1045| Promise\<[Point](#point9)> | Promise used to return the information about the center of the bounding box around the component.|
1046
1047**Error codes**
1048
1049For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1050
1051| ID| Error Message                              |
1052| -------- | ---------------------------------------- |
1053| 17000002 | The async function is not called with await. |
1054| 17000004 | The window or component is invisible or destroyed.           |
1055
1056**Example**
1057
1058```ts
1059import { Component, Driver, ON } from '@kit.TestKit';
1060async function demo() {
1061  let driver: Driver = Driver.create();
1062  let button: Component = await driver.findComponent(ON.type('Button'));
1063  let point = await button.getBoundsCenter();
1064}
1065```
1066
1067### isClickable<sup>9+</sup>
1068
1069isClickable(): Promise\<boolean>
1070
1071Obtains the clickable status of this component.
1072
1073**Atomic service API**: This API can be used in atomic services since API version 11.
1074
1075**System capability**: SystemCapability.Test.UiTest
1076
1077**Return value**
1078
1079| Type             | Description                                                        |
1080| ----------------- | ------------------------------------------------------------ |
1081| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is clickable, and **false** means the opposite.|
1082
1083**Error codes**
1084
1085For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1086
1087| ID| Error Message                              |
1088| -------- | ---------------------------------------- |
1089| 17000002 | The async function is not called with await. |
1090| 17000004 | The window or component is invisible or destroyed.           |
1091
1092**Example**
1093
1094```ts
1095import { Component, Driver, ON } from '@kit.TestKit';
1096async function demo() {
1097  let driver: Driver = Driver.create();
1098  let button: Component = await driver.findComponent(ON.type('Button'));
1099  if(await button.isClickable()) {
1100    console.info('This button can be Clicked');
1101  } else {
1102    console.info('This button can not be Clicked');
1103  }
1104}
1105```
1106
1107### isLongClickable<sup>9+</sup>
1108
1109isLongClickable(): Promise\<boolean>
1110
1111Obtains the long-clickable status of this component.
1112
1113**Atomic service API**: This API can be used in atomic services since API version 11.
1114
1115**System capability**: SystemCapability.Test.UiTest
1116
1117**Return value**
1118
1119| Type             | Description                                              |
1120| ----------------- |--------------------------------------------------|
1121| 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.|
1122
1123**Error codes**
1124
1125For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1126
1127| ID| Error Message                              |
1128| -------- | ---------------------------------------- |
1129| 17000002 | The async function is not called with await. |
1130| 17000004 | The window or component is invisible or destroyed.           |
1131
1132**Example**
1133
1134```ts
1135import { Component, Driver, ON } from '@kit.TestKit';
1136async function demo() {
1137  let driver: Driver = Driver.create();
1138  let button: Component = await driver.findComponent(ON.type('Button'));
1139  if(await button.isLongClickable()) {
1140    console.info('This button can longClick');
1141  } else {
1142    console.info('This button can not longClick');
1143  }
1144}
1145```
1146
1147### isChecked<sup>9+</sup>
1148
1149isChecked(): Promise\<boolean>
1150
1151Obtains the checked status of this component.
1152
1153**Atomic service API**: This API can be used in atomic services since API version 11.
1154
1155**System capability**: SystemCapability.Test.UiTest
1156
1157**Return value**
1158
1159| Type             | Description                                                        |
1160| ----------------- | ------------------------------------------------------------ |
1161| 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.|
1162
1163**Error codes**
1164
1165For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1166
1167| ID| Error Message                              |
1168| -------- | ---------------------------------------- |
1169| 17000002 | The async function is not called with await. |
1170| 17000004 | The window or component is invisible or destroyed.           |
1171
1172**Example**
1173
1174```ts
1175import { Component, Driver, ON } from '@kit.TestKit';
1176async function demo() {
1177  let driver: Driver = Driver.create();
1178  let checkBox: Component = await driver.findComponent(ON.type('Checkbox'));
1179  if(await checkBox.isChecked()) {
1180    console.info('This checkBox is checked');
1181  } else {
1182    console.info('This checkBox is not checked');
1183  }
1184}
1185```
1186
1187### isCheckable<sup>9+</sup>
1188
1189isCheckable(): Promise\<boolean>
1190
1191Obtains the checkable status of this component.
1192
1193**Atomic service API**: This API can be used in atomic services since API version 11.
1194
1195**System capability**: SystemCapability.Test.UiTest
1196
1197**Return value**
1198
1199| Type             | Description                                                        |
1200| ----------------- | ------------------------------------------------------------ |
1201| 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.|
1202
1203**Error codes**
1204
1205For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1206
1207| ID| Error Message                                |
1208| -------- | ---------------------------------------- |
1209| 17000002 | The async function is not called with await. |
1210| 17000004 | The window or component is invisible or destroyed.           |
1211
1212**Example**
1213
1214```ts
1215import { Component, Driver, ON } from '@kit.TestKit';
1216async function demo() {
1217  let driver: Driver = Driver.create();
1218  let checkBox: Component = await driver.findComponent(ON.type('Checkbox'));
1219  if(await checkBox.isCheckable()) {
1220    console.info('This checkBox is checkable');
1221  } else {
1222    console.info('This checkBox is not checkable');
1223  }
1224}
1225```
1226
1227### isScrollable<sup>9+</sup>
1228
1229isScrollable(): Promise\<boolean>
1230
1231Obtains the scrollable status of this component.
1232
1233**Atomic service API**: This API can be used in atomic services since API version 11.
1234
1235**System capability**: SystemCapability.Test.UiTest
1236
1237**Return value**
1238
1239| Type             | Description                                                        |
1240| ----------------- | ------------------------------------------------------------ |
1241| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is scrollable, and **false** means the opposite.|
1242
1243**Error codes**
1244
1245For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1246
1247| ID| Error Message                              |
1248| -------- | ---------------------------------------- |
1249| 17000002 | The async function is not called with await. |
1250| 17000004 | The window or component is invisible or destroyed.           |
1251
1252**Example**
1253
1254```ts
1255import { Component, Driver, ON } from '@kit.TestKit';
1256async function demo() {
1257  let driver: Driver = Driver.create();
1258  let scrollBar: Component = await driver.findComponent(ON.scrollable(true));
1259  if(await scrollBar.isScrollable()) {
1260    console.info('This scrollBar can be operated');
1261  } else {
1262    console.info('This scrollBar can not be operated');
1263  }
1264}
1265```
1266
1267
1268### isEnabled<sup>9+</sup>
1269
1270isEnabled(): Promise\<boolean>
1271
1272Obtains the enabled status of this component.
1273
1274**Atomic service API**: This API can be used in atomic services since API version 11.
1275
1276**System capability**: SystemCapability.Test.UiTest
1277
1278**Return value**
1279
1280| Type             | Description                                                      |
1281| ----------------- | ---------------------------------------------------------- |
1282| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is enabled, and **false** means the opposite.|
1283
1284**Error codes**
1285
1286For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1287
1288| ID| Error Message                              |
1289| -------- | ---------------------------------------- |
1290| 17000002 | The async function is not called with await. |
1291| 17000004 | The window or component is invisible or destroyed.           |
1292
1293**Example**
1294
1295```ts
1296import { Component, Driver, ON } from '@kit.TestKit';
1297async function demo() {
1298  let driver: Driver = Driver.create();
1299  let button: Component = await driver.findComponent(ON.type('Button'));
1300  if(await button.isEnabled()) {
1301    console.info('This button can be operated');
1302  } else {
1303    console.info('This button can not be operated');
1304  }
1305}
1306```
1307
1308### isFocused<sup>9+</sup>
1309
1310isFocused(): Promise\<boolean>
1311
1312Obtains the focused status of this component.
1313
1314**Atomic service API**: This API can be used in atomic services since API version 11.
1315
1316**System capability**: SystemCapability.Test.UiTest
1317
1318**Return value**
1319
1320| Type             | Description                                                        |
1321| ----------------- | ------------------------------------------------------------ |
1322| 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.|
1323
1324**Error codes**
1325
1326For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1327
1328| ID| Error Message                              |
1329| -------- | ---------------------------------------- |
1330| 17000002 | The async function is not called with await. |
1331| 17000004 | The window or component is invisible or destroyed.           |
1332
1333**Example**
1334
1335```ts
1336import { Component, Driver, ON } from '@kit.TestKit';
1337async function demo() {
1338  let driver: Driver = Driver.create();
1339  let button: Component = await driver.findComponent(ON.type('Button'));
1340  if(await button.isFocused()) {
1341    console.info('This button is focused');
1342  } else {
1343    console.info('This button is not focused');
1344  }
1345}
1346```
1347
1348### isSelected<sup>9+</sup>
1349
1350isSelected(): Promise\<boolean>
1351
1352Obtains the selected status of this component.
1353
1354**Atomic service API**: This API can be used in atomic services since API version 11.
1355
1356**System capability**: SystemCapability.Test.UiTest
1357
1358**Return value**
1359
1360| Type             | Description                                               |
1361| ----------------- | --------------------------------------------------- |
1362| Promise\<boolean> | Promise used to return the selected status of the component. The value **true** means that the component is selected, and **false** means the opposite.|
1363
1364**Error codes**
1365
1366For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1367
1368| ID| Error Message                              |
1369| -------- | ---------------------------------------- |
1370| 17000002 | The async function is not called with await. |
1371| 17000004 | The window or component is invisible or destroyed.           |
1372
1373**Example**
1374
1375```ts
1376import { Component, Driver, ON } from '@kit.TestKit';
1377async function demo() {
1378  let driver: Driver = Driver.create();
1379  let button: Component = await driver.findComponent(ON.type('Button'));
1380  if(await button.isSelected()) {
1381    console.info('This button is selected');
1382  } else {
1383    console.info('This button is not selected');
1384  }
1385}
1386```
1387
1388### inputText<sup>9+</sup>
1389
1390inputText(text: string): Promise\<void>
1391
1392Enters text into this component (available for text boxes).
1393
1394**Atomic service API**: This API can be used in atomic services since API version 11.
1395
1396**System capability**: SystemCapability.Test.UiTest
1397
1398**Parameters**
1399
1400| Name| Type  | Mandatory| Description                                    |
1401| ------ | ------ | ---- | ---------------------------------------- |
1402| text   | string | Yes  | Text to enter, which can contain English and special characters.|
1403
1404**Error codes**
1405
1406For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1407
1408| ID| Error Message                              |
1409| -------- | ---------------------------------------- |
1410| 17000002 | The async function is not called with await. |
1411| 17000004 | The window or component is invisible or destroyed.           |
1412| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1413
1414**Example**
1415
1416```ts
1417import { Component, Driver, ON } from '@kit.TestKit';
1418async function demo() {
1419  let driver: Driver = Driver.create();
1420  let text: Component = await driver.findComponent(ON.text('hello world'));
1421  await text.inputText('123');
1422}
1423```
1424
1425### clearText<sup>9+</sup>
1426
1427clearText(): Promise\<void>
1428
1429Clears text in this component. This API is applicable to text boxes.
1430
1431**Atomic service API**: This API can be used in atomic services since API version 11.
1432
1433**System capability**: SystemCapability.Test.UiTest
1434
1435**Error codes**
1436For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1437
1438| ID| Error Message                              |
1439| -------- | ---------------------------------------- |
1440| 17000002 | The async function is not called with await. |
1441| 17000004 | The window or component is invisible or destroyed.           |
1442
1443**Example**
1444
1445```ts
1446import { Component, Driver, ON } from '@kit.TestKit';
1447async function demo() {
1448  let driver: Driver = Driver.create();
1449  let text: Component = await driver.findComponent(ON.text('hello world'));
1450  await text.clearText();
1451}
1452```
1453
1454### scrollSearch<sup>9+</sup>
1455
1456scrollSearch(on: On): Promise\<Component>
1457
1458Scrolls on this component to search for the target component. This API is applicable to components that support scrolling.
1459
1460**Atomic service API**: This API can be used in atomic services since API version 11.
1461
1462**System capability**: SystemCapability.Test.UiTest
1463
1464**Parameters**
1465
1466| Name| Type      | Mandatory| Description                |
1467| ------ | ---------- | ---- | -------------------- |
1468| on     | [On](#on9) | Yes  | Attributes of the target component.|
1469
1470**Return value**
1471
1472| Type                              | Description                                 |
1473| ---------------------------------- | ------------------------------------- |
1474| Promise\<[Component](#component9)> | Promise used to return the target component.|
1475
1476**Error codes**
1477
1478For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1479
1480| ID| Error Message                              |
1481| -------- | ---------------------------------------- |
1482| 17000002 | The async function is not called with await. |
1483| 17000004 | The window or component is invisible or destroyed.           |
1484| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1485
1486**Example**
1487
1488```ts
1489import { Component, Driver, ON } from '@kit.TestKit';
1490async function demo() {
1491  let driver: Driver = Driver.create();
1492  let scrollBar: Component = await driver.findComponent(ON.type('Scroll'));
1493  let button = await scrollBar.scrollSearch(ON.text('next page'));
1494}
1495```
1496
1497### scrollToTop<sup>9+</sup>
1498
1499scrollToTop(speed?: number): Promise\<void>
1500
1501Scrolls to the top of this component. This API is applicable to components that support scrolling.
1502
1503**Atomic service API**: This API can be used in atomic services since API version 11.
1504
1505**System capability**: SystemCapability.Test.UiTest
1506
1507**Parameters**
1508
1509| Name| Type  | Mandatory| Description                                                        |
1510| ------ | ------ | ---- | ------------------------------------------------------------ |
1511| speed  | number | No  | Scroll speed, in pixel/s. The value ranges from 200 to 40000. If the set value is not in the range, the default value 600 is used.|
1512
1513**Error codes**
1514
1515For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1516
1517| ID| Error Message                              |
1518| -------- | ---------------------------------------- |
1519| 17000002 | The async function is not called with await. |
1520| 17000004 | The window or component is invisible or destroyed.           |
1521| 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.|
1522
1523**Example**
1524
1525```ts
1526import { Component, Driver, ON } from '@kit.TestKit';
1527async function demo() {
1528  let driver: Driver = Driver.create();
1529  let scrollBar: Component = await driver.findComponent(ON.type('Scroll'));
1530  await scrollBar.scrollToTop();
1531}
1532```
1533
1534### scrollToBottom<sup>9+</sup>
1535
1536scrollToBottom(speed?: number): Promise\<void>
1537
1538Scrolls to the bottom of this component. This API is applicable to components that support scrolling.
1539
1540**Atomic service API**: This API can be used in atomic services since API version 11.
1541
1542**System capability**: SystemCapability.Test.UiTest
1543
1544**Parameters**
1545
1546| Name| Type  | Mandatory| Description                                                        |
1547| ------ | ------ | ---- | ------------------------------------------------------------ |
1548| speed  | number | No  | Scroll speed, in pixel/s. The value ranges from 200 to 40000. If the set value is not in the range, the default value 600 is used.|
1549
1550**Error codes**
1551
1552For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1553
1554| ID| Error Message                              |
1555| -------- | ---------------------------------------- |
1556| 17000002 | The async function is not called with await. |
1557| 17000004 | The window or component is invisible or destroyed.           |
1558| 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.|
1559
1560**Example**
1561
1562```ts
1563import { Component, Driver, ON } from '@kit.TestKit';
1564async function demo() {
1565  let driver: Driver = Driver.create();
1566  let scrollBar: Component = await driver.findComponent(ON.type('Scroll'));
1567  await scrollBar.scrollToBottom();
1568}
1569```
1570
1571### dragTo<sup>9+</sup>
1572
1573dragTo(target: Component): Promise\<void>
1574
1575Drags this component to the target component.
1576
1577**Atomic service API**: This API can be used in atomic services since API version 11.
1578
1579**System capability**: SystemCapability.Test.UiTest
1580
1581**Parameters**
1582
1583| Name| Type                    | Mandatory| Description      |
1584| ------ | ------------------------ | ---- | ---------- |
1585| target | [Component](#component9) | Yes  | Target component.|
1586
1587**Error codes**
1588
1589For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1590
1591| ID| Error Message                              |
1592| -------- | ---------------------------------------- |
1593| 17000002 | The async function is not called with await. |
1594| 17000004 | The window or component is invisible or destroyed.           |
1595| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1596
1597**Example**
1598
1599```ts
1600import { Component, Driver, ON } from '@kit.TestKit';
1601async function demo() {
1602  let driver: Driver = Driver.create();
1603  let button: Component = await driver.findComponent(ON.type('Button'));
1604  let text: Component = await driver.findComponent(ON.text('hello world'));
1605  await button.dragTo(text);
1606}
1607```
1608
1609### pinchOut<sup>9+</sup>
1610
1611pinchOut(scale: number): Promise\<void>
1612
1613Pinches a component to scale it up to the specified ratio.
1614
1615**Atomic service API**: This API can be used in atomic services since API version 11.
1616
1617**System capability**: SystemCapability.Test.UiTest
1618
1619**Parameters**
1620
1621| Name| Type  | Mandatory| Description                           |
1622| ------ | ------ | ---- | ------------------------------- |
1623| scale  | number | Yes  | Scale factor, which is a value greater than 1.|
1624
1625**Error codes**
1626
1627For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1628
1629| ID| Error Message                              |
1630| -------- | ---------------------------------------- |
1631| 17000002 | The async function is not called with await. |
1632| 17000004 | The window or component is invisible or destroyed.           |
1633| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1634
1635**Example**
1636
1637```ts
1638import { Component, Driver, ON } from '@kit.TestKit';
1639async function demo() {
1640  let driver: Driver = Driver.create();
1641  let image: Component = await driver.findComponent(ON.type('Image'));
1642  await image.pinchOut(1.5);
1643}
1644```
1645
1646### pinchIn<sup>9+</sup>
1647
1648pinchIn(scale: number): Promise\<void>
1649
1650Pinches a component to scale it down to the specified ratio.
1651
1652**Atomic service API**: This API can be used in atomic services since API version 11.
1653
1654**System capability**: SystemCapability.Test.UiTest
1655
1656**Parameters**
1657
1658| Name| Type  | Mandatory| Description                           |
1659| ------ | ------ | ---- | ------------------------------- |
1660| scale  | number | Yes  | Scale factor, which is a value ranging from 0 to 1.|
1661
1662**Error codes**
1663
1664For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1665
1666| ID| Error Message                              |
1667| -------- | ---------------------------------------- |
1668| 17000002 | The async function is not called with await. |
1669| 17000004 | The window or component is invisible or destroyed.           |
1670| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1671
1672**Example**
1673
1674```ts
1675import { Component, Driver, ON } from '@kit.TestKit';
1676async function demo() {
1677  let driver: Driver = Driver.create();
1678  let image: Component = await driver.findComponent(ON.type('Image'));
1679  await image.pinchIn(0.5);
1680}
1681```
1682
1683### getDescription<sup>11+</sup>
1684
1685getDescription(): Promise\<string>
1686
1687Obtains the description of this component. This API uses a promise to return the result.
1688
1689**Atomic service API**: This API can be used in atomic services since API version 11.
1690
1691**System capability**: SystemCapability.Test.UiTest
1692
1693**Return value**
1694
1695| Type            | Description                             |
1696| ---------------- | --------------------------------- |
1697| Promise\<string> | Promise used to return the description of the component.|
1698
1699**Error codes**
1700
1701For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1702
1703| ID| Error Message                                                    |
1704| -------- | ------------------------------------------------------------ |
1705| 17000002 | The async function is not called with await.             |
1706| 17000004 | The window or component is invisible or destroyed.                  |
1707
1708**Example**
1709
1710```ts
1711import { Component, Driver, ON } from '@kit.TestKit';
1712async function demo() {
1713  let driver: Driver = Driver.create();
1714  let button: Component = await driver.findComponent(ON.type('Button'));
1715  let description = await button.getDescription();
1716}
1717```
1718
1719## Driver<sup>9+</sup>
1720
1721The **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.
1722All APIs provided by this class, except **Driver.create()**, use a promise to return the result and must be invoked using **await**.
1723
1724### create<sup>9+</sup>
1725
1726static create(): Driver
1727
1728Creates a **Driver** object and returns the object created. This API is a static API.
1729
1730**Atomic service API**: This API can be used in atomic services since API version 11.
1731
1732**System capability**: SystemCapability.Test.UiTest
1733
1734**Return value**
1735
1736| Type| Description          |
1737| -------- | ---------------------- |
1738| Driver   | **Driver** object created.|
1739
1740**Error codes**
1741
1742For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
1743
1744| ID| Error Message              |
1745| -------- | ---------------------- |
1746| 17000001 | Initialization failed. |
1747
1748**Example**
1749
1750```ts
1751import { Driver } from '@kit.TestKit';
1752async function demo() {
1753  let driver: Driver = Driver.create();
1754}
1755```
1756
1757### delayMs<sup>9+</sup>
1758
1759delayMs(duration: number): Promise\<void>
1760
1761Delays this **Driver** object within the specified duration.
1762
1763**Atomic service API**: This API can be used in atomic services since API version 11.
1764
1765**System capability**: SystemCapability.Test.UiTest
1766
1767**Parameters**
1768
1769| Name  | Type  | Mandatory| Description                           |
1770| -------- | ------ | ---- | ------------------------------- |
1771| duration | number | Yes  | Duration of time, in ms. The value must be greater than or equal to 0.|
1772
1773**Error codes**
1774
1775For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1776
1777| ID| Error Message                              |
1778| -------- | ---------------------------------------- |
1779| 17000002 | The async function is not called with await. |
1780| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1781
1782**Example**
1783
1784```ts
1785import { Driver } from '@kit.TestKit';
1786async function demo() {
1787  let driver: Driver = Driver.create();
1788  await driver.delayMs(1000);
1789}
1790```
1791
1792### findComponent<sup>9+</sup>
1793
1794findComponent(on: On): Promise\<Component>
1795
1796Searches this **Driver** object for the target component that matches the given attributes.
1797
1798**Atomic service API**: This API can be used in atomic services since API version 11.
1799
1800**System capability**: SystemCapability.Test.UiTest
1801
1802**Parameters**
1803
1804| Name| Type      | Mandatory| Description                |
1805| ------ | ---------- | ---- | -------------------- |
1806| on     | [On](#on9) | Yes  | Attributes of the target component.|
1807
1808**Return value**
1809
1810| Type                              | Description                             |
1811| ---------------------------------- | --------------------------------- |
1812| Promise\<[Component](#component9)> | Promise used to return the found component.|
1813
1814**Error codes**
1815
1816For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1817
1818| ID| Error Message                              |
1819| -------- | ---------------------------------------- |
1820| 17000002 | The async function is not called with await. |
1821| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1822
1823**Example**
1824
1825```ts
1826import { Component, Driver, ON } from '@kit.TestKit';
1827async function demo() {
1828  let driver: Driver = Driver.create();
1829  let button: Component = await driver.findComponent(ON.text('next page'));
1830}
1831```
1832
1833### findComponents<sup>9+</sup>
1834
1835findComponents(on: On): Promise\<Array\<Component>>
1836
1837Searches this **Driver** object for all components that match the given attributes.
1838
1839**Atomic service API**: This API can be used in atomic services since API version 11.
1840
1841**System capability**: SystemCapability.Test.UiTest
1842
1843**Parameters**
1844
1845| Name| Type      | Mandatory| Description                |
1846| ------ | ---------- | ---- | -------------------- |
1847| on     | [On](#on9) | Yes  | Attributes of the target component.|
1848
1849**Return value**
1850
1851| Type                                      | Description                                   |
1852| ------------------------------------------ | --------------------------------------- |
1853| Promise\<Array\<[Component](#component9)>> | Promise used to return a list of found components.|
1854
1855**Error codes**
1856
1857For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1858
1859| ID| Error Message                              |
1860| -------- | ---------------------------------------- |
1861| 17000002 | The async function is not called with await. |
1862| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1863
1864**Example**
1865
1866```ts
1867import { Component, Driver, ON } from '@kit.TestKit';
1868async function demo() {
1869  let driver: Driver = Driver.create();
1870  let buttonList: Array<Component> = await driver.findComponents(ON.text('next page'));
1871}
1872```
1873
1874### findWindow<sup>9+</sup>
1875
1876findWindow(filter: WindowFilter): Promise\<UiWindow>
1877
1878Searches for the window that matches the specified attributes.
1879
1880**Atomic service API**: This API can be used in atomic services since API version 11.
1881
1882**System capability**: SystemCapability.Test.UiTest
1883
1884**Parameters**
1885
1886| Name| Type                          | Mandatory| Description            |
1887| ------ | ------------------------------ | ---- | ---------------- |
1888| filter | [WindowFilter](#windowfilter9) | Yes  | Attributes of the target window.|
1889
1890**Return value**
1891
1892| Type                            | Description                                 |
1893| -------------------------------- | ------------------------------------- |
1894| Promise\<[UiWindow](#uiwindow9)> | Promise used to return the target window.|
1895
1896**Error codes**
1897
1898For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1899
1900| ID| Error Message                              |
1901| -------- | ---------------------------------------- |
1902| 17000002 | The async function is not called with await. |
1903| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1904
1905**Example**
1906
1907```ts
1908import { Driver, UiWindow } from '@kit.TestKit';
1909async function demo() {
1910  let driver: Driver = Driver.create();
1911  let window: UiWindow = await driver.findWindow({actived: true});
1912}
1913```
1914
1915### waitForComponent<sup>9+</sup>
1916
1917waitForComponent(on: On, time: number): Promise\<Component>
1918
1919Searches this **Driver** object for the target component that matches the given attributes within the specified duration.
1920
1921**Atomic service API**: This API can be used in atomic services since API version 11.
1922
1923**System capability**: SystemCapability.Test.UiTest
1924
1925**Parameters**
1926
1927| Name| Type      | Mandatory| Description                                     |
1928| ------ | ---------- | ---- | ----------------------------------------- |
1929| on    | [On](#on9) | Yes  | Attributes of the target component.                     |
1930| time   | number     | Yes  | Duration for searching for the target component, in ms. The value must be greater than or equal to 0.|
1931
1932**Return value**
1933
1934| Type                             | Description                             |
1935| --------------------------------- | --------------------------------- |
1936| Promise\<[Component](#component9)> | Promise used to return the found component.|
1937
1938**Error codes**
1939
1940For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1941
1942| ID| Error Message                              |
1943| -------- | ---------------------------------------- |
1944| 17000002 | The async function is not called with await. |
1945| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1946
1947**Example**
1948
1949```ts
1950import { Component, Driver, ON } from '@kit.TestKit';
1951async function demo() {
1952  let driver: Driver = Driver.create();
1953  let button: Component = await driver.waitForComponent(ON.text('next page'),500);
1954}
1955```
1956
1957### assertComponentExist<sup>9+</sup>
1958
1959assertComponentExist(on: On): Promise\<void>
1960
1961Asserts that a component that matches the given attributes exists on the current page.
1962
1963**Atomic service API**: This API can be used in atomic services since API version 11.
1964
1965**System capability**: SystemCapability.Test.UiTest
1966
1967**Parameters**
1968
1969| Name| Type      | Mandatory| Description                |
1970| ------ | ---------- | ---- | -------------------- |
1971| on     | [On](#on9) | Yes  | Attributes of the target component.|
1972
1973**Error codes**
1974
1975For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1976
1977| ID| Error Message                              |
1978| -------- | ---------------------------------------- |
1979| 17000002 | The async function is not called with await. |
1980| 17000003 | Assertion failed.   |
1981| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
1982
1983**Example**
1984
1985```ts
1986import { Driver, ON } from '@kit.TestKit';
1987async function demo() {
1988  let driver: Driver = Driver.create();
1989  await driver.assertComponentExist(ON.text('next page'));
1990}
1991```
1992
1993### pressBack<sup>9+</sup>
1994
1995pressBack(): Promise\<void>
1996
1997Presses the Back button on this **Driver** object.
1998
1999**Atomic service API**: This API can be used in atomic services since API version 11.
2000
2001**System capability**: SystemCapability.Test.UiTest
2002
2003**Error codes**
2004
2005For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
2006
2007| ID| Error Message                              |
2008| -------- | ---------------------------------------- |
2009| 17000002 | The async function is not called with await. |
2010
2011**Example**
2012
2013```ts
2014import { Driver } from '@kit.TestKit';
2015async function demo() {
2016  let driver: Driver = Driver.create();
2017  await driver.pressBack();
2018}
2019```
2020
2021### triggerKey<sup>9+</sup>
2022
2023triggerKey(keyCode: number): Promise\<void>
2024
2025Triggers the key of this **Driver** object that matches the given key code.
2026
2027**Atomic service API**: This API can be used in atomic services since API version 11.
2028
2029**System capability**: SystemCapability.Test.UiTest
2030
2031**Parameters**
2032
2033| Name | Type  | Mandatory| Description         |
2034| ------- | ------ | ---- | ------------- |
2035| keyCode | number | Yes  | Key code.|
2036
2037**Error codes**
2038
2039For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2040
2041| ID| Error Message                              |
2042| -------- | ---------------------------------------- |
2043| 17000002 | The async function is not called with await. |
2044| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2045
2046**Example**
2047
2048```ts
2049import { Driver } from '@kit.TestKit';
2050async function demo() {
2051  let driver: Driver = Driver.create();
2052  await driver.triggerKey(123);
2053}
2054```
2055
2056### triggerCombineKeys<sup>9+</sup>
2057
2058triggerCombineKeys(key0: number, key1: number, key2?: number): Promise\<void>
2059
2060Triggers 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**.
2061
2062**Atomic service API**: This API can be used in atomic services since API version 11.
2063
2064**System capability**: SystemCapability.Test.UiTest
2065
2066**Parameters**
2067
2068| Name| Type  | Mandatory| Description                          |
2069| ------ | ------ | ---- | ------------------------------ |
2070| key0   | number | Yes  | The first key value.           |
2071| key1   | number | Yes  | The second key value.           |
2072| key2   | number | No  | The third key value. The default value is **0**.|
2073
2074**Error codes**
2075
2076For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2077
2078| ID| Error Message                              |
2079| -------- | ---------------------------------------- |
2080| 17000002 | The async function is not called with await. |
2081| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2082
2083**Example**
2084
2085```ts
2086import { Driver } from '@kit.TestKit';
2087async function demo() {
2088  let driver: Driver = Driver.create();
2089  await driver.triggerCombineKeys(2072, 2047, 2035);
2090}
2091```
2092
2093
2094### click<sup>9+</sup>
2095
2096click(x: number, y: number): Promise\<void>
2097
2098Clicks a specific point of this **Driver** object based on the given coordinates.
2099
2100**Atomic service API**: This API can be used in atomic services since API version 11.
2101
2102**System capability**: SystemCapability.Test.UiTest
2103
2104**Parameters**
2105
2106| Name| Type  | Mandatory| Description                                           |
2107| ------ | ------ | ---- | ----------------------------------------------- |
2108| x      | number | Yes  | X coordinate of the end point. The value must be greater than or equal to 0.|
2109| y      | number | Yes  | Y coordinate of the end point. The value must be greater than or equal to 0.|
2110
2111**Error codes**
2112
2113For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2114
2115| ID| Error Message                              |
2116| -------- | ---------------------------------------- |
2117| 17000002 | The async function is not called with await. |
2118| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2119
2120**Example**
2121
2122```ts
2123import { Driver } from '@kit.TestKit';
2124async function demo() {
2125  let driver: Driver = Driver.create();
2126  await driver.click(100,100);
2127}
2128```
2129
2130### doubleClick<sup>9+</sup>
2131
2132doubleClick(x: number, y: number): Promise\<void>
2133
2134Double-clicks a specific point of this **Driver** object based on the given coordinates.
2135
2136**Atomic service API**: This API can be used in atomic services since API version 11.
2137
2138**System capability**: SystemCapability.Test.UiTest
2139
2140**Parameters**
2141
2142| Name| Type  | Mandatory| Description                                           |
2143| ------ | ------ | ---- | ----------------------------------------------- |
2144| x      | number | Yes  | X coordinate of the end point. The value must be greater than or equal to 0.|
2145| y      | number | Yes  | Y coordinate of the end point. The value must be greater than or equal to 0.|
2146
2147**Error codes**
2148
2149For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2150
2151| ID| Error Message                              |
2152| -------- | ---------------------------------------- |
2153| 17000002 | The async function is not called with await. |
2154| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2155
2156**Example**
2157
2158```ts
2159import { Driver } from '@kit.TestKit';
2160async function demo() {
2161  let driver: Driver = Driver.create();
2162  await driver.doubleClick(100,100);
2163}
2164```
2165
2166### longClick<sup>9+</sup>
2167
2168longClick(x: number, y: number): Promise\<void>
2169
2170Long-clicks a specific point of this **Driver** object based on the given coordinates.
2171
2172**Atomic service API**: This API can be used in atomic services since API version 11.
2173
2174**System capability**: SystemCapability.Test.UiTest
2175
2176**Parameters**
2177
2178| Name| Type  | Mandatory| Description                                           |
2179| ------ | ------ | ---- | ----------------------------------------------- |
2180| x      | number | Yes  | X coordinate of the end point. The value must be greater than or equal to 0.|
2181| y      | number | Yes  | Y coordinate of the end point. The value must be greater than or equal to 0.|
2182
2183**Error codes**
2184
2185For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2186
2187| ID| Error Message                              |
2188| -------- | ---------------------------------------- |
2189| 17000002 | The async function is not called with await. |
2190| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2191
2192**Example**
2193
2194```ts
2195import { Driver } from '@kit.TestKit';
2196async function demo() {
2197  let driver: Driver = Driver.create();
2198  await driver.longClick(100,100);
2199}
2200```
2201
2202### swipe<sup>9+</sup>
2203
2204swipe(startx: number, starty: number, endx: number, endy: number, speed?: number): Promise\<void>
2205
2206Swipes on this **Driver** object from the given start point to the given end point.
2207
2208**Atomic service API**: This API can be used in atomic services since API version 11.
2209
2210**System capability**: SystemCapability.Test.UiTest
2211
2212**Parameters**
2213
2214| Name| Type  | Mandatory| Description                                                        |
2215| ------ | ------ | ---- | ------------------------------------------------------------ |
2216| startx | number | Yes  | X coordinate of the start point. The value must be greater than or equal to 0.             |
2217| starty | number | Yes  | Y coordinate of the start point. The value must be greater than or equal to 0.             |
2218| endx   | number | Yes  | X coordinate of the end point. The value must be greater than or equal to 0.             |
2219| endy   | number | Yes  | Y coordinate of the end point. The value must be greater than or equal to 0.             |
2220| speed  | number | No  | Swipe speed, in pixel/s. The value ranges from 200 to 40000. If the set value is not in the range, the default value 600 is used.|
2221
2222**Error codes**
2223
2224For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2225
2226| ID| Error Message                              |
2227| -------- | ---------------------------------------- |
2228| 17000002 | The async function is not called with await. |
2229| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2230
2231**Example**
2232
2233```ts
2234import { Driver } from '@kit.TestKit';
2235async function demo() {
2236  let driver: Driver = Driver.create();
2237  await driver.swipe(100,100,200,200,600);
2238}
2239```
2240
2241### drag<sup>9+</sup>
2242
2243drag(startx: number, starty: number, endx: number, endy: number, speed?: number): Promise\<void>
2244
2245Drags this **Driver** object from the given start point to the given end point.
2246
2247**Atomic service API**: This API can be used in atomic services since API version 11.
2248
2249**System capability**: SystemCapability.Test.UiTest
2250
2251**Parameters**
2252
2253| Name| Type  | Mandatory| Description                                                        |
2254| ------ | ------ | ---- | ------------------------------------------------------------ |
2255| startx | number | Yes  | X coordinate of the start point. The value must be greater than or equal to 0.             |
2256| starty | number | Yes  | Y coordinate of the start point. The value must be greater than or equal to 0.             |
2257| endx   | number | Yes  | X coordinate of the end point. The value must be greater than or equal to 0.             |
2258| endy   | number | Yes  | Y coordinate of the end point. The value must be greater than or equal to 0.             |
2259| speed  | number | No  | Drag speed, in pixel/s. The value ranges from 200 to 40000. If the set value is not in the range, the default value 600 is used.|
2260
2261**Error codes**
2262
2263For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2264
2265| ID| Error Message                              |
2266| -------- | ---------------------------------------- |
2267| 17000002 | The async function is not called with await. |
2268| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2269
2270**Example**
2271
2272```ts
2273import { Driver } from '@kit.TestKit';
2274async function demo() {
2275  let driver: Driver = Driver.create();
2276  await driver.drag(100,100,200,200,600);
2277}
2278```
2279
2280### screenCap<sup>9+</sup>
2281
2282screenCap(savePath: string): Promise\<boolean>
2283
2284Captures the current screen of this **Driver** object and saves it as a PNG image to the given save path.
2285
2286**Atomic service API**: This API can be used in atomic services since API version 11.
2287
2288**System capability**: SystemCapability.Test.UiTest
2289
2290**Parameters**
2291
2292| Name  | Type  | Mandatory| Description                                      |
2293| -------- | ------ | ---- | ------------------------------------------ |
2294| savePath | string | Yes  | File save path. The path must be the sandbox path of the current application.|
2295
2296**Return value**
2297
2298| Type             | Description                                  |
2299| ----------------- | -------------------------------------- |
2300| Promise\<boolean> | Promise used to return the result. The value **true** means that the operation is successful.|
2301
2302**Error codes**
2303
2304For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2305
2306| ID| Error Message                              |
2307| -------- | ---------------------------------------- |
2308| 17000002 | The async function is not called with await. |
2309| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2310
2311**Example**
2312
2313```ts
2314import { Driver } from '@kit.TestKit';
2315async function demo() {
2316  let driver: Driver = Driver.create();
2317  await driver.screenCap('/data/storage/el2/base/cache/1.png');
2318}
2319```
2320
2321### setDisplayRotation<sup>9+</sup>
2322
2323setDisplayRotation(rotation: DisplayRotation): Promise\<void>
2324
2325Sets the display rotation of the current scene. It applies to rotatable scenarios.
2326
2327**Atomic service API**: This API can be used in atomic services since API version 11.
2328
2329**System capability**: SystemCapability.Test.UiTest
2330
2331**Parameters**
2332
2333| Name  | Type                                | Mandatory| Description            |
2334| -------- | ------------------------------------ | ---- | ---------------- |
2335| rotation | [DisplayRotation](#displayrotation9) | Yes  | Display rotation of the device.|
2336
2337**Error codes**
2338
2339For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2340
2341| ID| Error Message                              |
2342| -------- | ---------------------------------------- |
2343| 17000002 | The async function is not called with await. |
2344| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2345
2346**Example**
2347
2348```ts
2349import { Driver, DisplayRotation } from '@kit.TestKit';
2350async function demo() {
2351  let driver: Driver = Driver.create();
2352  await driver.setDisplayRotation(DisplayRotation.ROTATION_180);
2353}
2354```
2355
2356### getDisplayRotation<sup>9+</sup>
2357
2358getDisplayRotation(): Promise\<DisplayRotation>
2359
2360Obtains the display rotation of the current device.
2361
2362**Atomic service API**: This API can be used in atomic services since API version 11.
2363
2364**System capability**: SystemCapability.Test.UiTest
2365
2366**Return value**
2367
2368| Type                                          | Description                                   |
2369| ---------------------------------------------- | --------------------------------------- |
2370| Promise\<[DisplayRotation](#displayrotation9)> | Promise used to return the display rotation of the current device.|
2371
2372**Error codes**
2373
2374For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
2375
2376| ID| Error Message                              |
2377| -------- | ---------------------------------------- |
2378| 17000002 | The async function is not called with await. |
2379
2380**Example**
2381
2382```ts
2383import { DisplayRotation, Driver } from '@kit.TestKit';
2384async function demo() {
2385  let driver: Driver = Driver.create();
2386  let rotation: DisplayRotation = await driver.getDisplayRotation();
2387}
2388```
2389
2390### setDisplayRotationEnabled<sup>9+</sup>
2391
2392setDisplayRotationEnabled(enabled: boolean): Promise\<void>
2393
2394Enables or disables display rotation.
2395
2396**Atomic service API**: This API can be used in atomic services since API version 11.
2397
2398**System capability**: SystemCapability.Test.UiTest
2399
2400**Parameters**
2401
2402| Name | Type   | Mandatory| Description                                                   |
2403| ------- | ------- | ---- | ------------------------------------------------------- |
2404| enabled | boolean | Yes  | Whether to enable display rotation. The value **true** means to enable display rotation, and **false** means the opposite.|
2405
2406**Error codes**
2407
2408For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2409
2410| ID| Error Message                              |
2411| -------- | ---------------------------------------- |
2412| 17000002 | The async function is not called with await. |
2413| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2414
2415**Example**
2416
2417```ts
2418import { Driver } from '@kit.TestKit';
2419async function demo() {
2420  let driver: Driver = Driver.create();
2421  await driver.setDisplayRotationEnabled(false);
2422}
2423```
2424
2425### getDisplaySize<sup>9+</sup>
2426
2427getDisplaySize(): Promise\<Point>
2428
2429Obtains the display size of the current device.
2430
2431**Atomic service API**: This API can be used in atomic services since API version 11.
2432
2433**System capability**: SystemCapability.Test.UiTest
2434
2435**Return value**
2436
2437| Type                      | Description                                   |
2438| -------------------------- | --------------------------------------- |
2439| Promise\<[Point](#point9)> | Promise used to return the display size of the current device.|
2440
2441**Error codes**
2442
2443For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
2444
2445| ID| Error Message                              |
2446| -------- | ---------------------------------------- |
2447| 17000002 | The async function is not called with await. |
2448
2449**Example**
2450
2451```ts
2452import { Driver, } from '@kit.TestKit';
2453
2454async function demo() {
2455  let driver: Driver = Driver.create();
2456  let size = await driver.getDisplaySize();
2457}
2458```
2459
2460### getDisplayDensity<sup>9+</sup>
2461
2462getDisplayDensity(): Promise\<Point>
2463
2464Obtains the display density of the current device.
2465
2466**Atomic service API**: This API can be used in atomic services since API version 11.
2467
2468**System capability**: SystemCapability.Test.UiTest
2469
2470**Return value**
2471
2472| Type                      | Description                                     |
2473| -------------------------- | ----------------------------------------- |
2474| Promise\<[Point](#point9)> | Promise used to return the display density of the current device.|
2475
2476**Error codes**
2477
2478For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
2479
2480| ID| Error Message                              |
2481| -------- | ---------------------------------------- |
2482| 17000002 | The async function is not called with await. |
2483
2484**Example**
2485
2486```ts
2487import { Driver } from '@kit.TestKit';
2488async function demo() {
2489  let driver: Driver = Driver.create();
2490  let density = await driver.getDisplayDensity();
2491}
2492```
2493
2494### wakeUpDisplay<sup>9+</sup>
2495
2496wakeUpDisplay(): Promise\<void>
2497
2498Wakes up the device display.
2499
2500**Atomic service API**: This API can be used in atomic services since API version 11.
2501
2502**System capability**: SystemCapability.Test.UiTest
2503
2504**Error codes**
2505
2506For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
2507
2508| ID| Error Message                              |
2509| -------- | ---------------------------------------- |
2510| 17000002 | The async function is not called with await. |
2511
2512**Example**
2513
2514```ts
2515import { Driver } from '@kit.TestKit';
2516async function demo() {
2517  let driver: Driver = Driver.create();
2518  await driver.wakeUpDisplay();
2519}
2520```
2521
2522### pressHome<sup>9+</sup>
2523
2524pressHome(): Promise\<void>
2525
2526Returns to the home screen.
2527
2528**Atomic service API**: This API can be used in atomic services since API version 11.
2529
2530**System capability**: SystemCapability.Test.UiTest
2531
2532**Error codes**
2533
2534For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
2535
2536| ID| Error Message                              |
2537| -------- | ---------------------------------------- |
2538| 17000002 | The async function is not called with await. |
2539
2540**Example**
2541
2542```ts
2543import { Driver } from '@kit.TestKit';
2544async function demo() {
2545  let driver: Driver = Driver.create();
2546  await driver.pressHome();
2547}
2548```
2549
2550### waitForIdle<sup>9+</sup>
2551
2552waitForIdle(idleTime: number, timeout: number): Promise\<boolean>
2553
2554Checks whether all components on the current page are idle.
2555
2556**Atomic service API**: This API can be used in atomic services since API version 11.
2557
2558**System capability**: SystemCapability.Test.UiTest
2559
2560**Parameters**
2561
2562| Name  | Type  | Mandatory| Description                                                        |
2563| -------- | ------ | ---- | ------------------------------------------------------------ |
2564| idleTime | number | Yes  | Idle time threshold, in ms. If the duration for which a component remains inactive reaches this threshold, it is considered as idle. The value must be greater than or equal to 0.|
2565| timeout  | number | Yes  | Maximum idle waiting time, in ms. The value must be greater than or equal to 0.                   |
2566
2567**Return value**
2568
2569| Type             | Description                                               |
2570| ----------------- | --------------------------------------------------- |
2571| Promise\<boolean> | Promise used to return the result.|
2572
2573**Error codes**
2574
2575For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2576
2577| ID| Error Message                              |
2578| -------- | ---------------------------------------- |
2579| 17000002 | The async function is not called with await. |
2580| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2581
2582**Example**
2583
2584```ts
2585import { Driver } from '@kit.TestKit';
2586async function demo() {
2587  let driver: Driver = Driver.create();
2588  let idled:boolean = await driver.waitForIdle(4000,5000);
2589}
2590```
2591
2592### fling<sup>9+</sup>
2593
2594fling(from: Point, to: Point, stepLen: number, speed: number): Promise\<void>
2595
2596Simulates a fling operation on the screen.
2597
2598**Atomic service API**: This API can be used in atomic services since API version 11.
2599
2600**System capability**: SystemCapability.Test.UiTest
2601
2602**Parameters**
2603
2604| Name | Type            | Mandatory| Description                                                        |
2605| ------- | ---------------- | ---- | ------------------------------------------------------------ |
2606| from    | [Point](#point9) | Yes  | Coordinates of the point where the finger touches the screen.                                  |
2607| to      | [Point](#point9) | Yes  | Coordinates of the point where the finger leaves the screen.                                    |
2608| stepLen | number           | Yes  | Fling step length, in pixels.                                    |
2609| speed   | number           | Yes  | Fling speed, in pixel/s. The value ranges from 200 to 40000. If the set value is not in the range, the default value 600 is used.|
2610
2611**Error codes**
2612
2613For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2614
2615| ID| Error Message                              |
2616| -------- | ---------------------------------------- |
2617| 17000002 | The async function is not called with await. |
2618| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2619
2620**Example**
2621
2622```ts
2623import { Driver } from '@kit.TestKit';
2624async function demo() {
2625  let driver: Driver = Driver.create();
2626  await driver.fling({x: 500, y: 480},{x: 450, y: 480},5,600);
2627}
2628```
2629
2630### injectMultiPointerAction<sup>9+</sup>
2631
2632injectMultiPointerAction(pointers: PointerMatrix, speed?: number): Promise\<boolean>
2633
2634Injects a multi-touch operation to the device.
2635
2636**Atomic service API**: This API can be used in atomic services since API version 11.
2637
2638**System capability**: SystemCapability.Test.UiTest
2639
2640**Parameters**
2641
2642| Name  | Type                            | Mandatory| Description                                                        |
2643| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
2644| pointers | [PointerMatrix](#pointermatrix9) | Yes  | Scroll trajectory, including the number of fingers and an array of coordinates along the trajectory.                  |
2645| speed    | number                           | No  | Scroll speed, in pixel/s. The value ranges from 200 to 40000. If the set value is not in the range, the default value 600 is used.|
2646
2647**Return value**
2648
2649| Type             | Description                                 |
2650| ----------------- | ------------------------------------- |
2651| Promise\<boolean> | Promise used to return the result.|
2652
2653**Error codes**
2654
2655For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2656
2657| ID| Error Message                              |
2658| -------- | ---------------------------------------- |
2659| 17000002 | The async function is not called with await. |
2660| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2661
2662**Example**
2663
2664```ts
2665import { Driver, PointerMatrix } from '@kit.TestKit';
2666async function demo() {
2667  let driver: Driver = Driver.create();
2668  let pointers: PointerMatrix = PointerMatrix.create(2,5);
2669  pointers.setPoint(0,0,{x:250,y:480});
2670  pointers.setPoint(0,1,{x:250,y:440});
2671  pointers.setPoint(0,2,{x:250,y:400});
2672  pointers.setPoint(0,3,{x:250,y:360});
2673  pointers.setPoint(0,4,{x:250,y:320});
2674  pointers.setPoint(1,0,{x:250,y:480});
2675  pointers.setPoint(1,1,{x:250,y:440});
2676  pointers.setPoint(1,2,{x:250,y:400});
2677  pointers.setPoint(1,3,{x:250,y:360});
2678  pointers.setPoint(1,4,{x:250,y:320});
2679  await driver.injectMultiPointerAction(pointers);
2680}
2681```
2682
2683### fling<sup>10+</sup>
2684
2685fling(direction: UiDirection, speed: number): Promise\<void>;
2686
2687Simulates a fling operation on the screen, in the specified direction and speed.
2688
2689**Atomic service API**: This API can be used in atomic services since API version 11.
2690
2691**System capability**: SystemCapability.Test.UiTest
2692
2693**Parameters**
2694
2695| Name   | Type                         | Mandatory| Description                                                        |
2696| --------- | ----------------------------- | ---- | ------------------------------------------------------------ |
2697| direction | [UiDirection](#uidirection10) | Yes  | Direction of the fling operation.                                            |
2698| speed     | number                        | Yes  | Fling speed, in pixel/s. The value ranges from 200 to 40000. If the set value is not in the range, the default value 600 is used.|
2699
2700**Error codes**
2701
2702For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2703
2704| ID| Error Message                                                    |
2705| -------- | ------------------------------------------------------------ |
2706| 17000002 | The async function is not called with await.             |
2707| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2708
2709**Example**
2710
2711```ts
2712import { Driver, UiDirection } from '@kit.TestKit';
2713async function demo() {
2714  let driver: Driver = Driver.create();
2715  await driver.fling(UiDirection.DOWN, 10000);
2716}
2717```
2718
2719### screenCapture<sup>10+</sup>
2720
2721screenCapture(savePath: string, rect?: Rect): Promise\<boolean>;
2722
2723Captures the specified area of the current screen and saves the captured screenshot as a PNG image to the specified path.
2724
2725**Atomic service API**: This API can be used in atomic services since API version 11.
2726
2727**System capability**: SystemCapability.Test.UiTest
2728
2729**Parameters**
2730
2731| Name  | Type          | Mandatory| Description                                      |
2732| -------- | -------------- | ---- | ------------------------------------------ |
2733| savePath | string         | Yes  | File save path. The path must be the sandbox path of the current application.|
2734| rect     | [Rect](#rect9) | No  | Area of the screen to capture. The default value is the entire screen.                    |
2735
2736**Return value**
2737
2738| Type             | Description                                  |
2739| ----------------- | -------------------------------------- |
2740| Promise\<boolean> | Promise used to return the result. The value **true** means that the operation is successful.|
2741
2742**Error codes**
2743
2744For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2745
2746| ID| Error Message                                                    |
2747| -------- | ------------------------------------------------------------ |
2748| 17000002 | The async function is not called with await.             |
2749| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2750
2751**Example**
2752
2753```ts
2754import { Driver } from '@kit.TestKit';
2755async function demo() {
2756  let driver: Driver = Driver.create();
2757  await driver.screenCapture('/data/storage/el2/base/cache/1.png', {left: 0, top: 0, right: 100, bottom: 100});
2758}
2759```
2760
2761### mouseClick<sup>10+</sup>
2762
2763mouseClick(p: Point, btnId: MouseButton, key1?: number, key2?: number): Promise\<void>;
2764
2765Injects a mouse click at the specified coordinates, with the optional key or key combination. For example, if the value of **key1** is **2072**, the **Ctrl** button is pressed with the mouse click.
2766
2767**Atomic service API**: This API can be used in atomic services since API version 11.
2768
2769**System capability**: SystemCapability.Test.UiTest
2770
2771**Parameters**
2772
2773| Name| Type                         | Mandatory| Description                          |
2774| ------ | ----------------------------- | ---- | ------------------------------ |
2775| p      | [Point](#point9)              | Yes  | Coordinates of the mouse click.              |
2776| btnId  | [MouseButton](#mousebutton10) | Yes  | Mouse button pressed.              |
2777| key1   | number                        | No  | The first key value. The default value is **0**.|
2778| key2   | number                        | No  | The second key value. The default value is **0**.|
2779
2780**Error codes**
2781
2782For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2783
2784| ID| Error Message                                                    |
2785| -------- | ------------------------------------------------------------ |
2786| 17000002 | The async function is not called with await.             |
2787| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2788
2789**Example**
2790
2791```ts
2792import { Driver,MouseButton } from '@kit.TestKit';
2793async function demo() {
2794  let driver: Driver = Driver.create();
2795  await driver.mouseClick({x:248, y:194}, MouseButton.MOUSE_BUTTON_LEFT, 2072);
2796}
2797```
2798
2799### mouseScroll<sup>10+</sup>
2800
2801mouseScroll(p: Point, down: boolean, d: number, key1?: number, key2?: number): Promise\<void>;
2802
2803Injects a mouse scroll action at the specified coordinates, with the optional key or key combination. For example, if the value of **key1** is **2072**, the **Ctrl** button is pressed with mouse scrolling.
2804
2805**Atomic service API**: This API can be used in atomic services since API version 11.
2806
2807**System capability**: SystemCapability.Test.UiTest
2808
2809**Parameters**
2810
2811| Name| Type            | Mandatory| Description                                                       |
2812| ------ | ---------------- | ---- | ----------------------------------------------------------- |
2813| p      | [Point](#point9) | Yes  | Coordinates of the mouse click.                                           |
2814| down   | boolean          | Yes  | Whether the mouse wheel scrolls downward.<br>**true**: The mouse wheel scrolls downward.<br>**false**: The mouse wheel scrolls upward.|
2815| d      | number           | Yes  | Number of cells by which the mouse wheel scrolls. Scrolling by one cell means a 120-pixel offset of the end point.        |
2816| key1   | number           | No  | The first key value. The default value is **0**.                             |
2817| key2   | number           | No  | The second key value. The default value is **0**.                             |
2818
2819**Error codes**
2820
2821For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2822
2823| ID| Error Message                                                    |
2824| -------- | ------------------------------------------------------------ |
2825| 17000002 | The async function is not called with await.             |
2826| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2827
2828**Example**
2829
2830```ts
2831import { Driver } from '@kit.TestKit';
2832async function demo() {
2833  let driver: Driver = Driver.create();
2834  await driver.mouseScroll({x:360, y:640}, true, 30, 2072)
2835}
2836```
2837
2838### mouseMoveTo<sup>10+</sup>
2839
2840mouseMoveTo(p: Point): Promise\<void>;
2841
2842Moves the cursor to the end point.
2843
2844**System capability**: SystemCapability.Test.UiTest
2845
2846**Atomic service API**: This API can be used in atomic services since API version 11.
2847
2848**Parameters**
2849
2850| Name| Type            | Mandatory| Description          |
2851| ------ | ---------------- | ---- | -------------- |
2852| p      | [Point](#point9) | Yes  | Coordinates of the end point.|
2853
2854**Error codes**
2855
2856For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2857
2858| ID| Error Message                                                    |
2859| -------- | ------------------------------------------------------------ |
2860| 17000002 | The async function is not called with await.             |
2861| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2862
2863**Example**
2864
2865```ts
2866import { Driver } from '@kit.TestKit';
2867async function demo() {
2868  let driver: Driver = Driver.create();
2869  await driver.mouseMoveTo({x:100, y:100})
2870}
2871```
2872
2873### createUIEventObserver<sup>10+</sup>
2874
2875createUIEventObserver(): UIEventObserver;
2876
2877Creates a UI event listener.
2878
2879**Atomic service API**: This API can be used in atomic services since API version 11.
2880
2881**System capability**: SystemCapability.Test.UiTest
2882
2883**Return value**
2884
2885| Type                                  | Description                                 |
2886| ------------------------------------ | ------------------------------------- |
2887|[UIEventObserver](#uieventobserver10) | UI event listener.|
2888
2889**Error codes**
2890
2891For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
2892
2893| ID| Error Message                                |
2894| -------- | ---------------------------------------- |
2895| 17000002 | The async function is not called with await. |
2896
2897**Example**
2898
2899```ts
2900import { Driver, UIEventObserver } from '@kit.TestKit';
2901async function demo() {
2902  let driver: Driver = Driver.create();
2903  let observer: UIEventObserver = await driver.createUIEventObserver()
2904}
2905```
2906
2907### mouseScroll<sup>11+</sup>
2908
2909mouseScroll(p: Point, down: boolean, d: number, key1?: number, key2?: number, speed?: number): Promise\<void>
2910
2911Injects a mouse scroll action at the specified coordinates. You can specify the key or key combination to work with the action, as well as the scroll speed.
2912
2913**Atomic service API**: This API can be used in atomic services since API version 11.
2914
2915**System capability**: SystemCapability.Test.UiTest
2916
2917**Parameters**
2918
2919| Name| Type            | Mandatory| Description                                                        |
2920| ------ | ---------------- | ---- | ------------------------------------------------------------ |
2921| p      | [Point](#point9) | Yes  | Coordinates of the mouse click.                                            |
2922| down   | boolean          | Yes  | Whether the mouse wheel scrolls downward.<br>**true**: The mouse wheel scrolls downward.<br>**false**: The mouse wheel scrolls upward. |
2923| d      | number           | Yes  | Number of cells by which the mouse wheel scrolls. Scrolling by one cell means a 120-pixel offset of the end point.         |
2924| key1   | number           | No  | The first key value. The default value is **0**.                              |
2925| key2   | number           | No  | The second key value. The default value is **0**.                              |
2926| speed  | number           | No  | Scroll speed of the mouse wheel, in cells/second.<br>Value range: 1 to 500<br>If the value is not within the range, the default value **20** will be used.|
2927
2928**Error codes**
2929
2930For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2931
2932| ID| Error Message                                                    |
2933| -------- | ------------------------------------------------------------ |
2934| 17000002 | The async function is not called with await.             |
2935| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2936
2937**Example**
2938
2939```ts
2940import { Driver } from '@kit.TestKit';
2941async function demo() {
2942  let driver: Driver = Driver.create();
2943  await driver.mouseScroll({x:360, y:640}, true, 30, 2072,20)
2944}
2945```
2946
2947### mouseDoubleClick<sup>11+</sup>
2948
2949mouseDoubleClick(p: Point, btnId: MouseButton, key1?: number, key2?: number): Promise\<void>
2950
2951Injects a double-click action at the specified coordinates, with the optional key or key combination. For example, if the value of **key** is **2072**, the **Ctrl** button is pressed with the double-click.
2952
2953**Atomic service API**: This API can be used in atomic services since API version 11.
2954
2955**System capability**: SystemCapability.Test.UiTest
2956
2957**Parameters**
2958
2959| Name| Type                         | Mandatory| Description                          |
2960| ------ | ----------------------------- | ---- | ------------------------------ |
2961| p      | [Point](#point9)              | Yes  | Coordinates of the double-click.              |
2962| btnId  | [MouseButton](#mousebutton10) | Yes  | Mouse button pressed.              |
2963| key1   | number                        | No  | The first key value. The default value is **0**.|
2964| key2   | number                        | No  | The second key value. The default value is **0**.|
2965
2966**Error codes**
2967
2968For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2969
2970| ID| Error Message                                                    |
2971| -------- | ------------------------------------------------------------ |
2972| 17000002 | The async function is not called with await.             |
2973| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
2974
2975**Example**
2976
2977```ts
2978import { Driver,MouseButton } from '@kit.TestKit';
2979async function demo() {
2980  let driver: Driver = Driver.create();
2981  await driver.mouseDoubleClick({x:248, y:194}, MouseButton.MOUSE_BUTTON_LEFT, 2072);
2982}
2983```
2984
2985### mouseLongClick<sup>11+</sup>
2986
2987mouseLongClick(p: Point, btnId: MouseButton, key1?: number, key2?: number): Promise\<void>
2988
2989Injects a long-click action of the mouse device at the specified coordinates, with the optional key or key combination. For example, if the value of **Key** is **2072**, the **Ctrl** button is long-clicked with the mouse device.
2990
2991**Atomic service API**: This API can be used in atomic services since API version 11.
2992
2993**System capability**: SystemCapability.Test.UiTest
2994
2995**Parameters**
2996
2997| Name| Type                         | Mandatory| Description                          |
2998| ------ | ----------------------------- | ---- | ------------------------------ |
2999| p      | [Point](#point9)              | Yes  | Coordinates of the long-click of the mouse device.              |
3000| btnId  | [MouseButton](#mousebutton10) | Yes  | Mouse button pressed.              |
3001| key1   | number                        | No  | The first key value. The default value is **0**.|
3002| key2   | number                        | No  | The second key value. The default value is **0**.|
3003
3004**Error codes**
3005
3006For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3007
3008| ID| Error Message                                                    |
3009| -------- | ------------------------------------------------------------ |
3010| 17000002 | The async function is not called with await.             |
3011| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
3012
3013**Example**
3014
3015```ts
3016import { Driver,MouseButton } from '@kit.TestKit';
3017async function demo() {
3018  let driver:Driver = Driver.create();
3019  await driver.mouseLongClick({x:248, y:194}, MouseButton.MOUSE_BUTTON_LEFT, 2072);
3020}
3021```
3022
3023### mouseMoveWithTrack<sup>11+</sup>
3024
3025mouseMoveWithTrack(from: Point, to: Point, speed?: number): Promise\<void>
3026
3027Moves the mouse pointer from the start point to the end point.
3028
3029**Atomic service API**: This API can be used in atomic services since API version 11.
3030
3031**System capability**: SystemCapability.Test.UiTest
3032
3033**Parameters**
3034
3035| Name| Type            | Mandatory| Description                                                        |
3036| ------ | ---------------- | ---- | ------------------------------------------------------------ |
3037| from   | [Point](#point9) | Yes  | Coordinates of the start point.                                                |
3038| to     | [Point](#point9) | Yes  | Coordinates of the end point.                                                  |
3039| speed  | number           | No  | Scroll speed, in pixel/s. The value ranges from 200 to 40000. If the set value is not in the range, the default value 600 is used.|
3040
3041**Error codes**
3042
3043For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3044
3045| ID| Error Message                                                    |
3046| -------- | ------------------------------------------------------------ |
3047| 17000002 | The async function is not called with await.             |
3048| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
3049
3050**Example**
3051
3052```ts
3053import { Driver } from '@kit.TestKit';
3054async function demo() {
3055  let driver: Driver = Driver.create();
3056  await driver.mouseMoveWithTrack({x:100, y:100},{x:200, y:200},600);
3057}
3058```
3059
3060### mouseDrag<sup>11+</sup>
3061
3062mouseDrag(from: Point, to: Point, speed?: number): Promise\<void>
3063
3064Drags the mouse pointer from the start point to the end point.
3065
3066**Atomic service API**: This API can be used in atomic services since API version 11.
3067
3068**System capability**: SystemCapability.Test.UiTest
3069
3070**Parameters**
3071
3072| Name| Type            | Mandatory| Description                                                        |
3073| ------ | ---------------- | ---- | ------------------------------------------------------------ |
3074| from   | [Point](#point9) | Yes  | Coordinates of the start point.                                                |
3075| to     | [Point](#point9) | Yes  | Coordinates of the end point.                                                  |
3076| speed  | number           | No  | Drag speed, in pixel/s. The value ranges from 200 to 40000. If the set value is not in the range, the default value 600 is used.|
3077
3078**Error codes**
3079
3080For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3081
3082| ID| Error Message                                                    |
3083| -------- | ------------------------------------------------------------ |
3084| 17000002 | The async function is not called with await.             |
3085| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
3086
3087**Example**
3088
3089```ts
3090import { Driver } from '@kit.TestKit';
3091async function demo() {
3092  let driver: Driver = Driver.create();
3093  await driver.mouseDrag({x:100, y:100},{x:200, y:200},600);
3094}
3095```
3096
3097### inputText<sup>11+</sup>
3098
3099inputText(p: Point, text: string): Promise\<void>
3100
3101Enters text at the specified point.
3102
3103**Atomic service API**: This API can be used in atomic services since API version 11.
3104
3105**System capability**: SystemCapability.Test.UiTest
3106
3107**Parameters**
3108
3109| Name| Type            | Mandatory| Description              |
3110| ------ | ---------------- | ---- | ------------------ |
3111| p      | [Point](#point9) | Yes  | Coordinates of the end point.|
3112| text   | string           | Yes  | Text to enter.  |
3113
3114**Error codes**
3115
3116For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3117
3118| ID| Error Message                                                    |
3119| -------- | ------------------------------------------------------------ |
3120| 17000002 | The async function is not called with await.             |
3121| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
3122
3123**Example**
3124
3125```ts
3126import { Component, Driver, ON } from '@kit.TestKit';
3127async function demo() {
3128  let driver:Driver = Driver.create();
3129  let text: Component = await driver.findComponent(ON.type('TextInput'));
3130  let point = await text.getBoundsCenter();
3131  await driver.inputText(point, '123');
3132}
3133```
3134
3135## PointerMatrix<sup>9+</sup>
3136
3137Implements a **PointerMatrix** object that stores coordinates and behaviors of each action of each finger in a multi-touch operation.
3138
3139### create<sup>9+</sup>
3140
3141static create(fingers: number, steps: number): PointerMatrix
3142
3143Creates a **PointerMatrix** object and returns the object created. This API is a static API.
3144
3145**Atomic service API**: This API can be used in atomic services since API version 11.
3146
3147**System capability**: SystemCapability.Test.UiTest
3148
3149**Parameters**
3150
3151| Name | Type  | Mandatory| Description                                      |
3152| ------- | ------ | ---- | ------------------------------------------ |
3153| fingers | number | Yes  | Number of fingers in the multi-touch operation. Value range: [1,10].|
3154| steps   | number | Yes  | Number of steps operated by each finger. Value range: [1,1000].|
3155
3156**Return value**
3157
3158| Type                            | Description                         |
3159| -------------------------------- | ----------------------------- |
3160| [PointerMatrix](#pointermatrix9) | **PointerMatrix** object created.|
3161
3162**Error codes**
3163
3164For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3165
3166| ID| Error Message                                                    |
3167| -------- | ------------------------------------------------------------ |
3168| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
3169
3170**Example**
3171
3172```ts
3173import { PointerMatrix } from '@kit.TestKit';
3174async function demo() {
3175  let pointerMatrix: PointerMatrix = PointerMatrix.create(2,3);
3176}
3177```
3178
3179### setPoint<sup>9+</sup>
3180
3181setPoint(finger: number, step: number, point: Point): void
3182
3183Sets the coordinates for the action corresponding to the specified finger and step in the **PointerMatrix** object.
3184
3185**Atomic service API**: This API can be used in atomic services since API version 11.
3186
3187**System capability**: SystemCapability.Test.UiTest
3188
3189**Parameters**
3190
3191| Name| Type            | Mandatory| Description                                                      |
3192| ------ | ---------------- | ---- | ---------------------------------------------------------- |
3193| finger | number           | Yes  | Sequence number of the finger.                                              |
3194| step   | number           | Yes  | Sequence number of the step.                                              |
3195| point  | [Point](#point9) | Yes  | Coordinates of the action. It is recommended that the distance between adjacent coordinate points is within the range of 10 to 80 pixels.|
3196
3197**Error codes**
3198
3199For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3200
3201| ID| Error Message                                                    |
3202| -------- | ------------------------------------------------------------ |
3203| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
3204
3205**Example**
3206
3207```ts
3208import { PointerMatrix } from '@kit.TestKit';
3209async function demo() {
3210  let pointers: PointerMatrix = PointerMatrix.create(2,5);
3211  pointers.setPoint(0,0,{x:250,y:480});
3212  pointers.setPoint(0,1,{x:250,y:440});
3213  pointers.setPoint(0,2,{x:250,y:400});
3214  pointers.setPoint(0,3,{x:250,y:360});
3215  pointers.setPoint(0,4,{x:250,y:320});
3216  pointers.setPoint(1,0,{x:250,y:480});
3217  pointers.setPoint(1,1,{x:250,y:440});
3218  pointers.setPoint(1,2,{x:250,y:400});
3219  pointers.setPoint(1,3,{x:250,y:360});
3220  pointers.setPoint(1,4,{x:250,y:320});
3221}
3222```
3223
3224## UiWindow<sup>9+</sup>
3225
3226The **UiWindow** class represents a window on the UI and provides APIs for obtaining window attributes, dragging a window, and adjusting the window size.
3227All APIs provided in this class use a promise to return the result and must be invoked using **await**.
3228
3229### getBundleName<sup>9+</sup>
3230
3231getBundleName(): Promise\<string>
3232
3233Obtains the bundle name of the application to which this window belongs.
3234
3235**Atomic service API**: This API can be used in atomic services since API version 11.
3236
3237**System capability**: SystemCapability.Test.UiTest
3238
3239**Return value**
3240
3241| Type            | Description                                     |
3242| ---------------- | ----------------------------------------- |
3243| Promise\<string> | Promise used to return the bundle name.|
3244
3245**Error codes**
3246
3247For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3248
3249| ID| Error Message                              |
3250| -------- | ---------------------------------------- |
3251| 17000002 | The async function is not called with await. |
3252| 17000004 | The window or component is invisible or destroyed.           |
3253
3254**Example**
3255
3256```ts
3257import { Driver, UiWindow } from '@kit.TestKit';
3258
3259async function demo() {
3260  let driver: Driver = Driver.create();
3261  let window: UiWindow = await driver.findWindow({actived: true});
3262  let name: string = await window.getBundleName();
3263}
3264```
3265
3266### getBounds<sup>9+</sup>
3267
3268getBounds(): Promise\<Rect>
3269
3270Obtains the bounds information of this window.
3271
3272**Atomic service API**: This API can be used in atomic services since API version 11.
3273
3274**System capability**: SystemCapability.Test.UiTest
3275
3276**Return value**
3277
3278| Type                    | Description                             |
3279| ------------------------ | --------------------------------- |
3280| Promise\<[Rect](#rect9)> | Promise used to return the bounds information of the window.|
3281
3282**Error codes**
3283
3284For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3285
3286| ID| Error Message                              |
3287| -------- | ---------------------------------------- |
3288| 17000002 | The async function is not called with await. |
3289| 17000004 | The window or component is invisible or destroyed.           |
3290
3291**Example**
3292
3293```ts
3294import { Driver, UiWindow } from '@kit.TestKit';
3295async function demo() {
3296  let driver: Driver = Driver.create();
3297  let window: UiWindow = await driver.findWindow({actived: true});
3298  let rect = await window.getBounds();
3299}
3300```
3301
3302### getTitle<sup>9+</sup>
3303
3304getTitle(): Promise\<string>
3305
3306Obtains the title of this window.
3307
3308**Atomic service API**: This API can be used in atomic services since API version 11.
3309
3310**System capability**: SystemCapability.Test.UiTest
3311
3312**Return value**
3313
3314| Type            | Description                             |
3315| ---------------- | --------------------------------- |
3316| Promise\<string> | Promise used to return the title of the window.|
3317
3318**Error codes**
3319
3320For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3321
3322| ID| Error Message                              |
3323| -------- | ---------------------------------------- |
3324| 17000002 | The async function is not called with await. |
3325| 17000004 | The window or component is invisible or destroyed.           |
3326
3327**Example**
3328
3329```ts
3330import { Driver, UiWindow } from '@kit.TestKit';
3331async function demo() {
3332  let driver: Driver = Driver.create();
3333  let window: UiWindow = await driver.findWindow({actived: true});
3334  let rect = await window.getTitle();
3335}
3336```
3337
3338### getWindowMode<sup>9+</sup>
3339
3340getWindowMode(): Promise\<WindowMode>
3341
3342Obtains the window mode of this window.
3343
3344**Atomic service API**: This API can be used in atomic services since API version 11.
3345
3346**System capability**: SystemCapability.Test.UiTest
3347
3348**Return value**
3349
3350| Type                                | Description                                 |
3351| ------------------------------------ | ------------------------------------- |
3352| Promise\<[WindowMode](#windowmode9)> | Promise used to return the window mode of the window.|
3353
3354**Error codes**
3355
3356For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3357
3358| ID| Error Message                              |
3359| -------- | ---------------------------------------- |
3360| 17000002 | The async function is not called with await. |
3361| 17000004 | The window or component is invisible or destroyed.          |
3362
3363**Example**
3364
3365```ts
3366import { Driver, UiWindow } from '@kit.TestKit';
3367async function demo() {
3368  let driver: Driver = Driver.create();
3369  let window: UiWindow = await driver.findWindow({actived: true});
3370  let mode = await window.getWindowMode();
3371}
3372```
3373
3374### isFocused<sup>9+</sup>
3375
3376isFocused(): Promise\<boolean>
3377
3378Checks whether this window is in focused state.
3379
3380**Atomic service API**: This API can be used in atomic services since API version 11.
3381
3382**System capability**: SystemCapability.Test.UiTest
3383
3384**Return value**
3385
3386| Type             | Description                                                        |
3387| ----------------- | ------------------------------------------------------------ |
3388| Promise\<boolean> | Promise used to return the result. The value **true** means that the window is in focused state, and **false** means the opposite.|
3389
3390**Error codes**
3391
3392For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3393
3394| ID| Error Message                              |
3395| -------- | ---------------------------------------- |
3396| 17000002 | The async function is not called with await. |
3397| 17000004 | The window or component is invisible or destroyed.           |
3398
3399**Example**
3400
3401```ts
3402import { Driver, UiWindow } from '@kit.TestKit';
3403async function demo() {
3404  let driver: Driver = Driver.create();
3405  let window: UiWindow = await driver.findWindow({actived: true});
3406  let focused = await window.isFocused();
3407}
3408```
3409
3410### isActived<sup>(deprecated)</sup>
3411
3412isActived(): Promise\<boolean>
3413
3414Checks whether this window is active. This API uses a promise to return the result.
3415
3416This API is supported since API version 9 and deprecated since API version 11. You are advised to use [isActive<sup>11+</sup>](#isactive11) instead.
3417
3418**System capability**: SystemCapability.Test.UiTest
3419
3420**Return value**
3421
3422| Type             | Description                                                        |
3423| ----------------- | ------------------------------------------------------------ |
3424| Promise\<boolean> | Promise used to return the result. The value **true** means that the window is active, and **false** means the opposite.|
3425
3426**Error codes**
3427
3428For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3429
3430| ID| Error Message                              |
3431| -------- | ---------------------------------------- |
3432| 17000002 | The async function is not called with await. |
3433| 17000004 | The window or component is invisible or destroyed.           |
3434
3435**Example**
3436
3437```ts
3438import { Driver, UiWindow } from '@kit.TestKit';
3439async function demo() {
3440  let driver: Driver = Driver.create();
3441  let window: UiWindow = await driver.findWindow({actived: true});
3442  let focused = await window.isActived();
3443}
3444```
3445
3446### focus<sup>9+</sup>
3447
3448focus(): Promise\<void>
3449
3450Moves the focus to this window.
3451
3452**Atomic service API**: This API can be used in atomic services since API version 11.
3453
3454**System capability**: SystemCapability.Test.UiTest
3455
3456**Error codes**
3457
3458For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3459
3460| ID| Error Message                              |
3461| -------- | ---------------------------------------- |
3462| 17000002 | The async function is not called with await. |
3463| 17000004 | The window or component is invisible or destroyed.           |
3464
3465**Example**
3466
3467```ts
3468import { Driver, UiWindow } from '@kit.TestKit';
3469async function demo() {
3470  let driver: Driver = Driver.create();
3471  let window: UiWindow = await driver.findWindow({actived: true});
3472  await window.focus();
3473}
3474```
3475
3476### moveTo<sup>9+</sup>
3477
3478moveTo(x: number, y: number): Promise\<void>
3479
3480Moves this window to the end point. This API is applicable to moveable windows.
3481
3482**Atomic service API**: This API can be used in atomic services since API version 11.
3483
3484**System capability**: SystemCapability.Test.UiTest
3485
3486**Parameters**
3487
3488| Name| Type  | Mandatory| Description                                           |
3489| ------ | ------ | ---- | ----------------------------------------------- |
3490| x      | number | Yes  | X coordinate of the end point. The value must be greater than or equal to 0.|
3491| y      | number | Yes  | Y coordinate of the end point. The value must be greater than or equal to 0.|
3492
3493**Error codes**
3494
3495For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3496
3497| ID| Error Message                              |
3498| -------- | ---------------------------------------- |
3499| 17000002 | The async function is not called with await. |
3500| 17000004 | The window or component is invisible or destroyed.           |
3501| 17000005 | This operation is not supported.         |
3502| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
3503
3504**Example**
3505
3506```ts
3507import { Driver, UiWindow } from '@kit.TestKit';
3508async function demo() {
3509  let driver: Driver = Driver.create();
3510  let window: UiWindow = await driver.findWindow({actived: true});
3511  await window.moveTo(100, 100);
3512}
3513```
3514
3515### resize<sup>9+</sup>
3516
3517resize(wide: number, height: number, direction: ResizeDirection): Promise\<void>
3518
3519Resizes this window based on the specified width, height, and resize direction. This API is applicable to resizable windows.
3520
3521**Atomic service API**: This API can be used in atomic services since API version 11.
3522
3523**System capability**: SystemCapability.Test.UiTest
3524
3525**Parameters**
3526
3527| Name   | Type                                | Mandatory| Description                                                        |
3528| --------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
3529| wide      | number                               | Yes  | Target width.                        |
3530| height    | number                               | Yes  | Target height.                        |
3531| direction | [ResizeDirection](#resizedirection9) | Yes  | Resize direction.|
3532
3533**Error codes**
3534
3535For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3536
3537| ID| Error Message                              |
3538| -------- | ---------------------------------------- |
3539| 17000002 | The async function is not called with await. |
3540| 17000004 | The window or component is invisible or destroyed.           |
3541| 17000005 | This operation is not supported.         |
3542| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
3543
3544**Example**
3545
3546```ts
3547import { Driver, ResizeDirection, UiWindow } from '@kit.TestKit';
3548async function demo() {
3549  let driver: Driver = Driver.create();
3550  let window: UiWindow = await driver.findWindow({actived: true});
3551  await window.resize(100, 100, ResizeDirection.LEFT);
3552}
3553```
3554
3555### split<sup>9+</sup>
3556
3557split(): Promise\<void>
3558
3559Switches the window to split-screen mode. This API is applicable to windows that support screen splitting.
3560
3561**Atomic service API**: This API can be used in atomic services since API version 11.
3562
3563**System capability**: SystemCapability.Test.UiTest
3564
3565**Error codes**
3566
3567For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3568
3569| ID| Error Message                                |
3570| -------- | ---------------------------------------- |
3571| 17000002 | The async function is not called with await. |
3572| 17000004 | The window or component is invisible or destroyed.         |
3573| 17000005 | This operation is not supported.         |
3574
3575**Example**
3576
3577```ts
3578import { Driver, UiWindow } from '@kit.TestKit';
3579async function demo() {
3580  let driver: Driver = Driver.create();
3581  let window: UiWindow = await driver.findWindow({actived: true});
3582  await window.split();
3583}
3584```
3585
3586### maximize<sup>9+</sup>
3587
3588maximize(): Promise\<void>
3589
3590Maximizes this window. This API is applicable to windows that can be maximized.
3591
3592**Atomic service API**: This API can be used in atomic services since API version 11.
3593
3594**System capability**: SystemCapability.Test.UiTest
3595
3596**Error codes**
3597
3598For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3599
3600| ID| Error Message                              |
3601| -------- | ---------------------------------------- |
3602| 17000002 | The async function is not called with await. |
3603| 17000004 | The window or component is invisible or destroyed.           |
3604| 17000005 | This operation is not supported.         |
3605
3606**Example**
3607
3608```ts
3609import { Driver, UiWindow } from '@kit.TestKit';
3610async function demo() {
3611  let driver: Driver = Driver.create();
3612  let window: UiWindow = await driver.findWindow({actived: true});
3613  await window.maximize();
3614}
3615```
3616
3617### minimize<sup>9+</sup>
3618
3619minimize(): Promise\<void>
3620
3621Minimizes this window. This API is applicable to windows that can be minimized.
3622
3623**Atomic service API**: This API can be used in atomic services since API version 11.
3624
3625**System capability**: SystemCapability.Test.UiTest
3626
3627**Error codes**
3628
3629For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3630
3631| ID| Error Message                              |
3632| -------- | ---------------------------------------- |
3633| 17000002 | The async function is not called with await. |
3634| 17000004 | The window or component is invisible or destroyed.          |
3635| 17000005 | This operation is not supported.         |
3636
3637**Example**
3638
3639```ts
3640import { Driver, UiWindow } from '@kit.TestKit';
3641async function demo() {
3642  let driver: Driver = Driver.create();
3643  let window: UiWindow = await driver.findWindow({actived: true});
3644  await window.minimize();
3645}
3646```
3647
3648### resume<sup>9+</sup>
3649
3650resume(): Promise\<void>
3651
3652Restores this window to the previous window mode.
3653
3654**Atomic service API**: This API can be used in atomic services since API version 11.
3655
3656**System capability**: SystemCapability.Test.UiTest
3657
3658**Error codes**
3659
3660For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3661
3662| ID| Error Message                              |
3663| -------- | ---------------------------------------- |
3664| 17000002 | The async function is not called with await. |
3665| 17000004 | The window or component is invisible or destroyed.          |
3666| 17000005 | This operation is not supported.         |
3667
3668**Example**
3669
3670```ts
3671import { Driver, UiWindow } from '@kit.TestKit';
3672async function demo() {
3673  let driver: Driver = Driver.create();
3674  let window: UiWindow = await driver.findWindow({actived: true});
3675  await window.resume();
3676}
3677```
3678
3679### close<sup>9+</sup>
3680
3681close(): Promise\<void>
3682
3683Closes this window.
3684
3685**Atomic service API**: This API can be used in atomic services since API version 11.
3686
3687**System capability**: SystemCapability.Test.UiTest
3688
3689**Error codes**
3690
3691For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3692
3693| ID| Error Message                              |
3694| -------- | ---------------------------------------- |
3695| 17000002 | The async function is not called with await. |
3696| 17000004 | The window or component is invisible or destroyed.           |
3697| 17000005 | This operation is not supported.         |
3698
3699**Example**
3700
3701```ts
3702import { Driver, UiWindow } from '@kit.TestKit';
3703async function demo() {
3704  let driver:Driver = Driver.create();
3705  let window: UiWindow = await driver.findWindow({actived: true});
3706  await window.close();
3707}
3708```
3709
3710### isActive<sup>11+</sup>
3711
3712isActive(): Promise\<boolean>
3713
3714Checks whether this window is active.
3715
3716**Atomic service API**: This API can be used in atomic services since API version 11.
3717
3718**System capability**: SystemCapability.Test.UiTest
3719
3720**Return value**
3721
3722| Type             | Description                                                        |
3723| ----------------- | ------------------------------------------------------------ |
3724| Promise\<boolean> | Promise used to return the result. The value **true** means that the window is active, and **false** means the opposite.|
3725
3726**Error codes**
3727
3728For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
3729
3730| ID| Error Message                                        |
3731| -------- | ------------------------------------------------ |
3732| 17000002 | The async function is not called with await. |
3733| 17000004 | The window or component is invisible or destroyed.         |
3734
3735**Example**
3736
3737```ts
3738import { Driver, UiWindow } from '@kit.TestKit';
3739async function demo() {
3740  let driver: Driver = Driver.create();
3741  let window: UiWindow = await driver.findWindow({active: true});
3742  let focused = await window.isActive();
3743}
3744```
3745
3746## UIEventObserver<sup>10+</sup>
3747
3748UI event listener.
3749
3750### once('toastShow')
3751
3752once(type: 'toastShow', callback: Callback\<UIElementInfo>): void;
3753
3754Subscribes to events of the toast component. This API uses a callback to return the result.
3755
3756**Atomic service API**: This API can be used in atomic services since API version 11.
3757
3758**System capability**: SystemCapability.Test.UiTest
3759
3760**Parameters**
3761
3762| Name  | Type                                        | Mandatory| Description                             |
3763| -------- | -------------------------------------------- | ---- | --------------------------------- |
3764| type     | string                                       | Yes  | Event type. The value is fixed at **'toastShow'**.|
3765| callback | Callback\<[UIElementInfo](#uielementinfo10)> | Yes  | Callback used to return the result.         |
3766
3767**Error codes**
3768
3769For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3770
3771| ID| Error Message                                                    |
3772| -------- | ------------------------------------------------------------ |
3773| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
3774
3775**Example**
3776
3777```ts
3778import { Driver, UIElementInfo, UIEventObserver } from '@kit.TestKit';
3779async function demo() {
3780  let driver: Driver = Driver.create();
3781  let observer:  UIEventObserver = await driver.createUIEventObserver()
3782  let  callback = (UIElementInfo: UIElementInfo)=>{
3783    console.info(UIElementInfo.bundleName)
3784    console.info(UIElementInfo.text)
3785    console.info(UIElementInfo.type)
3786  }
3787  observer.once('toastShow', callback)
3788}
3789```
3790
3791### once('dialogShow')
3792
3793once(type: 'dialogShow', callback: Callback\<UIElementInfo>): void;
3794
3795Subscribes to events of the dialog component. This API uses a callback to return the result.
3796
3797**Atomic service API**: This API can be used in atomic services since API version 11.
3798
3799**System capability**: SystemCapability.Test.UiTest
3800
3801**Parameters**
3802
3803| Name  | Type                                        | Mandatory| Description                              |
3804| -------- | -------------------------------------------- | ---- | ---------------------------------- |
3805| type     | string                                       | Yes  | Event type. The value is fixed at **'dialogShow'**.|
3806| callback | Callback\<[UIElementInfo](#uielementinfo10)> | Yes  | Callback used to return the result.          |
3807
3808**Error codes**
3809
3810For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3811
3812| ID| Error Message                                                    |
3813| -------- | ------------------------------------------------------------ |
3814| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
3815
3816**Example**
3817
3818```ts
3819import { Driver, UIElementInfo, UIEventObserver } from '@kit.TestKit';
3820async function demo() {
3821  let driver: Driver = Driver.create();
3822  let observer: UIEventObserver = await driver.createUIEventObserver()
3823  let  callback = (UIElementInfo: UIElementInfo)=>{
3824    console.info(UIElementInfo.bundleName)
3825    console.info(UIElementInfo.text)
3826    console.info(UIElementInfo.type)
3827  }
3828  observer.once('dialogShow', callback)
3829}
3830```
3831
3832## By<sup>(deprecated)</sup>
3833
3834The UiTest framework provides a wide range of UI component feature description APIs in the **By** class to filter and match components.<br>
3835The APIs 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.
3836
3837This class is deprecated since API version 9. You are advised to use [On<sup>9+</sup>](#on9) instead.
3838
3839```ts
3840import { BY } from '@kit.TestKit';
3841BY.text('123').type('Button');
3842```
3843
3844### text<sup>(deprecated)</sup>
3845
3846text(txt: string, pattern?: MatchPattern): By
3847
3848Specifies the text attribute of the target component. Multiple match patterns are supported.
3849
3850This API is deprecated since API version 9. You are advised to use [text<sup>9+</sup>](#text9) instead.
3851
3852**System capability**: SystemCapability.Test.UiTest
3853
3854**Parameters**
3855
3856| Name | Type                         | Mandatory| Description                                               |
3857| ------- | ----------------------------- | ---- | --------------------------------------------------- |
3858| txt     | string                        | Yes  | Component text, used to match the target component.               |
3859| pattern | [MatchPattern](#matchpattern) | No  | Match pattern. The default value is [EQUALS](#matchpattern).|
3860
3861**Return value**
3862
3863| Type               | Description                              |
3864| ------------------- | ---------------------------------- |
3865| [By](#bydeprecated) | **By** object that matches the text attribute of the target component.|
3866
3867**Example**
3868
3869```ts
3870import { BY, By } from '@kit.TestKit';
3871let by: By = BY.text('123'); // Use the static constructor BY to create a By object and specify the text attribute of the target component.
3872```
3873
3874
3875### key<sup>(deprecated)</sup>
3876
3877key(key: string): By
3878
3879Specifies the key attribute of the target component.
3880
3881This API is deprecated since API version 9. You are advised to use [id<sup>9+</sup>](#id9) instead.
3882
3883**System capability**: SystemCapability.Test.UiTest
3884
3885**Parameters**
3886
3887| Name| Type  | Mandatory| Description             |
3888| ------ | ------ | ---- | ----------------- |
3889| key    | string | Yes  | Component key.|
3890
3891**Return value**
3892
3893| Type               | Description                               |
3894| ------------------- | ----------------------------------- |
3895| [By](#bydeprecated) | **By** object that matches the key attribute of the target component.|
3896
3897**Example**
3898
3899```ts
3900import { By, BY } from '@kit.TestKit';
3901let by: By = BY.key('123'); // Use the static constructor BY to create a By object and specify the key attribute of the target component.
3902```
3903
3904
3905### id<sup>(deprecated)</sup>
3906
3907id(id: number): By
3908
3909Specifies the ID attribute of the target component.
3910
3911This API is deprecated since API version 9.
3912
3913**System capability**: SystemCapability.Test.UiTest
3914
3915**Parameters**
3916
3917| Name| Type  | Mandatory| Description            |
3918| ------ | ------ | ---- | ---------------- |
3919| id     | number | Yes  | Component ID.|
3920
3921**Return value**
3922
3923| Type               | Description                            |
3924| ------------------- | -------------------------------- |
3925| [By](#bydeprecated) | **By** object that matches the ID attribute of the target component.|
3926
3927**Example**
3928
3929```ts
3930import { By, BY } from '@kit.TestKit';
3931let by: By = BY.id(123); // Use the static constructor BY to create a By object and specify the id attribute of the target component.
3932```
3933
3934
3935### type<sup>(deprecated)</sup>
3936
3937type(tp: string): By
3938
3939Specifies the type attribute of the target component.
3940
3941This API is deprecated since API version 9. You are advised to use [type<sup>9+</sup>](#type9) instead.
3942
3943**System capability**: SystemCapability.Test.UiTest
3944
3945**Parameters**
3946
3947| Name| Type  | Mandatory| Description          |
3948| ------ | ------ | ---- | -------------- |
3949| tp     | string | Yes  | Component type.|
3950
3951**Return value**
3952
3953| Type               | Description                                    |
3954| ------------------- | ---------------------------------------- |
3955| [By](#bydeprecated) | **By** object that matches the type attribute of the target component.|
3956
3957**Example**
3958
3959```ts
3960import { By, BY } from '@kit.TestKit';
3961let by: By = BY.type('Button'); // Use the static constructor BY to create a By object and specify the type attribute of the target component.
3962```
3963
3964
3965### clickable<sup>(deprecated)</sup>
3966
3967clickable(b?: boolean): By
3968
3969Specifies the clickable attribute of the target component.
3970
3971This API is deprecated since API version 9. You are advised to use [clickable<sup>9+</sup>](#clickable9) instead.
3972
3973**System capability**: SystemCapability.Test.UiTest
3974
3975**Parameters**
3976
3977| Name| Type   | Mandatory| Description                                                        |
3978| ------ | ------- | ---- | ------------------------------------------------------------ |
3979| b      | boolean | No  | Clickable status of the target component.<br>**true**: clickable.<br>**false**: not clickable.<br> Default value: **true**|
3980
3981**Return value**
3982
3983| Type               | Description                                      |
3984| ------------------- | ------------------------------------------ |
3985| [By](#bydeprecated) | **By** object that matches the clickable attribute of the target component.|
3986
3987**Example**
3988
3989```ts
3990import { By, BY } from '@kit.TestKit';
3991let by: By = BY.clickable(true); // Use the static constructor BY to create a By object and specify the clickable attribute of the target component.
3992```
3993
3994
3995### scrollable<sup>(deprecated)</sup>
3996
3997scrollable(b?: boolean): By
3998
3999Specifies the scrollable attribute of the target component.
4000
4001This API is deprecated since API version 9. You are advised to use [scrollable<sup>9+</sup>](#scrollable9) instead.
4002
4003**System capability**: SystemCapability.Test.UiTest
4004
4005**Parameters**
4006
4007| Name| Type   | Mandatory| Description                                                       |
4008| ------ | ------- | ---- | ----------------------------------------------------------- |
4009| b      | boolean | No  | Scrollable status of the target component.<br>**true**: scrollable.<br>**false**: not scrollable.<br> Default value: **true**|
4010
4011**Return value**
4012
4013| Type               | Description                                      |
4014| ------------------- | ------------------------------------------ |
4015| [By](#bydeprecated) | **By** object that matches the scrollable attribute of the target component.|
4016
4017**Example**
4018
4019```ts
4020import { By, BY } from '@kit.TestKit';
4021let by: By = BY.scrollable(true); // Use the static constructor BY to create a By object and specify the scrollable attribute of the target component.
4022```
4023
4024### enabled<sup>(deprecated)</sup>
4025
4026enabled(b?: boolean): By
4027
4028Specifies the enabled attribute of the target component.
4029
4030This API is deprecated since API version 9. You are advised to use [enabled<sup>9+</sup>](#enabled9) instead.
4031
4032**System capability**: SystemCapability.Test.UiTest
4033
4034**Parameters**
4035
4036| Name| Type   | Mandatory| Description                                                     |
4037| ------ | ------- | ---- | --------------------------------------------------------- |
4038| b      | boolean | No  | Enabled status of the target component.<br>**true**: enabled.<br>**false**: not enabled.<br> Default value: **true**|
4039
4040**Return value**
4041
4042| Type               | Description                                    |
4043| ------------------- | ---------------------------------------- |
4044| [By](#bydeprecated) | **By** object that matches the enabled attribute of the target component.|
4045
4046**Example**
4047
4048```ts
4049import { By, BY } from '@kit.TestKit';
4050let by: By = BY.enabled(true); // Use the static constructor BY to create a By object and specify the enabled attribute of the target component.
4051```
4052
4053### focused<sup>(deprecated)</sup>
4054
4055focused(b?: boolean): By
4056
4057Specifies the focused attribute of the target component.
4058
4059This API is deprecated since API version 9. You are advised to use [focused<sup>9+</sup>](#focused9) instead.
4060
4061**System capability**: SystemCapability.Test.UiTest
4062
4063**Parameters**
4064
4065| Name| Type   | Mandatory| Description                                                 |
4066| ------ | ------- | ---- | ----------------------------------------------------- |
4067| b      | boolean | No  | Focused status of the target component.<br>**true**: focused.<br>**false**: not focused.<br> Default value: **true**|
4068
4069**Return value**
4070
4071| Type               | Description                                    |
4072| ------------------- | ---------------------------------------- |
4073| [By](#bydeprecated) | **By** object that matches the focused attribute of the target component.|
4074
4075**Example**
4076
4077```ts
4078import { By, BY } from '@kit.TestKit';
4079let by: By = BY.focused(true); // Use the static constructor BY to create a By object and specify the focused attribute of the target component.
4080```
4081
4082### selected<sup>(deprecated)</sup>
4083
4084selected(b?: boolean): By
4085
4086Specifies the selected status of the target component.
4087
4088This API is deprecated since API version 9. You are advised to use [selected<sup>9+</sup>](#selected9) instead.
4089
4090**System capability**: SystemCapability.Test.UiTest
4091
4092**Parameters**
4093
4094| Name| Type   | Mandatory| Description                                                        |
4095| ------ | ------- | ---- | ------------------------------------------------------------ |
4096| b      | boolean | No  | Selected status of the target component.<br>**true**: selected.<br>**false**: not selected.<br> Default value: **true**|
4097
4098**Return value**
4099
4100| Type               | Description                                      |
4101| ------------------- | ------------------------------------------ |
4102| [By](#bydeprecated) | **By** object that matches the selected attribute of the target component.|
4103
4104**Example**
4105
4106```ts
4107import { By, BY } from '@kit.TestKit';
4108let by: By = BY.selected(true); // Use the static constructor BY to create a By object and specify the selected attribute of the target component.
4109```
4110
4111### isBefore<sup>(deprecated)</sup>
4112
4113isBefore(by: By): By
4114
4115Specifies that the target component is located before the given attribute component.
4116
4117This API is deprecated since API version 9. You are advised to use [isBefore<sup>9+</sup>](#isbefore9) instead.
4118
4119**System capability**: SystemCapability.Test.UiTest
4120
4121**Parameters**
4122
4123| Name| Type               | Mandatory| Description            |
4124| ------ | ------------------- | ---- | ---------------- |
4125| by     | [By](#bydeprecated) | Yes  | Information about the attribute component.|
4126
4127**Return value**
4128
4129| Type               | Description                                                |
4130| ------------------- | ---------------------------------------------------- |
4131| [By](#bydeprecated) | **By** object.|
4132
4133**Example**
4134
4135```ts
4136import { By, BY } from '@kit.TestKit';
4137
4138// Use the static constructor BY to create a by object and specify that the target component is located before the given attribute component.
4139let by: By = BY.type('Button').isBefore(BY.text('123')); // Search for the first <Button> component located before the component whose text is 123.
4140```
4141
4142### isAfter<sup>(deprecated)</sup>
4143
4144isAfter(by: By): By
4145
4146Specifies that the target component is located after the given attribute component.
4147
4148This API is deprecated since API version 9. You are advised to use [isAfter<sup>9+</sup>](#isafter9) instead.
4149
4150**System capability**: SystemCapability.Test.UiTest
4151
4152**Parameters**
4153
4154| Name| Type               | Mandatory| Description            |
4155| ------ | ------------------- | ---- | ---------------- |
4156| by     | [By](#bydeprecated) | Yes  | Information about the attribute component.|
4157
4158**Return value**
4159
4160| Type               | Description                                                |
4161| ------------------- | ---------------------------------------------------- |
4162| [By](#bydeprecated) | **By** object.|
4163
4164**Example**
4165
4166```ts
4167import { By, BY } from '@kit.TestKit';
4168
4169// Use the static constructor BY to create a by object and specify that the target component is located after the given attribute component.
4170let by: By = BY.type('Text').isAfter(BY.text('123')); // Search for the first <Text> component located after the component whose text is 123.
4171```
4172
4173## UiComponent<sup>(deprecated)</sup>
4174
4175In **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.
4176All APIs provided in this class use a promise to return the result and must be invoked using **await**.
4177
4178This class is deprecated since API version 9. You are advised to use [Component<sup>9+</sup>](#component9) instead.
4179
4180### click<sup>(deprecated)</sup>
4181
4182click(): Promise\<void>
4183
4184Clicks this component.
4185
4186This API is deprecated since API version 9. You are advised to use [click<sup>9+</sup>](#click9) instead.
4187
4188**System capability**: SystemCapability.Test.UiTest
4189
4190**Example**
4191
4192```ts
4193import { UiDriver, BY, Driver, UiComponent } from '@kit.TestKit';
4194async function demo() {
4195  let driver: UiDriver = UiDriver.create();
4196  let button: UiComponent = await driver.findComponent(BY.type('Button'));
4197  await button.click();
4198}
4199```
4200
4201### doubleClick<sup>(deprecated)</sup>
4202
4203doubleClick(): Promise\<void>
4204
4205Double-clicks this component.
4206
4207This API is deprecated since API version 9. You are advised to use [doubleClick<sup>9+</sup>](#doubleclick9) instead.
4208
4209**System capability**: SystemCapability.Test.UiTest
4210
4211**Example**
4212
4213```ts
4214import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4215async function demo() {
4216  let driver: UiDriver = UiDriver.create();
4217  let button: UiComponent = await driver.findComponent(BY.type('Button'));
4218  await button.doubleClick();
4219}
4220```
4221
4222### longClick<sup>(deprecated)</sup>
4223
4224longClick(): Promise\<void>
4225
4226Long-clicks this component.
4227
4228This API is deprecated since API version 9. You are advised to use [longClick<sup>9+</sup>](#longclick9) instead.
4229
4230**System capability**: SystemCapability.Test.UiTest
4231
4232**Example**
4233
4234```ts
4235import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4236async function demo() {
4237  let driver: UiDriver = UiDriver.create();
4238  let button: UiComponent = await driver.findComponent(BY.type('Button'));
4239  await button.longClick();
4240}
4241```
4242
4243### getId<sup>(deprecated)</sup>
4244
4245getId(): Promise\<number>
4246
4247Obtains the ID of this component.
4248
4249This API is deprecated since API version 9.
4250
4251**System capability**: SystemCapability.Test.UiTest
4252
4253**Return value**
4254
4255| Type            | Description                           |
4256| ---------------- | ------------------------------- |
4257| Promise\<number> | Promise used to return the ID of the component.|
4258
4259**Example**
4260
4261```ts
4262import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4263async function demo() {
4264  let driver: UiDriver = UiDriver.create();
4265  let button: UiComponent = await driver.findComponent(BY.type('Button'));
4266  let id = await button.getId();
4267}
4268```
4269
4270### getKey<sup>(deprecated)</sup>
4271
4272getKey(): Promise\<string>
4273
4274Obtains the key of this component.
4275
4276This API is deprecated since API version 9. You are advised to use [getId<sup>9+</sup>](#getid9) instead.
4277
4278**System capability**: SystemCapability.Test.UiTest
4279
4280**Return value**
4281
4282| Type            | Description                          |
4283| ---------------- | ------------------------------ |
4284| Promise\<string> | Promise used to return the key of the component.|
4285
4286**Example**
4287
4288```ts
4289import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4290async function demo() {
4291  let driver: UiDriver = UiDriver.create();
4292  let button: UiComponent = await driver.findComponent(BY.type('Button'));
4293  let str_key = await button.getKey();
4294}
4295```
4296
4297### getText<sup>(deprecated)</sup>
4298
4299getText(): Promise\<string>
4300
4301Obtains the text information of this component.
4302
4303This API is deprecated since API version 9. You are advised to use [getText<sup>9+</sup>](#gettext9) instead.
4304
4305**System capability**: SystemCapability.Test.UiTest
4306
4307**Return value**
4308
4309| Type            | Description                             |
4310| ---------------- | --------------------------------- |
4311| Promise\<string> | Promise used to return the text information of the component.|
4312
4313**Example**
4314
4315```ts
4316import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4317async function demo() {
4318  let driver: UiDriver = UiDriver.create();
4319  let button: UiComponent = await driver.findComponent(BY.type('Button'));
4320  let text = await button.getText();
4321}
4322```
4323
4324### getType<sup>(deprecated)</sup>
4325
4326getType(): Promise\<string>
4327
4328Obtains the type of this component.
4329
4330This API is deprecated since API version 9. You are advised to use [getType<sup>9+</sup>](#gettype9) instead.
4331
4332**System capability**: SystemCapability.Test.UiTest
4333
4334**Return value**
4335
4336| Type            | Description                         |
4337| ---------------- | ----------------------------- |
4338| Promise\<string> | Promise used to return the type of the component.|
4339
4340**Example**
4341
4342```ts
4343import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4344async function demo() {
4345  let driver: UiDriver = UiDriver.create();
4346  let button: UiComponent = await driver.findComponent(BY.type('Button'));
4347  let type = await button.getType();
4348}
4349```
4350
4351### isClickable<sup>(deprecated)</sup>
4352
4353isClickable(): Promise\<boolean>
4354
4355Obtains the clickable status of this component.
4356
4357This API is deprecated since API version 9. You are advised to use [isClickable<sup>9+</sup>](#isclickable9) instead.
4358
4359**System capability**: SystemCapability.Test.UiTest
4360
4361**Return value**
4362
4363| Type             | Description                                                        |
4364| ----------------- | ------------------------------------------------------------ |
4365| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is clickable, and **false** means the opposite.|
4366
4367**Example**
4368
4369```ts
4370import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4371async function demo() {
4372  let driver: UiDriver = UiDriver.create();
4373  let button: UiComponent = await driver.findComponent(BY.type('Button'));
4374  if(await button.isClickable()) {
4375    console.info('This button can be Clicked');
4376  } else {
4377    console.info('This button can not be Clicked');
4378  }
4379}
4380```
4381
4382### isScrollable<sup>(deprecated)</sup>
4383
4384isScrollable(): Promise\<boolean>
4385
4386Obtains the scrollable status of this component.
4387
4388This API is deprecated since API version 9. You are advised to use [isScrollable<sup>9+</sup>](#isscrollable9) instead.
4389
4390**System capability**: SystemCapability.Test.UiTest
4391
4392**Return value**
4393
4394| Type             | Description                                                        |
4395| ----------------- | ------------------------------------------------------------ |
4396| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is scrollable, and **false** means the opposite.|
4397
4398**Example**
4399
4400```ts
4401import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4402async function demo() {
4403  let driver: UiDriver = UiDriver.create();
4404  let scrollBar: UiComponent = await driver.findComponent(BY.scrollable(true));
4405  if(await scrollBar.isScrollable()) {
4406    console.info('This scrollBar can be operated');
4407  } else {
4408    console.info('This scrollBar can not be operated');
4409  }
4410}
4411```
4412
4413
4414### isEnabled<sup>(deprecated)</sup>
4415
4416isEnabled(): Promise\<boolean>
4417
4418Obtains the enabled status of this component.
4419
4420This API is deprecated since API version 9. You are advised to use [isEnabled<sup>9+</sup>](#isenabled9) instead.
4421
4422**System capability**: SystemCapability.Test.UiTest
4423
4424**Return value**
4425
4426| Type             | Description                                                      |
4427| ----------------- | ---------------------------------------------------------- |
4428| Promise\<boolean> | Promise used to return the result. The value **true** means that the component is enabled, and **false** means the opposite.|
4429
4430**Example**
4431
4432```ts
4433import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4434async function demo() {
4435  let driver: UiDriver = UiDriver.create();
4436  let button: UiComponent = await driver.findComponent(BY.type('Button'));
4437  if(await button.isEnabled()) {
4438    console.info('This button can be operated');
4439  } else {
4440    console.info('This button can not be operated');
4441  }
4442}
4443
4444```
4445
4446### isFocused<sup>(deprecated)</sup>
4447
4448isFocused(): Promise\<boolean>
4449
4450Obtains the focused status of this component.
4451
4452This API is deprecated since API version 9. You are advised to use [isFocused<sup>9+</sup>](#isfocused9) instead.
4453
4454**System capability**: SystemCapability.Test.UiTest
4455
4456**Return value**
4457
4458| Type             | Description                                                        |
4459| ----------------- | ------------------------------------------------------------ |
4460| Promise\<boolean> | Promise used to return the result. The value **true** means that the target component is focused, and **false** means the opposite.|
4461
4462**Example**
4463
4464```ts
4465import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4466async function demo() {
4467  let driver: UiDriver = UiDriver.create();
4468  let button: UiComponent = await driver.findComponent(BY.type('Button'));
4469  if(await button.isFocused()) {
4470    console.info('This button is focused');
4471  } else {
4472    console.info('This button is not focused');
4473  }
4474}
4475```
4476
4477### isSelected<sup>(deprecated)</sup>
4478
4479isSelected(): Promise\<boolean>
4480
4481Obtains the selected status of this component.
4482
4483This API is deprecated since API version 9. You are advised to use [isSelected<sup>9+</sup>](#isselected9) instead.
4484
4485**System capability**: SystemCapability.Test.UiTest
4486
4487**Return value**
4488
4489| Type             | Description                                                 |
4490| ----------------- | ----------------------------------------------------- |
4491| Promise\<boolean> | Promise used to return the selected status of the component. The value **true** means that the component is selected, and **false** means the opposite.|
4492
4493**Example**
4494
4495```ts
4496import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4497async function demo() {
4498  let driver: UiDriver = UiDriver.create();
4499  let button: UiComponent = await driver.findComponent(BY.type('Button'));
4500  if(await button.isSelected()) {
4501    console.info('This button is selected');
4502  } else {
4503    console.info('This button is not selected');
4504  }
4505}
4506```
4507
4508### inputText<sup>(deprecated)</sup>
4509
4510inputText(text: string): Promise\<void>
4511
4512Enters text into this component (available for text boxes).
4513
4514This API is deprecated since API version 9. You are advised to use [inputText<sup>9+</sup>](#inputtext9) instead.
4515
4516**System capability**: SystemCapability.Test.UiTest
4517
4518**Parameters**
4519
4520| Name| Type  | Mandatory| Description            |
4521| ------ | ------ | ---- | ---------------- |
4522| text   | string | Yes  | Text to enter.|
4523
4524**Example**
4525
4526```ts
4527import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4528async function demo() {
4529  let driver: UiDriver = UiDriver.create();
4530  let text: UiComponent = await driver.findComponent(BY.text('hello world'));
4531  await text.inputText('123');
4532}
4533```
4534
4535### scrollSearch<sup>(deprecated)</sup>
4536
4537scrollSearch(by: By): Promise\<UiComponent>
4538
4539Scrolls on this component to search for the target component (applicable to components that support scrolling, such as **List**).
4540
4541This API is deprecated since API version 9. You are advised to use [scrollSearch<sup>9+</sup>](#scrollsearch9) instead.
4542
4543**System capability**: SystemCapability.Test.UiTest
4544
4545**Parameters**
4546
4547| Name| Type               | Mandatory| Description                |
4548| ------ | ------------------- | ---- | -------------------- |
4549| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|
4550
4551**Return value**
4552
4553| Type                                           | Description                                 |
4554| ----------------------------------------------- | ------------------------------------- |
4555| Promise\<[UiComponent](#uicomponentdeprecated)> | Promise used to return the target component.|
4556
4557**Example**
4558
4559```ts
4560import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4561async function demo() {
4562  let driver: UiDriver = UiDriver.create();
4563  let scrollBar: UiComponent = await driver.findComponent(BY.type('Scroll'));
4564  let button = await scrollBar.scrollSearch(BY.text('next page'));
4565}
4566```
4567
4568## UiDriver<sup>(deprecated)</sup>
4569
4570The **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.
4571All APIs provided by this class, except **UiDriver.create()**, use a promise to return the result and must be invoked using **await**.
4572
4573This class is deprecated since API version 9. You are advised to use [Driver<sup>9+</sup>](#driver9) instead.
4574
4575### create<sup>(deprecated)</sup>
4576
4577static create(): UiDriver
4578
4579Creates a **UiDriver** object and returns the object created. This API is a static API.
4580
4581This API is deprecated since API version 9. You are advised to use [create<sup>9+</sup>](#create9) instead.
4582
4583**System capability**: SystemCapability.Test.UiTest
4584
4585**Return value**
4586
4587| Type    | Description                    |
4588| -------- | ------------------------ |
4589| UiDriver | **UiDriver** object created.|
4590
4591**Example**
4592
4593```ts
4594import { UiDriver } from '@kit.TestKit';
4595async function demo() {
4596  let driver: UiDriver = UiDriver.create();
4597}
4598```
4599
4600### delayMs<sup>(deprecated)</sup>
4601
4602delayMs(duration: number): Promise\<void>
4603
4604Delays this **UiDriver** object within the specified duration.
4605
4606This API is deprecated since API version 9. You are advised to use [delayMs<sup>9+</sup>](#delayms9) instead.
4607
4608**System capability**: SystemCapability.Test.UiTest
4609
4610**Parameters**
4611
4612| Name  | Type  | Mandatory| Description        |
4613| -------- | ------ | ---- | ------------ |
4614| duration | number | Yes  | Duration of time.|
4615
4616**Example**
4617
4618```ts
4619import { UiDriver } from '@kit.TestKit';
4620async function demo() {
4621  let driver: UiDriver = UiDriver.create();
4622  await driver.delayMs(1000);
4623}
4624```
4625
4626### findComponent<sup>(deprecated)</sup>
4627
4628findComponent(by: By): Promise\<UiComponent>
4629
4630Searches this **UiDriver** object for the target component that matches the given attributes.
4631
4632This API is deprecated since API version 9. You are advised to use [findComponent<sup>9+</sup>](#findcomponent9) instead.
4633
4634**System capability**: SystemCapability.Test.UiTest
4635
4636**Parameters**
4637
4638| Name| Type               | Mandatory| Description                |
4639| ------ | ------------------- | ---- | -------------------- |
4640| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|
4641
4642**Return value**
4643
4644| Type                                           | Description                             |
4645| ----------------------------------------------- | --------------------------------- |
4646| Promise\<[UiComponent](#uicomponentdeprecated)> | Promise used to return the found component.|
4647
4648**Example**
4649
4650```ts
4651import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4652async function demo() {
4653  let driver: UiDriver = UiDriver.create();
4654  let button: UiComponent = await driver.findComponent(BY.text('next page'));
4655}
4656```
4657
4658### findComponents<sup>(deprecated)</sup>
4659
4660findComponents(by: By): Promise\<Array\<UiComponent>>
4661
4662Searches this **UiDriver** object for all components that match the given attributes.
4663
4664This API is deprecated since API version 9. You are advised to use [findComponents<sup>9+</sup>](#findcomponents9) instead.
4665
4666**System capability**: SystemCapability.Test.UiTest
4667
4668**Parameters**
4669
4670| Name| Type               | Mandatory| Description                |
4671| ------ | ------------------- | ---- | -------------------- |
4672| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|
4673
4674**Return value**
4675
4676| Type                                                   | Description                                   |
4677| ------------------------------------------------------- | --------------------------------------- |
4678| Promise\<Array\<[UiComponent](#uicomponentdeprecated)>> | Promise used to return a list of found components.|
4679
4680**Example**
4681
4682```ts
4683import { UiDriver, BY, UiComponent } from '@kit.TestKit';
4684async function demo() {
4685  let driver: UiDriver = UiDriver.create();
4686  let buttonList: Array<UiComponent> = await driver.findComponents(BY.text('next page'));
4687}
4688```
4689
4690### assertComponentExist<sup>(deprecated)</sup>
4691
4692assertComponentExist(by: By): Promise\<void>
4693
4694Asserts 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.
4695
4696This API is deprecated since API version 9. You are advised to use [assertComponentExist<sup>9+</sup>](#assertcomponentexist9) instead.
4697
4698**System capability**: SystemCapability.Test.UiTest
4699
4700**Parameters**
4701
4702| Name| Type               | Mandatory| Description                |
4703| ------ | ------------------- | ---- | -------------------- |
4704| by     | [By](#bydeprecated) | Yes  | Attributes of the target component.|
4705
4706**Error codes**
4707
4708For details about the error codes, see [UiTest Error Codes](errorcode-uitest.md).
4709
4710| ID| Error Message                                        |
4711| -------- | ------------------------------------------------ |
4712| 401      | if the input parameters are invalid.             |
4713| 17000002 | if the async function was not called with await. |
4714| 17000003 | if the assertion failed.                         |
4715
4716**Example**
4717
4718```ts
4719import { UiDriver, BY } from '@kit.TestKit';
4720async function demo() {
4721  let driver: UiDriver = UiDriver.create();
4722  await driver.assertComponentExist(BY.text('next page'));
4723}
4724```
4725
4726### pressBack<sup>(deprecated)</sup>
4727
4728pressBack(): Promise\<void>
4729
4730Presses the Back button on this **UiDriver** object.
4731
4732This API is deprecated since API version 9. You are advised to use [pressBack<sup>9+</sup>](#pressback9) instead.
4733
4734**System capability**: SystemCapability.Test.UiTest
4735
4736**Example**
4737
4738```ts
4739import { UiDriver } from '@kit.TestKit';
4740async function demo() {
4741  let driver: UiDriver = UiDriver.create();
4742  await driver.pressBack();
4743}
4744```
4745
4746### triggerKey<sup>(deprecated)</sup>
4747
4748triggerKey(keyCode: number): Promise\<void>
4749
4750Triggers the key of this **UiDriver** object that matches the given key code.
4751
4752This API is deprecated since API version 9. You are advised to use [triggerKey<sup>9+</sup>](#triggerkey9) instead.
4753
4754**System capability**: SystemCapability.Test.UiTest
4755
4756**Parameters**
4757
4758| Name | Type  | Mandatory| Description         |
4759| ------- | ------ | ---- | ------------- |
4760| keyCode | number | Yes  | Key code.|
4761
4762**Example**
4763
4764```ts
4765import { Driver, UiDriver } from '@kit.TestKit';
4766async function demo() {
4767  let driver: UiDriver = UiDriver.create();
4768  await driver.triggerKey(123);
4769}
4770```
4771
4772
4773### click<sup>(deprecated)</sup>
4774
4775click(x: number, y: number): Promise\<void>
4776
4777Clicks a specific point of this **UiDriver** object based on the given coordinates.
4778
4779This API is deprecated since API version 9. You are advised to use [click<sup>9+</sup>](#click9) instead.
4780
4781**System capability**: SystemCapability.Test.UiTest
4782
4783**Parameters**
4784
4785| Name| Type  | Mandatory| Description                                  |
4786| ------ | ------ | ---- | -------------------------------------- |
4787| x      | number | Yes  | X coordinate of the end point.|
4788| y      | number | Yes  | Y coordinate of the end point.|
4789
4790**Example**
4791
4792```ts
4793import { UiDriver } from '@kit.TestKit';
4794async function demo() {
4795  let driver: UiDriver = UiDriver.create();
4796  await driver.click(100,100);
4797}
4798```
4799
4800### doubleClick<sup>(deprecated)</sup>
4801
4802doubleClick(x: number, y: number): Promise\<void>
4803
4804Double-clicks a specific point of this **UiDriver** object based on the given coordinates.
4805
4806This API is deprecated since API version 9. You are advised to use [doubleClick<sup>9+</sup>](#doubleclick9) instead.
4807
4808**System capability**: SystemCapability.Test.UiTest
4809
4810**Parameters**
4811
4812| Name| Type  | Mandatory| Description                                  |
4813| ------ | ------ | ---- | -------------------------------------- |
4814| x      | number | Yes  | X coordinate of the end point.|
4815| y      | number | Yes  | Y coordinate of the end point.|
4816
4817**Example**
4818
4819```ts
4820import { UiDriver } from '@kit.TestKit';
4821async function demo() {
4822  let driver: UiDriver = UiDriver.create();
4823  await driver.doubleClick(100,100);
4824}
4825```
4826
4827### longClick<sup>(deprecated)</sup>
4828
4829longClick(x: number, y: number): Promise\<void>
4830
4831Long-clicks a specific point of this **UiDriver** object based on the given coordinates.
4832
4833This API is deprecated since API version 9. You are advised to use [longClick<sup>9+</sup>](#longclick9) instead.
4834
4835**System capability**: SystemCapability.Test.UiTest
4836
4837**Parameters**
4838
4839| Name| Type  | Mandatory| Description                                  |
4840| ------ | ------ | ---- | -------------------------------------- |
4841| x      | number | Yes  | X coordinate of the end point.|
4842| y      | number | Yes  | Y coordinate of the end point.|
4843
4844**Example**
4845
4846```ts
4847import { UiDriver } from '@kit.TestKit';
4848async function demo() {
4849  let driver: UiDriver = UiDriver.create();
4850  await driver.longClick(100,100);
4851}
4852```
4853
4854### swipe<sup>(deprecated)</sup>
4855
4856swipe(startx: number, starty: number, endx: number, endy: number): Promise\<void>
4857
4858Swipes on this **UiDriver** object from the start point to the end point based on the given coordinates.
4859
4860This API is deprecated since API version 9. You are advised to use [swipe<sup>9+</sup>](#swipe9) instead.
4861
4862**System capability**: SystemCapability.Test.UiTest
4863
4864**Parameters**
4865
4866| Name| Type  | Mandatory| Description                                  |
4867| ------ | ------ | ---- | -------------------------------------- |
4868| startx | number | Yes  | X coordinate of the start point.|
4869| starty | number | Yes  | Y coordinate of the start point.|
4870| endx   | number | Yes  | X coordinate of the end point.|
4871| endy   | number | Yes  | Y coordinate of the end point.|
4872
4873**Example**
4874
4875```ts
4876import { UiDriver } from '@kit.TestKit';
4877async function demo() {
4878  let driver: UiDriver = UiDriver.create();
4879  await driver.swipe(100,100,200,200);
4880}
4881```
4882
4883### screenCap<sup>(deprecated)</sup>
4884
4885screenCap(savePath: string): Promise\<boolean>
4886
4887Captures the current screen of this **UiDriver** object and saves it as a PNG image to the given save path.
4888
4889This API is deprecated since API version 9. You are advised to use [screenCap<sup>9+</sup>](#screencap9) instead.
4890
4891**System capability**: SystemCapability.Test.UiTest
4892
4893**Parameters**
4894
4895| Name  | Type  | Mandatory| Description          |
4896| -------- | ------ | ---- | -------------- |
4897| savePath | string | Yes  | File save path.|
4898
4899**Return value**
4900
4901| Type             | Description                                  |
4902| ----------------- | -------------------------------------- |
4903| Promise\<boolean> | Promise used to return the result. The value **true** means that the operation is successful.|
4904
4905**Example**
4906
4907```ts
4908import { UiDriver } from '@kit.TestKit';
4909async function demo() {
4910  let driver: UiDriver = UiDriver.create();
4911  await driver.screenCap('/data/storage/el2/base/cache/1.png');
4912}
4913```
4914