# @ohos.UiTest The **UiTest** module provides APIs that you can use to simulate UI actions during testing, such as clicks, double-clicks, long-clicks, and swipes. This module provides the following functions: - [On9+](#on9): provides UI component feature description APIs for component filtering and matching. - [Component9+](#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. - [Driver9+](#driver9): works as the entry class and provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot. - [UiWindow9+](#uiwindow9): works as the entry class and provides APIs for obtaining window attributes, dragging windows, and adjusting window sizes. - [By(deprecated)](#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 [On9+](#on9) instead. - [UiComponent(deprecated)](#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 [Component9+](#component9) instead. - [UiDriver(deprecated)](#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 [Driver9+](#driver9) instead. > **NOTE** > - 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. > - The APIs of this module can be used only in [arkxtest](../../application-test/arkxtest-guidelines.md). > - The APIs of this module do not support concurrent calls. > - The APIs of this module are applicable to phones, tablets, PCs/2-in-1devices, wearables, smart visions, and head units. ## Modules to Import ```ts import { UiComponent, UiDriver, Component, Driver, UiWindow, ON, BY, MatchPattern, DisplayRotation, ResizeDirection, WindowMode, PointerMatrix, UiDirection, MouseButton, UIElementInfo, UIEventObserver } from '@kit.TestKit'; ``` ## MatchPattern Enumerates the match patterns supported for component attributes. **System capability**: SystemCapability.Test.UiTest | Name | Value| Description | |-----------------------|---|---------------------------------------------------------------------| | EQUALS | 0 | Equals the given value.
**Atomic service API**: This API can be used in atomic services since API version 11. | | CONTAINS | 1 | Contains the given value.
**Atomic service API**: This API can be used in atomic services since API version 11. | | STARTS_WITH | 2 | Starts with the given value.
**Atomic service API**: This API can be used in atomic services since API version 11. | | ENDS_WITH | 3 | Ends with the given value.
**Atomic service API**: This API can be used in atomic services since API version 11. | | REG_EXP18+ | 4 | Uses regular expression matching.
**Atomic service API**: This API can be used in atomic services since API version 18. | | REG_EXP_ICASE18+ | 5 | Uses case-insensitive regular expression matching.
**Atomic service API**: This API can be used in atomic services since API version 18.| ## ResizeDirection9+ Enumerates the directions in which a window can be resized. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest | Name | Value | Description | | ---------- | ---- | -------- | | LEFT | 0 | Left. | | RIGHT | 1 | Right. | | UP | 2 | Up. | | DOWN | 3 | Down. | | LEFT_UP | 4 | Upper left.| | LEFT_DOWN | 5 | Lower left.| | RIGHT_UP | 6 | Upper right.| | RIGHT_DOWN | 7 | Lower right.| ## Point9+ Provides the coordinates of a point. **System capability**: SystemCapability.Test.UiTest | Name| Type | Read-Only| Optional| Description | | ---- | ------ | ---- | ---- |-----------| | x | number | No | No | Horizontal coordinate of a coordinate point. The value is an integer greater than 0.
**Note**: Since API version 20, this attribute is no longer read-only.
**Atomic service API**: This API can be used in atomic services since API version 11.| | y | number | No | No | Vertical coordinate of a coordinate point. The value is an integer greater than 0.
**Note**: Since API version 20, this attribute is no longer read-only.
**Atomic service API**: This API can be used in atomic services since API version 11.| | displayId20+ | number | No | Yes | ID of the display to which the coordinate point belongs. The value is an integer greater than or equal to 0. The default value is the default screen ID of the device.
**Atomic service API**: This API can be used in atomic services since API version 20.| ## Rect9+ Provides bounds information of a component. **System capability**: SystemCapability.Test.UiTest | Name | Type | Read-Only| Optional| Description | | ------ | ------ | ---- | ---- | ------------------------- | | left | number | No | No|X coordinate of the upper left corner of the component border. The value is an integer greater than 0.
**Note**: Since API version 20, this attribute is no longer read-only.
**Atomic service API**: This API can be used in atomic services since API version 11.| | top | number | No | No|Y coordinate of the upper left corner of the component border. The value is an integer greater than 0.
**Note**: Since API version 20, this attribute is no longer read-only.
**Atomic service API**: This API can be used in atomic services since API version 11. | | right | number | No | No|X coordinate of the lower right corner of the component border. The value is an integer greater than 0.
**Note**: Since API version 20, this attribute is no longer read-only.
**Atomic service API**: This API can be used in atomic services since API version 11. | | bottom | number | No | No|Y coordinate of the lower right corner of the component border. The value is an integer greater than 0.
**Note**: Since API version 20, this attribute is no longer read-only.
**Atomic service API**: This API can be used in atomic services since API version 11. | | displayId20+ | number | No | Yes|ID of the display to which the component border belongs. The value is an integer greater than or equal to 0. The default value is the default screen ID of the device.
**Atomic service API**: This API can be used in atomic services since API version 20. | ## WindowMode9+ Enumerates the window modes. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest | Name | Value | Description | | ---------- | ---- | ---------- | | FULLSCREEN | 0 | Full-screen mode.| | PRIMARY | 1 | Primary window mode. | | SECONDARY | 2 | Secondary window mode.| | FLOATING | 3 | Floating window mode.| ## DisplayRotation9+ Describes the display rotation of the device. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest | Name | Value | Description | | ------------ | ---- | ---------------------------------------- | | ROTATION_0 | 0 | The device display is not rotated and is in its original vertical orientation. | | ROTATION_90 | 1 | The device display rotates 90° clockwise and is in landscape orientation. | | ROTATION_180 | 2 | The device display rotates 180° clockwise and is in reverse vertical orientation.| | ROTATION_270 | 3 | The device display rotates 270° clockwise and is in reverse landscape orientation.| ## WindowFilter9+ Provides the flag attributes of this window. **System capability**: SystemCapability.Test.UiTest | Name | Type | Read-Only| Optional| Description | | -------------------- | ------- | ---- | ---- |----------------------------------------------------------------------------------------| | bundleName | string | No | Yes | Bundle name of the application to which the window belongs. The default value is empty.
**Atomic service API**: This API can be used in atomic services since API version 11. | | title | string | No | Yes | Title of the window. The default value is empty.
**Atomic service API**: This API can be used in atomic services since API version 11. | | focused | boolean | No | Yes | Whether the window is focused. The value **true** indicates that the window is focused, and **false** indicates the opposite. The default value is **false**.
**Atomic service API**: This API can be used in atomic services since API version 11.| | actived(deprecated) | boolean | No | Yes | Whether the window is interacting with the user. The value **true** indicates that the window is interacting with the user, and **false** indicates the opposite.
This API is deprecated since API version 11. You are advised to use the **active** API instead. | | active11+ | boolean | No | Yes | Whether the window is interacting with the user. The value **true** indicates that the window is interacting with the user, and **false** indicates the opposite.
**Atomic service API**: This API can be used in atomic services since API version 11. | | displayId20+ | number | No | Yes | ID of the display to which the window belongs. The value is an integer greater than or equal to 0. The default value is the default screen ID of the device.
**Atomic service API**: This API can be used in atomic services since API version 20.| ## UiDirection10+ Describes the direction of a UI operation such as fling. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest | Name | Value | Description | | ----- | ---- | ------ | | LEFT | 0 | Leftward.| | RIGHT | 1 | Rightward.| | UP | 2 | Upward.| | DOWN | 3 | Downward.| ## MouseButton10+ Describes the injected simulated mouse button. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest | Name | Value | Description | | ------------------- | ---- | ------------ | | MOUSE_BUTTON_LEFT | 0 | Left button on the mouse. | | MOUSE_BUTTON_RIGHT | 1 | Right button on the mouse. | | MOUSE_BUTTON_MIDDLE | 2 | Middle button on the mouse.| ## UIElementInfo10+ Provides information about the UI event. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest | Name | Type | Read-Only| Optional| Description | | ---------- | ------ | ---- | ---- | --------------------- | | bundleName | string | Yes | No | Bundle name of the home application. | | type | string | Yes | No | Component or window type. | | text | string | Yes | No | Text information of the component or window.| ## TouchPadSwipeOptions18+ Describes information about the touchpad swipe gesture option. **Atomic service API**: This API can be used in atomic services since API version 18. **System capability**: SystemCapability.Test.UiTest | Name | Type | Read-Only| Optional| Description | | ---------- | ------ |----|----|--------------------------------------------------------| | stay | boolean | No | Yes | Whether the swipe gesture stays on the touchpad for 1s before it is lifted. The value **true** indicates that the swipe gesture stays on the touchpad for 1s, and **false** indicates the opposite. The default value is **false**.| | speed | number | No | Yes | Swipe speed, in px/s. The value is an integer ranges from 200 to 40000. If the set value is not in the range, the default value **2000** is used. | ## InputTextMode20+ Describes the text input mode. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.Test.UiTest | Name | Type | Read-Only| Optional| Description | | ---------- | ------ |----|----|----------------------------------------------------------| | paste | boolean | No | Yes | Whether to copy and paste text. The value **true** means to copy and paste text, and **false** means to type text. Default value: **false**
**NOTE**
1. If the input text contains Chinese characters or special characters or contains more than 200 characters, the text is copied and pasted regardless of the value of this parameter.
2. For smart wearable devices, this API does not support input in copy and paste mode.| | addition | boolean | No | Yes | Whether to input text in addition mode. The value **true** means to input text in addition mode, and **false** means the opposite. Default value: **false**| ## On9+ Since API version 9, the UiTest framework provides a wide range of UI component feature description APIs in the **On** class to filter and match components.
The APIs provided by the **On** class exhibit the following features:
1. Allow one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component.
2. Provide multiple match patterns for component attributes.
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.
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. ```ts import { ON } from '@kit.TestKit'; ON.text('123').type('Button'); ``` ### text9+ text(txt: string, pattern?: MatchPattern): On Specifies the text attribute of the target component. Multiple match patterns are supported. > **NOTE** > > If the [accessibilityLevel](../apis-arkui/arkui-ts/ts-universal-attributes-accessibility.md#accessibilitylevel) of a component is set to **no** or **no-hide-descendants**, this API cannot be used to specify the text attribute of the target component for searching for the component. In this case, you can use the [On.originalText ()](#originaltext20) API. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name | Type | Mandatory| Description | | ------- | ----------------------------- | ---- | --------------------------------------------------- | | txt | string | Yes | Component text, used to match the target component. | | pattern | [MatchPattern](#matchpattern) | No | Match pattern. The default value is [EQUALS](#matchpattern).| **Return value** | Type | Description | | ---------- | ---------------------------------- | | [On](#on9) | **On** object that matches the text attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.text('123'); // Use the static constructor ON to create an On object and specify the text attribute of the target component. ``` ### id9+ id(id: string): On Specifies the ID attribute of the target component. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | ---------------- | | id | string | Yes | Component ID.| **Return value** | Type | Description | | ---------- | -------------------------------- | | [On](#on9) | **On** object that matches the ID attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.id('123'); // Use the static constructor ON to create an On object and specify the id attribute of the target component. ``` ### id18+ id(id: string, pattern: MatchPattern): On Specifies the ID attribute of the target component. **Atomic service API**: This API can be used in atomic services since API version 18. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name | Type | Mandatory| Description | |-----------------------| ------ |----|---------------------------------------| | id | string | Yes | Component ID. | | pattern | [MatchPattern](#matchpattern) | Yes | Text matching pattern.| **Return value** | Type | Description | | ---------- | -------------------------------- | | [On](#on9) | **On** object that matches the ID attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| **Example** ```ts import { MatchPattern, On, ON } from '@kit.TestKit'; let on:On = ON.id('id', MatchPattern.REG_EXP_ICASE) // Use case-insensitive regular expression to match the ID attribute value of the component. ``` ### type9+ type(tp: string): On Specifies the type attribute of the target component. >**NOTE** > >You can define the type of the component. In addition, you can use [DevEco Testing](https://developer.huawei.com/consumer/en/download) to query the type information of the component. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name| Type | Mandatory| Description | | ------ | ------ | ---- | -------------- | | tp | string | Yes | Component type.| **Return value** | Type | Description | | ---------- | ---------------------------------------- | | [On](#on9) | **On** object that matches the type attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.type('Button'); // Use the static constructor ON to create an On object and specify the type attribute of the target component. ``` ### type18+ type(tp: string, pattern: MatchPattern): On Specifies the type attribute of the target component. >**NOTE** > >You can define the type of the component. In addition, you can use [DevEco Testing](https://developer.huawei.com/consumer/en/download) to query the type information of the component. **Atomic service API**: This API can be used in atomic services since API version 18. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name | Type | Mandatory| Description | |-----------------------| ------ |----|---------------------------------------| | tp | string | Yes | Component type. | | pattern | [MatchPattern](#matchpattern) | Yes | Text matching pattern.| **Return value** | Type | Description | | ---------- | ---------------------------------------- | | [On](#on9) | **On** object that matches the type attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.type('Button'); // Use the static constructor ON to create an On object and specify the type attribute of the target component. ``` ### clickable9+ clickable(b?: boolean): On Specifies the clickable attribute of the target component. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | ------------------------------------------------------------ | | b | boolean | No | Clickable status of the component. The value **true** indicates that the component is clickable, and **false** indicates the opposite. Default value: **true**| **Return value** | Type | Description | | ---------- | ------------------------------------------ | | [On](#on9) | **On** object that matches the clickable attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.clickable(true); // Use the static constructor ON to create an On object and specify the clickable attribute of the target component. ``` ### longClickable9+ longClickable(b?: boolean): On Specifies the long-clickable attribute of the target component. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | ------------------------------------------------------------ | | b | boolean | No | Long-clickable status of the component. The value **true** indicates that the component is long-clickable, and **false** indicates the opposite. Default value: **true**| **Return value** | Type | Description | | ---------- | ---------------------------------------------- | | [On](#on9) | **On** object that matches the long-clickable attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.longClickable(true); // Use the static constructor ON to create an On object and specify the longClickable attribute of the target component. ``` ### scrollable9+ scrollable(b?: boolean): On Specifies the scrollable attribute of the target component. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | ----------------------------------------------------------- | | b | boolean | No | Scrollable status of the component. The value **true** indicates that the component is scrollable, and **false** indicates the opposite. Default value: **true**| **Return value** | Type | Description | | ---------- | ------------------------------------------ | | [On](#on9) | **On** object that matches the scrollable attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.scrollable(true); // Use the static constructor ON to create an On object and specify the scrollable attribute of the target component. ``` ### enabled9+ enabled(b?: boolean): On Specifies the enabled attribute of the target component. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | --------------------------------------------------------- | | b | boolean | No | Enabled status of the component. The value **true** indicates that the component is enabled, and **false** indicates the opposite. Default value: **true**| **Return value** | Type | Description | | ---------- | ---------------------------------------- | | [On](#on9) | **On** object that matches the enabled attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.enabled(true); // Use the static constructor ON to create an On object and specify the enabled attribute of the target component. ``` ### focused9+ focused(b?: boolean): On Specifies the focused attribute of the target component. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | ----------------------------------------------------- | | b | boolean | No | Focused status of the component. The value **true** indicates that the component is focused, and **false** indicates the opposite. Default value: **true**| **Return value** | Type | Description | | ---------- | ---------------------------------------- | | [On](#on9) | **On** object that matches the focused attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.focused(true); // Use the static constructor ON to create an On object and specify the focused attribute of the target component. ``` ### selected9+ selected(b?: boolean): On Specifies the selected attribute of the target component. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | ------------------------------------------------------------ | | b | boolean | No | Selected status of the component. The value **true** indicates that the component is selected, and **false** indicates the opposite. Default value: **true**| **Return value** | Type | Description | | ---------- | ------------------------------------------ | | [On](#on9) | **On** object that matches the selected attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.selected(true); // Use the static constructor ON to create an On object and specify the selected attribute of the target component. ``` ### checked9+ checked(b?: boolean): On Specifies the checked attribute of the target component. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | ------------------------------------------------------------ | | b | boolean | No | Checked status of the component. The value **true** indicates that the component is checked, and **false** indicates the opposite. Default value: **true**| **Return value** | Type | Description | | ---------- | ------------------------------------------ | | [On](#on9) | **On** object that matches the checked attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1. Incorrect parameter types; 2. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.checked(true); // Use the static constructor ON to create an On object and specify the checked attribute of the target component. ``` ### checkable9+ checkable(b?: boolean): On Specifies the checkable attribute of the target component. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name| Type | Mandatory| Description | | ------ | ------- | ---- | ------------------------------------------------------------ | | b | boolean | No | Checkable status of the component. The value **true** indicates that the component is checkable, and **false** indicates the opposite. Default value: **true**| **Return value** | Type | Description | | ---------- | -------------------------------------------- | | [On](#on9) | **On** object that matches the checkable attribute of the target component.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. 1. Incorrect parameter types; 2. Parameter verification failed. | **Example** ```ts import { On, ON } from '@kit.TestKit'; let on:On = ON.checkable(true); // Use the static constructor ON to create an On object and specify the checkable attribute of the target component. ``` ### isBefore9+ isBefore(on: On): On Specifies that the target component is located before the given attribute component. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Test.UiTest **Parameters** | Name| Type | Mandatory| Description | | ------ | ---------- | ---- | -------------------- | | on | [On](#on9) | Yes | Information about the attribute component.| **Return value** | Type | Description | | ---------- | ---------------------------------------------------- | | [On](#on9) | **On** object.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| **Example** ```ts import { On, ON } from '@kit.TestKit'; // Use the static constructor ON to create an On object and specify that the target component is located before the given attribute component. let on:On = ON.type('Button').isBefore(ON.text('123')); // Search for the first