js-apis-uitest.md 109.7 KB
Newer Older
1
# @ohos.uitest (UiTest)
2

R
ry 已提交
3 4 5 6
UiTest提供模拟UI操作的能力,供开发者在测试场景使用,主要支持如点击、双击、长按、滑动等UI操作能力。

该模块提供以下功能:

7 8
- [On<sup>9+</sup>](#on9):提供控件特征描述能力,用于控件筛选匹配查找。
- [Component<sup>9+</sup>](#component9):代表UI界面上的指定控件,提供控件属性获取,控件点击,滑动查找,文本注入等能力。
9
- [Driver<sup>9+</sup>](#driver9):入口类,提供控件匹配/查找,按键注入,坐标点击/滑动,截图等能力。
10
- [UiWindow<sup>9+</sup>](#uiwindow9):入口类,提供窗口属性获取,窗口拖动、调整窗口大小等能力。
R
ry 已提交
11 12 13
- [By<sup>(deprecated)</sup>](#bydeprecated):提供控件特征描述能力,用于控件筛选匹配查找。从API version 9开始不再维护,建议使用[On<sup>9+</sup>](#on9)
- [UiComponent<sup>(deprecated)</sup>](#uicomponentdeprecated):代表UI界面上的指定控件,提供控件属性获取,控件点击,滑动查找,文本注入等能力。从API version 9开始不再维护,建议使用[Component<sup>9+</sup>](#component9)
- [UiDriver<sup>(deprecated)</sup>](#uidriverdeprecated):入口类,提供控件匹配/查找,按键注入,坐标点击/滑动,截图等能力。从API version 9开始不再维护,建议使用[Driver<sup>9+</sup>](#driver9)
R
ry 已提交
14

15 16 17 18 19 20 21
>**说明:**
>
>本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。


## 导入模块 

22
```js
23
import {UiComponent, UiDriver, Component, Driver, UiWindow, ON, BY, MatchPattern, DisplayRotation, ResizeDirection, WindowMode, PointerMatrix} from '@ohos.uitest';
24 25
```

R
ry 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
## MatchPattern

控件属性支持的匹配模式。

**系统能力**:SystemCapability.Test.UiTest

| 名称        | 值   | 说明           |
| ----------- | ---- | -------------- |
| EQUALS      | 0    | 等于给定值。   |
| CONTAINS    | 1    | 包含给定值。   |
| STARTS_WITH | 2    | 以给定值开始。 |
| ENDS_WITH   | 3    | 以给定值结束。 |

## ResizeDirection<sup>9+</sup>

窗口调整大小的方向。

**系统能力**:SystemCapability.Test.UiTest

45 46 47 48 49 50 51 52 53 54
| 名称       | 值   | 说明     |
| ---------- | ---- | -------- |
| LEFT       | 0    | 左方。   |
| RIGHT      | 1    | 右方。   |
| UP         | 2    | 上方。   |
| DOWN       | 3    | 下方。   |
| LEFT_UP    | 4    | 左上方。 |
| LEFT_DOWN  | 5    | 左下方。 |
| RIGHT_UP   | 6    | 右上方。 |
| RIGHT_DOWN | 7    | 右下方。 |
R
ry 已提交
55 56 57 58 59 60 61

## Point<sup>9+</sup>

坐标点信息。

**系统能力**:SystemCapability.Test.UiTest

62 63 64 65
| 名称 | 类型   | 可读 | 可写 | 说明             |
| ---- | ------ | ---- | ---- | ---------------- |
| X    | number | 是   | 否   | 坐标点的横坐标。 |
| Y    | number | 是   | 否   | 坐标点的纵坐标。 |
R
ry 已提交
66 67 68 69 70 71 72

## Rect<sup>9+</sup>

控件的边框信息。

**系统能力**:SystemCapability.Test.UiTest

73 74 75 76 77 78
| 名称    | 类型   | 可读 | 可写 | 说明                      |
| ------- | ------ | ---- | ---- | ------------------------- |
| leftX   | number | 是   | 否   | 控件边框的左上角的X坐标。 |
| topY    | number | 是   | 否   | 控件边框的左上角的Y坐标。 |
| rightX  | number | 是   | 否   | 控件边框的右下角的X坐标。 |
| bottomY | number | 是   | 否   | 控件边框的右下角的Y坐标。 |
R
ry 已提交
79 80 81 82 83 84 85

## WindowMode<sup>9+</sup>

**系统能力**:SystemCapability.Test.UiTest

窗口的窗口模式。

86 87 88 89 90 91
| 名称       | 值   | 说明       |
| ---------- | ---- | ---------- |
| FULLSCREEN | 0    | 全屏模式。 |
| PRIMARY    | 1    | 主窗口。   |
| SECONDARY  | 2    | 第二窗口。 |
| FLOATING   | 3    | 浮动窗口。 |
R
ry 已提交
92 93 94 95 96 97 98

## DisplayRotation<sup>9+</sup>

**系统能力**:SystemCapability.Test.UiTest

设备显示器的显示方向。

99 100 101 102 103 104
| 名称         | 值   | 说明                                     |
| ------------ | ---- | ---------------------------------------- |
| ROTATION_0   | 0    | 设备显示器不旋转,初始形态垂直显示。     |
| ROTATION_90  | 1    | 设备显示器顺时针旋转90°,水平显示。      |
| ROTATION_180 | 2    | 设备显示器顺时针旋转180°,逆向垂直显示。 |
| ROTATION_270 | 3    | 设备显示器顺时针旋转270°,逆向水平显示。 |
R
ry 已提交
105 106 107 108 109 110 111

## WindowFilter<sup>9+</sup>

窗口的标志属性信息。

**系统能力**:SystemCapability.Test.UiTest

112 113 114 115 116 117
| 名称       | 类型    | 可读 | 可写 | 说明                       |
| ---------- | ------- | ---- | ---- | -------------------------- |
| bundleName | string  | 是   | 否   | 窗口归属应用的包名。       |
| title      | string  | 是   | 否   | 窗口的标题信息。           |
| focused    | boolean | 是   | 否   | 窗口是否处于获焦状态。     |
| actived    | boolean | 是   | 否   | 窗口是否正与用户进行交互。 |
R
ry 已提交
118

119
## On<sup>9+</sup>
120

R
ry 已提交
121
UiTest框架在API 9中,通过On类提供了丰富的控件特征描述API,用于进行控件筛选来匹配/查找出目标控件。<br>
122
On提供的API能力具有以下几个特点:<br>1、支持单属性匹配和多属性组合匹配,例如同时指定目标控件text和id。<br>2、控件属性支持多种匹配模式。<br>3、支持控件绝对定位,相对定位,可通过[ON.isBefore](#isbefore)[ON.isAfter](#isafter)等API限定邻近控件特征进行辅助定位。<br>On类提供的所有API均为同步接口,建议使用者通过静态构造器ON来链式创建On对象。
123 124

```js
125
ON.text('123').type('button');
126
```
127

128
### text<sup>9+</sup>
129

130
text(txt: string, pattern?: MatchPattern): On
131

132
指定目标控件文本属性,支持多种匹配模式,返回On对象自身。
133 134 135 136 137

**系统能力**:SystemCapability.Test.UiTest

**参数:**

138 139 140 141
| 参数名  | 类型                          | 必填 | 说明                                                |
| ------- | ----------------------------- | ---- | --------------------------------------------------- |
| txt     | string                        | 是   | 指定控件文本,用于匹配目标控件文本。                |
| pattern | [MatchPattern](#matchpattern) | 否   | 指定的文本匹配模式,默认为[EQUALS](#matchpattern)。 |
142 143 144

**返回值:**

145 146 147
| 类型       | 说明                               |
| ---------- | ---------------------------------- |
| [On](#on9) | 返回指定目标控件文本属性的On对象。 |
148 149 150

**示例:**

151
```js
152
let on = ON.text('123'); // 使用静态构造器ON创建On对象,指定目标控件的text属性。
153 154 155
```


156
### id<sup>9+</sup>
157

158
id(id: string): On
159

160
指定目标控件id属性,返回On对象自身。
161 162 163 164 165

**系统能力**:SystemCapability.Test.UiTest

**参数:**

166 167
| 参数名 | 类型   | 必填 | 说明             |
| ------ | ------ | ---- | ---------------- |
168
| id     | string | 是   | 指定控件的id值。 |
169 170 171

**返回值:**

172 173 174 175
| 类型       | 说明                             |
| ---------- | -------------------------------- |
| [On](#on9) | 返回指定目标控件id属性的On对象。 |

176 177
**示例:**

178
```js
179
let on = ON.id('123'); // 使用静态构造器ON创建On对象,指定目标控件的id属性。
180 181 182
```


183
### type<sup>9+</sup>
184

185
type(tp: string): On
186

187
指定目标控件的控件类型属性,返回On对象自身。
188 189 190 191 192

**系统能力**:SystemCapability.Test.UiTest

**参数:**

193 194 195
| 参数名 | 类型   | 必填 | 说明           |
| ------ | ------ | ---- | -------------- |
| tp     | string | 是   | 指定控件类型。 |
196 197 198

**返回值:**

199 200 201 202
| 类型       | 说明                                     |
| ---------- | ---------------------------------------- |
| [On](#on9) | 返回指定目标控件的控件类型属性的On对象。 |

203 204
**示例:**

205
```js
206
let on = ON.type('button'); // 使用静态构造器ON创建On对象,指定目标控件的控件类型属性。
207 208 209
```


210
### clickable<sup>9+</sup>
211

212
clickable(b?: boolean): On
213

214
指定目标控件的可点击状态属性,返回On对象自身。
215 216 217 218 219

**系统能力**:SystemCapability.Test.UiTest

**参数:**

220 221
| 参数名 | 类型    | 必填 | 说明                                                         |
| ------ | ------- | ---- | ------------------------------------------------------------ |
222
| b      | boolean | 否   | 指定控件可点击状态,true:可点击,false:不可点击。默认为true。 |
223 224 225

**返回值:**

226 227 228 229
| 类型       | 说明                                       |
| ---------- | ------------------------------------------ |
| [On](#on9) | 返回指定目标控件的可点击状态属性的On对象。 |

230 231
**示例:**

232
```js
233
let on = ON.clickable(true); // 使用静态构造器ON创建On对象,指定目标控件的可点击状态属性。
234
```
235

236
### longClickable<sup>9+</sup>
237

238
longClickable(b?: boolean): On
239

240
指定目标控件的可长按点击状态属性,返回On对象自身。
241 242 243 244 245

**系统能力**:SystemCapability.Test.UiTest

**参数:**

246 247
| 参数名 | 类型    | 必填 | 说明                                                         |
| ------ | ------- | ---- | ------------------------------------------------------------ |
248
| b      | boolean | 否   | 指定控件可长按点击状态,true:可长按点击,false:不可长按点击。默认为true。 |
249 250 251

**返回值:**

252 253 254 255
| 类型       | 说明                                           |
| ---------- | ---------------------------------------------- |
| [On](#on9) | 返回指定目标控件的可长按点击状态属性的On对象。 |

256 257 258
**示例:**

```js
259
let on = ON.longClickable(true); // 使用静态构造器ON创建On对象,指定目标控件的可长按点击状态属性。
260 261 262
```


263
### scrollable<sup>9+</sup>
264

265
scrollable(b?: boolean): On
266

267
指定目标控件的可滑动状态属性,返回On对象自身。
268 269 270 271 272

**系统能力**:SystemCapability.Test.UiTest

**参数:**

273 274
| 参数名 | 类型    | 必填 | 说明                                                        |
| ------ | ------- | ---- | ----------------------------------------------------------- |
275
| b      | boolean | 否   | 控件可滑动状态,true:可滑动,false:不可滑动。默认为true。 |
276 277 278

**返回值:**

279 280 281 282
| 类型       | 说明                                       |
| ---------- | ------------------------------------------ |
| [On](#on9) | 返回指定目标控件的可滑动状态属性的On对象。 |

283 284
**示例:**

285
```js
286
let on = ON.scrollable(true); // 使用静态构造器ON创建On对象,指定目标控件的可滑动状态属性。
287 288
```

289
### enabled<sup>9+</sup>
290

291
enabled(b?: boolean): On
292

293
指定目标控件的使能状态属性,返回On对象自身。
294 295 296 297 298

**系统能力**:SystemCapability.Test.UiTest

**参数:**

299 300
| 参数名 | 类型    | 必填 | 说明                                                      |
| ------ | ------- | ---- | --------------------------------------------------------- |
301
| b      | boolean | 否   | 指定控件使能状态,true:使能,false:未使能。默认为true。 |
302 303 304

**返回值:**

305 306 307 308
| 类型       | 说明                                     |
| ---------- | ---------------------------------------- |
| [On](#on9) | 返回指定目标控件的使能状态属性的On对象。 |

309 310
**示例:**

311
```js
312
let on = ON.enabled(true); // 使用静态构造器ON创建On对象,指定目标控件的使能状态属性。
313 314
```

315
### focused<sup>9+</sup>
316

317
focused(b?: boolean): On
318

319
指定目标控件的获焦状态属性,返回On对象自身。
320 321 322 323 324

**系统能力**:SystemCapability.Test.UiTest

**参数:**

325 326
| 参数名 | 类型    | 必填 | 说明                                                  |
| ------ | ------- | ---- | ----------------------------------------------------- |
327
| b      | boolean | 否   | 控件获焦状态,true:获焦,false:未获焦。默认为true。 |
328 329 330

**返回值:**

331 332 333 334
| 类型       | 说明                                     |
| ---------- | ---------------------------------------- |
| [On](#on9) | 返回指定目标控件的获焦状态属性的On对象。 |

335 336
**示例:**

337
```js
338
let on = ON.focused(true); // 使用静态构造器ON创建On对象,指定目标控件的获焦状态属性。
339 340
```

341
### selected<sup>9+</sup>
342

343
selected(b?: boolean): On
344

345
指定目标控件的被选中状态属性,返回On对象自身。
346

347 348 349 350
**系统能力**:SystemCapability.Test.UiTest

**参数:**

351 352
| 参数名 | 类型    | 必填 | 说明                                                         |
| ------ | ------- | ---- | ------------------------------------------------------------ |
353
| b      | boolean | 否   | 指定控件被选中状态,true:被选中,false:未被选中。默认为true。 |
354 355 356

**返回值:**

357 358 359 360
| 类型       | 说明                                       |
| ---------- | ------------------------------------------ |
| [On](#on9) | 返回指定目标控件的被选中状态属性的On对象。 |

361 362 363
**示例:**

```js
364
let on = ON.selected(true); // 使用静态构造器ON创建On对象,指定目标控件的被选中状态属性。
365 366
```

367
### checked<sup>9+</sup>
368

369
checked(b?: boolean): On
370

371
指定目标控件的被勾选状态属性,返回On对象自身。
372 373 374 375 376

**系统能力**:SystemCapability.Test.UiTest

**参数:**

377 378
| 参数名 | 类型    | 必填 | 说明                                                         |
| ------ | ------- | ---- | ------------------------------------------------------------ |
379
| b      | boolean | 否   | 指定控件被勾选状态,true:被勾选,false:未被勾选。默认为false。 |
380 381 382

**返回值:**

383 384 385 386
| 类型       | 说明                                       |
| ---------- | ------------------------------------------ |
| [On](#on9) | 返回指定目标控件的被勾选状态属性的On对象。 |

387 388
**示例:**

389
```js
390
let on = ON.checked(true); // 使用静态构造器ON创建On对象,指定目标控件的被勾选状态属性
391
```
392

393
### checkable<sup>9+</sup>
394

395
checkable(b?: boolean): On
396

397
指定目标控件能否被勾选状态属性,返回On对象自身。
398 399 400 401 402

**系统能力**:SystemCapability.Test.UiTest

**参数:**

403 404
| 参数名 | 类型    | 必填 | 说明                                                         |
| ------ | ------- | ---- | ------------------------------------------------------------ |
405
| b      | boolean | 否   | 指定控件能否被勾选状态,true:能被勾选,false:不能被勾选。默认为false。 |
406 407 408

**返回值:**

409 410 411 412
| 类型       | 说明                                         |
| ---------- | -------------------------------------------- |
| [On](#on9) | 返回指定目标控件能否被勾选状态属性的On对象。 |

413 414 415
**示例:**

```js
416
let on = ON.checkable(true); // 使用静态构造器ON创建On对象,指定目标控件的能否被勾选状态属性。
417 418
```

419
### isBefore<sup>9+</sup>
420

421
isBefore(on: On): On
422

423
指定目标控件位于给出的特征属性控件之前,返回On对象自身。
424 425 426 427 428

**系统能力**:SystemCapability.Test.UiTest

**参数:**

429 430 431
| 参数名 | 类型       | 必填 | 说明                 |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | 是   | 特征控件的属性要求。 |
432 433 434

**返回值:**

435 436 437 438
| 类型       | 说明                                                 |
| ---------- | ---------------------------------------------------- |
| [On](#on9) | 返回指定目标控件位于给出的特征属性控件之前的On对象。 |

439 440
**示例:**

441
```js
442
let on = ON.isBefore(ON.text('123')); // 使用静态构造器ON创建On对象,指定目标控件位于给出的特征属性控件之前。
443 444
```

445
### isAfter<sup>9+</sup>
446

447
isAfter(on: On): On
448

449
指定目标控件位于给出的特征属性控件之后,返回On对象自身。
450 451 452 453 454

**系统能力**:SystemCapability.Test.UiTest

**参数:**

455 456 457
| 参数名 | 类型       | 必填 | 说明                 |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | 是   | 特征控件的属性要求。 |
458 459 460

**返回值:**

461 462 463 464
| 类型       | 说明                                                 |
| ---------- | ---------------------------------------------------- |
| [On](#on9) | 返回指定目标控件位于给出的特征属性控件之后的On对象。 |

465 466
**示例:**

467
```js
468
let on = ON.isAfter(ON.text('123')); // 使用静态构造器ON创建On对象,指定目标控件位于给出的特征属性控件之后。
469 470
```

471
## Component<sup>9+</sup>
472

473
UiTest框架在API9中,Component类代表了UI界面上的一个控件,提供控件属性获取,控件点击,滑动查找,文本注入等API。
474 475
该类提供的所有方法都使用Promise方式作为异步方法,需使用await调用。

476
### click<sup>9+</sup>
477

478
click(): Promise\<void>
479

480
控件对象进行点击操作。
481

482
**系统能力**:SystemCapability.Test.UiTest
483

484
**错误码:**
485

486
以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)
487

488
| 错误码ID | 错误信息                                 |
489 490 491
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
492 493 494

**示例:**

495
```js
496
async function demo() {
497 498 499
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    await button.click();
500
}
501 502
```

503
### doubleClick<sup>9+</sup>
504

505
doubleClick(): Promise\<void>
506 507 508 509 510

控件对象进行双击操作。

**系统能力**:SystemCapability.Test.UiTest

511 512 513 514
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

515
| 错误码ID | 错误信息                                 |
516 517 518 519
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

520 521
**示例:**

522
```js
523
async function demo() {
524 525 526
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    await button.doubleClick();
527
}
528 529
```

530
### longClick<sup>9+</sup>
531

532
longClick(): Promise\<void>
533 534 535 536 537

控件对象进行长按操作。

**系统能力**:SystemCapability.Test.UiTest

538 539 540 541
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

542
| 错误码ID | 错误信息                                 |
543 544 545 546
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

547 548
**示例:**

549
```js
550
async function demo() {
551 552 553
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    await button.longClick();
554
}
555 556
```

557
### getId<sup>9+</sup>
558

559
getId(): Promise\<string>
560 561 562 563 564 565 566

获取控件对象的id值。

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

567 568
| 类型             | 说明                            |
| ---------------- | ------------------------------- |
569
| Promise\<string> | 以Promise形式返回的控件的id值。 |
570

571
**错误码:**
572

573
以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)
574

575
| 错误码ID | 错误信息                                 |
576 577 578
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
579 580 581

**示例:**

582
```js
583
async function demo() {
584 585 586
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let num = await button.getId();
587
}
588 589
```

590
### getText<sup>9+</sup>
591

592
getText(): Promise\<string>
593 594 595 596 597 598 599

获取控件对象的文本信息。

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

600 601 602
| 类型             | 说明                              |
| ---------------- | --------------------------------- |
| Promise\<string> | 以Promise形式返回控件的文本信息。 |
603

604 605 606 607
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

608
| 错误码ID | 错误信息                               |
609 610 611 612
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

613 614
**示例:**

615
```js
616
async function demo() {
617 618 619
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let text = await button.getText();
620
}
621 622
```

623
### getType<sup>9+</sup>
624

625
getType(): Promise\<string>
626 627 628 629 630 631 632

获取控件对象的控件类型。

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

633 634 635
| 类型             | 说明                          |
| ---------------- | ----------------------------- |
| Promise\<string> | 以Promise形式返回控件的类型。 |
636

637 638 639 640
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

641
| 错误码ID | 错误信息                               |
642 643 644 645
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

646 647
**示例:**

648
```js
649
async function demo() {
650 651 652
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let type = await button.getType();
653
}
654 655
```

656
### getBounds<sup>9+</sup>
657

658
getBounds(): Promise\<Rect>
659 660 661 662 663 664 665

获取控件对象的边框信息。

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

666 667 668
| 类型                     | 说明                                  |
| ------------------------ | ------------------------------------- |
| Promise\<[Rect](#rect9)> | 以Promise形式返回控件对象的边框信息。 |
669

670 671 672 673
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

674
| 错误码ID | 错误信息                               |
675 676 677 678
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

679 680 681 682
**示例:**

```js
async function demo() {
683 684 685
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let rect = await button.getBounds();
686 687 688
}
```

689
### getBoundsCenter<sup>9+</sup>
690 691 692

getBoundsCenter(): Promise\<Point>

R
ry 已提交
693
获取控件对象所占区域的中心点信息。
694 695 696 697 698

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

R
ry 已提交
699 700 701
| 类型                       | 说明                                            |
| -------------------------- | ----------------------------------------------- |
| Promise\<[Point](#point9)> | 以Promise形式返回控件对象所占区域的中心点信息。 |
702

703 704 705 706
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

707
| 错误码ID | 错误信息                               |
708 709 710 711
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

712 713 714 715
**示例:**

```js
async function demo() {
716 717 718
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let point = await button.getBoundsCenter();
719 720 721
}
```

722
### isClickable<sup>9+</sup>
723

R
ry 已提交
724
isClickable(): Promise\<boolean>
725

R
ry 已提交
726
获取控件对象可点击属性。
727 728 729 730 731

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

732 733
| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
R
ry 已提交
734
| Promise\<boolean> | 以Promise形式返回控件对象是否可点击,true:可点击,false:不可点击。 |
735

736 737 738 739
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

740
| 错误码ID | 错误信息                               |
741 742 743 744
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

745 746
**示例:**

747
```js
748
async function demo() {
749 750
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
751
    if(await button.isClickable()) {
752 753 754
        console.info('This button can be Clicked');
    } else {
        console.info('This button can not be Clicked');
755 756
    }
}
757 758
```

759
### isLongClickable<sup>9+</sup>
760

R
ry 已提交
761
isLongClickable(): Promise\<boolean> 
762

R
ry 已提交
763
获取控件对象可长按点击属性。
764 765 766 767 768

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

769 770
| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
R
ry 已提交
771
| Promise\<boolean> | 以Promise形式返回控件对象是否可安装点击,true:可长按点击,false:不可长按点击。 |
772

773 774 775 776
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

777
| 错误码ID | 错误信息                               |
778 779 780 781
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

782 783 784 785
**示例:**

```js
async function demo() {
786 787
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
788
    if(await button.isLongClickable()) {
789 790 791
        console.info('This button can longClick');
    } else {
        console.info('This button can not longClick');
792 793 794 795
    }
}
```

796
### isChecked<sup>9+</sup>
797

R
ry 已提交
798
isChecked(): Promise\<boolean>
799 800 801 802 803 804 805

获取控件对象被勾选状态。

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

806 807
| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
808
| Promise\<boolean> | 以Promise形式返回控件对象被勾选状态,true:被勾选,false:未被勾选。 |
809

810 811 812 813
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

814
| 错误码ID | 错误信息                               |
815 816 817 818
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

819 820 821 822
**示例:**

```js
async function demo() {
823
    let driver = Driver.create();
824
    let checkBox = await driver.findComponent(ON.type('Checkbox'));
825
    if(await checkBox.isChecked) {
826 827 828
        console.info('This checkBox is checked');
    } else {
        console.info('This checkBox is not checked');
829 830 831 832
    }
}
```

833
### isCheckable<sup>9+</sup>
834

R
ry 已提交
835
isCheckable(): Promise\<boolean>
836

R
ry 已提交
837
获取控件对象能否被勾选属性。
838 839 840 841 842

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

843
| 类型              | 说明                                                         |
844
| ----------------- | ------------------------------------------------------------ |
R
ry 已提交
845
| Promise\<boolean> | 以Promise形式返回控件对象能否可被勾选属性,true:可被勾选,false:不可被勾选。 |
846

847 848 849 850
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

851
| 错误码ID | 错误信息                                 |
852 853 854 855
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

856 857
**示例:**

858 859
```js
async function demo() {
860
    let driver = Driver.create();
861
    let checkBox = await driver.findComponent(ON.type('Checkbox'));
862
    if(await checkBox.isCheckable) {
863 864 865
        console.info('This checkBox is checkable');
    } else {
        console.info('This checkBox is not checkable');
866 867
    }
}
868
```
869

870
### isScrollable<sup>9+</sup>
871

R
ry 已提交
872
isScrollable(): Promise\<boolean>
873

R
ry 已提交
874
获取控件对象可滑动属性。
875 876 877 878 879

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

880 881
| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
R
ry 已提交
882
| Promise\<boolean> | 以Promise形式返回控件对象是否可滑动,true:可滑动,false:不可滑动。 |
883

884 885 886 887
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

888
| 错误码ID | 错误信息                               |
889 890 891 892
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

893 894 895
**示例:**

```js
896
async function demo() {
897
    let driver = Driver.create();
898
    let scrollBar = await driver.findComponent(ON.scrollable(true));
899
    if(await scrollBar.isScrollable()) {
900 901 902
        console.info('This scrollBar can be operated');
    } else {
        console.info('This scrollBar can not be operated');
903 904
    }
}
905 906 907
```


908
### isEnabled<sup>9+</sup>
909

R
ry 已提交
910
isEnabled(): Promise\<boolean>
911 912 913 914 915 916 917

获取控件使能状态。

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

918 919
| 类型              | 说明                                                       |
| ----------------- | ---------------------------------------------------------- |
920
| Promise\<boolean> | 以Promise形式返回控件使能状态,true:使能,false:未使能。 |
921

922 923 924 925
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

926
| 错误码ID | 错误信息                               |
927 928 929 930
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

931 932
**示例:**

933
```js
934
async function demo() {
935 936
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
937
    if(await button.isEnabled()) {
938 939 940
        console.info('This button can be operated');
    } else {
        console.info('This button can not be operated');
941 942 943
    }
}

944 945
```

946
### isFocused<sup>9+</sup>
947

R
ry 已提交
948
isFocused(): Promise\<boolean>
949

R
ry 已提交
950
判断控件对象获焦状态。
951 952 953 954 955

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

956 957
| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
R
ry 已提交
958
| Promise\<boolean> | 以Promise形式返回控件对象获焦状态,true:获焦,false:未获焦。 |
959

960 961 962 963
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

964
| 错误码ID | 错误信息                               |
965 966 967 968
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

969 970
**示例:**

971
```js
972
async function demo() {
973 974
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
975
    if(await button.isFocused()) {
976 977 978
        console.info('This button is focused');
    } else {
        console.info('This button is not focused');
979 980
	}
}
981 982
```

983
### isSelected<sup>9+</sup>
984

R
ry 已提交
985
isSelected(): Promise\<boolean>
986 987 988 989 990 991 992

获取控件对象被选中状态。

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

R
ry 已提交
993 994 995
| 类型              | 说明                                                |
| ----------------- | --------------------------------------------------- |
| Promise\<boolean> | 控件对象被选中状态,true:被选中,false:未被选中。 |
996

997 998 999 1000
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1001
| 错误码ID | 错误信息                               |
1002 1003 1004 1005
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

1006 1007
**示例:**

1008
```js
1009
async function demo() {
1010 1011
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
1012
    if(await button.isSelected()) {
1013 1014 1015
        console.info('This button is selected');
	} else {
        console.info('This button is not selected');
1016 1017
    }
}
1018 1019
```

1020
### inputText<sup>9+</sup>
1021

1022
inputText(text: string): Promise\<void>
1023 1024 1025 1026 1027 1028 1029

向控件中输入文本(适用于文本框控件)。

**系统能力**:SystemCapability.Test.UiTest

**参数:**

R
ry 已提交
1030 1031 1032
| 参数名 | 类型   | 必填 | 说明                                     |
| ------ | ------ | ---- | ---------------------------------------- |
| text   | string | 是   | 输入的文本信息,当前支持英文和特殊字符。 |
1033

1034 1035 1036 1037
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1038
| 错误码ID | 错误信息                               |
1039 1040 1041 1042
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

1043 1044
**示例:**

1045 1046
```js
async function demo() {
1047
    let driver = Driver.create();
1048
    let text = await driver.findComponent(ON.text('hello world'));
1049
    await text.inputText('123');
1050
}
1051
```
1052

1053
### clearText<sup>9+</sup>
1054

1055
clearText(): Promise\<void>
1056 1057 1058 1059 1060

清除控件的文本信息(适用于文本框控件)。

**系统能力**:SystemCapability.Test.UiTest

1061 1062
**错误码:**

1063
| 错误码ID | 错误信息                               |
1064 1065 1066 1067
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

1068 1069 1070
**示例:**

```js
1071
async function demo() {
1072
    let driver = Driver.create();
1073
    let text = await driver.findComponent(ON.text('hello world'));
1074
    await text.clearText();
1075
}
1076 1077
```

1078
### scrollSearch<sup>9+</sup>
1079

1080
scrollSearch(on: On): Promise\<Component>
1081

R
ry 已提交
1082
在控件上滑动查找目标控件(适用支持滑动的控件)。
1083 1084 1085 1086 1087

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1088 1089 1090
| 参数名 | 类型       | 必填 | 说明                 |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | 是   | 目标控件的属性要求。 |
1091 1092 1093

**返回值:**

1094 1095 1096 1097 1098 1099 1100 1101
| 类型                               | 说明                                  |
| ---------------------------------- | ------------------------------------- |
| Promise\<[Component](#component9)> | 以Promise形式返回找到的目标控件对象。 |

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1102
| 错误码ID | 错误信息                               |
1103 1104 1105
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
1106 1107 1108

**示例:**

1109
```js
1110
async function demo() {
1111 1112 1113
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('Scroll'));
    let button = await scrollBar.scrollSearch(ON.text('next page'));
1114
}
1115 1116
```

1117
### scrollToTop<sup>9+</sup>
1118

1119
scrollToTop(speed?: number): Promise\<void>
1120

R
ry 已提交
1121
在控件上滑动到顶部(适用支持滑动的控件)。
1122 1123 1124

**系统能力**:SystemCapability.Test.UiTest

1125 1126
**参数:**

1127 1128
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
1129 1130 1131 1132 1133 1134
| speed  | number | 否   | 滑动速率,范围:200-15000,不在范围内设为默认值为600,单位:像素点/秒。 |

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1135
| 错误码ID | 错误信息                               |
1136 1137 1138
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
1139

1140 1141 1142 1143
**示例:**

```js
async function demo() {
1144
    let driver = Driver.create();
1145
    let scrollBar = await driver.findComponent(ON.type('Scroll'));
1146
    await scrollBar.scrollToTop();
1147 1148 1149
}
```

1150
### scrollToBottom<sup>9+</sup>
1151

1152
scrollToBottom(speed?: number): Promise\<void>
1153

R
ry 已提交
1154
在控件上滑动到底部(适用支持滑动的控件)。
1155 1156 1157

**系统能力**:SystemCapability.Test.UiTest

1158 1159
**参数:**

1160 1161
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
1162 1163 1164 1165 1166 1167
| speed  | number | 否   | 滑动速率,范围:200-15000,不在范围内设为默认值为600,单位:像素点/秒。 |

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1168
| 错误码ID | 错误信息                               |
1169 1170 1171
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
1172

1173 1174 1175 1176
**示例:**

```js
async function demo() {
1177
    let driver = Driver.create();
1178
    let scrollBar = await driver.findComponent(ON.type('Scroll'));
1179
    await scrollBar.scrollToBottom();
1180 1181 1182
}
```

1183
### dragTo<sup>9+</sup>
1184

1185
dragTo(target: Component): Promise\<void>
1186 1187 1188 1189 1190 1191 1192

将控件拖拽至目标控件处。

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1193 1194 1195 1196 1197 1198 1199 1200
| 参数名 | 类型                     | 必填 | 说明       |
| ------ | ------------------------ | ---- | ---------- |
| target | [Component](#component9) | 是   | 目标控件。 |

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1201
| 错误码ID | 错误信息                               |
1202 1203 1204
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
1205 1206 1207 1208 1209

**示例:**

```js
async function demo() {
1210 1211 1212 1213
    let driver = Driver.create();
    let button = await driver.findComponent(ON.type('button'));
    let text = await driver.findComponent(ON.text('hello world'));
    await button.dragTo(text);
1214 1215 1216
    }
```

1217 1218 1219 1220 1221 1222 1223 1224 1225 1226
### pinchOut<sup>9+</sup>

pinchOut(scale: number): Promise\<void>

将控件按指定的比例进行捏合放大。

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1227 1228 1229
| 参数名 | 类型   | 必填 | 说明             |
| ------ | ------ | ---- | ---------------- |
| scale  | number | 是   | 指定放大的比例。 |
1230

1231 1232 1233 1234
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1235
| 错误码ID | 错误信息                               |
1236 1237 1238 1239
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

1240 1241 1242 1243
**示例:**

```js
async function demo() {
1244
    let driver = Driver.create();
1245
    let image = await driver.findComponent(ON.type('image'));
1246
    await image.pinchOut(1.5);
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
    }
```

### pinchIn<sup>9+</sup>

pinchIn(scale: number): Promise\<void>

将控件按指定的比例进行捏合缩小。

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1260 1261 1262
| 参数名 | 类型   | 必填 | 说明             |
| ------ | ------ | ---- | ---------------- |
| scale  | number | 是   | 指定缩小的比例。 |
1263

1264 1265 1266 1267
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1268
| 错误码ID | 错误信息                               |
1269 1270 1271 1272
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

1273 1274 1275 1276
**示例:**

```js
async function demo() {
1277
    let driver = Driver.create();
1278
    let image = await driver.findComponent(ON.type('image'));
1279
    await image.pinchIn(0.5);
1280 1281 1282
    }
```

1283
## Driver<sup>9+</sup>
1284

R
ry 已提交
1285 1286
Driver类为uitest测试框架的总入口,提供控件匹配/查找,按键注入,坐标点击/滑动,截图等能力。
该类提供的方法除Driver.create()以外的所有方法都使用Promise方式作为异步方法,需使用await方式调用。
1287

1288
### create<sup>9+</sup>
1289

1290
static create(): Driver
1291

1292
静态方法,构造一个Driver对象,并返回该对象。
1293 1294 1295 1296 1297

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

1298
| 类型 | 说明           |
1299 1300 1301 1302 1303 1304 1305
| -------- | ---------------------- |
| Driver   | 返回构造的Driver对象。 |

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1306
| 错误码ID | 错误信息           |
1307 1308
| -------- | ------------------ |
| 17000001 | Initialize failed. |
1309 1310 1311

**示例:**

1312
```js
1313
async function demo() {
1314
    let driver = Driver.create();
1315
}
1316 1317
```

1318
### delayMs<sup>9+</sup>
1319

1320
delayMs(duration: number): Promise\<void>
1321

1322
Driver对象在给定的时间内延时。
1323 1324 1325 1326 1327

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1328 1329 1330 1331 1332 1333 1334 1335
| 参数名   | 类型   | 必填 | 说明                   |
| -------- | ------ | ---- | ---------------------- |
| duration | number | 是   | 给定的时间,单位:ms。 |

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1336
| 错误码ID | 错误信息                               |
1337 1338
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
1339 1340 1341

**示例:**

1342
```js
1343
async function demo() {
1344 1345
    let driver = Driver.create();
    await driver.delayMs(1000);
1346
}
1347 1348
```

1349
### findComponent<sup>9+</sup>
1350

1351
findComponent(on: On): Promise\<Component>
1352

1353
在Driver对象中,根据给出的目标控件属性要求查找目标控件。
1354 1355 1356 1357 1358

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1359 1360 1361
| 参数名 | 类型       | 必填 | 说明                 |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | 是   | 目标控件的属性要求。 |
1362 1363 1364

**返回值:**

1365 1366
| 类型                               | 说明                              |
| ---------------------------------- | --------------------------------- |
1367
| Promise\<[Component](#component9)> | 以Promise形式返回找到的控件对象。 |
1368 1369 1370 1371 1372

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1373
| 错误码ID | 错误信息                               |
1374 1375
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
1376 1377 1378

**示例:**

1379
```js
1380
async function demo() {
1381 1382
    let driver = Driver.create();
    let button = await driver.findComponent(ON.text('next page'));
1383
}
1384 1385
```

1386
### findComponents<sup>9+</sup>
1387

1388
findComponents(on: On): Promise\<Array\<Component>>
1389

1390
在Driver对象中,根据给出的目标控件属性要求查找出所有匹配控件,以列表保存。
1391 1392 1393 1394 1395

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1396 1397 1398
| 参数名 | 类型       | 必填 | 说明                 |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | 是   | 目标控件的属性要求。 |
1399 1400 1401

**返回值:**

1402 1403
| 类型                                       | 说明                                    |
| ------------------------------------------ | --------------------------------------- |
1404
| Promise\<Array\<[Component](#component9)>> | 以Promise形式返回找到的控件对象的列表。 |
1405 1406 1407 1408 1409

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1410
| 错误码ID | 错误信息                               |
1411 1412
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
1413 1414 1415

**示例:**

1416
```js
1417
async function demo() {
1418 1419
    let driver = Driver.create();
    let buttonList = await driver.findComponents(ON.text('next page'));
1420
}
1421 1422
```

1423
### findWindow<sup>9+</sup>
1424 1425 1426 1427 1428 1429 1430 1431 1432

findWindow(filter: WindowFilter): Promise\<UiWindow>

通过指定窗口的属性来查找目标窗口。

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1433 1434 1435
| 参数名 | 类型                           | 必填 | 说明             |
| ------ | ------------------------------ | ---- | ---------------- |
| filter | [WindowFilter](#windowfilter9) | 是   | 目标窗口的属性。 |
1436 1437 1438

**返回值:**

1439 1440 1441
| 类型                             | 说明                                  |
| -------------------------------- | ------------------------------------- |
| Promise\<[UiWindow](#uiwindow9)> | 以Promise形式返回找到的目标窗口对象。 |
1442

1443 1444 1445 1446
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1447
| 错误码ID | 错误信息                               |
1448 1449 1450
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1451 1452 1453 1454
**示例:**

```js
async function demo() {
1455 1456
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
1457 1458 1459
}
```

1460
### waitForComponent<sup>9+</sup>
1461

1462
waitForComponent(on: On, time: number): Promise\<Component>
1463

1464
在Driver对象中,在用户给定的时间内,持续查找满足控件属性要求的目标控件。
1465 1466 1467 1468 1469

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1470 1471 1472 1473
| 参数名 | 类型       | 必填 | 说明                             |
| ------ | ---------- | ---- | -------------------------------- |
| On     | [On](#on9) | 是   | 目标控件的属性要求。             |
| time   | number     | 是   | 查找目标控件的持续时间。单位ms。 |
1474 1475 1476

**返回值:**

1477 1478
| 类型                              | 说明                              |
| --------------------------------- | --------------------------------- |
1479
| Promise\<[Component](#component)> | 以Promise形式返回找到的控件对象。 |
1480 1481 1482 1483 1484

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1485
| 错误码ID | 错误信息                               |
1486 1487
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
1488 1489 1490 1491 1492

**示例:**

```js
async function demo() {
1493 1494
    let driver = Driver.create();
    let button = await driver.waitForComponent(ON.text('next page'),500);
1495 1496 1497
}
```

1498
### assertComponentExist<sup>9+</sup>
1499

1500
assertComponentExist(on: On): Promise\<void>
1501

R
ry 已提交
1502
断言API,用于断言当前界面是否存在满足给出的目标属性的控件。
1503 1504 1505 1506 1507

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1508 1509 1510 1511 1512 1513 1514 1515
| 参数名 | 类型       | 必填 | 说明                 |
| ------ | ---------- | ---- | -------------------- |
| on     | [On](#on9) | 是   | 目标控件的属性要求。 |

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1516
| 错误码ID | 错误信息                               |
1517 1518 1519
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000003 | Component existence assertion failed.    |
1520 1521 1522

**示例:**

1523
```js
1524
async function demo() {
1525 1526
    let driver = Driver.create();
    await driver.assertComponentExist(ON.text('next page'));
1527
}
1528 1529
```

1530
### pressBack<sup>9+</sup>
1531

1532
pressBack(): Promise\<void>
1533

1534
Driver对象进行点击BACK键的操作。
1535 1536 1537

**系统能力**:SystemCapability.Test.UiTest

1538 1539 1540 1541
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1542
| 错误码ID | 错误信息                               |
1543 1544 1545
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1546 1547
**示例:**

1548
```js
1549
async function demo() {
1550 1551
    let driver = Driver.create();
    await driver.pressBack();
1552
}
1553 1554
```

1555
### triggerKey<sup>9+</sup>
1556

1557
triggerKey(keyCode: number): Promise\<void>
1558

R
ry 已提交
1559
Driver对象采取如下操作:传入key值实现模拟点击对应按键的效果。
1560 1561 1562 1563 1564

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1565 1566 1567
| 参数名  | 类型   | 必填 | 说明          |
| ------- | ------ | ---- | ------------- |
| keyCode | number | 是   | 指定的key值。 |
1568

1569 1570 1571 1572
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1573
| 错误码ID | 错误信息                               |
1574 1575 1576
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1577 1578
**示例:**

1579
```js
1580
async function demo() {
1581 1582
    let driver = Driver.create();
    await driver.triggerKey(123);
1583
}
1584 1585
```

1586
### triggerCombineKeys<sup>9+</sup>
1587

1588
triggerCombineKeys(key0: number, key1: number, key2?: number): Promise\<void>
1589

R
ry 已提交
1590
Driver对象通过给定的key值,找到对应组合键并点击。例如,Key值为(2072, 2019)时,Driver对象找到key值对应的组合键并点击,如ctrl+c。
1591 1592 1593 1594 1595

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
| 参数名 | 类型   | 必填 | 说明                |
| ------ | ------ | ---- | ------------------- |
| key0   | number | 是   | 指定的第一个key值。 |
| key1   | number | 是   | 指定的第二个key值。 |
| key2   | number | 否   | 指定的第三个key值。 |

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1606
| 错误码ID | 错误信息                               |
1607 1608
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
1609 1610 1611

**示例:**

1612 1613
```js
async function demo() {
1614 1615
    let driver = Driver.create();
    await driver.triggerCombineKeys(2072, 2047, 2035);
1616 1617 1618
}
```

1619

1620
### click<sup>9+</sup>
1621

1622
click(x: number, y: number): Promise\<void>
1623

1624
Driver对象采取如下操作:在目标坐标点单击。
1625 1626 1627 1628 1629

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1630 1631 1632 1633
| 参数名 | 类型   | 必填 | 说明                                   |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | 是   | 以number的形式传入目标点的横坐标信息。 |
| y      | number | 是   | 以number的形式传入目标点的纵坐标信息。 |
1634

1635 1636 1637 1638
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1639
| 错误码ID | 错误信息                               |
1640 1641 1642
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1643 1644
**示例:**

1645
```js
1646
async function demo() {
1647 1648
    let driver = Driver.create();
    await driver.click(100,100);
1649
}
1650 1651
```

1652
### doubleClick<sup>9+</sup>
1653

1654
doubleClick(x: number, y: number): Promise\<void>
1655

1656
Driver对象采取如下操作:在目标坐标点双击。
1657 1658 1659 1660 1661

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1662 1663 1664 1665
| 参数名 | 类型   | 必填 | 说明                                   |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | 是   | 以number的形式传入目标点的横坐标信息。 |
| y      | number | 是   | 以number的形式传入目标点的纵坐标信息。 |
1666

1667 1668 1669 1670
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1671
| 错误码ID | 错误信息                               |
1672 1673 1674
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1675 1676
**示例:**

1677
```js
1678
async function demo() {
1679 1680
    let driver = Driver.create();
    await driver.doubleClick(100,100);
1681
}
1682 1683
```

1684
### longClick<sup>9+</sup>
1685

1686
longClick(x: number, y: number): Promise\<void>
1687

R
ry 已提交
1688
Driver对象采取如下操作:在目标坐标点长按。
1689 1690 1691 1692 1693

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1694 1695 1696 1697
| 参数名 | 类型   | 必填 | 说明                                   |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | 是   | 以number的形式传入目标点的横坐标信息。 |
| y      | number | 是   | 以number的形式传入目标点的纵坐标信息。 |
1698

1699 1700 1701 1702
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1703
| 错误码ID | 错误信息                               |
1704 1705 1706
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1707 1708
**示例:**

1709
```js
1710
async function demo() {
1711 1712
    let driver = Driver.create();
    await driver.longClick(100,100);
1713
}
1714 1715
```

1716
### swipe<sup>9+</sup>
1717

1718
swipe(startx: number, starty: number, endx: number, endy: number, speed?: number): Promise\<void>
1719

R
ry 已提交
1720
Driver对象采取如下操作:从起始坐标点滑向目的坐标点。
1721 1722 1723 1724 1725

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1726 1727 1728 1729 1730 1731
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| startx | number | 是   | 以number的形式传入起始点的横坐标信息。                       |
| starty | number | 是   | 以number的形式传入起始点的纵坐标信息。                       |
| endx   | number | 是   | 以number的形式传入目的点的横坐标信息。                       |
| endy   | number | 是   | 以number的形式传入目的点的纵坐标信息。                       |
1732 1733 1734 1735 1736 1737
| speed  | number | 否   | 滑动速率,范围:200-15000,不在范围内设为默认值为600,单位:像素点/秒。 |

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1738
| 错误码ID | 错误信息                               |
1739 1740
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
1741 1742 1743

**示例:**

1744
```js
1745
async function demo() {
1746 1747
    let driver = Driver.create();
    await driver.swipe(100,100,200,200,600);
1748
}
1749 1750
```

1751
### drag<sup>9+</sup>
1752

1753
drag(startx: number, starty: number, endx: number, endy: number, speed?: number): Promise\<void>
1754

R
ry 已提交
1755
Driver对象采取如下操作:从起始坐标点拖拽至目的坐标点。
1756 1757 1758 1759 1760

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1761 1762 1763 1764 1765 1766
| 参数名 | 类型   | 必填 | 说明                                                         |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| startx | number | 是   | 以number的形式传入起始点的横坐标信息。                       |
| starty | number | 是   | 以number的形式传入起始点的纵坐标信息。                       |
| endx   | number | 是   | 以number的形式传入目的点的横坐标信息。                       |
| endy   | number | 是   | 以number的形式传入目的点的纵坐标信息。                       |
1767 1768 1769 1770 1771 1772
| speed  | number | 否   | 滑动速率,范围:200-15000,不在范围内设为默认值为600,单位:像素点/秒。 |

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1773
| 错误码ID | 错误信息                               |
1774 1775
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
1776 1777 1778 1779 1780

**示例:**

```js
async function demo() {
1781 1782
    let driver = Driver.create();
    await driver.drag(100,100,200,200,600);
1783 1784 1785
}
```

1786
### screenCap<sup>9+</sup>
1787

R
ry 已提交
1788
screenCap(savePath: string): Promise\<boolean>
1789

1790
Driver对象采取如下操作:捕获当前屏幕,并保存为PNG格式的图片至给出的保存路径中。
1791 1792 1793 1794 1795

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1796 1797 1798
| 参数名   | 类型   | 必填 | 说明           |
| -------- | ------ | ---- | -------------- |
| savePath | string | 是   | 文件保存路径。 |
1799

1800 1801
**返回值:**

1802 1803
| 类型              | 说明                                   |
| ----------------- | -------------------------------------- |
R
ry 已提交
1804
| Promise\<boolean> | 截图操作是否成功完成。成功完成为true。 |
1805

1806 1807 1808 1809
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1810
| 错误码ID | 错误信息                               |
1811 1812 1813
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1814 1815
**示例:**

1816
```js
1817
async function demo() {
1818
    let driver = Driver.create();
1819
    await driver.screenCap('/local/tmp/1.png');
1820
}
1821
```
1822

1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836
### setDisplayRotation<sup>9+</sup>

setDisplayRotation(rotation: DisplayRotation): Promise\<void>

将设备的屏幕显示方向设置为指定的显示方向。

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名   | 类型                                 | 必填 | 说明             |
| -------- | ------------------------------------ | ---- | ---------------- |
| rotation | [DisplayRotation](#displayrotation9) | 是   | 设备的显示方向。 |

1837 1838 1839 1840
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1841
| 错误码ID | 错误信息                               |
1842 1843 1844
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1845 1846 1847 1848
**示例:**

```js
async function demo() {
1849 1850
    let driver = Driver.create();
    await driver.setDisplayRotation(DisplayRotation.ROTATION_180);
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863
}
```

### getDisplayRotation<sup>9+</sup>

getDisplayRotation(): Promise\<DisplayRotation>

获取当前设备的屏幕显示方向。

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

1864 1865 1866
| 类型                                           | 说明                                    |
| ---------------------------------------------- | --------------------------------------- |
| Promise\<[DisplayRotation](#displayrotation9)> | 以Promise的形式返回当前设备的显示方向。 |
1867

1868 1869 1870 1871
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1872
| 错误码ID | 错误信息                               |
1873 1874 1875
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1876 1877 1878 1879
**示例:**

```js
async function demo() {
1880 1881
    let driver = Driver.create();
    let rotation = await driver.getDisplayRotation();
1882 1883 1884 1885 1886
}
```

### setDisplayRotationEnabled<sup>9+</sup>

R
ry 已提交
1887
setDisplayRotationEnabled(enabled: boolean): Promise\<void>
1888 1889 1890 1891 1892 1893 1894

启用/禁用设备旋转屏幕的功能。

**系统能力**:SystemCapability.Test.UiTest

**参数:**

1895 1896
| 参数名  | 类型    | 必填 | 说明                                                    |
| ------- | ------- | ---- | ------------------------------------------------------- |
1897
| enabled | boolean | 是   | 能否旋转屏幕的标识,true:可以旋转,false:不可以旋转。 |
1898

1899 1900 1901 1902
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1903
| 错误码ID | 错误信息                               |
1904 1905 1906
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1907 1908 1909 1910
**示例:**

```js
async function demo() {
1911 1912
    let driver = Driver.create();
    await driver.setDisplayRotationEnabled(false);
1913 1914 1915 1916 1917
}
```

### getDisplaySize<sup>9+</sup>

1918
getDisplaySize(): Promise\<Point>
1919 1920 1921 1922 1923 1924 1925

获取当前设备的屏幕大小。

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

1926 1927 1928
| 类型                       | 说明                                    |
| -------------------------- | --------------------------------------- |
| Promise\<[Point](#point9)> | 以Promise的形式返回当前设备的屏幕大小。 |
1929

1930 1931 1932 1933
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1934
| 错误码ID | 错误信息                               |
1935 1936 1937
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1938 1939 1940 1941
**示例:**

```js
async function demo() {
1942 1943
    let driver = Driver.create();
    let size = await driver.getDisplaySize();
1944 1945 1946 1947 1948
}
```

### getDisplayDensity<sup>9+</sup>

1949
getDisplayDensity(): Promise\<Point>
1950

R
ry 已提交
1951
获取当前设备屏幕的分辨率。
1952 1953 1954 1955 1956

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

R
ry 已提交
1957 1958 1959
| 类型                       | 说明                                      |
| -------------------------- | ----------------------------------------- |
| Promise\<[Point](#point9)> | 以Promise的形式返回当前设备屏幕的分辨率。 |
1960

1961 1962 1963 1964
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1965
| 错误码ID | 错误信息                               |
1966 1967 1968
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1969 1970 1971 1972
**示例:**

```js
async function demo() {
1973 1974
    let driver = Driver.create();
    let density = await driver.getDisplayDensity();
1975 1976 1977 1978 1979
}
```

### wakeUpDisplay<sup>9+</sup>

1980
wakeUpDisplay(): Promise\<void>
1981

R
ry 已提交
1982
唤醒当前设备即设备亮屏。
1983 1984 1985

**系统能力**:SystemCapability.Test.UiTest

1986 1987 1988 1989
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

1990
| 错误码ID | 错误信息                               |
1991 1992 1993
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

1994 1995 1996 1997
**示例:**

```js
async function demo() {
1998 1999
    let driver = Driver.create();
    await driver.wakeUpDisplay();
2000 2001 2002 2003 2004
}
```

### pressHome<sup>9+</sup>

2005
pressHome(): Promise\<void>
2006 2007 2008 2009 2010

设备返回到桌面。

**系统能力**:SystemCapability.Test.UiTest

2011 2012 2013 2014
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2015
| 错误码ID | 错误信息                               |
2016 2017 2018
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

2019 2020 2021 2022
**示例:**

```js
async function demo() {
2023 2024
    let driver = Driver.create();
    await driver.pressHome();
2025 2026 2027 2028 2029
}
```

### waitForIdle<sup>9+</sup>

R
ry 已提交
2030
waitForIdle(idleTime: number, timeout: number): Promise\<boolean>
2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044

判断当前界面的所有控件是否已经空闲。

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名   | 类型   | 必填 | 说明                                                         |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| idleTime | number | 是   | 空闲时间的阈值。在这个时间段控件不发生变化,视为该控件空闲,单位:毫秒。 |
| timeout  | number | 是   | 等待空闲的最大时间,单位:毫秒。                             |

**返回值:**

2045 2046
| 类型              | 说明                                                |
| ----------------- | --------------------------------------------------- |
R
ry 已提交
2047
| Promise\<boolean> | 以Promise的形式返回当前界面的所有控件是否已经空闲。 |
2048

2049 2050 2051 2052
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2053
| 错误码ID | 错误信息                               |
2054 2055 2056
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

2057 2058 2059 2060
**示例:**

```js
async function demo() {
2061 2062
    let driver = Driver.create();
    let idled = await driver.waitForIdle(4000,5000);
2063 2064 2065 2066 2067
}
```

### fling<sup>9+</sup>

2068
fling(from: Point, to: Point, stepLen: number, speed: number): Promise\<void>
2069

2070
模拟手指滑动后脱离屏幕的快速滑动操作。
2071 2072 2073 2074 2075 2076 2077

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名  | 类型             | 必填 | 说明                                                         |
| ------- | ---------------- | ---- | ------------------------------------------------------------ |
2078
| from    | [Point](#point9) | 是   | 手指接触屏幕的起始点坐标。                                   |
2079
| to      | [Point](#point9) | 是   | 手指离开屏幕时的坐标点。                                     |
2080
| stepLen | number           | 是   | 间隔距离,单位:像素点。                                     |
2081 2082 2083 2084 2085 2086
| speed   | number           | 是   | 滑动速率,范围:200-15000,不在范围内设为默认值为600,单位:像素点/秒。 |

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2087
| 错误码ID | 错误信息                               |
2088 2089
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
2090 2091 2092 2093 2094

**示例:**

```js
async function demo() {
2095 2096
    let driver = Driver.create();
    await driver.fling({X: 500, Y: 480},{X: 450, Y: 480},5,600);
2097 2098 2099 2100 2101
}
```

### injectMultiPointerAction<sup>9+</sup>

R
ry 已提交
2102
injectMultiPointerAction(pointers: PointerMatrix, speed?: number): Promise\<boolean>
2103 2104 2105 2106 2107 2108 2109 2110 2111

向设备注入多指操作。

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名   | 类型                             | 必填 | 说明                                                         |
| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
R
ry 已提交
2112
| pointers | [PointerMatrix](#pointermatrix9) | 是   | 滑动轨迹,包括操作手指个数和滑动坐标序列。                   |
2113
| speed    | number                           | 否   | 滑动速率,范围:200-15000,不在范围内设为默认值为600,单位:像素点/秒。 |
2114 2115 2116

**返回值:**

R
ry 已提交
2117 2118 2119
| 类型              | 说明                                  |
| ----------------- | ------------------------------------- |
| Promise\<boolean> | 以Promise的形式返回操作是否成功完成。 |
2120

2121 2122 2123 2124
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2125
| 错误码ID | 错误信息                               |
2126 2127 2128
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |

2129 2130 2131 2132
**示例:**

```js
async function demo() {
2133
    let driver = Driver.create();
2134 2135 2136 2137 2138 2139 2140 2141
    let pointers = PointerMatrix.create(2,3);
    pointers.setPoint(0,0,{X:230,Y:480});
    pointers.setPoint(0,1,{X:250,Y:380});
    pointers.setPoint(0,2,{X:270,Y:280});
    pointers.setPoint(1,0,{X:230,Y:680});
    pointers.setPoint(1,1,{X:240,Y:580});
    pointers.setPoint(1,2,{X:250,Y:480});
    await driver.injectMultiPointerAction(pointers);
2142 2143 2144
}
```

2145
## PointerMatrix<sup>9+</sup>
2146

R
ry 已提交
2147
存储多指操作中每根手指每一步动作的坐标点及其行为的二维数组。
2148 2149

### create<sup>9+</sup>
2150

2151
static create(fingers: number, steps: number): PointerMatrix
2152

2153
静态方法,构造一个PointerMatrix对象,并返回该对象。
2154

2155
**系统能力**:SystemCapability.Test.UiTest
2156

2157
**参数:**
2158

2159 2160 2161 2162
| 参数名  | 类型   | 必填 | 说明                                       |
| ------- | ------ | ---- | ------------------------------------------ |
| fingers | number | 是   | 多指操作中注入的手指数,取值范围:[1,10]。 |
| steps   | number | 是   | 每根手指操作的步骤数,取值范围:[1,1000]。 |
2163

2164
**返回值:**
2165

2166 2167 2168
| 类型                             | 说明                          |
| -------------------------------- | ----------------------------- |
| [PointerMatrix](#pointermatrix9) | 返回构造的PointerMatrix对象。 |
2169 2170 2171 2172 2173

**示例:**

```js
async function demo() {
2174
    let pointerMatrix = PointerMatrix.create(2,3);
2175
}
2176 2177
```

2178
### setPoint<sup>9+</sup>
2179

2180
setPoint(finger: number, step: number, point: Point): void
2181

2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197
设置PointerMatrix对象中指定手指和步骤对应动作的坐标点。

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型             | 必填 | 说明             |
| ------ | ---------------- | ---- | ---------------- |
| finger | number           | 是   | 手指的序号。     |
| step   | number           | 是   | 步骤的序号。     |
| point  | [Point](#point9) | 是   | 该行为的坐标点。 |

**示例:**

```js
async function demo() {
2198 2199 2200 2201 2202 2203 2204
    let pointers = PointerMatrix.create(2,3);
    pointers.setPoint(0,0,{X:230,Y:480});
    pointers.setPoint(0,1,{X:250,Y:380});
    pointers.setPoint(0,2,{X:270,Y:280});
    pointers.setPoint(1,0,{X:230,Y:680});
    pointers.setPoint(1,1,{X:240,Y:580});
    pointers.setPoint(1,2,{X:250,Y:480});
2205 2206 2207 2208 2209
}
```

## UiWindow<sup>9+</sup>

R
ry 已提交
2210 2211
UiWindow代表了UI界面上的一个窗口,提供窗口属性获取,窗口拖动、调整窗口大小等能力。
该类提供的所有方法都使用Promise方式作为异步方法,需使用await方式调用。
2212 2213 2214 2215 2216

### getBundleName<sup>9+</sup>

getBundleName(): Promise\<string>

R
ry 已提交
2217
获取窗口归属应用的包名信息。
2218 2219 2220 2221 2222

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

R
ry 已提交
2223 2224 2225
| 类型             | 说明                                      |
| ---------------- | ----------------------------------------- |
| Promise\<string> | 以Promise形式返回窗口归属应用的包名信息。 |
2226 2227 2228 2229 2230

**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2231
| 错误码ID | 错误信息                               |
2232 2233 2234 2235 2236 2237 2238 2239
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

**示例:**

```js
async function demo() {
2240 2241 2242
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let name = await window.getBundleName();
2243 2244 2245 2246 2247 2248 2249 2250
}
```

### getBounds<sup>9+</sup>

getBounds(): Promise\<Rect>

获取窗口的边框信息。
2251 2252 2253 2254 2255

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

2256 2257 2258
| 类型                     | 说明                              |
| ------------------------ | --------------------------------- |
| Promise\<[Rect](#rect9)> | 以Promise形式返回窗口的边框信息。 |
2259

2260 2261 2262 2263
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2264
| 错误码ID | 错误信息                               |
2265 2266 2267 2268
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

2269 2270 2271 2272
**示例:**

```js
async function demo() {
2273 2274 2275
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let rect = await window.getBounds();
2276 2277 2278
}
```

2279
### getTitle<sup>9+</sup>
2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292

getTitle(): Promise\<string>

获取窗口的标题信息。

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

| 类型             | 说明                              |
| ---------------- | --------------------------------- |
| Promise\<string> | 以Promise形式返回窗口的标题信息。 |

2293 2294 2295 2296
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2297
| 错误码ID | 错误信息                               |
2298 2299 2300 2301
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

2302 2303 2304 2305
**示例:**

```js
async function demo() {
2306 2307 2308
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let rect = await window.getTitle();
2309 2310 2311
}
```

2312
### getWindowMode<sup>9+</sup>
2313 2314 2315 2316 2317 2318 2319 2320 2321

getWindowMode(): Promise\<WindowMode>

获取窗口的窗口模式信息。

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

2322 2323
| 类型                                 | 说明                                  |
| ------------------------------------ | ------------------------------------- |
2324
| Promise\<[WindowMode](#windowmode9)> | 以Promise形式返回窗口的窗口模式信息。 |
2325

2326 2327 2328 2329
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2330
| 错误码ID | 错误信息                               |
2331 2332 2333 2334
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

2335 2336 2337 2338
**示例:**

```js
async function demo() {
2339 2340 2341
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let mode = await window.getWindowMode();
2342 2343 2344
}
```

2345
### isFocused<sup>9+</sup>
2346

R
ry 已提交
2347
isFocused(): Promise\<boolean>
2348

R
ry 已提交
2349
判断窗口是否处于获焦状态。
2350 2351 2352 2353 2354

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

2355 2356
| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
R
ry 已提交
2357
| Promise\<boolean> | 以Promise形式返回窗口对象是否获取获焦状态,true:获焦,false:未获焦。 |
2358

2359 2360 2361 2362
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2363
| 错误码ID | 错误信息                               |
2364 2365 2366 2367
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

2368 2369 2370 2371
**示例:**

```js
async function demo() {
2372 2373 2374
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let focused = await window.isFocused();
2375 2376 2377
}
```

2378
### isActived<sup>9+</sup>
2379

R
ry 已提交
2380
isActived(): Promise\<boolean>
2381

R
ry 已提交
2382
判断窗口是否为用户正在交互窗口。
2383 2384 2385 2386 2387

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

2388 2389
| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
R
ry 已提交
2390
| Promise\<boolean> | 以Promise形式返回窗口对象是否为用户正在交互窗口,true:交互窗口,false:非交互窗口。 |
2391

2392 2393 2394 2395
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2396
| 错误码ID | 错误信息                               |
2397 2398 2399 2400
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |

2401 2402 2403 2404
**示例:**

```js
async function demo() {
2405 2406 2407
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    let focused = await window.isActived();
2408 2409 2410
}
```

2411
### focus<sup>9+</sup>
2412

2413
focus(): Promise\<void>
2414

2415
让窗口获焦。
2416 2417 2418

**系统能力**:SystemCapability.Test.UiTest

2419
**错误码:**
2420

2421 2422
以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2423
| 错误码ID | 错误信息                               |
2424 2425 2426
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
2427 2428 2429 2430 2431

**示例:**

```js
async function demo() {
2432 2433 2434
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.focus();
2435 2436 2437
}
```

2438
### moveTo<sup>9+</sup>
2439

2440
moveTo(x: number, y: number): Promise\<void>
2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452

将窗口移动到目标点。适用于支持移动的窗口。

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型   | 必填 | 说明                                   |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | 是   | 以number的形式传入目标点的横坐标信息。 |
| y      | number | 是   | 以number的形式传入目标点的纵坐标信息。 |

2453 2454 2455
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)
2456

2457
| 错误码ID | 错误信息                               |
2458 2459 2460 2461
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |
2462 2463 2464 2465 2466

**示例:**

```js
async function demo() {
2467 2468 2469
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.moveTo(100, 100);
2470 2471 2472
}
```

2473
### resize<sup>9+</sup>
2474

2475
resize(wide: number, height: number, direction: ResizeDirection): Promise\<void>
2476

R
ry 已提交
2477
根据传入的宽、高和调整方向来调整窗口的大小。适用于支持调整大小的窗口。
2478 2479 2480 2481 2482

**系统能力**:SystemCapability.Test.UiTest

**参数:**

2483 2484 2485 2486
| 参数名    | 类型                                 | 必填 | 说明                                                         |
| --------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| wide      | number                               | 是   | 以number的形式传入调整后窗口的宽度。                         |
| height    | number                               | 是   | 以number的形式传入调整后窗口的高度。                         |
2487
| direction | [ResizeDirection](#resizedirection9) | 是   | 以[ResizeDirection](#resizedirection9)的形式传入窗口调整的方向。 |
2488

2489
**错误码:**
2490

2491 2492
以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2493
| 错误码ID | 错误信息                               |
2494 2495 2496 2497
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |
2498 2499 2500 2501 2502

**示例:**

```js
async function demo() {
2503 2504 2505
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.resize(100, 100, ResizeDirection.LEFT);
2506 2507 2508
}
```

2509
### split<sup>9+</sup>
2510

2511
split(): Promise\<void>
2512

R
ry 已提交
2513
将窗口模式切换成分屏模式。适用于支持切换分屏模式的窗口。
2514 2515 2516

**系统能力**:SystemCapability.Test.UiTest

2517 2518 2519
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)
2520

2521
| 错误码ID | 错误信息                                 |
2522 2523 2524 2525
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |
2526 2527 2528 2529 2530

**示例:**

```js
async function demo() {
2531 2532 2533
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.split();
2534 2535 2536
}
```

2537
### maximize<sup>9+</sup>
2538

2539
maximize(): Promise\<void>
2540 2541 2542 2543 2544

将窗口最大化。适用于支持窗口最大化操作的窗口。

**系统能力**:SystemCapability.Test.UiTest

2545
**错误码:**
2546

2547 2548
以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2549
| 错误码ID | 错误信息                               |
2550 2551 2552 2553
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |
2554 2555 2556 2557 2558

**示例:**

```js
async function demo() {
2559 2560 2561
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.maximize();
2562 2563 2564
}
```

2565
### minimize<sup>9+</sup>
2566

2567
minimize(): Promise\<void>
2568 2569 2570 2571 2572

将窗口最小化。适用于支持窗口最小化操作的窗口。

**系统能力**:SystemCapability.Test.UiTest

2573 2574 2575
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)
2576

2577
| 错误码ID | 错误信息                               |
2578 2579 2580 2581
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |
2582 2583 2584 2585 2586

**示例:**

```js
async function demo() {
2587 2588 2589
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.minimize();
2590 2591 2592
}
```

2593
### resume<sup>9+</sup>
2594

2595
resume(): Promise\<void>
2596

R
ry 已提交
2597
将窗口恢复到之前的窗口模式。
2598 2599 2600

**系统能力**:SystemCapability.Test.UiTest

2601
**错误码:**
2602

2603 2604
以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)

2605
| 错误码ID | 错误信息                               |
2606 2607 2608 2609
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |
2610 2611 2612 2613 2614

**示例:**

```js
async function demo() {
2615 2616 2617
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.resume();
2618 2619 2620
}
```

2621
### close<sup>9+</sup>
2622

2623
close(): Promise\<void>
2624 2625 2626 2627 2628

将窗口关闭。

**系统能力**:SystemCapability.Test.UiTest

2629 2630 2631
**错误码:**

以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)
2632

2633
| 错误码ID | 错误信息                               |
2634 2635 2636 2637
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
| 17000004 | Component lost/UiWindow lost.            |
| 17000005 | This operation is not supported.         |
2638 2639 2640 2641 2642

**示例:**

```js
async function demo() {
2643 2644 2645
    let driver = Driver.create();
    let window = await driver.findWindow({actived: true});
    await window.close();
2646 2647 2648
}
```

2649 2650 2651
## By<sup>(deprecated)</sup>

UiTest框架通过By类提供了丰富的控件特征描述API,用于进行控件筛选来匹配/查找出目标控件。<br>
2652
By提供的API能力具有以下几个特点:<br>1、支持单属性匹配和多属性组合匹配,例如同时指定目标控件text和id。<br>2、控件属性支持多种匹配模式。<br>3、支持控件绝对定位,相对定位,可通过[By.isBefore<sup>(deprecated)</sup>](#isbeforedeprecated)[By.isAfter<sup>(deprecated)</sup>](#isafterdeprecated)等API限定邻近控件特征进行辅助定位。<br>By类提供的所有API均为同步接口,建议使用者通过静态构造器BY来链式创建By对象。
2653

R
ry 已提交
2654
从API version 9开始不再维护,建议使用[On<sup>9+</sup>](#on9)
2655 2656

```js
2657
BY.text('123').type('button');
2658 2659 2660 2661 2662 2663 2664 2665
```

### text<sup>(deprecated)</sup>

text(txt: string, pattern?: MatchPattern): By

指定目标控件文本属性,支持多种匹配模式,返回By对象自身。

R
ry 已提交
2666
从API version 9开始不再维护,建议使用[text<sup>9+</sup>](#text9)
2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名  | 类型                          | 必填 | 说明                                                |
| ------- | ----------------------------- | ---- | --------------------------------------------------- |
| txt     | string                        | 是   | 指定控件文本,用于匹配目标控件文本。                |
| pattern | [MatchPattern](#matchpattern) | 否   | 指定的文本匹配模式,默认为[EQUALS](#matchpattern)。 |

**返回值:**

2679 2680
| 类型                | 说明                               |
| ------------------- | ---------------------------------- |
2681
| [By](#bydeprecated) | 返回指定目标控件文本属性的By对象。 |
2682 2683 2684 2685

**示例:**

```js
2686
let by = BY.text('123'); // 使用静态构造器BY创建by对象,指定目标控件的text属性。
2687 2688 2689 2690 2691 2692 2693 2694 2695
```


### key<sup>(deprecated)</sup>

key(key: string): By

指定目标控件key值属性,返回By对象自身。

R
ry 已提交
2696
从API version 9开始不再维护,建议使用[id<sup>9+</sup>](#id9)
2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型   | 必填 | 说明              |
| ------ | ------ | ---- | ----------------- |
| key    | string | 是   | 指定控件的Key值。 |

**返回值:**

2708 2709
| 类型                | 说明                                |
| ------------------- | ----------------------------------- |
2710
| [By](#bydeprecated) | 返回指定目标控件key值属性的By对象。 |
2711 2712 2713 2714

**示例:**

```js
2715
let by = BY.key('123'); // 使用静态构造器BY创建by对象,指定目标控件的key值属性。
2716 2717 2718 2719 2720 2721 2722 2723 2724
```


### id<sup>(deprecated)</sup>

id(id: number): By

指定目标控件id属性,返回By对象自身。

R
ry 已提交
2725
从API version 9开始废弃。
2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型   | 必填 | 说明             |
| ------ | ------ | ---- | ---------------- |
| id     | number | 是   | 指定控件的id值。 |

**返回值:**

2737 2738
| 类型                | 说明                             |
| ------------------- | -------------------------------- |
2739
| [By](#bydeprecated) | 返回指定目标控件id属性的By对象。 |
2740 2741 2742 2743

**示例:**

```js
2744
let by = BY.id(123); // 使用静态构造器BY创建by对象,指定目标控件的id属性。
2745 2746 2747 2748 2749 2750 2751 2752 2753
```


### type<sup>(deprecated)</sup>

type(tp: string): By

指定目标控件的控件类型属性,返回By对象自身。

R
ry 已提交
2754
从API version 9开始不再维护,建议使用[type<sup>9+</sup>](#type9)
2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型   | 必填 | 说明           |
| ------ | ------ | ---- | -------------- |
| tp     | string | 是   | 指定控件类型。 |

**返回值:**

2766 2767
| 类型                | 说明                                     |
| ------------------- | ---------------------------------------- |
2768
| [By](#bydeprecated) | 返回指定目标控件的控件类型属性的By对象。 |
2769 2770 2771 2772

**示例:**

```js
2773
let by = BY.type('button'); // 使用静态构造器BY创建by对象,指定目标控件的控件类型属性。
2774 2775 2776 2777 2778 2779 2780 2781 2782
```


### clickable<sup>(deprecated)</sup>

clickable(b?: boolean): By

指定目标控件的可点击状态属性,返回By对象自身。

R
ry 已提交
2783
从API version 9开始不再维护,建议使用[clickable<sup>9+</sup>](#clickable9)
2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型    | 必填 | 说明                                                         |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| b      | boolean | 否   | 指定控件可点击状态,true:可点击,false:不可点击。默认为true。 |

**返回值:**

2795 2796
| 类型                | 说明                                       |
| ------------------- | ------------------------------------------ |
2797
| [By](#bydeprecated) | 返回指定目标控件的可点击状态属性的By对象。 |
2798 2799 2800 2801

**示例:**

```js
2802
let by = BY.clickable(true); // 使用静态构造器BY创建by对象,指定目标控件的可点击状态属性。
2803 2804 2805 2806 2807 2808 2809 2810 2811
```


### scrollable<sup>(deprecated)</sup>

scrollable(b?: boolean): By

指定目标控件的可滑动状态属性,返回By对象自身。

R
ry 已提交
2812
从API version 9开始不再维护,建议使用[scrollable<sup>9+</sup>](#scrollable9)
2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型    | 必填 | 说明                                                        |
| ------ | ------- | ---- | ----------------------------------------------------------- |
| b      | boolean | 否   | 控件可滑动状态,true:可滑动,false:不可滑动。默认为true。 |

**返回值:**

2824 2825
| 类型                | 说明                                       |
| ------------------- | ------------------------------------------ |
2826
| [By](#bydeprecated) | 返回指定目标控件的可滑动状态属性的By对象。 |
2827 2828 2829 2830

**示例:**

```js
2831
let by = BY.scrollable(true); // 使用静态构造器BY创建by对象,指定目标控件的可滑动状态属性。
2832 2833 2834 2835 2836 2837 2838 2839
```

### enabled<sup>(deprecated)</sup>

enabled(b?: boolean): By

指定目标控件的使能状态属性,返回By对象自身。

R
ry 已提交
2840
从API version 9开始不再维护,建议使用[enabled<sup>9+</sup>](#enabled9)
2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型    | 必填 | 说明                                                      |
| ------ | ------- | ---- | --------------------------------------------------------- |
| b      | boolean | 否   | 指定控件使能状态,true:使能,false:未使能。默认为true。 |

**返回值:**

2852 2853
| 类型                | 说明                                     |
| ------------------- | ---------------------------------------- |
2854
| [By](#bydeprecated) | 返回指定目标控件的使能状态属性的By对象。 |
2855 2856 2857 2858

**示例:**

```js
2859
let by = BY.enabled(true); // 使用静态构造器BY创建by对象,指定目标控件的使能状态属性。
2860 2861 2862 2863 2864 2865 2866 2867
```

### focused<sup>(deprecated)</sup>

focused(b?: boolean): By

指定目标控件的获焦状态属性,返回By对象自身。

R
ry 已提交
2868
从API version 9开始不再维护,建议使用[focused<sup>9+</sup>](#focused9)
2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型    | 必填 | 说明                                                  |
| ------ | ------- | ---- | ----------------------------------------------------- |
| b      | boolean | 否   | 控件获焦状态,true:获焦,false:未获焦。默认为true。 |

**返回值:**

2880 2881
| 类型                | 说明                                     |
| ------------------- | ---------------------------------------- |
2882
| [By](#bydeprecated) | 返回指定目标控件的获焦状态属性的By对象。 |
2883 2884 2885 2886

**示例:**

```js
2887
let by = BY.focused(true); // 使用静态构造器BY创建by对象,指定目标控件的获焦状态属性。
2888 2889 2890 2891 2892 2893 2894 2895
```

### selected<sup>(deprecated)</sup>

selected(b?: boolean): By

指定目标控件的被选中状态属性,返回By对象自身。

R
ry 已提交
2896
从API version 9开始不再维护,建议使用[selected<sup>9+</sup>](#selected9)
2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型    | 必填 | 说明                                                         |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| b      | boolean | 否   | 指定控件被选中状态,true:被选中,false:未被选中。默认为true。 |

**返回值:**

2908 2909
| 类型                | 说明                                       |
| ------------------- | ------------------------------------------ |
2910
| [By](#bydeprecated) | 返回指定目标控件的被选中状态属性的By对象。 |
2911 2912 2913 2914

**示例:**

```js
2915
let by = BY.selected(true); // 使用静态构造器BY创建by对象,指定目标控件的被选中状态属性。
2916 2917 2918 2919 2920 2921 2922 2923
```

### isBefore<sup>(deprecated)</sup>

isBefore(by: By): By

指定目标控件位于给出的特征属性控件之前,返回By对象自身。

R
ry 已提交
2924
从API version 9开始不再维护,建议使用[isBefore<sup>9+</sup>](#isbefore9)
2925 2926 2927 2928 2929

**系统能力**:SystemCapability.Test.UiTest

**参数:**

2930 2931
| 参数名 | 类型                | 必填 | 说明             |
| ------ | ------------------- | ---- | ---------------- |
2932
| by     | [By](#bydeprecated) | 是   | 特征控件的属性。 |
2933 2934 2935

**返回值:**

2936 2937
| 类型                | 说明                                                 |
| ------------------- | ---------------------------------------------------- |
2938
| [By](#bydeprecated) | 返回指定目标控件位于给出的特征属性控件之前的By对象。 |
2939 2940 2941 2942

**示例:**

```js
2943
let by = BY.isBefore(BY.text('123')); // 使用静态构造器BY创建by对象,指定目标控件位于给出的特征属性控件之前。
2944 2945 2946 2947 2948 2949 2950 2951
```

### isAfter<sup>(deprecated)</sup>

isAfter(by: By): By

指定目标控件位于给出的特征属性控件之后,返回By对象自身。

R
ry 已提交
2952
从API version 9开始不再维护,建议使用[isAfter<sup>9+</sup>](#isafter9)
2953 2954 2955 2956 2957

**系统能力**:SystemCapability.Test.UiTest

**参数:**

2958 2959
| 参数名 | 类型                | 必填 | 说明             |
| ------ | ------------------- | ---- | ---------------- |
2960
| by     | [By](#bydeprecated) | 是   | 特征控件的属性。 |
2961 2962 2963

**返回值:**

2964 2965
| 类型                | 说明                                                 |
| ------------------- | ---------------------------------------------------- |
2966
| [By](#bydeprecated) | 返回指定目标控件位于给出的特征属性控件之后的By对象。 |
2967 2968 2969 2970

**示例:**

```js
2971
let by = BY.isAfter(BY.text('123')); // 使用静态构造器BY创建by对象,指定目标控件位于给出的特征属性控件之后。
2972 2973 2974 2975 2976 2977 2978
```

## UiComponent<sup>(deprecated)</sup>

UiTest中,UiComponent类代表了UI界面上的一个控件,提供控件属性获取,控件点击,滑动查找,文本注入等API。
该类提供的所有方法都使用Promise方式作为异步方法,需使用await调用。

R
ry 已提交
2979
从API version 9开始不再维护,建议使用[Component<sup>9+</sup>](#component9)
2980 2981 2982 2983 2984 2985 2986

### click<sup>(deprecated)</sup>

click(): Promise\<void>

控件对象进行点击操作。

R
ry 已提交
2987
从API version 9开始不再维护,建议使用[click<sup>9+</sup>](#click9)
2988 2989 2990 2991 2992 2993 2994

**系统能力**:SystemCapability.Test.UiTest

**示例:**

```js
async function demo() {
2995 2996 2997
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    await button.click();
2998 2999 3000 3001 3002 3003 3004 3005 3006
}
```

### doubleClick<sup>(deprecated)</sup>

doubleClick(): Promise\<void>

控件对象进行双击操作。

R
ry 已提交
3007
从API version 9开始不再维护,建议使用[doubleClick<sup>9+</sup>](#doubleclick9)
3008 3009 3010 3011 3012 3013 3014

**系统能力**:SystemCapability.Test.UiTest

**示例:**

```js
async function demo() {
3015 3016 3017
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    await button.doubleClick();
3018 3019 3020 3021 3022 3023 3024 3025 3026
}
```

### longClick<sup>(deprecated)</sup>

longClick(): Promise\<void>

控件对象进行长按操作。

R
ry 已提交
3027
从API version 9开始不再维护,建议使用[longClick<sup>9+</sup>](#longclick9)
3028 3029 3030 3031 3032 3033 3034

**系统能力**:SystemCapability.Test.UiTest

**示例:**

```js
async function demo() {
3035 3036 3037
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    await button.longClick();
3038 3039 3040 3041 3042 3043 3044 3045 3046
}
```

### getId<sup>(deprecated)</sup>

getId(): Promise\<number>

获取控件对象的id值。

R
ry 已提交
3047
从API version 9开始不再维护,被废弃。
3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

| 类型             | 说明                            |
| ---------------- | ------------------------------- |
| Promise\<number> | 以Promise形式返回的控件的id值。 |

**示例:**

```js
async function demo() {
3061 3062 3063
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let num = await button.getId();
3064 3065 3066 3067 3068 3069 3070 3071 3072
}
```

### getKey<sup>(deprecated)</sup>

getKey(): Promise\<string>

获取控件对象的key值。

R
ry 已提交
3073
从API version 9开始不再维护,建议使用[getId<sup>9+</sup>](#getid9)
3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

| 类型             | 说明                           |
| ---------------- | ------------------------------ |
| Promise\<string> | 以Promise形式返回控件的key值。 |

**示例:**

```js
async function demo() {
3087 3088 3089
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let str_key = await button.getKey();
3090 3091 3092 3093 3094 3095 3096 3097 3098
}
```

### getText<sup>(deprecated)</sup>

getText(): Promise\<string>

获取控件对象的文本信息。

R
ry 已提交
3099
从API version 9开始不再维护,建议使用[getText<sup>9+</sup>](#gettext9)
3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

| 类型             | 说明                              |
| ---------------- | --------------------------------- |
| Promise\<string> | 以Promise形式返回控件的文本信息。 |

**示例:**

```js
async function demo() {
3113 3114 3115
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let text = await button.getText();
3116 3117 3118 3119 3120 3121 3122 3123 3124
}
```

### getType<sup>(deprecated)</sup>

getType(): Promise\<string>

获取控件对象的控件类型。

R
ry 已提交
3125
从API version 9开始不再维护,建议使用[getType<sup>9+</sup>](#gettype9)
3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

| 类型             | 说明                          |
| ---------------- | ----------------------------- |
| Promise\<string> | 以Promise形式返回控件的类型。 |

**示例:**

```js
async function demo() {
3139 3140 3141
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
    let type = await button.getType();
3142 3143 3144 3145 3146 3147 3148 3149 3150
}
```

### isClickable<sup>(deprecated)</sup>

isClickable(): Promise\<boolean>

获取控件对象可点击状态。

R
ry 已提交
3151
从API version 9开始不再维护,建议使用[isClickable<sup>9+</sup>](#isclickable9)
3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | 以Promise形式返回控件对象可点击状态,true:可点击,false:不可点击。 |

**示例:**

```js
async function demo() {
3165 3166
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
3167
    if(await button.isClickable()) {
3168 3169 3170
        console.info('This button can be Clicked');
    } else {
        console.info('This button can not be Clicked');
3171 3172 3173 3174 3175 3176 3177 3178 3179 3180
    }
}
```

### isScrollable<sup>(deprecated)</sup>

isScrollable(): Promise\<boolean>

获取控件对象可滑动状态。

R
ry 已提交
3181
从API version 9开始不再维护,建议使用[isScrollable<sup>9+</sup>](#isscrollable9)
3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | 以Promise形式返回控件对象可滑动状态,true:可滑动,false:不可滑动。 |

**示例:**

```js
async function demo() {
3195 3196
    let driver = UiDriver.create();
    let scrollBar = await driver.findComponent(BY.scrollable(true));
3197
    if(await scrollBar.isScrollable()) {
3198 3199 3200
        console.info('This scrollBar can be operated');
    } else {
        console.info('This scrollBar can not be operated');
3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211
    }
}
```


### isEnabled<sup>(deprecated)</sup>

isEnabled(): Promise\<boolean>

获取控件使能状态。

R
ry 已提交
3212
从API version 9开始不再维护,建议使用[isEnabled<sup>9+</sup>](#isenabled9)
3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

| 类型              | 说明                                                       |
| ----------------- | ---------------------------------------------------------- |
| Promise\<boolean> | 以Promise形式返回控件使能状态,true:使能,false:未使能。 |

**示例:**

```js
async function demo() {
3226 3227
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
3228
    if(await button.isEnabled()) {
3229 3230 3231
        console.info('This button can be operated');
    } else {
        console.info('This button can not be operated');
3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242
    }
}

```

### isFocused<sup>(deprecated)</sup>

isFocused(): Promise\<boolean>

判断控件对象是否获焦。

R
ry 已提交
3243
从API version 9开始不再维护,建议使用[isFocused<sup>9+</sup>](#isfocused9)
3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | 以Promise形式返回控件对象是否获焦,true:获焦,false:未获焦。 |

**示例:**

```js
async function demo() {
3257 3258
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
3259
    if(await button.isFocused()) {
3260 3261 3262
        console.info('This button is focused');
    } else {
        console.info('This button is not focused');
3263 3264 3265 3266 3267 3268 3269 3270 3271 3272
	}
}
```

### isSelected<sup>(deprecated)</sup>

isSelected(): Promise\<boolean>

获取控件对象被选中状态。

R
ry 已提交
3273
从API version 9开始不再维护,建议使用[isSelected<sup>9+</sup>](#isselected9)
3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

| 类型              | 说明                                                  |
| ----------------- | ----------------------------------------------------- |
| Promise\<boolean> | 控件对象被选中的状态,true:被选中,false:未被选中。 |

**示例:**

```js
async function demo() {
3287 3288
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.type('button'));
3289
    if(await button.isSelected()) {
3290 3291 3292
        console.info('This button is selected');
    } else {
        console.info('This button is not selected');
3293 3294 3295 3296 3297 3298 3299 3300 3301 3302
    }
}
```

### inputText<sup>(deprecated)</sup>

inputText(text: string): Promise\<void>

向控件中输入文本(适用于文本框控件)。

R
ry 已提交
3303
从API version 9开始不再维护,建议使用[inputText<sup>9+</sup>](#inputtext9)
3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型   | 必填 | 说明             |
| ------ | ------ | ---- | ---------------- |
| text   | string | 是   | 输入的文本信息。 |

**示例:**

```js
async function demo() {
3317 3318 3319
    let driver = UiDriver.create();
    let text = await driver.findComponent(BY.text('hello world'));
    await text.inputText('123');
3320 3321 3322 3323 3324 3325 3326 3327 3328
}
```

### scrollSearch<sup>(deprecated)</sup>

scrollSearch(by: By): Promise\<UiComponent>

在控件上滑动查找目标控件(适用于List等支持滑动的控件)。

R
ry 已提交
3329
从API version 9开始不再维护,建议使用[scrollSearch<sup>9+</sup>](#scrollsearch9)
3330 3331 3332 3333 3334

**系统能力**:SystemCapability.Test.UiTest

**参数:**

3335 3336
| 参数名 | 类型                | 必填 | 说明                 |
| ------ | ------------------- | ---- | -------------------- |
3337
| by     | [By](#bydeprecated) | 是   | 目标控件的属性要求。 |
3338 3339 3340

**返回值:**

3341 3342 3343
| 类型                                            | 说明                                  |
| ----------------------------------------------- | ------------------------------------- |
| Promise\<[UiComponent](#uicomponentdeprecated)> | 以Promise形式返回找到的目标控件对象。 |
3344 3345 3346 3347 3348

**示例:**

```js
async function demo() {
3349 3350 3351
    let driver = UiDriver.create();
    let scrollBar = await driver.findComponent(BY.type('Scroll'));
    let button = await scrollBar.scrollSearch(BY.text('next page'));
3352 3353 3354 3355 3356 3357 3358 3359
}
```

## UiDriver<sup>(deprecated)</sup>

UiDriver类为uitest测试框架的总入口,提供控件匹配/查找,按键注入,坐标点击/滑动,截图等API。
该类提供的方法除UiDriver.create()以外的所有方法都使用Promise方式作为异步方法,需使用await调用。

R
ry 已提交
3360
从API version 9开始不再维护,建议使用[Driver<sup>9+</sup>](#driver9)
3361 3362 3363 3364 3365 3366 3367

### create<sup>(deprecated)</sup>

static create(): UiDriver

静态方法,构造一个UiDriver对象,并返回该对象。

R
ry 已提交
3368
从API version 9开始不再维护,建议使用[create<sup>9+</sup>](#create9)
3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381

**系统能力**:SystemCapability.Test.UiTest

**返回值:**

| 类型     | 说明                     |
| -------- | ------------------------ |
| UiDriver | 返回构造的UiDriver对象。 |

**示例:**

```js
async function demo() {
3382
    let driver = UiDriver.create();
3383 3384 3385 3386 3387 3388 3389 3390 3391
}
```

### delayMs<sup>(deprecated)</sup>

delayMs(duration: number): Promise\<void>

UiDriver对象在给定的时间内延时。

R
ry 已提交
3392
从API version 9开始不再维护,建议使用[delayMs<sup>9+</sup>](#delayms9)
3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名   | 类型   | 必填 | 说明         |
| -------- | ------ | ---- | ------------ |
| duration | number | 是   | 给定的时间。 |

**示例:**

```js
async function demo() {
3406 3407
    let driver = UiDriver.create();
    await driver.delayMs(1000);
3408 3409 3410 3411 3412 3413 3414 3415 3416
}
```

### findComponent<sup>(deprecated)</sup>

findComponent(by: By): Promise\<UiComponent>

在UiDriver对象中,根据给出的目标控件属性要求查找目标控件。

R
ry 已提交
3417
从API version 9开始不再维护,建议使用[findComponent<sup>9+</sup>](#findcomponent9)
3418 3419 3420 3421 3422

**系统能力**:SystemCapability.Test.UiTest

**参数:**

3423 3424
| 参数名 | 类型                | 必填 | 说明                 |
| ------ | ------------------- | ---- | -------------------- |
3425
| by     | [By](#bydeprecated) | 是   | 目标控件的属性要求。 |
3426 3427 3428

**返回值:**

3429 3430 3431
| 类型                                            | 说明                              |
| ----------------------------------------------- | --------------------------------- |
| Promise\<[UiComponent](#uicomponentdeprecated)> | 以Promise形式返回找到的控件对象。 |
3432 3433 3434 3435 3436

**示例:**

```js
async function demo() {
3437 3438
    let driver = UiDriver.create();
    let button = await driver.findComponent(BY.text('next page'));
3439 3440 3441 3442 3443 3444 3445 3446 3447
}
```

### findComponents<sup>(deprecated)</sup>

findComponents(by: By): Promise\<Array\<UiComponent>>

在UiDriver对象中,根据给出的目标控件属性要求查找出所有匹配控件,以列表保存。

R
ry 已提交
3448
从API version 9开始不再维护,建议使用[findComponents<sup>9+</sup>](#findcomponents9)
3449 3450 3451 3452 3453

**系统能力**:SystemCapability.Test.UiTest

**参数:**

3454 3455
| 参数名 | 类型                | 必填 | 说明                 |
| ------ | ------------------- | ---- | -------------------- |
3456
| by     | [By](#bydeprecated) | 是   | 目标控件的属性要求。 |
3457 3458 3459

**返回值:**

3460 3461 3462
| 类型                                                    | 说明                                    |
| ------------------------------------------------------- | --------------------------------------- |
| Promise\<Array\<[UiComponent](#uicomponentdeprecated)>> | 以Promise形式返回找到的控件对象的列表。 |
3463 3464 3465 3466 3467

**示例:**

```js
async function demo() {
3468 3469
    let driver = UiDriver.create();
    let buttonList = await driver.findComponents(BY.text('next page'));
3470 3471 3472 3473 3474 3475 3476 3477 3478
}
```

### assertComponentExist<sup>(deprecated)</sup>

assertComponentExist(by: By): Promise\<void>

断言API,用于断言当前界面存在满足给出的目标控件属性的控件; 如果控件不存在,该API将抛出JS异常,使当前测试用例失败。

R
ry 已提交
3479
从API version 9开始不再维护,建议使用[assertComponentExist<sup>9+</sup>](#assertcomponentexist9)
3480 3481 3482 3483 3484

**系统能力**:SystemCapability.Test.UiTest

**参数:**

3485 3486
| 参数名 | 类型                | 必填 | 说明                 |
| ------ | ------------------- | ---- | -------------------- |
3487
| by     | [By](#bydeprecated) | 是   | 目标控件的属性要求。 |
3488 3489 3490 3491 3492

**示例:**

```js
async function demo() {
3493 3494
    let driver = UiDriver.create();
    await driver.assertComponentExist(BY.text('next page'));
3495 3496 3497 3498 3499 3500 3501 3502 3503
}
```

### pressBack<sup>(deprecated)</sup>

pressBack(): Promise\<void>

UiDriver对象进行点击BACK键的操作。

R
ry 已提交
3504
从API version 9开始不再维护,建议使用[pressBack<sup>9+</sup>](#pressback9)
3505 3506 3507 3508 3509 3510 3511

**系统能力**:SystemCapability.Test.UiTest

**示例:**

```js
async function demo() {
3512 3513
    let driver = UiDriver.create();
    await driver.pressBack();
3514 3515 3516 3517 3518 3519 3520 3521 3522
}
```

### triggerKey<sup>(deprecated)</sup>

triggerKey(keyCode: number): Promise\<void>

UiDriver对象采取如下操作:通过key值找到对应键并点击。

R
ry 已提交
3523
从API version 9开始不再维护,建议使用[triggerKey<sup>9+</sup>](#triggerkey9)
3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名  | 类型   | 必填 | 说明          |
| ------- | ------ | ---- | ------------- |
| keyCode | number | 是   | 指定的key值。 |

**示例:**

```js
async function demo() {
3537 3538
    let driver = UiDriver.create();
    await driver.triggerKey(123);
3539 3540 3541 3542 3543 3544 3545 3546 3547 3548
}
```


### click<sup>(deprecated)</sup>

click(x: number, y: number): Promise\<void>

UiDriver对象采取如下操作:在目标坐标点单击。

R
ry 已提交
3549
从API version 9开始不再维护,建议使用[click<sup>9+</sup>](#click9)
3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型   | 必填 | 说明                                   |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | 是   | 以number的形式传入目标点的横坐标信息。 |
| y      | number | 是   | 以number的形式传入目标点的纵坐标信息。 |

**示例:**

```js
async function demo() {
3564 3565
    let driver = UiDriver.create();
    await driver.click(100,100);
3566 3567 3568 3569 3570 3571 3572 3573 3574
}
```

### doubleClick<sup>(deprecated)</sup>

doubleClick(x: number, y: number): Promise\<void>

UiDriver对象采取如下操作:在目标坐标点双击。

R
ry 已提交
3575
从API version 9开始不再维护,建议使用[doubleClick<sup>9+</sup>](#doubleclick9)
3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型   | 必填 | 说明                                   |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | 是   | 以number的形式传入目标点的横坐标信息。 |
| y      | number | 是   | 以number的形式传入目标点的纵坐标信息。 |

**示例:**

```js
async function demo() {
3590 3591
    let driver = UiDriver.create();
    await driver.doubleClick(100,100);
3592 3593 3594 3595 3596 3597 3598 3599 3600
}
```

### longClick<sup>(deprecated)</sup>

longClick(x: number, y: number): Promise\<void>

UiDriver对象采取如下操作:在目标坐标点长按下鼠标左键。

R
ry 已提交
3601
从API version 9开始不再维护,建议使用[longClick<sup>9+</sup>](#longclick9)
3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型   | 必填 | 说明                                   |
| ------ | ------ | ---- | -------------------------------------- |
| x      | number | 是   | 以number的形式传入目标点的横坐标信息。 |
| y      | number | 是   | 以number的形式传入目标点的纵坐标信息。 |

**示例:**

```js
async function demo() {
3616 3617
    let driver = UiDriver.create();
    await driver.longClick(100,100);
3618 3619 3620 3621 3622 3623 3624 3625 3626
}
```

### swipe<sup>(deprecated)</sup>

swipe(startx: number, starty: number, endx: number, endy: number): Promise\<void>

UiDriver对象采取如下操作:从给出的起始坐标点滑向给出的目的坐标点。

R
ry 已提交
3627
从API version 9开始不再维护,建议使用[swipe<sup>9+</sup>](#swipe9)
3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名 | 类型   | 必填 | 说明                                   |
| ------ | ------ | ---- | -------------------------------------- |
| startx | number | 是   | 以number的形式传入起始点的横坐标信息。 |
| starty | number | 是   | 以number的形式传入起始点的纵坐标信息。 |
| endx   | number | 是   | 以number的形式传入目的点的横坐标信息。 |
| endy   | number | 是   | 以number的形式传入目的点的纵坐标信息。 |

**示例:**

```js
async function demo() {
3644 3645
    let driver = UiDriver.create();
    await driver.swipe(100,100,200,200);
3646 3647 3648 3649 3650 3651 3652 3653 3654
}
```

### screenCap<sup>(deprecated)</sup>

screenCap(savePath: string): Promise\<boolean>

UiDriver对象采取如下操作:捕获当前屏幕,并保存为PNG格式的图片至给出的保存路径中。

R
ry 已提交
3655
从API version 9开始不再维护,建议使用[screenCap<sup>9+</sup>](#screencap9)
3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674

**系统能力**:SystemCapability.Test.UiTest

**参数:**

| 参数名   | 类型   | 必填 | 说明           |
| -------- | ------ | ---- | -------------- |
| savePath | string | 是   | 文件保存路径。 |

**返回值:**

| 类型              | 说明                                   |
| ----------------- | -------------------------------------- |
| Promise\<boolean> | 截图操作是否成功完成。成功完成为true。 |

**示例:**

```js
async function demo() {
3675 3676
    let driver = UiDriver.create();
    await driver.screenCap('/local/tmp/1.png');
3677 3678
}
```