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