>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
```
import {UiDriver,BY,MatchPattern} from '@ohos.uitest'
```
## By
The UiTest framework provides a wide range of UI component feature description APIs in the **By** class to filter and match components.
The API capabilities provided by the **By** class exhibit the following features:
1.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.
2.Provides multiple match patterns for component attributes.
3.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.
| by | By | Yes | Attributes of the component before which the target component is located.|
**Return value**
| Type| Description |
| ---- | -------------- |
| By | Returns the **By** object itself.|
**Example**
```
let by = BY.isBefore(by.text('123')) // Use the static constructor BY to create a By object and specify the attributes of the component before which the target component is located.
```
### By.isAfter
isAfter(by:By):By;
Specifies the attributes of the component after which the target component is located.
| by | By | Yes | Attributes of the component after which the target component is located.|
**Return value**
| Type| Description |
| ---- | -------------- |
| By | Returns the **By** object itself.|
**Example**
```
let by = BY.isAfter(by.text('123')) // Use the static constructor BY to create a By object and specify the attributes of the component after which the target component is located.
```
## UiComponent
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**.
| Promise<UiComponent>; | Promise used to return the target component.|
**Example**
```
let button = await scrollBar.scrollSearch(By.text('next page'))
```
## UiDriver
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.
All APIs provided by this class, except for **UiDriver.create()**, use a promise to return the result and must be invoked using **await**.
### UiDriver.create
static create():UiDriver;
Creates a **UiDriver** object and returns the object created. This API is a static API.
| Promise<Array<UiComponent>>; | Promise used to return a list of found components.|
**Example**
```
let <Array<button>> = await UiDriver.findComponents(By.text('next page'))
```
### UiDriver.assertComponentExist
assertComponentExist(by:By):Promise<void>;
Asserts that a component that matches the given attributes exists on the current page. If the component does not exist, the API throws a JS exception, causing the current test case to fail.