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

!19374 翻译完成 18206+17570+18991+18409+17736+18885+18929

Merge pull request !19374 from ester.zhou/TR-18206
......@@ -3,7 +3,7 @@
## Overview
To accelerate test automation of OpenHarmony, arkXtest — an automated test framework that supports both the JavaScript (JS) and TypeScript (TS) programming languages — is provided.
To accelerate test automation of OpenHarmony, arkXtest — an automated unit and UI test framework that supports both the JavaScript (JS) and TypeScript (TS) programming languages — is provided.
In this document you will learn about the key functions of arkXtest and how to use it to perform unit testing on application or system APIs and to write UI automated test scripts.
......@@ -13,7 +13,7 @@ In this document you will learn about the key functions of arkXtest and how to u
arkXtest is part of the OpenHarmony toolkit and provides basic capabilities of writing and running OpenHarmony automated test scripts. In terms of test script writing, arkXtest offers a wide range of APIs, including basic process APIs, assertion APIs, and APIs related to UI operations. In terms of test script running, arkXtest offers such features as identifying, scheduling, and executing test scripts, as well as summarizing test script execution results.
### Principles
### Implementation
arkXtest is divided into two parts: unit test framework and UI test framework.
......@@ -27,16 +27,16 @@ arkXtest is divided into two parts: unit test framework and UI test framework.
![](figures/TestFlow.PNG)
- UI Testing Framework
- UI Test Framework
The UI test framework provides [UiTest APIs](../reference/apis/js-apis-uitest.md) for you to call in different test scenarios. The test scripts are executed on top of the unit test framework mentioned above.
The UI test framework provides [UiTest APIs](../reference/apis/js-apis-uitest.md) for you to call in different test scenarios. The UI test scripts are executed on top of the aformentioned unit test framework.
The figure below shows the main functions of the UI test framework.
![](figures/Uitest.PNG)
### Limitations and Constraints
### Constraints
- The features of the UI test framework are available only in OpenHarmony 3.1 and later versions.
- The feature availability of the unit test framework varies by version. For details about the mappings between the features and versions, see [arkXtest](https://gitee.com/openharmony/testfwk_arkxtest/blob/master/README_en.md).
......@@ -46,9 +46,9 @@ arkXtest is divided into two parts: unit test framework and UI test framework.
### Environment Requirements
Software for writing test scripts: DevEco Studio 3.0 or later
Software: DevEco Studio 3.0 or later
Hardware for running test scripts: PC connected to an OpenHarmony device, such as the RK3568 development board
Hardware: PC connected to an OpenHarmony device, such as the RK3568 development board
### Setting Up the Environment
......@@ -57,7 +57,7 @@ Hardware for running test scripts: PC connected to an OpenHarmony device, such a
## Creating a Test Script
1. Open DevEco Studio and create a project, where the **ohos** directory is where the test script is located.
1. Open DevEco Studio and create a project, in which the **ohos** directory is where the test script is located.
2. Open the .ets file of the module to be tested in the project directory. Move the cursor to any position in the code, and then right-click and choose **Show Context Actions** > **Create Ohos Test** or press **Alt+Enter** and choose **Create Ohos Test** to create a test class.
## Writing a Unit Test Script
......@@ -95,7 +95,7 @@ export default function abilityTest() {
The unit test script must contain the following basic elements:
1. Import of the dependency package so that the dependent test APIs can be used.
1. Import of the dependencies so that the dependent test APIs can be used.
2. Test code, mainly about the related logic, such as API invoking.
......@@ -105,7 +105,7 @@ The unit test script must contain the following basic elements:
You write a UI test script based on the unit test framework, adding the invoking of APIs provided by the UI test framework to implement the corresponding test logic.
In this example, the UI test script is written based on the preceding unit test script. First, add the dependency package, as shown below:
In this example, the UI test script is written based on the preceding unit test script. First, import the dependency, as shown below:
```js
import {Driver,ON,Component,MatchPattern} from '@ohos.uitest'
......@@ -158,11 +158,9 @@ export default function abilityTest() {
You can run a test script in DevEco Studio in any of the following modes:
1. Test package level: All test cases in the test package are executed.
2. Test suite level: All test cases defined in the **describe** method are executed.
3. Test method level: The specified **it** method, that is, a single test case, is executed.
- Test package level: All test cases in the test package are executed.
- Test suite level: All test cases defined in the **describe** method are executed.
- Test method level: The specified **it** method, that is, a single test case, is executed.
![](figures/Execute.PNG)
......@@ -176,7 +174,7 @@ After the test is complete, you can view the test result in DevEco Studio, as sh
To run a test script in the CLI, execute **aa** commands with different execution control keywords.
Parameters in aa test commands
The table below lists the keywords in **aa** test commands.
| Keyword | Abbreviation| Description | Example |
| ------------- | ------------ | -------------------------------------- | ---------------------------------- |
......@@ -187,18 +185,18 @@ Parameters in aa test commands
The framework supports multiple test case execution modes, which are triggered by the key-value pair following the **-s** keyword. The table below lists the available keys and values.
| Key | Description | Value | Parameter |
| Key | Description | Value | Example |
| ------------ | ----------------------------------------------------------------------------- | ------------------------------------------------------------ | ----------------------------------------- |
| unittest | OpenHarmonyTestRunner object used for test case execution. | **OpenHarmonyTestRunner** or custom runner name. | - s unittest OpenHarmonyTestRunner |
| unittest | **OpenHarmonyTestRunner** object used for test case execution. | **OpenHarmonyTestRunner** or custom runner name. | - s unittest OpenHarmonyTestRunner |
| class | Test suite or test case to be executed. | {describeName}#{itName}, {describeName} | -s class attributeTest#testAttributeIt |
| notClass | Test suite or test case that does not need to be executed. | {describeName}#{itName}, {describeName} | -s notClass attributeTest#testAttributeIt |
| itName | Test case to be executed. | {itName} | -s itName testAttributeIt |
| timeout | Timeout interval for executing a test case. | Positive integer (unit: ms). If no value is set, the default value 5000 is used. | -s timeout 15000 |
| breakOnError | Whether to enable break-on-error mode. When this mode is enabled, the test execution process exits if a test assertion error or any other error occurs.| **true**/**false** (default value) | -s breakOnError true |
| breakOnError | Whether to enable break-on-error mode. When this mode is enabled, the test execution process exits if a test assertion failure or error occurs.| **true**/**false** (default value) | -s breakOnError true |
| random | Whether to execute test cases in random sequence.| **true**/**false** (default value) | -s random true |
| testType | Type of the test case to be executed. | function, performance, power, reliability, security, global, compatibility, user, standard, safety, resilience| -s testType function |
| level | Level of the test case to be executed. | 0, 1, 2, 3, 4 | -s level 0 |
| size | Size of the test case to be executed. | small, medium, large | -s size small |
| size | Size of the test case to be executed. | small, medium, large | -s size small
| stress | Number of times that the test case is executed. | Positive integer | -s stress 1000 |
**Running Commands**
......@@ -306,7 +304,7 @@ OHOS_REPORT_STATUS: consuming=4
| OHOS_REPORT_STATUS: stream | Error information of the current test case.|
| OHOS_REPORT_STATUS: test| Name of the current test case.|
| OHOS_REPORT_STATUS_CODE | Execution result of the current test case. The options are as follows:<br>**0**: pass<br>**1**: error<br>**2**: fail|
| OHOS_REPORT_STATUS: consuming | Execution duration of the current test case.|
| OHOS_REPORT_STATUS: consuming | Time spent in executing the current test case.|
- After the commands are executed, the log information similar to the following is displayed:
......@@ -324,7 +322,7 @@ OHOS_REPORT_STATUS: taskconsuming=16029
| Failure | Number of failed test cases.|
| Error | Number of test cases whose execution encounters errors. |
| Pass | Number of passed test cases.|
| Ignore | Number of test cases not executed.|
| Ignore | Number of test cases not yet executed.|
| taskconsuming| Total time spent in executing the current test case.|
> When an error occurs in break-on-error mode, check the **Ignore** and interrupt information.
......@@ -341,11 +339,11 @@ The logs added to the test case are displayed after the test case execution, rat
**Possible Causes**
More than one asynchronous interface is called in the test case.<br>In principle, logs in the test case are printed before the test case execution is complete.
More than one asynchronous API is called in the test case.<br>In principle, logs in the test case are printed before the test case execution is complete.
**Solution**
If more than one asynchronous interface is called, you are advised to encapsulate the interface invoking into the promise mode
If more than one asynchronous API is called, you are advised to encapsulate the API invoking into the promise mode.
#### Error "fail to start ability" is reported during test case execution
......@@ -373,7 +371,7 @@ After the test case execution is complete, the console displays the error messag
2. The time taken for API invocation is longer than the timeout interval set for test case execution.
3. Test assertion fails, and a failure exception is thrown. As a result, the test case execution does not end until the timeout expires.
3. Test assertion fails, and a failure exception is thrown. As a result, the test case execution does not end until it times out.
**Solution**
......@@ -388,11 +386,11 @@ After the test case execution is complete, the console displays the error messag
**Problem**
The UI test case fails to be executed. The HiLog file contains the error message "Get windows failed/GetRootByWindow failed".
The UI test case fails to be executed. The HiLog file contains the error message "Get windows failed/GetRootByWindow failed."
**Possible Causes**
The ArkUI feature is disabled. As a result, the control tree information on the test page is not generated.
The ArkUI feature is disabled. As a result, the component tree information is not generated on the test page.
**Solution**
......@@ -410,13 +408,13 @@ The UI test case fails to be executed. The HiLog file contains the error message
**Possible Causes**
1. In the test case, the **await** operator is not added to the asynchronous interface provided by the UI test framework.
1. In the test case, the **await** operator is not added to the asynchronous API provided by the UI test framework.
2. The UI test case is executed in multiple processes. As a result, multiple UI test processes are started. The framework does not support multi-process invoking.
**Solution**
1. Check the case implementation and add the **await** operator to the asynchronous interface invoking.
1. Check the case implementation and add the **await** operator to the asynchronous API.
2. Do not execute UI test cases in multiple processes.
......@@ -424,11 +422,11 @@ The UI test case fails to be executed. The HiLog file contains the error message
**Problem**
The UI test case fails to be executed. The HiLog file contains the error message "does not exist on current UI! Check if the UI has changed after you got the widget object".
The UI test case fails to be executed. The HiLog file contains the error message "does not exist on current UI! Check if the UI has changed after you got the widget object."
**Possible Causes**
After the target component is found in the code of the test case, the device UI changes. As a result, the found component is lost and the emulation operation cannot be performed.
After the target component is found in the code of the test case, the device UI changes, resulting in loss of the found component and inability to perform emulation.
**Solution**
......
......@@ -4,7 +4,7 @@
To develop an application based on the [stage model](application-configuration-file-overview-stage.md), it will be helpful if you have a basic understanding of the structure of the application package created after the application is built and packaged, as well as the related basic concepts.
- In development, an application contains one or more modules. You can [create modules](https://developer.harmonyos.com/en/docs/documentation/doc-guides-V3/ohos-adding-deleting-module-0000001218760594-V3) in the application project in [DevEco Studio](https://developer.harmonyos.com/en/develop/deveco-studio/). As a basic functional unit of an OpenHarmony application/service, a module contains source code, resource files, third-party libraries, and application/service configuration files, and can be built and run independently. Modules can be classified as Ability or Library. A module of the Ability type is built into a Harmony Ability Package (HAP) file, and a module of the Library type is built into a [Harmony Archive (HAR)](har-package.md) file or a [Harmony Shared Package (HSP)](shared-guide.md).
- In development, an application contains one or more modules. You can [create modules](https://developer.harmonyos.com/en/docs/documentation/doc-guides-V3/add_new_module-0000001053223741-V3) in the application project in [DevEco Studio](https://developer.harmonyos.com/en/develop/deveco-studio/). As a basic functional unit of an OpenHarmony application/service, a module contains source code, resource files, third-party libraries, and application/service configuration files, and can be built and run independently. Modules can be classified as Ability or Library. A module of the Ability type is built into a Harmony Ability Package (HAP) file, and a module of the Library type is built into a [Harmony Archive (HAR)](har-package.md) file or a [Harmony Shared Package (HSP)](shared-guide.md).
A module can contain one or more [UIAbility](../application-models/uiability-overview.md) components, as shown in the figure below.
**Figure 1** Relationship between modules and UIAbility components
......
# $ Syntax: Two-Way Synchronization of Built-in Components
# $$ Syntax: Two-Way Synchronization of Built-in Components
The $$ operator provides a TS variable by-reference to a built-in component so that the variable value and the internal state of that component are kept in sync.
......
......@@ -18,9 +18,9 @@ Sets a timer for the system to call a function after the timer goes off.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| handler | Function \| string | Yes| Function to be called after the timer goes off.|
| handler | Function \| string | Yes| Function to be called after the timer goes off. If the type is string, error information is printed and no other processing is performed.|
| delay | number | No| Number of milliseconds delayed before the execution. If this parameter is left empty, the default value **0** is used, which means that the execution starts immediately or as soon as possible.|
| ...arguments | Array&lt;any&gt; | No| Additional parameters to pass to the handler after the timer goes off.|
| ...arguments | any[] | No| Additional parameters to pass to the handler after the timer goes off.|
**Return value**
......@@ -31,19 +31,15 @@ Sets a timer for the system to call a function after the timer goes off.
**Example**
```js
export default {
setTimeOut() {
var timeoutID = setTimeout(function() {
console.log('delay 1s');
}, 1000);
}
}
setTimeout(function() {
console.log('delay 1s');
}, 1000);
```
## clearTimeout
clearTimeout(timeoutID: number): void
clearTimeout(timeoutID?: number): void
Cancels the timer created via **setTimeout()**.
......@@ -53,19 +49,15 @@ Cancels the timer created via **setTimeout()**.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| timeoutID | number | Yes| ID of the timer to cancel, which is returned by **setTimeout()**|
| timeoutID | number | No| ID of the timer to cancel, which is returned by **setTimeout()** If this parameter is omitted, no timer is canceled.|
**Example**
```js
export default {
clearTimeOut() {
var timeoutID = setTimeout(function() {
console.log('do after 1s delay.');
}, 1000);
clearTimeout(timeoutID);
}
}
```js
let timeoutID = setTimeout(function() {
console.log('do after 1s delay.');
}, 1000);
clearTimeout(timeoutID);
```
......@@ -81,32 +73,28 @@ Sets a repeating timer for the system to repeatedly call a function at a fixed i
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| handler | Function \| string | Yes| Function to be called repeatedly.|
| handler | Function \| string | Yes| Function to be called repeatedly. If the type is string, error information is printed and no other processing is performed.|
| delay | number | Yes| Number of milliseconds delayed before the execution.|
| ...arguments | Array&lt;any&gt; | No| Additional parameters to pass to the handler after the timer goes off.|
| ...arguments | any[] | No| Additional parameters to pass to the handler after the timer goes off.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | ID of the repeating timer.|
| number | Timer ID.|
**Example**
```js
export default {
setInterval() {
var intervalID = setInterval(function() {
console.log('do very 1s.');
}, 1000);
}
}
setInterval(function() {
console.log('do every 1s.');
}, 1000);
```
## clearInterval
clearInterval(intervalID: number): void
clearInterval(intervalID?: number): void
Cancels the repeating timer set via **setInterval()**.
......@@ -116,17 +104,13 @@ Cancels the repeating timer set via **setInterval()**.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| intervalID | number | Yes| ID of the repeating timer to cancel, which is returned by **setInterval()**.|
| intervalID | number | No| ID of the repeating timer to cancel, which is returned by **setInterval()**. If this parameter is omitted, no timer is canceled.|
**Example**
```js
export default {
clearInterval() {
var intervalID = setInterval(function() {
console.log('do very 1s.');
}, 1000);
clearInterval(intervalID);
}
}
```js
let intervalID = setInterval(function() {
console.log('do every 1s.');
}, 1000);
clearInterval(intervalID);
```
......@@ -12,6 +12,7 @@
- [Mouse Event](ts-universal-mouse-key.md)
- [Component Area Change Event](ts-universal-component-area-change-event.md)
- [Visible Area Change Event](ts-universal-component-visible-area-change-event.md)
- [Custom Keyboard Shortcuts](ts-universal-events-keyboardshortcut.md)
- Universal Attributes
- [Size](ts-universal-attributes-size.md)
- [Location](ts-universal-attributes-location.md)
......@@ -42,6 +43,9 @@
- [Background Blur](ts-universal-attributes-backgroundBlurStyle.md)
- [restoreId](ts-universal-attributes-restoreId.md)
- [Foreground Color](ts-universal-attributes-foreground-color.md)
- [Spherical Effect](ts-universal-attributes-sphericalEffect.md)
- [Light Up Effect](ts-universal-attributes-lightUpEffect.md)
- [Pixel Stretch Effect](ts-universal-attributes-pixelStretchEffect.md)
- [Universal Text Attributes](ts-universal-attributes-text-style.md)
- Gesture Handling
- [Gesture Binding Methods](ts-gesture-settings.md)
......@@ -62,10 +66,11 @@
- [DataPanel](ts-basic-components-datapanel.md)
- [DatePicker](ts-basic-components-datepicker.md)
- [Divider](ts-basic-components-divider.md)
- [Formcomponent](ts-basic-components-formcomponent.md)
- [FormComponent](ts-basic-components-formcomponent.md)
- [Gauge](ts-basic-components-gauge.md)
- [Image](ts-basic-components-image.md)
- [ImageAnimator](ts-basic-components-imageanimator.md)
- [ImageSpan](ts-basic-components-imagespan.md)
- [LoadingProgress](ts-basic-components-loadingprogress.md)
- [Marquee](ts-basic-components-marquee.md)
- [Menu](ts-basic-components-menu.md)
......@@ -140,8 +145,8 @@
- [Shape](ts-drawing-components-shape.md)
- Canvas Components
- [Canvas](ts-components-canvas-canvas.md)
- [CanvasRenderingContext2D](ts-canvasrenderingcontext2d.md)
- [CanvasGradient](ts-components-canvas-canvasgradient.md)
- [CanvasRenderingContext2D](ts-canvasrenderingcontext2d.md)
- [ImageBitmap](ts-components-canvas-imagebitmap.md)
- [ImageData](ts-components-canvas-imagedata.md)
- [OffscreenCanvasRenderingContext2D](ts-offscreencanvasrenderingcontext2d.md)
......@@ -164,6 +169,7 @@
- [Time Picker Dialog Box](ts-methods-timepicker-dialog.md)
- [Text Picker Dialog Box](ts-methods-textpicker-dialog.md)
- [Menu](ts-methods-menu.md)
- [Custom Component Lifecycle](ts-custom-component-lifecycle.md)
- [State Management with Application-level Variables](ts-state-management.md)
- [Pixel Units](ts-pixel-units.md)
- [Enums](ts-appendix-enums.md)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册