• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# arkXtest User Guide
2
3
4## Overview
5
6arkXtest is an automated test framework that consists of JsUnit and UiTest.<br>JsUnit is a unit test framework that provides basic APIs for compiling test cases and generating test reports for testing system and application APIs.<br>UiTest is a UI test framework that provides the UI component search and operation capabilities through simple and easy-to-use APIs, and allows you to develop automated test scripts based on GUI operations. This document will help to familiarize you with arkXtest, describing its main functions, implementation principles, environment setup, and test script compilation and execution.
7
8
9## Implementation
10
11arkXtest is divided into two parts: unit test framework and UI test framework.<br>As the backbone of arkXtest, the unit test framework offers such features as identifying, scheduling, and executing test scripts, as well as summarizing test script execution results.<br>The UI test framework provides UiTest APIs for you to call in different test scenarios. Its test scripts are executed on top of the unit test framework.
12
13### Unit Test Framework
14
15  Figure 1 Main functions of the unit test framework
16
17  ![](figures/UnitTest.PNG)
18
19  Figure 2 Basic script process
20
21  ![](figures/TestFlow.PNG)
22
23
24### UI Test Framework
25
26  Figure 3 Main functions of the UI test framework
27
28  ![](figures/Uitest.PNG)
29
30
31## Constraints
32
33- The features of the UI test framework are available only in OpenHarmony 3.1 Release and later versions.
34
35## Preparing the Environment
36
37### Environment Requirements
38
39- Software: DevEco Studio 3.0 or later
40
41- Hardware: PC connected to a test device, such as a <!--RP1-->development board<!--RP1End-->.
42
43### Setting Up the Environment
44
45[Download DevEco Studio](https://developer.harmonyos.com/cn/develop/deveco-studio#download) and set it up as instructed on the official website.
46
47## Creating and Compiling a Test Script
48
49### Creating a Test Script
50
51<!--RP2-->
521. Open DevEco Studio and create a project, in which the **ohos** directory is where the test script is located.
532. 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. For more details, see [DevEco Studio User Guide](https://developer.harmonyos.com/en/docs/documentation/doc-guides-V3/harmonyos_jnit_jsunit-0000001092459608-V3?catalogVersion=V3#section13366184061415).
54<!--RP2End-->
55
56### Writing a Unit Test Script
57
58This section describes how to use the unit test framework to write a unit test script. For details about the functionality of the unit test framework, see [arkXtest](https://gitee.com/openharmony/testfwk_arkxtest/blob/master/README_en.md).
59
60The unit test script must contain the following basic elements:
61
621. Import of the dependencies so that the dependent test APIs can be used.
63
642. Test code, mainly about the related logic, such as API invoking.
65
663. Invoking of the assertion APIs and setting of checkpoints. If there is no checkpoint, the test script is considered as incomplete.
67
68The following sample code is used to start the test page to check whether the page displayed on the device is the expected page.
69
70```ts
71import { describe, it, expect } from '@ohos/hypium';
72import { abilityDelegatorRegistry } from '@kit.TestKit';
73import { UIAbility, Want } from '@kit.AbilityKit';
74
75const delegator = abilityDelegatorRegistry.getAbilityDelegator()
76const bundleName = abilityDelegatorRegistry.getArguments().bundleName;
77function sleep(time: number) {
78  return new Promise<void>((resolve: Function) => setTimeout(resolve, time));
79}
80export default function abilityTest() {
81  describe('ActsAbilityTest', () =>{
82    it('testUiExample',0, async (done: Function) => {
83      console.info("uitest: TestUiExample begin");
84      //start tested ability
85      const want: Want = {
86        bundleName: bundleName,
87        abilityName: 'EntryAbility'
88      }
89      await delegator.startAbility(want);
90      await sleep(1000);
91      // Check the top display ability.
92      await delegator.getCurrentTopAbility().then((Ability: UIAbility)=>{
93        console.info("get top ability");
94        expect(Ability.context.abilityInfo.name).assertEqual('EntryAbility');
95      })
96      done();
97    })
98  })
99}
100```
101
102### Writing a UI Test Script
103
104 <br>To write a UI test script to complete the corresponding test activities, simply add the invoking of the UiTest API to a unit test script. For details about the available APIs, see [@ohos.UiTest](../../application-dev/reference/apis-test-kit/js-apis-uitest.md).<br>In this example, the UI test script is written based on the preceding unit test script. It implements the click operation on the started application page and checks whether the page changes as expected.
105
1061. Write the demo code in the **index.ets** file.
107
108```ts
109@Entry
110@Component
111struct Index {
112  @State message: string = 'Hello World'
113
114  build() {
115    Row() {
116      Column() {
117        Text(this.message)
118          .fontSize(50)
119          .fontWeight(FontWeight.Bold)
120        Text("Next")
121          .fontSize(50)
122          .margin({top:20})
123          .fontWeight(FontWeight.Bold)
124        Text("after click")
125          .fontSize(50)
126          .margin({top:20})
127          .fontWeight(FontWeight.Bold)
128      }
129      .width('100%')
130    }
131    .height('100%')
132  }
133}
134```
135
1362. Write test code in the **.test.ets** file under **ohosTest** > **ets** > **test**.
137
138```ts
139import { describe, it, expect } from '@ohos/hypium';
140// Import the test dependencies.
141import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit';
142import { UIAbility, Want } from '@kit.AbilityKit';
143
144const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator()
145const bundleName = abilityDelegatorRegistry.getArguments().bundleName;
146function sleep(time: number) {
147  return new Promise<void>((resolve: Function) => setTimeout(resolve, time));
148}
149export default function abilityTest() {
150  describe('ActsAbilityTest', () => {
151    it('testUiExample',0, async (done: Function) => {
152      console.info("uitest: TestUiExample begin");
153      //start tested ability
154      const want: Want = {
155        bundleName: bundleName,
156        abilityName: 'EntryAbility'
157      }
158      await delegator.startAbility(want);
159      await sleep(1000);
160      // Check the top display ability.
161      await delegator.getCurrentTopAbility().then((Ability: UIAbility)=>{
162        console.info("get top ability");
163        expect(Ability.context.abilityInfo.name).assertEqual('EntryAbility');
164      })
165      // UI test code
166      // Initialize the driver.
167      let driver = Driver.create();
168      await driver.delayMs(1000);
169      // Find the button on text 'Next'.
170      let button = await driver.findComponent(ON.text('Next'));
171      // Click the button.
172      await button.click();
173      await driver.delayMs(1000);
174      // Check text.
175      await driver.assertComponentExist(ON.text('after click'));
176      await driver.pressBack();
177      done();
178    })
179  })
180}
181```
182
183## Running the Test Script
184
185### In DevEco Studio
186
187You can run a test script in DevEco Studio in any of the following modes:
188
1891. Test package level: All test cases in the test package are executed.
190
1912. Test suite level: All test cases defined in the **describe** method are executed.
192
1933. Test method level: The specified **it** method, that is, a single test case, is executed.
194
195![](figures/Execute.PNG)
196
197**Viewing the Test Result**
198
199After the test is complete, you can view the test result in DevEco Studio, as shown in the following figure.
200
201![](figures/TestResult.PNG)
202
203**Viewing the Test Case Coverage**
204
205After the test is complete, you can view the test case coverage.
206
207### In the CLI
208
209Install the application test package on the test device and run the **aa** command with different execution control keywords in the CLI.
210
211> **NOTE**
212>
213> Before running commands in the CLI, make sure hdc-related environment variables have been configured.
214
215The table below lists the keywords in **aa** test commands.
216
217| Keyword | Abbreviation| Description                          | Example                      |
218| ------------- | ------------ | -------------------------------------- | ---------------------------------- |
219| --bundleName  | -b           | Application bundle name.                        | - b com.test.example               |
220| --packageName | -p           | Application module name, which is applicable to applications developed in the FA model.          | - p com.test.example.entry         |
221| --moduleName  | -m           | Application module name, which is applicable to applications developed in the stage model.       | -m entry                           |
222| NA            | -s           | \<key, value> pair.| - s unittest /ets/testrunner/OpenHarmonyTestRunner |
223
224The 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.
225
226| Name    | Description                                                | Value                                              | Example                             |
227| ------------ | -----------------------------------------------------------------------------    | ------------------------------------------------------------ | ----------------------------------------- |
228| unittest     | **OpenHarmonyTestRunner** object used for test case execution. | **OpenHarmonyTestRunner** or custom runner name.                 | - s unittest OpenHarmonyTestRunner        |
229| class        | Test suite or test case to be executed.                                  | {describeName}#{itName}, {describeName}                     | -s class attributeTest#testAttributeIt    |
230| notClass     | Test suite or test case that does not need to be executed.                              | {describeName}#{itName}, {describeName}                     | -s notClass attributeTest#testAttributeIt |
231| itName       | Test case to be executed.                                        | {itName}                                                     | -s itName testAttributeIt                 |
232| 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                          |
233| 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                      |
234| random | Whether to execute test cases in random sequence.| **true**/**false** (default value)                                          | -s random true                      |
235| testType     | Type of the test case to be executed.                                     | function, performance, power, reliability, security, global, compatibility, user, standard, safety, resilience| -s testType function                      |
236| level        | Level of the test case to be executed.                                     | 0, 1, 2, 3, 4                                                   | -s level 0                                |
237| size         | Size of the test case to be executed.                                   | small, medium, large                                        | -s size small
238| stress       | Number of times that the test case is executed.                                   |  Positive integer                                        | -s stress 1000                            |
239
240**Running Commands**
241
242- Parameter configuration and commands are based on the stage model.
243- Open the CLI.
244- Run the **aa test** commands.
245
246
247Example 1: Execute all test cases.
248
249```shell
250 hdc shell aa test -b xxx -m xxx -s unittest OpenHarmonyTestRunner
251```
252
253Example 2: Execute cases in the specified test suites, separated by commas (,).
254
255```shell
256  hdc shell aa test -b xxx -m xxx -s unittest OpenHarmonyTestRunner -s class s1,s2
257```
258
259Example 3: Execute specified cases in the specified test suites, separated by commas (,).
260
261```shell
262  hdc shell aa test -b xxx -m xxx -s unittest OpenHarmonyTestRunner -s class testStop#stop_1,testStop1#stop_0
263```
264
265Example 4: Execute all test cases except the specified ones, separated by commas (,).
266
267```shell
268  hdc shell aa test -b xxx -m xxx -s unittest OpenHarmonyTestRunner -s notClass testStop
269```
270
271Example 5: Execute specified test cases, separated by commas (,).
272
273```shell
274  hdc shell aa test -b xxx -m xxx -s unittest OpenHarmonyTestRunner -s itName stop_0
275```
276
277Example 6: Set the timeout interval for executing a test case.
278
279```shell
280  hdc shell aa test -b xxx -m xxx -s unittest OpenHarmonyTestRunner -s timeout 15000
281```
282
283Example 7: Enable break-on-error mode.
284
285```shell
286  hdc shell aa test -b xxx -m xxx -s unittest OpenHarmonyTestRunner -s breakOnError true
287```
288
289Example 8: Execute test cases of the specified type.
290
291```shell
292  hdc shell aa test -b xxx -m xxx -s unittest OpenHarmonyTestRunner -s testType function
293```
294
295Example 9: Execute test cases at the specified level.
296
297```shell
298  hdc shell aa test -b xxx -m xxx -s unittest OpenHarmonyTestRunner -s level 0
299```
300
301Example 10: Execute test cases with the specified size.
302
303```shell
304  hdc shell aa test -b xxx -m xxx -s unittest OpenHarmonyTestRunner -s size small
305```
306
307Example 11: Execute test cases for a specified number of times.
308
309```shell
310  hdc shell aa test -b xxx -m xxx -s unittest OpenHarmonyTestRunner -s stress 1000
311```
312
313**Viewing the Test Result**
314
315- During test execution in the CLI, the log information similar to the following is displayed:
316
317```
318OHOS_REPORT_STATUS: class=testStop
319OHOS_REPORT_STATUS: current=1
320OHOS_REPORT_STATUS: id=JS
321OHOS_REPORT_STATUS: numtests=447
322OHOS_REPORT_STATUS: stream=
323OHOS_REPORT_STATUS: test=stop_0
324OHOS_REPORT_STATUS_CODE: 1
325
326OHOS_REPORT_STATUS: class=testStop
327OHOS_REPORT_STATUS: current=1
328OHOS_REPORT_STATUS: id=JS
329OHOS_REPORT_STATUS: numtests=447
330OHOS_REPORT_STATUS: stream=
331OHOS_REPORT_STATUS: test=stop_0
332OHOS_REPORT_STATUS_CODE: 0
333OHOS_REPORT_STATUS: consuming=4
334```
335
336| Log Field              | Description      |
337| -------           | -------------------------|
338| OHOS_REPORT_SUM    | Total number of test cases in the current test suite.|
339| OHOS_REPORT_STATUS: class | Name of the test suite that is being executed.|
340| OHOS_REPORT_STATUS: id | Case execution language. The default value is JS. |
341| OHOS_REPORT_STATUS: numtests | Total number of test cases in the test package.|
342| OHOS_REPORT_STATUS: stream | Error information of the current test case.|
343| OHOS_REPORT_STATUS: test| Name of the current test case.|
344| OHOS_REPORT_STATUS_CODE | Execution result of the current test case.<br>**0**: pass.<br>**1**: error.<br>**2**: fail.|
345| OHOS_REPORT_STATUS: consuming | Time spent in executing the current test case, in milliseconds.|
346
347- After the commands are executed, the following log information is displayed:
348
349```
350OHOS_REPORT_RESULT: stream=Tests run: 447, Failure: 0, Error: 1, Pass: 201, Ignore: 245
351OHOS_REPORT_CODE: 0
352
353OHOS_REPORT_RESULT: breakOnError model, Stopping whole test suite if one specific test case failed or error
354OHOS_REPORT_STATUS: taskconsuming=16029
355
356```
357| Log Field              | Description          |
358| ------------------| -------------------------|
359| run    | Total number of test cases in the current test package.|
360| Failure | Number of failed test cases.|
361| Error | Number of test cases whose execution encounters errors. |
362| Pass | Number of passed test cases.|
363| Ignore | Number of test cases not yet executed.|
364| taskconsuming| Total time spent in executing the current test case, in milliseconds.|
365
366> When an error occurs in break-on-error mode, check the **Ignore** and interrupt information.
367
368## Recording User Operations
369### Using the Recording Feature
370> You can record the operations performed on the current page to **/data/local/tmp/layout/record.csv**. To end the recording, press **Ctrl+C**.
371
372```shell
373 hdc shell uitest uiRecord record
374```
375### Viewing Recording Data
376You can view the recording data in either of the following ways.
377
378#### Reading and Printing Recording Data
379
380```shell
381 hdc shell uitest uiRecord read
382```
383#### Exporting the record.csv File
384```shell
385hdc file recv /data/local/tmp/layout/record.csv D:\tool  # D:\tool indicates the local save path, which can be customized.
386```
387- The following describes the fields in the recording data:
388```
389{
390	"ABILITY": "com.ohos.launcher.MainAbility", // Foreground application page.
391	"BUNDLE": "com.ohos.launcher", // Application.
392	"CENTER_X": "", // Reserved field.
393	"CENTER_Y": "", // Reserved field.
394	"EVENT_TYPE": "pointer", //
395	"LENGTH": "0", // Total length.
396	"OP_TYPE": "click", // Event type. Currently, click, double-click, long-press, drag, pinch, swipe, and fling types are supported.
397	"VELO": "0.000000", // Hands-off velocity.
398	"direction.X": "0.000000",// Movement along the x-axis.
399	"direction.Y": "0.000000", // Movement along the y-axis.
400	"duration": 33885000.0, // Gesture duration.
401	"fingerList": [{
402		"LENGTH": "0", // Total length.
403		"MAX_VEL": "40000", // Maximum velocity.
404		"VELO": "0.000000", // Hands-off velocity.
405		"W1_BOUNDS": "{"bottom":361,"left":37,"right":118,"top":280}", // Starting component bounds.
406		"W1_HIER": "ROOT,3,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0", // Starting component hierarchy.
407		"W1_ID": "", // ID of the starting component.
408		"W1_Text": "", // Text of the starting component.
409		"W1_Type": "Image", // Type of the starting component.
410		"W2_BOUNDS": "{"bottom":361,"left":37,"right":118,"top":280}", // Ending component bounds.
411		"W2_HIER": "ROOT,3,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0", // Ending component hierarchy.
412		"W2_ID": "", // ID of the ending component.
413		"W2_Text": "", // Text of the ending component.
414		"W2_Type": "Image", // Type of the ending component.
415		"X2_POSI": "47", // X coordinate of the ending point.
416		"X_POSI": "47", // X coordinate of the starting point.
417		"Y2_POSI": "301", // Y coordinate of the ending point.
418		"Y_POSI": "301", // Y coordinate of the starting point.
419		"direction.X": "0.000000", // Movement along the x-axis.
420		"direction.Y": "0.000000" // Movement along the y-axis.
421	}],
422	"fingerNumber": "1" // Number of fingers.
423}
424```
425
426## Injecting Simulated UI Operations in Shell Command Mode
427> Supported operation types: click, double-click, long press, fling, swipe, drag, text input, and key event.
428
429| Name      | Description                                 | Value                                                                                                                                                                                                               | Example                                                                                 |
430|-------------|-----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|
431| click       | Simulates a click.                                 | point_x (X coordinate of the click point. Mandatory.)<br> point_y (Y coordinate of the click point. Mandatory.)                                                                                                                                                                     | hdc shell uitest uiInput click point_x point_y                                      |
432| doubleClick | Simulates a double-click.                                 | point_x (X coordinate of the double-click point. Mandatory.)<br> point_y (Y coordinate of the double-click point. Mandatory.)                                                                                                                                                                     | hdc shell uitest uiInput doubleClick point_x point_y                                |
433| longClick   | Simulates a long-click.                                 | point_x (X coordinate of the long-click point. Mandatory.)<br> point_y (Y coordinate of the long-click point. Mandatory.)                                                                                                                                                                     | hdc shell uitest uiInput longClick point_x point_y                                  |
434| fling       | Simulates a fling.                                 | from_x (X coordinate of the fling start point. Mandatory.)<br> from_y (Y coordinate of the fling start point. Mandatory.)<br> to_x (X coordinate of the fling end point. Mandatory.)<br> to_y (Y coordinate of the fling end point. Mandatory.)<br> swipeVelocityPps_ (Fling speed. Value range: 200-40000. Default value: 600. Optional.)<br> stepLength (Fling step. Default value: Fling distance/50. Unit: px. Optional.)| hdc shell uitest uiInput fling from_x from_y to_x to_y swipeVelocityPps_ stepLength |
435| swipe       | Simulates a swipe.                                 | from_x (X coordinate of the swipe start point. Mandatory.)<br> from_y (Y coordinate of the swipe start point. Mandatory.)<br> to_x (X coordinate of the swipe end point. Mandatory.)<br> to_y (Y coordinate of the swipe end point. Mandatory.)<br> swipeVelocityPps_ (Fling speed. Value range: 200-40000. Default value: 600. Unit: px/s. Optional.)                                              | hdc shell uitest uiInput swipe from_x from_y to_x to_y swipeVelocityPps_            |
436| drag        | Simulates a drag and drop.                                 | from_x (X coordinate of the drag point. Mandatory.)<br> from_y (Y coordinate of the drag point. Mandatory.)<br> to_x (X coordinate of the drop point. Mandatory.)<br> to_y (Y coordinate of the drop point. Mandatory.)<br> swipeVelocityPps_ (Drag speed. Value range: 200-40000. Default value: 600. Unit: px/s. Optional.)                                      | hdc shell uitest uiInput drag from_x from_y to_x to_y swipeVelocityPps_             |
437| dircFling   | Simulates a directional fling.                             | direction (Fling direction. Value range: [0, 1, 2, 3]. Fling direction: [left, right, up, down]. Default value: 0. Optional.)<br> swipeVelocityPps_ (Fling speed. Value range: 200-40000. Default value: 600. Optional.)<br> stepLength (Fling step. Default value: Fling distance/50. Unit: px. Optional.)                                           | hdc shell uitest uiInput dircFling direction swipeVelocityPps_ stepLength                                       |
438| inputText        | Simulates text input in a text box.                            | point_x (X coordinate of the text box. Mandatory.)<br> point_y (Y coordinate of the text box. Mandatory.)<br> input (Text entered.)                                                                                                                                                  | hdc shell uitest uiInput inputText  point_x point_y text                                  |
439| keyEvent    | Simulates a physical key event (such as pressing a keyboard key, pressing the power key, returning to the previous page, or returning to the home screen) or a key combination.| keyID (ID of a physical key. Mandatory.)<br> keyID2 (ID of a physical key. Optional.)                                                                                                                                                                    | hdc shell uitest uiInput keyEvent keyID                                             |
440
441Example 1: Perform a click.
442```shell
443 hdc shell uitest uiInput click 100 100
444```
445Example 2: Perform a double-click.
446```shell
447 hdc shell uitest uiInput doubleClick 100 100
448```
449Example 3: Perform a long-click.
450```shell
451 hdc shell uitest uiInput longClick 100 100
452```
453Example 4: Perform a fling.
454```shell
455hdc shell uitest uiInput fling 10 10 200 200 500
456```
457Example 5: Perform a swipe.
458```shell
459hdc shell uitest uiInput swipe 10 10 200 200 500
460```
461Example 6: Perform a drag and drop.
462```shell
463hdc shell uitest uiInput drag 10 10 100 100 500
464```
465Example 7: Perform a fling-left.
466```shell
467hdc shell uitest uiInput dircFling 0 500
468```
469Example 8: Perform a fling-right.
470```shell
471hdc shell uitest uiInput dircFling 1 600
472```
473Example 9: Perform a fling-up.
474```shell
475hdc shell uitest uiInput dircFling 2
476```
477Example 10: Perform a fling-down.
478```shell
479hdc shell uitest uiInput dircFling 3
480```
481
482Example 11: Enter text in the text box.
483```shell
484hdc shell uitest uiInput inputText 100 100 hello
485```
486
487Example 12: Return to the home screen.
488```shell
489hdc shell uitest uiInput keyEvent Home
490```
491Example 13: Return to the previous page.
492```shell
493hdc shell uitest uiInput keyEvent Back
494```
495Example 14: Perform a key combination to copy and paste text.
496```shell
497hdc shell uitest uiInput keyEvent 2072 2038
498```
499
500<!--Del-->
501## Examples
502
503### Unit Test Scripts
504
505#### Using Assertion APIs of the Unit Test
506For details about how to use the available APIs, see [Example of Using Assertion APIs](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/jsunit/entry/src/ohosTest/ets/test/assertExampleTest/assertExample.test.ets).
507
508#### Defining Unit Test Suites
509For details about how to define and nest the unit test suite, see [Example of Defining Test Suites](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/jsunit/entry/src/ohosTest/ets/test/coverExampleTest/coverExample.test.ets).
510
511#### Testing Custom Application Functions Using Unit Test
512For details about how to test the custom functions in an application, see [Example of Testing Custom Application Functions](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/jsunit/entry/src/ohosTest/ets/test/customExampleTest/customExample.test.ets).
513
514#### Using Data-Driven Capability of the Unit Test
515For details about how to use the data-driven capability and configure repeat script execution, see [Example of Using Data-Driven Capability](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/jsunit/entry/src/ohosTest/ets/test/paramExampleTest/paramExample.test.ets).
516
517### UI Test Scripts for Components
518
519#### Searching for Specified Components
520For details about how to search for a component in an application UI by specifying the attributes of the component, see [Example of Searching for Specified Components](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/findCommentExampleTest/Component/findCommentExample.test.ets).
521
522#### Simulating Click Events
523For details about how to simulate a click event, a long-click event or a double-click event, see [Example of Simulating Click Events](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/operationExampleTest/ui/clickEvent.test.ets).
524
525#### Simulating Mouse Events
526For details about how to simulate a mouse left-click event, a mouse right-click event, or a mouse scroll wheel event, see [Example of Simulating Mouse Events](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/operationExampleTest/ui/MouseEvent.test.ets).
527
528#### Simulating Input Events
529For details about how to simulate the input of Chinese and English text, see [Example of Simulating Input Events](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/operationExampleTest/ui/InputEvent.test.ets).
530
531#### Simulating Screenshot Events
532For details about how to simulate capturing a screenshot (in a specified area), see [Example of Simulating Screenshot Events](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/operationExampleTest/ui/ScreenCapEvent.test.ets).
533
534#### Simulating Fling Events
535For details about how to simulate a fling event(the finger leaves the screen after sliding), see [Example of Simulating Fling Events](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/operationExampleTest/ui/FlingEvent.test.ets).
536
537#### Simulating Swipe Events
538For details about how to simulate a swipe event (the finger stays on the screen after sliding), see [Example of Simulating Swipe Events](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/operationExampleTest/ui/SwipeEvent.test.ets).
539
540#### Simulating Pinch Events
541For details about how to simulate a zoom-in and zoom-out operation on pictures, see [Example of Simulating Pinch Events](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/operationExampleTest/ui/PinchEvent.test.ets).
542
543#### Simulating Scroll Events
544For details about how to simulate components scrolling, see [Example of Simulating Scroll Events](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/operationExampleTest/ui/ScrollerEvent.test.ets).
545
546### UI Test Scripts for Windows
547
548#### Searching for Specified Windows
549For details about how to search for an application window by using the bundle name of the application, see [Example of Searching for Specified Windows](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/findCommentExampleTest/window/findWindowExample.test.ets).
550
551#### Simulating Window Move Events
552For details about how to simulate moving a window to a specified position, see [Example of Simulating Window Move Events](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/operationExampleTest/window/MoveToEvent.test.ets).
553
554#### Simulating Window Size Adjustments
555For details about how to simulate a window size adjustment and direction specification, see [Example of Simulating Window Size Adjustments](https://gitee.com/openharmony/applications_app_samples/blob/master/code/Project/Test/uitest/entry/src/ohosTest/ets/test/operationExampleTest/window/ReSizeWindow.test.ets).
556
557<!--DelEnd-->
558
559## FAQs
560
561### FAQs About Unit Test Cases
562
563**The logs in the test case are printed after the test case result**
564
565**Problem**
566
567The logs added to the test case are displayed after the test case execution, rather than during the test case execution.
568
569**Possible Causes**
570
571More 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.
572
573**Solutions**
574
575If more than one asynchronous API is called, you are advised to encapsulate the API invoking into the promise mode.
576
577**Error "fail to start ability" is reported during test case execution**
578
579**Problem**
580
581When a test case is executed, the console returns the error message "fail to start ability".
582
583**Possible Causes**
584
585An error occurs during the packaging of the test package, and the test framework dependency file is not included in the test package.
586
587**Solutions**
588
589Check whether the test package contains the **OpenHarmonyTestRunner.abc** file. If the file does not exist, rebuild and pack the file and perform the test again.
590
591**Test case execution timeout**
592
593**Problem**
594
595After the test case execution is complete, the console displays the error message "execute time XXms", indicating that the case execution times out.
596
597**Possible Causes**
598
5991. The test case is executed through an asynchronous interface, but the **done** function is not executed during the execution. As a result, the test case execution does not end until it times out.
600
6012. The time taken for API invocation is longer than the timeout interval set for test case execution.
602
6033. Test assertion fails, and a failure exception is thrown. As a result, the test case execution does not end until it times out.
604
605**Solutions**
606
6071. Check the code logic of the test case to ensure that the **done** function is executed even if the assertion fails.
608
6092. Modify the case execution timeout settings under **Run/Debug Configurations** in DevEco Studio.
610
6113. Check the code logic and assertion result of the test case and make sure that the assertion is passed.
612### FAQs About UI Test Cases
613
614**The failure log contains "Get windows failed/GetRootByWindow failed"**
615
616**Problem**
617
618The UI test case fails to be executed. The HiLog file contains the error message "Get windows failed/GetRootByWindow failed."
619
620**Possible Causes**
621
622The ArkUI feature is disabled. As a result, the component tree information is not generated on the test page.
623
624**Solutions**
625
626Run the following command, restart the device, and execute the test case again:
627
628```shell
629hdc shell param set persist.ace.testmode.enabled 1
630```
631
632**The failure log contains "uitest-api does not allow calling concurrently"**
633
634**Problem**
635
636The UI test case fails to be executed. The HiLog file contains the error message "uitest-api does not allow calling concurrently."
637
638**Possible Causes**
639
6401. In the test case, the **await** operator is not added to the asynchronous API provided by the UI test framework.
641
6422. 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.
643
644**Solutions**
645
6461. Check the case implementation and add the **await** operator to the asynchronous API.
647
6482. Do not execute UI test cases in multiple processes.
649
650**The failure log contains "does not exist on current UI! Check if the UI has changed after you got the widget object"**
651
652**Problem**
653
654The 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."
655
656**Possible Causes**
657
658After 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.
659
660**Solutions**
661
662Run the UI test case again.
663