未验证 提交 e5c0e640 编写于 作者: O openharmony_ci 提交者: Gitee

!5566 翻译完成 4650:js-apis-uitest.md修改失败示例代码 等

Merge pull request !5566 from ester.zhou/C2-0617
......@@ -13,7 +13,7 @@ Each application can subscribe to common events as required. After your applicat
## Common Event Subscription Development
### When to Use
You can create a subscriber object to subscribe to a common event to obtain the parameters passed in the event. Certain system common events require specific permissions to subscribe to. For details, see [Required Permissions](../reference/apis/js-apis-commonEvent.md).
You can create a subscriber object to subscribe to a common event to obtain the parameters passed in the event. Certain system common events require specific permissions to subscribe to. For details, see [Required Permissions](../reference/apis/js-apis-commonEvent.md#required-permissions).
### Available APIs
| API | Description|
......@@ -25,13 +25,13 @@ You can create a subscriber object to subscribe to a common event to obtain the
### How to Develop
1. Import the **commonEvent** module.
```javascript
```js
import commonEvent from '@ohos.commonEvent';
```
2. Create a **subscribeInfo** object. For details about the data types and parameters of the object, see [CommonEventSubscribeInfo](../reference/apis/js-apis-commonEvent.md#commoneventsubscribeinfo).
```javascript
```js
private subscriber = null // Used to save the created subscriber object for subsequent subscription and unsubscription.
// Subscriber information
......@@ -42,7 +42,7 @@ var subscribeInfo = {
3. Create a subscriber object and save the returned object for subsequent operations such as subscription and unsubscription.
```javascript
```js
// Callback for subscriber creation.
commonEvent.createSubscriber(subscribeInfo, (err, subscriber) => {
if (err.code) {
......@@ -57,7 +57,7 @@ commonEvent.createSubscriber(subscribeInfo, (err, subscriber) => {
4. Create a subscription callback, which is triggered when an event is received. The data returned by the subscription callback contains information such as the common event name and data carried by the publisher. For details about the data types and parameters of the common event data, see [CommonEventData](../reference/apis/js-apis-commonEvent.md#commoneventdata).
```javascript
```js
// Callback for common event subscription.
if (this.subscriber != null) {
commonEvent.subscribe(this.subscriber, (err, data) => {
......@@ -74,7 +74,7 @@ if (this.subscriber != null) {
}
```
## Public Event Publishing Development
## Common Event Publishing Development
### When to Use
You can use the **publish** APIs to publish a custom common event, which can carry data for subscribers to parse and process.
......@@ -89,13 +89,13 @@ You can use the **publish** APIs to publish a custom common event, which can car
#### Development for Publishing a Common Event
1. Import the **commonEvent** module.
```javascript
```js
import commonEvent from '@ohos.commonEvent';
```
2. Pass in the common event name and callback, and publish the event.
```javascript
```js
// Publish a common event.
commonEvent.publish("event", (err) => {
if (err.code) {
......@@ -109,13 +109,13 @@ commonEvent.publish("event", (err) => {
#### Development for Publishing a Common Event with Given Attributes
1. Import the **commonEvent** module.
```javascript
```js
import commonEvent from '@ohos.commonEvent'
```
2. Define attributes of the common event to publish. For details about the data types and parameters in the data to publish, see [CommonEventPublishData](../reference/apis/js-apis-commonEvent.md#commoneventpublishdata).
```javascript
```js
// Attributes of a common event.
var options = {
code: 1, // Result code of the common event
......@@ -125,7 +125,7 @@ var options = {
3. Pass in the common event name, attributes of the common event, and callback, and publish the event.
```javascript
```js
// Publish a common event.
commonEvent.publish("event", options, (err) => {
if (err.code) {
......@@ -149,14 +149,14 @@ You can use the **unsubscribe** API to unsubscribe from a common event.
### How to Develop
1. Import the **commonEvent** module.
```javascript
```js
import commonEvent from '@ohos.commonEvent';
```
2. Subscribe to a common event by following instructions in [Common Event Subscription Development](#Common-Event-Subscription-Development).
3. Invoke the **unsubscribe** API in **CommonEvent** to unsubscribe from the common event.
```javascript
```js
if (this.subscriber != null) {
commonEvent.unsubscribe(this.subscriber, (err) => {
if (err.code) {
......
......@@ -4,26 +4,26 @@
### System Capabilities and APIs
SysCap is short for System Capability. It refers to a standalone feature in the operating system, for example, Bluetooth, Wi-Fi, NFC, or camera. Each system capability corresponds to a set of bound APIs, whose availability depends on the support of the target device. Such a set of APIs can be provided in the IDE for association.
SysCap is short for System Capability. It refers to a standalone feature in the operating system, for example, Bluetooth, Wi-Fi, NFC, or camera. Each SysCap corresponds to a set of bound APIs, whose availability depends on the support of the target device. Such a set of APIs are provided in DevEco Studio for association.
![image-20220326064841782](figures/image-20220326064841782.png)
### Supported Capability Set, Associated Capability Set, and Required Capability Set
### Supported SysCap Set, Associated SysCap Set, and Required SysCap Set
The supported capability set, associated capability set, and required capability set are collections of system capabilities.
The supported capability set covers the device capabilities, and the required capability set covers the application capabilities. If the capability set required by application A is a subset of the capability set supported by device N, application A can be distributed to device N for installation and running. Otherwise, application A cannot be distributed.
The associated capability set covers the system capabilities of associated APIs that the IDE offers during application development.
The supported SysCap set, associated SysCap set, and required SysCap set are collections of SysCaps.
The supported SysCap set covers the device capabilities, and the required SysCap set covers the application capabilities. If the SysCap set required by application A is a subset of the SysCap set supported by device N, application A can be distributed to device N for installation and running. Otherwise, application A cannot be distributed.
The associated SysCap set covers the system capabilities of associated APIs that the IDE offers during application development.
![image-20220326064913834](figures/image-20220326064913834.png)
### Devices and Supported Capability Sets
### Devices and Supported SysCap Sets
Each device provides a capability set that matches its hardware capability.
The SDK classifies devices into general devices and custom devices. The general devices' supported capability set is defined by OpenHarmony, and the custom devices' is defined by device vendors.
Each device provides a SysCap set that matches its hardware capability.
The SDK classifies devices into general devices and custom devices. The general devices' supported SysCap set is defined by OpenHarmony, and the custom devices' is defined by device vendors.
![image-20220326064955505](figures/image-20220326064955505.png)
......@@ -31,7 +31,7 @@ The SDK classifies devices into general devices and custom devices. The general
### Mapping Between Devices and SDK Capabilities
The SDK provides a full set of APIs for the IDE. The IDE identifies the supported capability set based on the devices supported by the project, filters the APIs contained in the capability set, and provides the supported APIs for association (to autocomplete input).
The SDK provides a full set of APIs for the IDE. DevEco Studio identifies the supported SysCap set based on the devices supported by the project, filters the APIs contained in the SysCap set, and provides the supported APIs for association (to autocomplete input).
![image-20220326065043006](figures/image-20220326065043006.png)
......@@ -49,11 +49,11 @@ Right-click the project directory and choose **Import Product Compatibility ID**
### Configuring the Associated Capability Set and Required Capability Set
### Configuring the Associated SysCap Set and Required SysCap Set
The IDE automatically configures the associated capability set and required capability set based on the settings supported by the created project. You can modify the capability sets when necessary.
You can add APIs to the associated capability set in the IDE by adding system capabilities. However, note that these APIs may not be supported on the device. Therefore, check whether these APIs are supported before using them.
Exercise caution when modifying the required capability set. Incorrect modifications may cause the application to unable to be distributed to the target device.
DevEco Studio automatically configures the associated SysCap set and required SysCap set based on the settings supported by the created project. You can modify these SysCap sets when necessary.
You can add APIs to the associated SysCap set in DevEco Studio by adding system capabilities. However, note that these APIs may not be supported on the device. Therefore, check whether these APIs are supported before using them.
Exercise caution when modifying the required SysCap set. Incorrect modifications may result in the application being unable to be distributed to the target device.
```
/* syscap.json */
......@@ -74,15 +74,15 @@ Exercise caution when modifying the required capability set. Incorrect modificat
...
]
},
development: { /* The SysCap set in addedSysCaps and the SysCap set supported by each device configured in devices form the associated capability set. */
development: { /* The SysCap set in addedSysCaps and the SysCap set supported by each device configured in devices form the associated SysCap set. */
addedSysCaps: [
"SystemCapability.Location.Location.Lite",
...
]
},
production: { /* Used to generate the RPCID. Exercise caution when adding this parameter. Under incorrect settings, applications may fail to be distributed to target devices. */
addedSysCaps: [], // Intersection of SysCap sets supported by devices configured in devices. It is the required capability set with addedSysCaps set and removedSysCaps set.
removedSysCaps: [] // When the required capability set is a capability subset of a device, the application can be distributed to the device.
addedSysCaps: [], // Intersection of SysCap sets supported by devices configured in devices. It is the required SysCap set with addedSysCaps set and removedSysCaps set.
removedSysCaps: [] // When the required SysCap set is a capability subset of a device, the application can be distributed to the device.
}
}
```
......@@ -91,7 +91,7 @@ Exercise caution when modifying the required capability set. Incorrect modificat
### Single-Device Application Development
By default, the association capability set and required system capability set of the application are the same as the supported system capability set of the device. Exercise caution when modifying the required capability set.
By default, the associated SysCap set and required SysCap set of the application are the same as the supported SysCap set of the device. Exercise caution when modifying the required SysCap set.
![image-20220326065124911](figures/image-20220326065124911.png)
......@@ -99,7 +99,7 @@ By default, the association capability set and required system capability set of
### Cross-Device Application Development
By default, the associated capability set of the application is the union of multiple devices' supported capability sets. The capability sets must be the intersection.
By default, the associated SysCap set of an application is the union of multiple devices' supported SysCap sets, while the required SysCap set is the intersection of the devices' supported SysCap sets.
![image-20220326065201867](figures/image-20220326065201867.png)
......@@ -133,9 +133,9 @@ if (geolocation) {
### Checking the Differences Between Devices with the Same Capability
### Checking the Differences Between Devices with a Specific SysCap
The performance of a system capability may vary by device type. For example, a tablet is superior to a smart wearable device in terms of the camera capability.
The performance of a SysCap may vary by device type. For example, a tablet is superior to a smart wearable device in terms of the camera capability.
```
import userAuth from '@ohos.userIAM.userAuth';
......@@ -158,11 +158,11 @@ authenticator.execute('FACE_ONLY', 'S1', (err, result) => {
### How Do SysCap Differences Arise Between Devices
The SysCap of devices varies according to the component combination defined by the product solution vendor. The following figure shows the overall process.
The device SysCaps in product solutions vary according to the component combination defined by the product solution vendor. The following figure shows the overall process.
![image-20220326072448840](figures/image-20220326072448840.png)
1. A set of OpenHarmony source code consists of optional and mandatory components. Different components have different system capabilities. In other words, different components represent different SysCaps.
1. A set of OpenHarmony source code consists of optional and mandatory components. Different components represent different SysCaps.
2. In a normalized released SDK, APIs are mapped to SysCap sets.
......@@ -170,10 +170,10 @@ The SysCap of devices varies according to the component combination defined by t
4. The components configured for a product can be OpenHarmony components or proprietary components developed by a third party. Since there is mapping between components and SysCap, the SysCap set of the product can be obtained after all components are assembled.
5. The SysCap set is encoded to generate the PCID. You can import the PCID to the IDE and decode it into SysCap. During development, compatibility processing is performed to mitigate the SysCap differences of devices.
5. The SysCap set is encoded to generate the PCID. You can import the PCID to DevEco Studio and decode it into SysCaps. During development, compatibility processing is performed to mitigate the SysCap differences of devices.
6. System parameters deployed on devices contain the SysCap set. The system provides native interfaces and application interfaces for components and applications to check whether a SysCap set is available.
6. System parameters deployed on devices contain the SysCap set. The system provides native interfaces and application interfaces for components and applications to check whether a specific SysCap is available.
7. During application development, the SysCap required by the application is encoded into the Required Product Compatibility ID (RPCID) and written into the application installation package. During application installation, the package manager decodes the RPCID to obtain the SysCap required by the application and compares it with the SysCap of the device. If the SysCap required by the application is met, the application can be installed.
7. During application development, the SysCap set required by the application is encoded into the Required Product Compatibility ID (RPCID) and written into the application installation package. During application installation, the package manager decodes the RPCID to obtain the SysCap set required by the application and compares it with the SysCap set supported by the device. If the SysCap set required by the application is met, the application can be installed on the device.
8. When an application is running, the **canIUse** API can be used to query whether the SysCap is compatible with the device.
8. When an application is running on a device, the **canIUse** API can be used to query whether the device is compatible with a specific SysCap.
# Upload and Download
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> **NOTE**<br>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
......@@ -15,23 +14,23 @@ import request from '@ohos.request';
## Constraints
- HTTPS is supported by default. To support HTTP, you need to add **network** to the **config.json** file and set the **cleartextTraffic** attribute to **true**.
```
"deviceConfig": {
"default": {
"network": {
"cleartextTraffic": true
}
...
HTTPS is supported by default. To support HTTP, you need to add **network** to the **config.json** file and set the **cleartextTraffic** attribute to **true**.
```
"deviceConfig": {
"default": {
"network": {
"cleartextTraffic": true
}
...
}
```
}
```
## Constants
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -65,7 +64,7 @@ upload(config: UploadConfig): Promise&lt;UploadTask&gt;
Uploads files. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
......@@ -84,11 +83,13 @@ Uploads files. This API uses a promise to return the result.
**Example**
```js
request.upload({ url: 'https://patch' }).then((data) => {
uploadTask = data;
}).catch((err) => {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
})
let file1 = { filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" };
let uploadTask;
request.upload({ url: 'https://patch', files: [file1] }).then((data) => {
uploadTask = data;
}).catch((err) => {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
})
```
......@@ -98,7 +99,7 @@ upload(config: UploadConfig, callback: AsyncCallback&lt;UploadTask&gt;): void
Uploads files. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
......@@ -112,19 +113,21 @@ Uploads files. This API uses an asynchronous callback to return the result.
**Example**
```js
request.upload({ url: 'https://patch' }, (err, data) => {
if (err) {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
return;
}
uploadTask = data;
});
let file1 = { filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" };
let uploadTask;
request.upload({ url: 'https://patch', files: [file1] }, (err, data) => {
if (err) {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
return;
}
uploadTask = data;
});
```
## UploadTask
Implements file uploads. Before using a method of this class, you must obtain an **UploadTask** object.
Implements file uploads. Before using any APIs of this class, you must obtain an **UploadTask** object.
### on('progress')
......@@ -133,7 +136,7 @@ on(type: 'progress', callback:(uploadedSize: number, totalSize: number) =&gt; vo
Subscribes to the upload progress event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
......@@ -154,10 +157,10 @@ Parameters of the callback function
**Example**
```js
uploadTask.on('progress', function callback(uploadedSize, totalSize) {
console.info("upload totalSize:" + totalSize + " uploadedSize:" + uploadedSize);
}
);
uploadTask.on('progress', function callback(uploadedSize, totalSize) {
console.info("upload totalSize:" + totalSize + " uploadedSize:" + uploadedSize);
}
);
```
......@@ -167,7 +170,7 @@ on(type: 'headerReceive', callback: (header: object) =&gt; void): void
Subscribes to the **headerReceive** event, which is triggered when an HTTP response header is received. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
......@@ -187,10 +190,10 @@ Parameters of the callback function
**Example**
```js
uploadTask.on('headerReceive', function callback(headers){
console.info("upOnHeader headers:" + JSON.stringify(headers));
}
);
uploadTask.on('headerReceive', function callback(headers){
console.info("upOnHeader headers:" + JSON.stringify(headers));
}
);
```
......@@ -200,7 +203,7 @@ off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) =&g
Unsubscribes from the upload progress event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
......@@ -221,10 +224,10 @@ Parameters of the callback function
**Example**
```js
uploadTask.off('progress', function callback(uploadedSize, totalSize) {
console.info('uploadedSize: ' + uploadedSize, 'totalSize: ' + totalSize);
}
);
uploadTask.off('progress', function callback(uploadedSize, totalSize) {
console.info('uploadedSize: ' + uploadedSize, 'totalSize: ' + totalSize);
}
);
```
......@@ -234,7 +237,7 @@ off(type: 'headerReceive', callback?: (header: object) =&gt; void): void
Unsubscribes from the **headerReceive** event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
......@@ -254,10 +257,10 @@ Parameters of the callback function
**Example**
```js
uploadTask.off('headerReceive', function callback(headers) {
console.info("upOnHeader headers:" + JSON.stringify(headers));
}
);
uploadTask.off('headerReceive', function callback(headers) {
console.info("upOnHeader headers:" + JSON.stringify(headers));
}
);
```
......@@ -267,7 +270,7 @@ remove(): Promise&lt;boolean&gt;
Removes this upload task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
......@@ -280,15 +283,15 @@ Removes this upload task. This API uses a promise to return the result.
**Example**
```js
uploadTask.remove().then((result) => {
if (result) {
console.info('Upload task removed successfully. ');
} else {
console.error('Failed to remove the upload task. ');
}
}).catch((err) => {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err));
});
uploadTask.remove().then((result) => {
if (result) {
console.info('Upload task removed successfully. ');
} else {
console.error('Failed to remove the upload task. ');
}
}).catch((err) => {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err));
});
```
......@@ -298,7 +301,7 @@ remove(callback: AsyncCallback&lt;boolean&gt;): void
Removes this upload task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
......@@ -311,17 +314,17 @@ Removes this upload task. This API uses an asynchronous callback to return the r
**Example**
```js
uploadTask.remove((err, result) => {
if (err) {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Upload task removed successfully.');
} else {
console.error('Failed to remove the upload task.');
}
});
uploadTask.remove((err, result) => {
if (err) {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err));
return;
}
if (result) {
console.info('Upload task removed successfully.');
} else {
console.error('Failed to remove the upload task.');
}
});
```
......@@ -366,7 +369,7 @@ download(config: DownloadConfig): Promise&lt;DownloadTask&gt;
Downloads files. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -384,13 +387,14 @@ Downloads files. This API uses a promise to return the result.
**Example**
```js
request.download({ url: 'https://xxxx/xxxx.hap' }).then((data) => {
downloadTask = data;
}).catch((err) => {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
})
```
```js
let downloadTask;
request.download({ url: 'https://xxxx/xxxx.hap' }).then((data) => {
downloadTask = data;
}).catch((err) => {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
})
```
## request.download
......@@ -399,7 +403,7 @@ download(config: DownloadConfig, callback: AsyncCallback&lt;DownloadTask&gt;): v
Downloads files. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -413,14 +417,15 @@ Downloads files. This API uses an asynchronous callback to return the result.
**Example**
```js
request.download({ url: 'https://xxxx/xxxxx.hap',
filePath: 'xxx/xxxxx.hap'}, (err, data) => {
if (err) {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
return;
}
downloadTask = data;
});
let downloadTask;
request.download({ url: 'https://xxxx/xxxxx.hap',
filePath: 'xxx/xxxxx.hap'}, (err, data) => {
if (err) {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
return;
}
downloadTask = data;
});
```
......@@ -435,7 +440,7 @@ on(type: 'progress', callback:(receivedSize: number, totalSize: number) =&gt; vo
Subscribes to the download progress event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -456,12 +461,6 @@ Parameters of the callback function
**Example**
```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask = data;
downloadTask.on('progress', function download_callback(receivedSize, totalSize) {
console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize);
}
......@@ -476,7 +475,7 @@ off(type: 'progress', callback?: (receivedSize: number, totalSize: number) =&gt;
Unsubscribes from the download progress event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -497,17 +496,11 @@ Parameters of the callback function
**Example**
```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask = data;
downloadTask .off('progress', function download_callback(receivedSize, totalSize) {
console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize);
}
);
});
downloadTask .off('progress', function download_callback(receivedSize, totalSize) {
console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize);
}
);
});
```
......@@ -517,7 +510,7 @@ on(type: 'complete'|'pause'|'remove', callback:() =&gt; void): void
Subscribes to a download event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -531,17 +524,11 @@ Subscribes to a download event. This API uses an asynchronous callback to return
**Example**
```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask= data;
downloadTask.on('complete', function callback() {
console.info('Download task completed.');
}
);
});
downloadTask.on('complete', function callback() {
console.info('Download task completed.');
}
);
});
```
......@@ -551,7 +538,7 @@ off(type: 'complete'|'pause'|'remove', callback?:() =&gt; void): void
Unsubscribes from the download event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -565,17 +552,11 @@ Unsubscribes from the download event. This API uses an asynchronous callback to
**Example**
```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + JSON.stringify(err));
return;
}
downloadTask = data;
downloadTask.off('complete', function callback() {
console.info('Download task completed.');
}
);
});
downloadTask.off('complete', function callback() {
console.info('Download task completed.');
}
);
});
```
......@@ -585,7 +566,7 @@ on(type: 'fail', callback: (err: number) =&gt; void): void
Subscribes to the download task failure event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -604,18 +585,12 @@ Parameters of the callback function
**Example**
```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask = data;
downloadTask.on('fail', function callBack(err) {
console.info('Download task failed. Cause:' + err);
}
);
});
```js
downloadTask.on('fail', function callBack(err) {
console.info('Download task failed. Cause:' + err);
}
);
});
```
......@@ -625,7 +600,7 @@ off(type: 'fail', callback?: (err: number) =&gt; void): void
Unsubscribes from the download task failure event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -645,12 +620,6 @@ Parameters of the callback function
**Example**
```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask = data;
downloadTask.off('fail', function callBack(err) {
console.info('Download task failed. Cause:' + err);
}
......@@ -665,7 +634,7 @@ remove(): Promise&lt;boolean&gt;
Removes this download task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -696,7 +665,7 @@ remove(callback: AsyncCallback&lt;boolean&gt;): void
Removes this download task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -709,17 +678,17 @@ Removes this download task. This API uses an asynchronous callback to return the
**Example**
```js
downloadTask.remove((err, result)=>{
if(err) {
console.error('Failed to remove the download task.');
return;
}
if (result) {
console.info('Download task removed.');
} else {
console.error('Failed to remove the download task.');
}
});
downloadTask.remove((err, result)=>{
if(err) {
console.error('Failed to remove the download task.');
return;
}
if (result) {
console.info('Download task removed.');
} else {
console.error('Failed to remove the download task.');
}
});
```
......@@ -729,7 +698,7 @@ query(): Promise&lt;DownloadInfo&gt;
Queries this download task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -742,11 +711,11 @@ Queries this download task. This API uses a promise to return the result.
**Example**
```js
downloadTask.query().then((downloadInfo) => {
console.info('Download task queried. Data:' + JSON.stringify(downloadInfo))
}) .catch((err) => {
console.error('Failed to query the download task. Cause:' + err)
});
downloadTask.query().then((downloadInfo) => {
console.info('Download task queried. Data:' + JSON.stringify(downloadInfo))
}) .catch((err) => {
console.error('Failed to query the download task. Cause:' + err)
});
```
......@@ -756,7 +725,7 @@ query(callback: AsyncCallback&lt;DownloadInfo&gt;): void
Queries this download task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -769,13 +738,13 @@ Queries this download task. This API uses an asynchronous callback to return the
**Example**
```js
downloadTask.query((err, downloadInfo)=>{
if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err));
} else {
console.info('download query success. data:'+ JSON.stringify(downloadInfo));
}
});
downloadTask.query((err, downloadInfo)=>{
if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err));
} else {
console.info('download query success. data:'+ JSON.stringify(downloadInfo));
}
});
```
......@@ -785,7 +754,7 @@ queryMimeType(): Promise&lt;string&gt;
Queries **MimeType** of this download task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -798,11 +767,11 @@ Queries **MimeType** of this download task. This API uses a promise to return th
**Example**
```js
downloadTask.queryMimeType().then((data) => {
console.info('Download task queried. Data:' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to query the download MimeType. Cause:' + JSON.stringify(err))
});
downloadTask.queryMimeType().then((data) => {
console.info('Download task queried. Data:' + JSON.stringify(data));
}).catch((err) => {
console.error('Failed to query the download MimeType. Cause:' + JSON.stringify(err))
});
```
......@@ -812,7 +781,7 @@ queryMimeType(callback: AsyncCallback&lt;string&gt;): void;
Queries **MimeType** of this download task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -825,13 +794,13 @@ Queries **MimeType** of this download task. This API uses an asynchronous callba
**Example**
```js
downloadTask.queryMimeType((err, data)=>{
if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err));
} else {
console.info('Download task queried. data:' + JSON.stringify(data));
}
});
downloadTask.queryMimeType((err, data)=>{
if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err));
} else {
console.info('Download task queried. data:' + JSON.stringify(data));
}
});
```
......@@ -841,7 +810,7 @@ pause(): Promise&lt;void&gt;
Pauses this download task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -854,15 +823,15 @@ Pauses this download task. This API uses a promise to return the result.
**Example**
```js
downloadTask.pause().then((result) => {
if (result) {
console.info('Download task paused. ');
} else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result));
}
}).catch((err) => {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err));
});
downloadTask.pause().then((result) => {
if (result) {
console.info('Download task paused. ');
} else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result));
}
}).catch((err) => {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err));
});
```
......@@ -872,7 +841,7 @@ pause(callback: AsyncCallback&lt;void&gt;): void
Pauses this download task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -885,17 +854,17 @@ Pauses this download task. This API uses an asynchronous callback to return the
**Example**
```js
downloadTask.pause((err, result)=>{
if(err) {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err));
return;
}
if (result) {
console.info('Download task paused. ');
} else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result));
}
});
downloadTask.pause((err, result)=>{
if(err) {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err));
return;
}
if (result) {
console.info('Download task paused. ');
} else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result));
}
});
```
......@@ -905,7 +874,7 @@ resume(): Promise&lt;void&gt;
Resumes this download task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -918,16 +887,16 @@ Resumes this download task. This API uses a promise to return the result.
**Example**
```js
downloadTask.resume().then((result) => {
if (result) {
console.info('Download task resumed.')
} else {
console.error('Failed to resume the download task. ');
}
console.info('Download task resumed.')
}).catch((err) => {
console.error('Failed to resume the download task. Cause:' + err);
});
downloadTask.resume().then((result) => {
if (result) {
console.info('Download task resumed.')
} else {
console.error('Failed to resume the download task. ');
}
console.info('Download task resumed.')
}).catch((err) => {
console.error('Failed to resume the download task. Cause:' + err);
});
```
......@@ -937,7 +906,7 @@ resume(callback: AsyncCallback&lt;void&gt;): void
Resumes this download task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
......@@ -950,17 +919,17 @@ Resumes this download task. This API uses an asynchronous callback to return the
**Example**
```js
downloadTask.resume((err, result)=>{
if (err) {
console.error('Failed to resume the download task. Cause:' + err);
return;
}
if (result) {
console.info('Download task resumed.');
} else {
console.error('Failed to resume the download task.');
}
});
downloadTask.resume((err, result)=>{
if (err) {
console.error('Failed to resume the download task. Cause:' + err);
return;
}
if (result) {
console.info('Download task resumed.');
} else {
console.error('Failed to resume the download task.');
}
});
```
......
# UiTest
>**NOTE**
>**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
......@@ -13,46 +12,27 @@ 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:
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: <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.
- 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.
**System capability**: SystemCapability.Test.UiTest
| Name | Value | Description |
| ----------- | ---- | ------------ |
| EQUALS | 0 | Equal to the given value. |
| CONTAINS | 1 | Contain the given value. |
| STARTS_WITH | 2 | Start with the given value.|
| ENDS_WITH | 3 | End with the given value.|
```js
BY.text('123').type('button')
```
### By.text
text(txt:string,pattern?:MatchPattern):By
text(txt: string, pattern?: MatchPattern): By
Specifies the text attribute of the target component. Multiple match patterns are supported.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------ | ---- | ---------------------------------- |
| txt | string | Yes | Component text, used to match the target component.|
| pattern | MatchPattern | No | Match pattern. The default value is **EQUALS**. |
| Name | Type | Mandatory| Description |
| ------- | ------------ | ---- | ------------------------------------------------- |
| txt | string | Yes | Component text, used to match the target component. |
| pattern | MatchPattern | No | Match pattern. The default value is [EQUALS](#matchpattern).|
**Return value**
......@@ -62,324 +42,382 @@ Specifies the text attribute of the target component. Multiple match patterns ar
**Example**
```
let by = BY.text('123') // Use the static constructor BY to create a By object and specify the text attribute
of the target component.
```js
let by = BY.text('123') // Use the static constructor BY to create a By object and specify the text attribute of the target component.
```
### By.key
key(key:string):By;
key(key: string): By
Specifies the key attribute of the target component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | --------------- |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ----------------- |
| key | string | Yes | Component key.|
**Return value**
| Type| Description |
| ---- | -------------- |
| Type| Description |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
**Example**
```
let by = BY.key('123') // Use the static constructor BY to create a By object and specify the key attribute
of the target component.
```js
let by = BY.key('123') // Use the static constructor BY to create a By object and specify the key attribute of the target component.
```
### By.id
id(id:number):By;
Specifies the ID property of the target component.
id(id: number): By
**Required permissions**: none
Specifies the ID attribute of the target component.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------ |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------- |
| id | number | Yes | Component ID.|
**Return value**
| Type| Description |
| ---- | -------------- |
| Type| Description |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
**Example**
```
let by = BY.id(123) // Use the static constructor BY to create a By object and specify the ID attribute
of the target component.
```js
let by = BY.id(123) // Use the static constructor BY to create a By object and specify the id attribute of the target component.
```
### By.type
type(tp:string):By;
type(tp: string): By
Specifies the type property of the target component.
**Required permissions**: none
Specifies the type attribute of the target component.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------ |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------- |
| tp | string | Yes | Component type.|
**Return value**
| Type| Description |
| ---- | -------------- |
| Type| Description |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
**Example**
```
let by = BY.type('button') // Use the static constructor BY to create a By object and specify the type attribute
of the target component.
```js
let by = BY.type('button') // Use the static constructor BY to create a By object and specify the type attribute of the target component.
```
### By.clickable
clickable(b?:bool):By;
clickable(b?: bool): By
Specifies the clickable attribute of the target component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ------------------------------ |
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------------------------- |
| b | bool | No | Clickable status of the target component. The default value is **true**.|
**Return value**
| Type| Description |
| ---- | -------------- |
| Type| Description |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
**Example**
```js
let by = BY.clickable(true) // Use the static constructor BY to create a By object and specify the clickable status attribute of the target component.
```
let by = BY.clickable(true) // Use the static constructor BY to create a By object and specify the clickable attribute
of the target component.
### By.longClickable<sup>9+</sup>
longClickable(b?: bool): By
Specifies the long-clickable status attribute of the target component.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ------------------------------------ |
| 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
let by = 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
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.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------------------- |
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ---------------------------- |
| b | bool | No | Scrollable status of the target component. The default value is **true**.|
**Return value**
| Type| Description |
| ---- | -------------- |
| Type| Description |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
**Example**
```
let by = BY.scrollable(true) // Use the static constructor BY to create a By object and specify the scrollable attribute
of the target component.
```js
let by = BY.scrollable(true) // Use the static constructor BY to create a By object and specify the scrollable status attribute of the target component.
```
### By.enabled
enabled(b?:bool):By;
Specifies the enable attribute of the target component.
enabled(b?: bool): By
**Required permissions**: none
Specifies the enabled status attribute of the target component.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ---------------------------- |
| b | bool | No | Enable status of the target component. The default value is **true**.|
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ------------------------------ |
| b | bool | No | Enabled status of the target component. The default value is **true**.|
**Return value**
| Type| Description |
| ---- | -------------- |
| Type| Description |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
**Example**
```
let by = BY.enabled(true) // Use the static constructor BY to create a By object and specify the enable attribute
of the target component.
```js
let by = BY.enabled(true) // Use the static constructor BY to create a By object and specify the enabled status attribute of the target component.
```
### By.focused
focused(b?:bool):By;
Specifies the focused attribute of the target component.
focused(b?: bool): By
**Required permissions**: none
Specifies the focused status attribute of the target component.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ------------------------ |
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------------------- |
| b | bool | No | Focused status of the target component. The default value is **true**.|
**Return value**
| Type| Description |
| ---- | -------------- |
| Type| Description |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
**Example**
```
let by = BY.enabled(true) // Use the static constructor BY to create a By object and specify the focused attribute
of the target component.
```js
let by = BY.focused(true) // Use the static constructor BY to create a By object and specify the focused status attribute of the target component.
```
### By.selected
selected(b?:bool):By;
Specifies the selected attribute of the target component.
selected(b?: bool): By
**Required permissions**: none
Specifies the selected status attribute of the target component.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ------------------------------ |
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------------------------- |
| b | bool | No | Selected status of the target component. The default value is **true**.|
**Return value**
| Type| Description |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
**Example**
```js
let by = BY.selected(true) // Use the static constructor BY to create a By object and specify the selected status attribute of the target component.
```
### By.checked<sup>9+</sup>
checked(b?: bool): By
Specifies the checked status attribute of the target component.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | --------------------------------- |
| b | bool | No | Checked status of the target component. The default value is **false**.|
**Return value**
| Type| Description |
| ---- | -------------- |
| By | Returns the **By** object itself.|
**Example**
```js
let by = BY.checked(true) // Use the static constructor BY to create a By object and specify the checked status attribute of the target component.
```
let by = BY.selected(true) // Use the static constructor BY to create a By object and specify the selected attribute
of the target component.
### By.checkable<sup>9+</sup>
checkable(b?: bool): By
Specifies the checkable status attribute of the target component.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ------------------------------------- |
| b | bool | No | Checkable status of the target component. The default value is **false**.|
**Return value**
| Type| Description |
| ---- | ---------------- |
| By | Returns the **By** object itself.|
**Example**
```js
let by = BY.checkable(true) // Use the static constructor BY to create a By object and specify the checkable status attribute of the target component.
```
### By.isBefore
isBefore(by:By):By;
isBefore(by: By): By
Specifies the attributes of the component before which the target component is located.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------- |
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ---------------- |
| by | By | Yes | Attributes of the component before which the target component is located.|
**Return value**
| Type| Description |
| ---- | -------------- |
| 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.
```js
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;
isAfter(by: By): By
Specifies the attributes of the component after which the target component is located.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------- |
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ---------------- |
| by | By | Yes | Attributes of the component before which the target component is located.|
**Return value**
| Type| Description |
| ---- | -------------- |
| 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.
```js
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**.
All APIs provided in this class use a promise to return the result and must be invoked using **await**.
### Rect<sup>9+</sup>
Provides border information of a component.
**System capability**: SystemCapability.Test.UiTest
| Name | Type| Readable| Writable| Description |
| ------- | -------- | ---- | ---- | ------------------------- |
| leftX | number | Yes | No | X coordinate of the upper left corner of the component borders.|
| topY | number | Yes | No | Y coordinate of the upper left corner of the component borders.|
| rightX | number | Yes | No | X coordinate of the lower right corner of the component borders.|
| bottomY | number | Yes | No | Y coordinate of the lower right corner of the component borders.|
### UiComponent.click
click():Promise<void>;
click(): Promise\<void>
Clicks this component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
......@@ -389,37 +427,33 @@ async function demo() {
### UiComponent.doubleClick
doubleClick():Promise<void>;
doubleClick(): Promise\<void>
Double-clicks this component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
await buttont.doubleClick()
await button.doubleClick()
}
```
### UiComponent.longClick
longClick():Promise<void>;
longClick(): Promise\<void>
Long-clicks this component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
......@@ -429,23 +463,21 @@ async function demo() {
### UiComponent.getId
getId():Promise<number>;
getId(): Promise\<number>
Obtains the ID of this component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| ---------------- | ------------------------- |
| Promise<number>; | Promise used to return the component ID.|
| Type | Description |
| ---------------- | ------------------------------- |
| Promise\<number> | Promise used to return the ID of the component.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
......@@ -455,23 +487,21 @@ async function demo() {
### UiComponent.getKey
getKey():Promise<string>;
getKey(): Promise\<string>
Obtains the key of this component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| ---------------- | -------------------------- |
| Promise<string>; | Promise used to return the component key.|
| Type | Description |
| ---------------- | ------------------------------ |
| Promise\<string> | Promise used to return the key of the component.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
......@@ -481,23 +511,21 @@ async function demo() {
### UiComponent.getText
getText():Promise<string>;
getText(): Promise\<string>
Obtains the text information of this component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| ---------------- | ------------------------------- |
| Promise<string>; | Promise used to return the text information of the component.|
| Type | Description |
| ---------------- | --------------------------------- |
| Promise\<string> | Promise used to return the text information of the component.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
......@@ -507,23 +535,21 @@ async function demo() {
### UiComponent.getType
getType():Promise<string>;
getType(): Promise\<string>
Obtains the type of this component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| ---------------- | ------------------------------- |
| Promise<string>; | Promise used to return the component type.|
| Type | Description |
| ---------------- | ----------------------------- |
| Promise\<string> | Promise used to return the type of the component.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
......@@ -531,25 +557,47 @@ async function demo() {
}
```
### UiComponent.getBounds<sup>9+</sup>
getBounds(): Promise\<Rect>
Obtains the bounds of this component.
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| -------------- | ------------------------------------- |
| Promise\<Rect> | Promise used to return the bounds of the component.|
**Example**
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
let rect = await button.getBounds()
}
```
### UiComponent.isClickable
isClickable():Promise<bool>;
isClickable(): Promise\<bool>
Obtains the clickable status of this component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| -------------- | ----------------------------------- |
| Promise<bool>; | Promise used to return the clickable status of the component.|
| Type | Description |
| -------------- | ------------------------------------- |
| Promise\<bool> | Promise used to return the clickable status of the component.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
......@@ -562,25 +610,110 @@ async function demo() {
}
```
### UiComponent.isScrollable
### UiComponent.isLongClickable<sup>9+</sup>
isScrollable():Promise<bool>;
isLongClickable(): Promise\<bool>
Obtains the scrollable status of this component.
Obtains the long clickable status of this component.
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| -------------- | ------------------------------------------- |
| Promise\<bool> | Promise used to return the long clickable status of the component.|
**Example**
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
if(await button.isLongClickable()) {
console.info('This button can longClick')
}
else{
console.info('This button can not longClick')
}
}
```
### UiComponent.isChecked<sup>9+</sup>
isChecked(): Promise\<bool>
**Required permissions**: none
Obtains the checked status of this component.
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| -------------- | ----------------------------------- |
| Promise<bool>; | Promise used to return the scrollable status of the component.|
| Type | Description |
| -------------- | ------------------------------------- |
| Promise\<bool> | Promise used to return the checked status of the component.|
**Example**
```js
async function demo() {
let driver = UiDriver.create()
let checkBox = await driver.findComponent(BY.type('Checkbox'))
if(await checkBox.isChecked) {
console.info('This checkBox is checked')
}
else{
console.info('This checkBox is not checked')
}
}
```
### UiComponent.isCheckable<sup>9+</sup>
isCheckable(): Promise\<bool>
Obtains the checked status of this component.
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| -------------- | ------------------------------------------- |
| Promise\<bool> | Promise used to return the checked status of the component.|
**Example**
```js
async function demo() {
let driver = UiDriver.create()
let checkBox = await driver.findComponent(BY.type('Checkbox'))
if(await checkBox.isCheckable) {
console.info('This checkBox is checkable')
}
else{
console.info('This checkBox is not checkable')
}
}
```
### UiComponent.isScrollable
isScrollable(): Promise\<bool>
Obtains the scrollable status of this component.
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| -------------- | ------------------------------------- |
| Promise\<bool> | Promise used to return the scrollable status of the component.|
**Example**
```js
async function demo() {
let driver = UiDriver.create()
let scrollBar = await driver.findComponent(BY.scrollable(true))
......@@ -596,23 +729,21 @@ async function demo() {
### UiComponent.isEnabled
isEnabled():Promise<bool>;
isEnabled(): Promise\<bool>
Obtains the enable status of this component.
**Required permissions**: none
Obtains the enabled status of this component.
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| -------------- | ----------------------------- |
| Promise<bool>; | Promise used to return the enable status of the component.|
| Type | Description |
| -------------- | ------------------------------- |
| Promise\<bool> | Promise used to return the enabled status of the component.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
......@@ -628,23 +759,21 @@ async function demo() {
### UiComponent.isFocused
isFocused():Promise<bool>;
isFocused(): Promise\<bool>
Obtains the focused status of this component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| -------------- | --------------------------------- |
| Promise<bool>; | Promise used to return the focused status of the component.|
| Type | Description |
| -------------- | ----------------------------------- |
| Promise\<bool> | Promise used to return the focused status of the component.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
......@@ -659,23 +788,21 @@ async function demo() {
### UiComponent.isSelected
isSelected():Promise<bool>;
isSelected(): Promise\<bool>
Obtains the selected status of this component.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| -------------- | ----------------------------------- |
| Promise<bool>; | Promise used to return the selected status of the component.|
| Type | Description |
| -------------- | -------------------- |
| Promise\<bool> | Promise used to return the selected status of the component.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
......@@ -690,37 +817,51 @@ async function demo() {
### UiComponent.inputText
inputText(text: string):Promise<void>;
inputText(text: string): Promise\<void>
Enters text into this component (available for text boxes).
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------- |
| text | string | Yes | Text to be entered to the component.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------- |
| text | string | Yes | Text to enter.|
**Example**
```js
async function demo() {
let driver = UiDriver.create()
let text = await driver.findComponent(BY.text('hello world'))
await text.inputText('123')
}
```
### UiComponent.clearText<sup>9+</sup>
clearText(): Promise\<void>
Clears text in this component (available for text boxes).
**System capability**: SystemCapability.Test.UiTest
**Example**
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
await button.inputText('next page')
let text = await driver.findComponent(BY.text('hello world'))
await text.clearText()
}
```
### UiComponent.scrollSearch
scrollSearch(by:By):Promise<UiComponent>;
Scrolls on this component to search for the target component (available for lists).
scrollSearch(by: By): Promise\<UiComponent>
**Required permissions**: none
Scrolls on this component to search for the target component (applicable to component that support scrolling, such as **\<List>**).
**System capability**: SystemCapability.Test.UiTest
......@@ -732,20 +873,81 @@ Scrolls on this component to search for the target component (available for list
**Return value**
| Type | Description |
| --------------------- | ----------------------------------- |
| Promise<UiComponent>; | Promise used to return the target component.|
| Type | Description |
| --------------------- | ------------------------------------- |
| Promise\<UiComponent> | Promise used to return the target component.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let scrollBar = await driver.findComponent(BY.scrollable(true))
let scrollBar = await driver.findComponent(BY.type('Scroll'))
let button = await scrollBar.scrollSearch(BY.text('next page'))
}
```
### UiComponent.scrollToTop<sup>9+</sup>
scrollToTop(): Promise\<void>
Scrolls to the top of this a component (applicable to component that support scrolling, such as **\<List>**).
**System capability**: SystemCapability.Test.UiTest
**Example**
```js
async function demo() {
let driver = UiDriver.create()
let scrollBar = await driver.findComponent(BY.type('Scroll'))
await scrollBar.scrollToTop()
}
```
### UiComponent.scrollToBottom<sup>9+</sup>
scrollToBottom(): Promise\<void>
Scrolls to the bottom of this a component (applicable to component that support scrolling, such as **\<List>**).
**System capability**: SystemCapability.Test.UiTest
**Example**
```js
async function demo() {
let driver = UiDriver.create()
let scrollBar = await driver.findComponent(BY.type('Scroll'))
await scrollBar.scrollToBottom()
}
```
### UiComponent.dragTo<sup>9+</sup>
dragTo(target: UiComponent): Promise\<void>
Drags this component to the target component.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------- | ---- | ---------- |
| target | UiComponent | Yes | Target component.|
**Example**
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.type('button'))
let text = await driver.findComponent(BY.text('hello world'))
await button.dragTo(text)
}
```
## 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.
......@@ -753,23 +955,21 @@ All APIs provided by this class, except for **UiDriver.create()**, use a promise
### UiDriver.create
static create():UiDriver;
static create(): UiDriver
Creates a **UiDriver** object and returns the object created. This API is a static API.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Return value**
| Type | Description |
| ------- | ---------------------- |
| Type | Description |
| ------- | ------------------------ |
| UiDrive | Returns the **UiDriver** object created.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
}
......@@ -777,23 +977,21 @@ async function demo() {
### UiDriver.delayMs
delayMs(duration:number):Promise<void>;
delayMs(duration: number): Promise\<void>
Delays this **UiDriver** object within the specified duration.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------- |
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------ |
| duration | number | Yes | Duration of time.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
await driver.delayMs(1000)
......@@ -802,29 +1000,27 @@ async function demo() {
### UiDriver.findComponent
findComponent(by:By):Promise<UiComponent>;
Searches this **UiDriver** object for the target component that has the given attributes.
findComponent(by: By): Promise\<UiComponent>
**Required permissions**: none
Searches this **UiDriver** object for the target component that matches the given attributes.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ------------------ |
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------------- |
| by | By | Yes | Attributes of the target component.|
**Return value**
| Type | Description |
| --------------------- | ------------------------------- |
| Promise<UiComponent>; | Promise used to return the found component.|
| Type | Description |
| --------------------- | --------------------------------- |
| Promise\<UiComponent> | Promise used to return the found component.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.findComponent(BY.text('next page'))
......@@ -833,54 +1029,80 @@ async function demo() {
### UiDriver.findComponents
findComponents(by:By):Promise<Array<UiComponent>>;
findComponents(by: By): Promise\<Array\<UiComponent>>
Searches this **UiDriver** object for all components that match the given attributes.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ------------------ |
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------------- |
| by | By | Yes | Attributes of the target component.|
**Return value**
| Type | Description |
| ---------------------------- | ------------------------------------- |
| Promise<Array<UiComponent>>; | Promise used to return a list of found components.|
| Type | Description |
| ----------------------------- | --------------------------------------- |
| Promise\<Array\<UiComponent>> | Promise used to return a list of found components.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
let buttonList = await driver.findComponents(BY.text('next page'))
}
```
### UiDriver.waitForComponent<sup>9+</sup>
waitForComponent(by: By, time: number): Promise\<UiComponent>
Searches this **UiDriver** object for the target component that matches the given attributes within the specified duration.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------- |
| by | By | Yes | Attributes of the target component. |
| time | number | Yes | Duration for searching for the target component, in ms.|
**Return value**
| Type | Description |
| --------------------- | --------------------------------- |
| Promise\<UiComponent> | Promise used to return the found component.|
**Example**
```js
async function demo() {
let driver = UiDriver.create()
let button = await driver.waitForComponent(BY.text('next page'),500)
}
```
### UiDriver.assertComponentExist
assertComponentExist(by:By):Promise<void>;
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.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | ------------------ |
| Name| Type| Mandatory| Description |
| ------ | ---- | ---- | -------------------- |
| by | By | Yes | Attributes of the target component.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
await driver.assertComponentExist(BY.text('next page'))
......@@ -889,17 +1111,15 @@ async function demo() {
### UiDriver.pressBack
pressBack():Promise<void>;
pressBack(): Promise\<void>
Presses the Back button on this **UiDriver** object.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
await driver.pressBack()
......@@ -908,23 +1128,21 @@ async function demo() {
### UiDriver.triggerKey
triggerKey(keyCode:number):Promise<void>;
triggerKey(keyCode: number): Promise\<void>
Triggers the key of this **UiDriver** object that matches the given key code.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | --------- |
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------------- |
| keyCode | number | Yes | Key code.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
await driver.triggerKey(123)
......@@ -933,23 +1151,22 @@ async function demo() {
### UiDriver.click
click(x:number,y:number):Promise<void>;
click(x: number, y: number): Promise\<void>
Clicks a specific point of this **UiDriver** object based on the given coordinates.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------- | ---- | ------------------------------------------- |
| x,y | number,number | Yes | Coordinate information of a specific point in the (number,number) format.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- |
| x | number | Yes | X coordinate of the target point.|
| y | number | Yes | Y coordinate of the target point.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
await driver.click(100,100)
......@@ -958,23 +1175,22 @@ async function demo() {
### UiDriver.doubleClick
doubleClick(x:number,y:number):Promise<void>;
doubleClick(x: number, y: number): Promise\<void>
Double-clicks a specific point of this **UiDriver** object based on the given coordinates.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------- | ---- | ------------------------------------------- |
| x,y | number,number | Yes | Coordinate information of a specific point in the (number,number) format.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- |
| x | number | Yes | X coordinate of the target point.|
| y | number | Yes | Y coordinate of the target point.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
await driver.doubleClick(100,100)
......@@ -983,23 +1199,22 @@ async function demo() {
### UiDriver.longClick
longClick(x:number,y:number):Promise<void>;
longClick(x: number, y: number): Promise\<void>
Long-clicks a specific point of this **UiDriver** object based on the given coordinates.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------- | ---- | ------------------------------------------- |
| x,y | number,number | Yes | Coordinate information of a specific point in the (number,number) format.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- |
| x | number | Yes | X coordinate of the target point.|
| y | number | Yes | Y coordinate of the target point.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
await driver.longClick(100,100)
......@@ -1008,51 +1223,96 @@ async function demo() {
### UiDriver.swipe
swipe(startx:number,starty:number,endx:number,endy:number):Promise<void>;
Swipes from the start point to the end point of this **UiDriver** object based on the given coordinates.
swipe(startx: number, starty: number, endx: number, endy: number): Promise\<void>
**Required permissions**: none
Swipes on this **UiDriver** object from the start point to the end point based on the given coordinates.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | ------------- | ---- | ------------------------------------------- |
| startx,starty | number,number | Yes | Coordinate information of the start point in the (number,number) format.|
| endx,endy | number,number | Yes | Coordinate information of the end point in the (number,number) format.|
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- |
| startx | number | Yes | X coordinate of the start point.|
| starty | number | Yes | Y coordinate of the start point.|
| endx | number | Yes | X coordinate of the end point.|
| endy | number | Yes | Y coordinate of the end point.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
await driver.swipe(100,100,200,200)
}
```
### UiDriver.drag<sup>9+</sup>
drag(startx: number, starty: number, endx: number, endy: number): Promise\<void>
Drags this **UiDriver** object from the given start point to the given end point.
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- |
| startx | number | Yes | X coordinate of the start point.|
| starty | number | Yes | Y coordinate of the start point.|
| endx | number | Yes | X coordinate of the end point.|
| endy | number | Yes | Y coordinate of the end point.|
**Example**
```js
async function demo() {
let driver = UiDriver.create()
await driver.drag(100,100,200,200)
}
```
### UiDriver.screenCap
screenCap(savePath:string):Promise<bool>;
screenCap(savePath: string): Promise\<bool>
Captures the current screen of this **UiDriver** object and saves it as a PNG image to the given save path.
**Required permissions**: none
**System capability**: SystemCapability.Test.UiTest
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------ |
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | -------------- |
| savePath | string | Yes | File save path.|
**Return value**
| Type | Description |
| -------------- | -------------------------------------- |
| Promise\<bool> | Promise used to return the operation result. The value **true** means that the operation is successful.|
**Example**
```
```js
async function demo() {
let driver = UiDriver.create()
await driver.screenCap('/local/tmp/')
}
```
## MatchPattern
Enumerates the match patterns supported for component attributes.
**System capability**: SystemCapability.Test.UiTest
| Name | Value | Description |
| ----------- | ---- | -------------- |
| EQUALS | 0 | Equal to the given value. |
| CONTAINS | 1 | Containing the given value. |
| STARTS_WITH | 2 | Starting from the given value.|
| ENDS_WITH | 3 | Ending with the given value.|
###
# Interpolation Calculation
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> **NOTE**<br>
> This animation is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import curves from '@ohos.curves'
```
......@@ -27,11 +27,12 @@ Implements initialization for the interpolation curve, which is used to create a
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- |
| curve | Curve | No | Linear | Curve object. |
| curve | Curve | No | Linear | Curve object. |
- Return values
- Return value
Curve object.
......@@ -44,12 +45,13 @@ Constructs a step curve object.
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- |
| count | number | Yes | - | Number of steps. Must be a positive integer. |
| end | boolean | No | true | Step change at the start or end point of each interval. Defaults to **true**, indicating that the step change occurs at the end point. |
| count | number | Yes | - | Number of steps. Must be a positive integer. |
| end | boolean | Yes | true | Step change at the start or end point of each interval. Defaults to **true**, indicating that the step change occurs at the end point. |
- Return values
- Return value
Curve object.
......@@ -62,14 +64,15 @@ Constructs a third-order Bezier curve object. The curve value must be between 0
- Parameters
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| x1 | number | Yes | Horizontal coordinate of the first point on the Bezier curve. |
| y1 | number | Yes | Vertical coordinate of the first point on the Bezier curve. |
| x2 | number | Yes | Horizontal coordinate of the second point on the Bezier curve. |
| y2 | number | Yes | Vertical coordinate of the second point on the Bezier curve. |
| x1 | number | Yes | Horizontal coordinate of the first point on the Bezier curve. |
| y1 | number | Yes | Vertical coordinate of the first point on the Bezier curve. |
| x2 | number | Yes | Horizontal coordinate of the second point on the Bezier curve. |
| y2 | number | Yes | Vertical coordinate of the second point on the Bezier curve. |
- Return values
- Return value
Curve object.
......@@ -82,20 +85,21 @@ Constructs a spring curve object.
- Parameters
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| velocity | number | Yes | Initial velocity. |
| mass | number | Yes | Mass. |
| stiffness | number | Yes | Stiffness. |
| damping | number | Yes | Damping. |
| velocity | number | Yes | Initial velocity. |
| mass | number | Yes | Mass. |
| stiffness | number | Yes | Stiffness. |
| damping | number | Yes | Damping. |
- Return values
- Return value
Curve object.
## Example
```
import Curves from '@ohos.curves'
let curve1 = Curves.init() // Create a default linear interpolation curve.
......@@ -105,14 +109,14 @@ let curve3 = Curves.cubicBezier(0.1, 0.0, 0.1, 1.0) // Create a third-order Bezi
```
Curve objects can be created only by the preceding APIs.
| API | Description |
Curve objects can be created only by the preceding APIs.
| API | Description |
| -------- | -------- |
| interpolate(time: number): number | Calculation function of the interpolation curve. Passing a normalized time parameter to this function returns the current interpolation.<br/>**time**: indicates the current normalized time. The value ranges from 0 to 1.<br/>The curve interpolation corresponding to the normalized time point is returned. |
| interpolate(time: number): number | Calculation function of the interpolation curve. Passing a normalized time parameter to this function returns the current interpolation.<br/>**time**: indicates the current normalized time. The value ranges from 0 to 1.<br/>The curve interpolation corresponding to the normalized time point is returned. |
- Example
```
import Curves from '@ohos.curves'
let curve = Curves.init(Curve.EaseIn) // Create an interpolation curve which is slow and then fast by default.
......@@ -122,7 +126,7 @@ let curve3 = Curves.cubicBezier(0.1, 0.0, 0.1, 1.0) // Create a third-order Bezi
## Example
```
import Curves from '@ohos.curves'
@Entry
......
......@@ -23,9 +23,9 @@ The name of a resource qualifier consists of one or more qualifiers that represe
Table1 Resource qualifiers
| Data Type | Description and Value Range |
| Data Type | Description and Value Range |
| -------- | -------- |
| Screen density | Indicates the screen density of the device, in dpi. The value can be:<br/>- ldpi: low-density screen (~120 dpi) (0.75 x Reference density)<br/>- mdpi: medium-density screen (~160 dpi) (reference density)<br/>- hdpi: high-density screen (~240 dpi) (1.5 x Reference density)<br/>- xhdpi: extra high-density screen (~320 dpi) (2.0 x Reference density)<br/>- xxhdpi: extra extra high-density screen (~480 dpi) (3.0 x Reference density)<br/>- xxxhdpi: extra extra extra high-density screen (~640 dpi) (4.0 x Reference density) |
| Screen density | Indicates the screen density of the device, in dpi. The value can be:<br/>- ldpi: low-density screen (\~120 dpi) (0.75 x Reference density)<br/>- mdpi: medium-density screen (\~160 dpi) (reference density)<br/>- hdpi: high-density screen (\~240 dpi) (1.5 x Reference density)<br/>- xhdpi: extra high-density screen (\~320 dpi) (2.0 x Reference density)<br/>- xxhdpi: extra extra high-density screen (\~480 dpi) (3.0 x Reference density)<br/>- xxxhdpi: extra extra extra high-density screen (\~640 dpi) (4.0 x Reference density) |
## Rules for Matching Qualifiers Files and Device Resources
......@@ -91,5 +91,5 @@ resources/res-defaults.json:
</div>
```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**:
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> The resource qualifier file does not support color enumeration.
# @Styles
The @Styles decorator adds new attribute functions to basic components, such as &lt;Text&gt;, &lt;Column&gt;, and &lt;Button&gt;. Currently, @Styles supports only universal attributes. You can use the @Styles decorator to quickly define and reuse the custom styles of a component.
The **@Styles** decorator adds new attribute functions to basic components, such as **\<Text>**, **\<Column>**, and **\<Button>**. Currently, **@Styles** supports only universal attributes. You can use the **@Styles** decorator to quickly define and reuse the custom styles of a component.
@Styles can be defined inside or outside a component. When it is defined outside a component, the keyword function must be included.
**@Styles** can be defined inside or outside a component. When it is defined outside a component, the keyword function must be included.
......@@ -36,11 +35,10 @@ struct FancyUse {
}
```
@Styles can also be used inside the StateStyles attribute to assign state-specific attributes to components.
**@Styles** can also be used inside the **StateStyles** attribute to assign state-specific attributes to components.
In StateStyles, styles defined outside the component can be directly called. However, the keyword this must be used to call styles defined in the component.
In **StateStyles**, styles defined outside the component can be directly called. However, the keyword **this** must be used to call styles defined in the component.
......@@ -53,22 +51,22 @@ In StateStyles, styles defined outside the component can be directly called. How
@Entry
@Component
struct FancyUse {
@Styles function componentFancy() {
@Styles componentFancy() {
.width(50)
.height(50)
}
build() {
Row({ space: 10 }) {
Button() {
Text("Fancy")
Text("Fancy")
}
.stateStyles({
normal: {
.width(80)
.height(80)
},
disabled: this.componentFancy,
pressed: globalFancy
normal: {
.width(80)
.height(80)
},
disabled: this.componentFancy,
pressed: globalFancy
})
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册