>**NOTE**<br>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 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.
## Modules to Import
## Modules to Import
...
@@ -13,46 +12,27 @@ import {UiDriver,BY,MatchPattern} from '@ohos.uitest'
...
@@ -13,46 +12,27 @@ import {UiDriver,BY,MatchPattern} from '@ohos.uitest'
## By
## By
The UiTest framework provides a wide range of UI component feature description APIs in the **By** class to filter and match components.
The UiTest framework provides a wide range of UI component feature description APIs in the **By** class to filter and match components.<br>
The API capabilities provided by the **By** class exhibit the following features:
The API capabilities provided by the **By** class exhibit the following features:<br>1. Allow one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component. <br>2. Provide multiple match patterns for component attributes. <br>3. Support absolute positioning and relative positioning for components. APIs such as [By.isBefore](#byisbefore) and [By.isAfter](#byisafter) 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.
- Allows one or more attributes as the match conditions. For example, you can specify both the **text** and **id** attributes to find the target component.
```js
BY.text('123').type('button')
- Provides multiple match patterns for component attributes.
```
- Supports absolute positioning and relative positioning for components. APIs such as **isBefore** and **isAfter** can be used to specify the features of adjacent components to assist positioning.
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, for example, **BY.text('123').type('button')**.
### enum MatchPattern
Enumerates the match patterns supported for component attributes.
| b | bool | No | Long-clickable status of the target component. The default value is **true**.|
**Return value**
| Type| Description |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
**Example**
```js
letby=BY.longClickable(true)// Use the static constructor BY to create a By object and specify the long-clickable status attribute of the target component.
```
```
### By.scrollable
### By.scrollable
scrollable(b?:bool):By;
scrollable(b?: bool): By
Specifies the scrollable attribute of the target component.
**Required permissions**: none
Specifies the scrollable status attribute of the target component.
| by | By | Yes | Attributes of the component before which the target component is located.|
| by | By | Yes | Attributes of the component before which the target component is located.|
**Return value**
**Return value**
| Type| Description |
| Type| Description |
| ---- | -------------- |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
| By | Returns the **By** object itself.|
**Example**
**Example**
```
```js
let by = BY.isBefore(BY.text('123')) // Use the static constructor BY to create a By object and specify the attributes
letby=BY.isBefore(BY.text('123'))// Use the static constructor BY to create a By object and specify the attributes of the component before which the target component is located.
of the component before which the target component is located.
```
```
### By.isAfter
### By.isAfter
isAfter(by:By):By;
isAfter(by: By): By
Specifies the attributes of the component after which the target component is located.
Specifies the attributes of the component after which the target component is located.
| by | By | Yes | Attributes of the component before which the target component is located.|
| by | By | Yes | Attributes of the component before which the target component is located.|
**Return value**
**Return value**
| Type| Description |
| Type| Description |
| ---- | -------------- |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
| By | Returns the **By** object itself.|
**Example**
**Example**
```
```js
let by = BY.isAfter(BY.text('123')) // Use the static constructor BY to create a By object and specify the attributes
letby=BY.isAfter(BY.text('123'))// Use the static constructor BY to create a By object and specify the attributes of the component after which the target component is located.
of the component after which the target component is located.
```
```
## UiComponent
## UiComponent
In **UiTest**, the **UiComponent** class represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection.
In **UiTest**, the **UiComponent** class represents a component on the UI and provides APIs for obtaining component attributes, clicking a component, scrolling to search for a component, and text injection.
All APIs provided by this class use a promise to return the result and must be invoked using **await**.
All APIs provided in this class use a promise to return the result and must be invoked using **await**.
The **UiDriver** class is the main entry to the **uitest** test framework. It provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot.
The **UiDriver** class is the main entry to the **uitest** test framework. It provides APIs for features such as component matching/search, key injection, coordinate clicking/sliding, and screenshot.
...
@@ -753,23 +955,21 @@ All APIs provided by this class, except for **UiDriver.create()**, use a promise
...
@@ -753,23 +955,21 @@ All APIs provided by this class, except for **UiDriver.create()**, use a promise
### UiDriver.create
### UiDriver.create
static create():UiDriver;
static create(): UiDriver
Creates a **UiDriver** object and returns the object created. This API is a static API.
Creates a **UiDriver** object and returns the object created. This API is a static API.
Asserts that a component that matches the given attributes exists on the current page. If the component does not exist, the API throws a JS exception, causing the current test case to fail.
Asserts that a component that matches the given attributes exists on the current page. If the component does not exist, the API throws a JS exception, causing the current test case to fail.