Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
810e0fc5
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
810e0fc5
编写于
5月 24, 2022
作者:
O
openharmony_ci
提交者:
Gitee
5月 24, 2022
浏览文件
操作
浏览文件
下载
差异文件
!4285 js-apis-uitest.md规范修改,增加新接口描述
Merge pull request !4285 from 周柯/master
上级
7619755c
91ad7495
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
587 addition
and
312 deletion
+587
-312
zh-cn/application-dev/reference/apis/js-apis-uitest.md
zh-cn/application-dev/reference/apis/js-apis-uitest.md
+587
-312
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-uitest.md
浏览文件 @
810e0fc5
...
@@ -13,42 +13,27 @@ import {UiDriver,BY,MatchPattern} from '@ohos.uitest'
...
@@ -13,42 +13,27 @@ import {UiDriver,BY,MatchPattern} from '@ohos.uitest'
## By
## By
UiTest框架通过By类提供了丰富的控件特征描述API,用以进行控件筛选来匹配/查找出目标控件。
UiTest框架通过By类提供了丰富的控件特征描述API,用以进行控件筛选来匹配/查找出目标控件。
<br>
By提供的API能力具有以下几个特点:
By提供的API能力具有以下几个特点:
<br>
1、支持单属性匹配和多属性组合匹配,例如同时指定目标控件text和id。
<br>
2、控件属性支持多种匹配模式。
<br>
3、支持控件绝对定位,相对定位,可通过
[
By.isBefore
](
#byisbefore
)
和
[
By.isAfter
](
#byisafter
)
等API限定邻近控件特征进行辅助定位。
<br>
By类提供的所有API均为同步接口,建议使用者通过静态构造器BY来链式创建By对象。
1、支持单属性匹配和多属性组合匹配,例如同时指定目标控件text和id
2、控件属性支持多种匹配模式
3、支持控件绝对定位,相对定位,可通过isBefore和isAfter等API限定邻近控件特征进行辅助定位
By类提供的所有API均为同步接口,建议使用者通过静态构造器BY来链式创建By对象,例如:BY.text('123').type('button')
### enum MatchPattern
```
js
BY
.
text
(
'
123
'
).
type
(
'
button
'
)
控件属性支持的匹配模式
```
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Test.UiTest
| 名称 | 值 | 说明 |
| ----------- | ---- | ------------ |
| EQUALS | 0 | 等于给定值 |
| CONTAINS | 1 | 包含给定值 |
| STARTS_WITH | 2 | 以给定值开始 |
| ENDS_WITH | 3 | 以给定值结束 |
### By.text
### By.text
text(txt:
string,pattern?:MatchPattern):
By
text(txt:
string, pattern?: MatchPattern):
By
指定目标控件文本属性,支持多种匹配模式,返回By对象自身。
指定目标控件文本属性,支持多种匹配模式,返回By对象自身。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------- | ------------ | ---- | ---------------------------------- |
| ------- | ------------ | ---- | ----------------------------------
---------------
|
| txt | string | 是 | 指定控件文本,用于匹配目标控件文本 |
| txt | string | 是 | 指定控件文本,用于匹配目标控件文本
。
|
| pattern | MatchPattern | 否 | 指定的文本匹配模式,默认为
EQUALS
|
| pattern | MatchPattern | 否 | 指定的文本匹配模式,默认为
[
EQUALS
](
#matchpattern
)
|
**返回值:**
**返回值:**
...
@@ -58,226 +43,262 @@ text(txt:string,pattern?:MatchPattern):By
...
@@ -58,226 +43,262 @@ text(txt:string,pattern?:MatchPattern):By
**示例:**
**示例:**
```
```
js
let by = BY.text('123') //使用静态构造器BY创建by对象,指定目标控件的text属性
let
by
=
BY
.
text
(
'
123
'
)
//使用静态构造器BY创建by对象,指定目标控件的text属性
。
```
```
### By.key
### By.key
key(key:
string):By;
key(key:
string): By
指定目标控件key值属性,返回By对象自身。
指定目标控件key值属性,返回By对象自身。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ------ | ---- | --------------- |
| ------ | ------ | ---- | ---------------
--
|
| key | string | 是 | 指定控件的Key值 |
| key | string | 是 | 指定控件的Key值
。
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---- | -------------- |
| ---- | --------------
--
|
| By | 返回By对象自身 |
| By | 返回By对象自身
。
|
**示例:**
**示例:**
```
```
js
let by = BY.key('123') //使用静态构造器BY创建by对象,指定目标控件的key值属性
let
by
=
BY
.
key
(
'
123
'
)
//使用静态构造器BY创建by对象,指定目标控件的key值属性
。
```
```
### By.id
### By.id
id(id:
number):By;
id(id:
number): By
指定目标控件id属性,返回By对象自身。
指定目标控件id属性,返回By对象自身。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ------ | ---- | ------------ |
| ------ | ------ | ---- | ------------
----
|
| id | number | 是 | 指定控件
id值
|
| id | number | 是 | 指定控件
的id值。
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---- | -------------- |
| ---- | --------------
--
|
| By | 返回By对象自身 |
| By | 返回By对象自身
。
|
**示例:**
**示例:**
```
```
js
let by = BY.id(123) //使用静态构造器BY创建by对象,指定目标控件的id属性
let
by
=
BY
.
id
(
123
)
//使用静态构造器BY创建by对象,指定目标控件的id属性
。
```
```
### By.type
### By.type
type(tp:
string):By;
type(tp:
string): By
指定目标控件的控件类型属性,返回By对象自身。
指定目标控件的控件类型属性,返回By对象自身。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ------ | ---- | ------------ |
| ------ | ------ | ---- | ------------
--
|
| tp | string | 是 | 指定控件类型 |
| tp | string | 是 | 指定控件类型
。
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---- | -------------- |
| ---- | --------------
--
|
| By | 返回By对象自身 |
| By | 返回By对象自身
。
|
**示例:**
**示例:**
```
```
js
let by = BY.type('button') //使用静态构造器BY创建by对象,指定目标控件的控件类型属性
let
by
=
BY
.
type
(
'
button
'
)
//使用静态构造器BY创建by对象,指定目标控件的控件类型属性
。
```
```
### By.clickable
### By.clickable
clickable(b?:
bool):By;
clickable(b?:
bool): By
指定目标控件的可点击状态属性,返回By对象自身。
指定目标控件的可点击状态属性,返回By对象自身。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ---- | ---- | ------------------------------ |
| ------ | ---- | ---- | ------------------------------
--
|
| b | bool | 否 | 指定控件可点击状态,默认为true |
| b | bool | 否 | 指定控件可点击状态,默认为true
。
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---- | -------------- |
| ---- | --------------
--
|
| By | 返回By对象自身 |
| By | 返回By对象自身
。
|
**示例:**
**示例:**
```
js
let
by
=
BY
.
clickable
(
true
)
//使用静态构造器BY创建by对象,指定目标控件的可点击状态属性。
```
```
let by = BY.clickable(true) //使用静态构造器BY创建by对象,指定目标控件的可点击状态属性
### By.longClickable<sup>9+</sup>
longClickable(b?: bool): By
指定目标控件的可长按点击状态属性,返回By对象自身。
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---- | ---- | ------------------------------------ |
| b | bool | 否 | 指定控件可长按点击状态,默认为true。 |
**返回值:**
| 类型 | 说明 |
| ---- | ---------------- |
| By | 返回By对象自身。 |
**示例:**
```
js
let
by
=
BY
.
longClickable
(
true
)
//使用静态构造器BY创建by对象,指定目标控件的可长按点击状态属性。
```
```
### By.scrollable
### By.scrollable
scrollable(b?:
bool):By;
scrollable(b?:
bool): By
指定目标控件的可滑动状态属性,返回By对象自身。
指定目标控件的可滑动状态属性,返回By对象自身。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ---- | ---- | -------------------------- |
| ------ | ---- | ---- | --------------------------
--
|
| b | bool | 否 | 控件可滑动状态,默认为true |
| b | bool | 否 | 控件可滑动状态,默认为true
。
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---- | -------------- |
| ---- | --------------
--
|
| By | 返回By对象自身 |
| By | 返回By对象自身
。
|
**示例:**
**示例:**
```
```
js
let by = BY.scrollable(true) //使用静态构造器BY创建by对象,指定目标控件的可滑动状态属性
let
by
=
BY
.
scrollable
(
true
)
//使用静态构造器BY创建by对象,指定目标控件的可滑动状态属性
。
```
```
### By.enabled
### By.enabled
enabled(b?:
bool):By;
enabled(b?:
bool): By
指定目标控件的使能状态属性,返回By对象自身。
指定目标控件的使能状态属性,返回By对象自身。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ---- | ---- | ---------------------------- |
| ------ | ---- | ---- | ----------------------------
--
|
| b | bool | 否 | 指定控件使能状态,默认为true |
| b | bool | 否 | 指定控件使能状态,默认为true
。
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---- | -------------- |
| ---- | --------------
--
|
| By | 返回By对象自身 |
| By | 返回By对象自身
。
|
**示例:**
**示例:**
```
```
js
let by = BY.enabled(true) //使用静态构造器BY创建by对象,指定目标控件的使能状态属性
let
by
=
BY
.
enabled
(
true
)
//使用静态构造器BY创建by对象,指定目标控件的使能状态属性
。
```
```
### By.focused
### By.focused
focused(b?:
bool):By;
focused(b?:
bool): By
指定目标控件的获焦状态属性,返回By对象自身。
指定目标控件的获焦状态属性,返回By对象自身。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ---- | ---- | ------------------------ |
| ------ | ---- | ---- | ------------------------
--
|
| b | bool | 否 | 控件获焦状态,默认为true |
| b | bool | 否 | 控件获焦状态,默认为true
。
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---- | -------------- |
| ---- | --------------
--
|
| By | 返回By对象自身 |
| By | 返回By对象自身
。
|
**示例:**
**示例:**
```
```
js
let by = BY.focused(true) //使用静态构造器BY创建by对象,指定目标控件的获焦状态属性
let
by
=
BY
.
focused
(
true
)
//使用静态构造器BY创建by对象,指定目标控件的获焦状态属性
。
```
```
### By.selected
### By.selected
selected(b?:
bool):By;
selected(b?:
bool): By
指定目标控件的被选中状态属性,返回By对象自身。
指定目标控件的被选中状态属性,返回By对象自身。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---- | ---- | -------------------------------- |
| b | bool | 否 | 指定控件被选中状态,默认为true。 |
**返回值:**
| 类型 | 说明 |
| ---- | ---------------- |
| By | 返回By对象自身。 |
**示例:**
```
js
let
by
=
BY
.
selected
(
true
)
//使用静态构造器BY创建by对象,指定目标控件的被选中状态属性。
```
### By.checked<sup>9+</sup>
checked(b?: bool): By
指定目标控件的被勾选状态属性,返回By对象自身。
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ---- | ---- | ------------------------------ |
| ------ | ---- | ---- | ------------------------------
---
|
| b | bool | 否 | 指定控件被
选中状态,默认为true
|
| b | bool | 否 | 指定控件被
勾选状态,默认为false。
|
**返回值:**
**返回值:**
...
@@ -287,64 +308,86 @@ selected(b?:bool):By;
...
@@ -287,64 +308,86 @@ selected(b?:bool):By;
**示例:**
**示例:**
```
js
let
by
=
BY
.
checked
(
true
)
//使用静态构造器BY创建by对象,指定目标控件的被勾选状态属性
```
```
let by = BY.selected(true) //使用静态构造器BY创建by对象,指定目标控件的被选中状态属性
### By.checkable<sup>9+</sup>
checkable(b?: bool): By
指定目标控件能否被勾选状态属性,返回By对象自身。
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---- | ---- | ------------------------------------- |
| b | bool | 否 | 指定控件能否被勾选状态,默认为false。 |
**返回值:**
| 类型 | 说明 |
| ---- | ---------------- |
| By | 返回By对象自身。 |
**示例:**
```
js
let
by
=
BY
.
checkable
(
true
)
//使用静态构造器BY创建by对象,指定目标控件的能否被勾选状态属性。
```
```
### By.isBefore
### By.isBefore
isBefore(by:
By):By;
isBefore(by:
By): By
指定目标控件位于给出的特征属性控件之前,返回By对象自身。
指定目标控件位于给出的特征属性控件之前,返回By对象自身。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ---- | ---- | -------------- |
| ------ | ---- | ---- | --------------
--
|
| by | By | 是 | 特征控件的属性 |
| by | By | 是 | 特征控件的属性
。
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---- | -------------- |
| ---- | --------------
--
|
| By | 返回By对象自身 |
| By | 返回By对象自身
。
|
**示例:**
**示例:**
```
```
js
let by = BY.isBefore(BY.text('123')) //使用静态构造器BY创建by对象,指定目标控件位于给出的特征属性控件之前
let
by
=
BY
.
isBefore
(
BY
.
text
(
'
123
'
))
//使用静态构造器BY创建by对象,指定目标控件位于给出的特征属性控件之前
。
```
```
### By.isAfter
### By.isAfter
isAfter(by:
By):By;
isAfter(by:
By): By
指定目标控件位于给出的特征属性控件之后,返回By对象自身。
指定目标控件位于给出的特征属性控件之后,返回By对象自身。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ---- | ---- | -------------- |
| ------ | ---- | ---- | --------------
--
|
| by | By | 是 | 特征控件的属性 |
| by | By | 是 | 特征控件的属性
。
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---- | -------------- |
| ---- | --------------
--
|
| By | 返回By对象自身 |
| By | 返回By对象自身
。
|
**示例:**
**示例:**
```
```
js
let by = BY.isAfter(BY.text('123')) //使用静态构造器BY创建by对象,指定目标控件位于给出的特征属性控件之后
let
by
=
BY
.
isAfter
(
BY
.
text
(
'
123
'
))
//使用静态构造器BY创建by对象,指定目标控件位于给出的特征属性控件之后
。
```
```
## UiComponent
## UiComponent
...
@@ -352,19 +395,30 @@ let by = BY.isAfter(BY.text('123')) //使用静态构造器BY创建by对象,
...
@@ -352,19 +395,30 @@ let by = BY.isAfter(BY.text('123')) //使用静态构造器BY创建by对象,
UiTest中,UiComponent类代表了UI界面上的一个控件,提供控件属性获取,控件点击,滑动查找,文本注入等API。
UiTest中,UiComponent类代表了UI界面上的一个控件,提供控件属性获取,控件点击,滑动查找,文本注入等API。
该类提供的所有方法都使用Promise方式作为异步方法,需使用await调用。
该类提供的所有方法都使用Promise方式作为异步方法,需使用await调用。
### Rect<sup>9+</sup>
控件的边框信息。
**系统能力**
:SystemCapability.Test.UiTest
| 名称 | 参数类型 | 可读 | 可写 | 描述 |
| ------- | -------- | ---- | ---- | ------------------------- |
| leftX | number | 是 | 否 | 控件边框的左上角的X坐标。 |
| topY | number | 是 | 否 | 控件边框的左上角的Y坐标。 |
| rightX | number | 是 | 否 | 控件边框的右下角的X坐标。 |
| bottomY | number | 是 | 否 | 控件边框的右下角的Y坐标。 |
### UiComponent.click
### UiComponent.click
click():
Promise
<void>
;
click():
Promise
\<
void>
控件对象进行点击操作。
控件对象进行点击操作。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
...
@@ -374,17 +428,15 @@ async function demo() {
...
@@ -374,17 +428,15 @@ async function demo() {
### UiComponent.doubleClick
### UiComponent.doubleClick
doubleClick():
Promise
<void>
;
doubleClick():
Promise
\<
void>
控件对象进行双击操作。
控件对象进行双击操作。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
...
@@ -394,17 +446,15 @@ async function demo() {
...
@@ -394,17 +446,15 @@ async function demo() {
### UiComponent.longClick
### UiComponent.longClick
longClick():
Promise
<void>
;
longClick():
Promise
\<
void>
控件对象进行长按操作。
控件对象进行长按操作。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
...
@@ -414,23 +464,21 @@ async function demo() {
...
@@ -414,23 +464,21 @@ async function demo() {
### UiComponent.getId
### UiComponent.getId
getId():
Promise
<number>
;
getId():
Promise
\<
number>
获取控件对象的id值。
获取控件对象的id值。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---------------- | ------------------------- |
| ---------------- | -------------------------
------
|
| Promise
<number>
; | 以Promise形式返回控件id值
|
| Promise
\<
number> | 以Promise形式返回的控件的id值。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
...
@@ -440,23 +488,21 @@ async function demo() {
...
@@ -440,23 +488,21 @@ async function demo() {
### UiComponent.getKey
### UiComponent.getKey
getKey():
Promise
<string>
;
getKey():
Promise
\<
string>
获取控件对象的key值。
获取控件对象的key值。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---------------- | -------------------------- |
| ---------------- | --------------------------
----
|
| Promise
<string>
; | 以Promise形式返回控件key值
|
| Promise
\<
string> | 以Promise形式返回控件的key值。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
...
@@ -466,23 +512,21 @@ async function demo() {
...
@@ -466,23 +512,21 @@ async function demo() {
### UiComponent.getText
### UiComponent.getText
getText():
Promise
<string>
;
getText():
Promise
\<
string>
获取控件对象的文本信息。
获取控件对象的文本信息。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ---------------- | ------------------------------- |
| ---------------- | -------------------------------
--
|
| Promise
<string>
; | 以Promise形式返回控件的文本信息
|
| Promise
\<
string> | 以Promise形式返回控件的文本信息。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
...
@@ -492,23 +536,21 @@ async function demo() {
...
@@ -492,23 +536,21 @@ async function demo() {
### UiComponent.getType
### UiComponent.getType
getType():
Promise
<string>
;
getType():
Promise
\<
string>
获取控件对象的控件类型。
获取控件对象的控件类型。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
**返回值:**
| 类型 | 说明
|
| 类型 | 说明 |
| ---------------- | -----------------------------
--
|
| ---------------- | ----------------------------- |
| Promise
<string>
; | 以Promise形式返回控件对象的类型
|
| Promise
\<
string> | 以Promise形式返回控件的类型。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
...
@@ -516,25 +558,47 @@ async function demo() {
...
@@ -516,25 +558,47 @@ async function demo() {
}
}
```
```
### UiComponent.getBounds<sup>9+</sup>
getBounds(): Promise
\<
Rect>
获取控件对象的边框信息。
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------------------- |
| Promise
\<
Rect> | 以Promise形式返回控件对象的边框信息。 |
**示例:**
```
js
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
rect
=
await
button
.
getBounds
()
}
```
### UiComponent.isClickable
### UiComponent.isClickable
isClickable():
Promise
<bool>
;
isClickable():
Promise
\<
bool>
获取控件对象可点击状态。
获取控件对象可点击状态。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| -------------- | ----------------------------------- |
| -------------- | -----------------------------------
--
|
| Promise
<bool>
; | 以Promise形式返回控件对象可点击状态
|
| Promise
\<
bool> | 以Promise形式返回控件对象可点击状态。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
...
@@ -547,25 +611,110 @@ async function demo() {
...
@@ -547,25 +611,110 @@ async function demo() {
}
}
```
```
### UiComponent.is
Scrollable
### UiComponent.is
LongClickable<sup>9+</sup>
is
Scrollable():Promise
<bool>
;
is
LongClickable(): Promise
\<
bool>
获取控件对象可滑动状态。
获取控件对象可长按点击状态。
**系统能力**
:SystemCapability.Test.UiTest
**需要权限**
:NA
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------------------------- |
| Promise
\<
bool> | 以Promise形式返回控件对象能否长按点击状态。 |
**示例:**
```
js
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
if
(
await
button
.
isLongClickable
())
{
console
.
info
(
'
This button can longClick
'
)
}
else
{
console
.
info
(
'
This button can not longClick
'
)
}
}
```
### UiComponent.isChecked<sup>9+</sup>
isLongClickable(): Promise
\<
bool>
获取控件对象被勾选状态。
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------------- | ----------------------------------- |
| -------------- | ------------------------------------- |
| Promise
<bool>
; | 以Promise形式返回控件对象可滑动状态 |
| Promise
\<
bool> | 以Promise形式返回控件对象被勾选状态。 |
**示例:**
```
js
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
checkBox
=
await
driver
.
findComponent
(
BY
.
type
(
'
Checkbox
'
))
if
(
await
checkBox
.
isChecked
)
{
console
.
info
(
'
This checkBox is checked
'
)
}
else
{
console
.
info
(
'
This checkBox is not checked
'
)
}
}
```
### UiComponent.isCheckable<sup>9+</sup>
isCheckable(): Promise
\<
bool>
获取控件对象能否被勾选的属性。
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------------------------- |
| Promise
\<
bool> | 以Promise形式返回控件对象能否被勾选的属性。 |
**示例:**
**示例:**
```
js
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
checkBox
=
await
driver
.
findComponent
(
BY
.
type
(
'
Checkbox
'
))
if
(
await
checkBox
.
isCheckable
)
{
console
.
info
(
'
This checkBox is checkable
'
)
}
else
{
console
.
info
(
'
This checkBox is not checkable
'
)
}
}
```
```
### UiComponent.isScrollable
isScrollable(): Promise
\<
bool>
获取控件对象可滑动状态。
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------------------- |
| Promise
\<
bool> | 以Promise形式返回控件对象可滑动状态。 |
**示例:**
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
scrollBar
=
await
driver
.
findComponent
(
BY
.
scrollable
(
true
))
let
scrollBar
=
await
driver
.
findComponent
(
BY
.
scrollable
(
true
))
...
@@ -581,23 +730,21 @@ async function demo() {
...
@@ -581,23 +730,21 @@ async function demo() {
### UiComponent.isEnabled
### UiComponent.isEnabled
isEnabled():
Promise
<bool>
;
isEnabled():
Promise
\<
bool>
获取控件使能状态。
获取控件使能状态。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| -------------- | ----------------------------- |
| -------------- | -----------------------------
--
|
| Promise
<bool>
; | 以Promise形式返回控件使能状态
|
| Promise
\<
bool> | 以Promise形式返回控件使能状态。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
...
@@ -613,23 +760,21 @@ async function demo() {
...
@@ -613,23 +760,21 @@ async function demo() {
### UiComponent.isFocused
### UiComponent.isFocused
isFocused():
Promise
<bool>
;
isFocused():
Promise
\<
bool>
判断控件对象是否获焦。
判断控件对象是否获焦。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| -------------- | --------------------------------- |
| -------------- | ---------------------------------
--
|
| Promise
<bool>
; | 以Promise形式返回控件对象是否获焦
|
| Promise
\<
bool> | 以Promise形式返回控件对象是否获焦。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
...
@@ -644,23 +789,21 @@ async function demo() {
...
@@ -644,23 +789,21 @@ async function demo() {
### UiComponent.isSelected
### UiComponent.isSelected
isSelected():
Promise
<bool>
;
isSelected():
Promise
\<
bool>
获取控件对象被选中状态。
获取控件对象被选中状态。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
**返回值:**
| 类型 | 说明
|
| 类型 | 说明 |
| -------------- | --------------------
---------------
|
| -------------- | -------------------- |
| Promise
<bool>
; | 以Promise形式返回控件对象被选中
状态 |
| Promise
\<
bool> | 控件对象被选中的
状态 |
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
...
@@ -675,37 +818,51 @@ async function demo() {
...
@@ -675,37 +818,51 @@ async function demo() {
### UiComponent.inputText
### UiComponent.inputText
inputText(text: string):
Promise
<void>
;
inputText(text: string):
Promise
\<
void>
向控件中输入文本(适用于文本框控件)。
向控件中输入文本(适用于文本框控件)。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明
|
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ----------------
---------
|
| ------ | ------ | ---- | ---------------- |
| text | string | 是 |
用于向控件输入的文本信息,
|
| text | string | 是 |
输入的文本信息。
|
**示例:**
**示例:**
```
js
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
text
=
await
driver
.
findComponent
(
BY
.
text
(
'
hello world
'
))
await
text
.
inputText
(
'
123
'
)
}
```
```
### UiComponent.clearText<sup>9+</sup>
clearText(): Promise
\<
void>
清除控件的文本信息(适用于文本框控件)。
**系统能力**
:SystemCapability.Test.UiTest
**示例:**
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'button
'
))
let
text
=
await
driver
.
findComponent
(
BY
.
text
(
'
hello world
'
))
await
button
.
inputText
(
'next page'
)
await
text
.
clearText
(
)
}
}
```
```
### UiComponent.scrollSearch
### UiComponent.scrollSearch
scrollSearch(by:By):
Promise
<UiComponent>
;
scrollSearch(by:By):
Promise
\<
UiComponent>
在控件上滑动查找目标控件(适用于List等控件)。
在控件上滑动查找目标控件(适用于List等支持滑动的控件)。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
...
@@ -713,24 +870,85 @@ scrollSearch(by:By):Promise<UiComponent>;
...
@@ -713,24 +870,85 @@ scrollSearch(by:By):Promise<UiComponent>;
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---- | ---- | -------------------- |
| ------ | ---- | ---- | -------------------- |
| by | By | 是 | 目标控件的
体属性要求
|
| by | By | 是 | 目标控件的
属性要求。
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| --------------------- | ----------------------------------- |
| --------------------- | -----------------------------------
--
|
| Promise
<UiComponent>
; | 以Promise形式返回找到的目标控件对象
|
| Promise
\<
UiComponent> | 以Promise形式返回找到的目标控件对象。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
scrollBar
=
await
driver
.
findComponent
(
BY
.
scrollable
(
true
))
let
scrollBar
=
await
driver
.
findComponent
(
BY
.
type
(
'
Scroll
'
))
let
button
=
await
scrollBar
.
scrollSearch
(
BY
.
text
(
'
next page
'
))
let
button
=
await
scrollBar
.
scrollSearch
(
BY
.
text
(
'
next page
'
))
}
}
```
```
### UiComponent.scrollToTop<sup>9+</sup>
scrollToTop(): Promise
\<
void>
在控件上滑动到顶部(适用于List等支持滑动的控件)。
**系统能力**
:SystemCapability.Test.UiTest
**示例:**
```
js
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
scrollBar
=
await
driver
.
findComponent
(
BY
.
type
(
'
Scroll
'
))
await
scrollBar
.
scrollToTop
()
}
```
### UiComponent.scrollToBottom<sup>9+</sup>
scrollToBottom(): Promise
\<
void>
在控件上滑动到底部(适用于List等支持滑动的控件)。
**系统能力**
:SystemCapability.Test.UiTest
**示例:**
```
js
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
scrollBar
=
await
driver
.
findComponent
(
BY
.
type
(
'
Scroll
'
))
await
scrollBar
.
scrollToBottom
()
}
```
### UiComponent.dragTo<sup>9+</sup>
dragTo(by:By): Promise
\<
void>
将控件拖拽至目标控件处。
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---- | ---- | -------------------- |
| by | By | 是 | 目标控件的属性要求。 |
**示例:**
```
js
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
type
(
'
button
'
))
await
button
.
dragTo
(
BY
.
text
(
'
hello world
'
))
}
}
```
## UiDriver
## UiDriver
UiDriver类为uitest测试框架的总入口,提供控件匹配/查找,按键注入,坐标点击/滑动,截图等API。
UiDriver类为uitest测试框架的总入口,提供控件匹配/查找,按键注入,坐标点击/滑动,截图等API。
...
@@ -738,23 +956,21 @@ UiDriver类为uitest测试框架的总入口,提供控件匹配/查找,按
...
@@ -738,23 +956,21 @@ UiDriver类为uitest测试框架的总入口,提供控件匹配/查找,按
### UiDriver.create
### UiDriver.create
static create():
UiDriver;
static create():
UiDriver
静态方法,构造一个UiDriver对象,并返回该对象。
静态方法,构造一个UiDriver对象,并返回该对象。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| ------- | ---------------------- |
| ------- | ----------------------
--
|
| UiDrive | 返回构造的UiDriver对象 |
| UiDrive | 返回构造的UiDriver对象
。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
}
}
...
@@ -762,23 +978,21 @@ async function demo() {
...
@@ -762,23 +978,21 @@ async function demo() {
### UiDriver.delayMs
### UiDriver.delayMs
delayMs(duration:
number):Promise
<void>
;
delayMs(duration:
number): Promise
\<
void>
UiDriver对象在给定的时间内延时。
UiDriver对象在给定的时间内延时。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| -------- | ------ | ---- | ---------- |
| -------- | ------ | ---- | ----------
--
|
| duration | number | 是 | 给定的时间 |
| duration | number | 是 | 给定的时间
。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
await
driver
.
delayMs
(
1000
)
await
driver
.
delayMs
(
1000
)
...
@@ -787,29 +1001,27 @@ async function demo() {
...
@@ -787,29 +1001,27 @@ async function demo() {
### UiDriver.findComponent
### UiDriver.findComponent
findComponent(by:
By):Promise
<UiComponent>
;
findComponent(by:
By): Promise
\<
UiComponent>
在UiDriver对象中,根据给出的目标控件属性要求查找目标控件。
在UiDriver对象中,根据给出的目标控件属性要求查找目标控件。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ---- | ---- | ------------------ |
| ------ | ---- | ---- | ------------------
--
|
| by | By | 是 | 目标控件的属性要求 |
| by | By | 是 | 目标控件的属性要求
。
|
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明
|
| --------------------- | ------------------------------- |
| --------------------- | -------------------------------
--
|
| Promise
<UiComponent>
; | 以Promise形式返回找到的控件对象
|
| Promise
\<
UiComponent> | 以Promise形式返回找到的控件对象。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
findComponent
(
BY
.
text
(
'
next page
'
))
let
button
=
await
driver
.
findComponent
(
BY
.
text
(
'
next page
'
))
...
@@ -818,54 +1030,80 @@ async function demo() {
...
@@ -818,54 +1030,80 @@ async function demo() {
### UiDriver.findComponents
### UiDriver.findComponents
findComponents(by:
By):Promise
<Array
<
UiComponent
>
>;
findComponents(by:
By): Promise
\<
Array
\<
UiComponent>>
在UiDriver对象中,根据给出的目标控件属性要求查找出所有匹配控件,以列表保存。
在UiDriver对象中,根据给出的目标控件属性要求查找出所有匹配控件,以列表保存。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ---- | ---- | ------------------ |
| ------ | ---- | ---- | ------------------
--
|
| by | By | 是 | 目标控件的属性要求 |
| by | By | 是 | 目标控件的属性要求
。
|
**返回值:**
**返回值:**
| 类型
| 说明
|
| 类型
| 说明
|
| ----------------------------
|
------------------------------------- |
| ----------------------------
- | --
------------------------------------- |
| Promise
<Array
<
UiComponent
>
>; | 以Promise形式返回找到的控件对象的列表
|
| Promise
\<
Array
\<
UiComponent>> | 以Promise形式返回找到的控件对象的列表。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
let
buttonList
=
await
driver
.
findComponents
(
BY
.
text
(
'
next page
'
))
let
buttonList
=
await
driver
.
findComponents
(
BY
.
text
(
'
next page
'
))
}
}
```
```
### UiDriver.waitForComponent<sup>9+</sup>
waitForComponent(by: By, time: number): Promise
\<
UiComponent>
在UiDriver对象中,在用户给定的时间内,持续查找满足控件属性要求的目标控件。
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------------- |
| by | By | 是 | 目标控件的属性要求。 |
| time | number | 是 | 查找目标控件的持续时间。单位ms。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | --------------------------------- |
| Promise
\<
UiComponent> | 以Promise形式返回找到的控件对象。 |
**示例:**
```
js
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
button
=
await
driver
.
waitForComponent
(
BY
.
text
(
'
next page
'
),
500
)
}
```
### UiDriver.assertComponentExist
### UiDriver.assertComponentExist
assertComponentExist(by:
By):Promise
<void>
;
assertComponentExist(by:
By): Promise
\<
void>
断言API,用于断言当前界面存在满足给出的目标控件属性的控件; 如果控件不存在,该API将抛出JS异常,使当前测试用例失败。
断言API,用于断言当前界面存在满足给出的目标控件属性的控件; 如果控件不存在,该API将抛出JS异常,使当前测试用例失败。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------ | ---- | ---- | ------------------ |
| ------ | ---- | ---- | ------------------
--
|
| by | By | 是 | 目标控件的属性要求 |
| by | By | 是 | 目标控件的属性要求
。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
await
driver
.
assertComponentExist
(
BY
.
text
(
'
next page
'
))
await
driver
.
assertComponentExist
(
BY
.
text
(
'
next page
'
))
...
@@ -874,17 +1112,15 @@ async function demo() {
...
@@ -874,17 +1112,15 @@ async function demo() {
### UiDriver.pressBack
### UiDriver.pressBack
pressBack():
Promise
<void>
;
pressBack():
Promise
\<
void>
UiDriver对象进行点击BACK键的操作。
UiDriver对象进行点击BACK键的操作。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
await
driver
.
pressBack
()
await
driver
.
pressBack
()
...
@@ -893,23 +1129,21 @@ async function demo() {
...
@@ -893,23 +1129,21 @@ async function demo() {
### UiDriver.triggerKey
### UiDriver.triggerKey
triggerKey(keyCode:
number):Promise
<void>
;
triggerKey(keyCode:
number): Promise
\<
void>
UiDriver对象采取如下操作:通过key值找到对应键并点击。
UiDriver对象采取如下操作:通过key值找到对应键并点击。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明
|
| ------- | ------ | ---- | --------- |
| ------- | ------ | ---- | ---------
----
|
| keyCode | number | 是 | 指定
key值
|
| keyCode | number | 是 | 指定
的key值。
|
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
await
driver
.
triggerKey
(
123
)
await
driver
.
triggerKey
(
123
)
...
@@ -918,23 +1152,22 @@ async function demo() {
...
@@ -918,23 +1152,22 @@ async function demo() {
### UiDriver.click
### UiDriver.click
click(x:
number,y:number):Promise
<void>
;
click(x:
number, y: number): Promise
\<
void>
UiDriver对象采取如下操作:在目标坐标点单击。
UiDriver对象采取如下操作:在目标坐标点单击。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------- | ---- | ------------------------------------------- |
| ------ | ------ | ---- | -------------------------------------- |
| x,y | number,number | 是 | 以(number,number)的形式传入特定点的坐标信息 |
| x | number | 是 | 以number的形式传入目标点的横坐标信息。 |
| y | number | 是 | 以number的形式传入目标点的纵坐标信息。 |
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
await
driver
.
click
(
100
,
100
)
await
driver
.
click
(
100
,
100
)
...
@@ -943,23 +1176,22 @@ async function demo() {
...
@@ -943,23 +1176,22 @@ async function demo() {
### UiDriver.doubleClick
### UiDriver.doubleClick
doubleClick(x:
number,y:number):Promise
<void>
;
doubleClick(x:
number, y: number): Promise
\<
void>
UiDriver对象采取如下操作:在目标坐标点双击。
UiDriver对象采取如下操作:在目标坐标点双击。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------- | ---- | ------------------------------------------- |
| ------ | ------ | ---- | -------------------------------------- |
| x,y | number,number | 是 | 以(number,number)的形式传入特定点的坐标信息 |
| x | number | 是 | 以number的形式传入目标点的横坐标信息。 |
| y | number | 是 | 以number的形式传入目标点的纵坐标信息。 |
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
await
driver
.
doubleClick
(
100
,
100
)
await
driver
.
doubleClick
(
100
,
100
)
...
@@ -968,23 +1200,22 @@ async function demo() {
...
@@ -968,23 +1200,22 @@ async function demo() {
### UiDriver.longClick
### UiDriver.longClick
longClick(x:
number,y:number):Promise
<void>
;
longClick(x:
number, y: number): Promise
\<
void>
UiDriver对象采取如下操作:在目标坐标点长按下鼠标左键。
UiDriver对象采取如下操作:在目标坐标点长按下鼠标左键。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------- | ---- | ------------------------------------------- |
| ------ | ------ | ---- | -------------------------------------- |
| x,y | number,number | 是 | 以(number,number)的形式传入特定点的坐标信息 |
| x | number | 是 | 以number的形式传入目标点的横坐标信息。 |
| y | number | 是 | 以number的形式传入目标点的纵坐标信息。 |
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
await
driver
.
longClick
(
100
,
100
)
await
driver
.
longClick
(
100
,
100
)
...
@@ -993,52 +1224,96 @@ async function demo() {
...
@@ -993,52 +1224,96 @@ async function demo() {
### UiDriver.swipe
### UiDriver.swipe
swipe(startx:
number,starty:number,endx:number,endy:number):Promise
<void>
;
swipe(startx:
number, starty: number, endx: number, endy: number): Promise
\<
void>
UiDriver对象采取如下操作:从给出的起始坐标点滑向给出的目的坐标点。
UiDriver对象采取如下操作:从给出的起始坐标点滑向给出的目的坐标点。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | ------------- | ---- | ------------------------------------------- |
| ------ | ------ | ---- | -------------------------------------- |
| startx,starty | number,number | 是 | 以(number,number)的形式传入起始点的坐标信息 |
| startx | number | 是 | 以number的形式传入起始点的横坐标信息。 |
| endx,endy | number,number | 是 | 以(number,number)的形式传入目的点的坐标信息 |
| starty | number | 是 | 以number的形式传入起始点的纵坐标信息。 |
| endx | number | 是 | 以number的形式传入目的点的横坐标信息。 |
| endy | number | 是 | 以number的形式传入目的点的纵坐标信息。 |
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
await
driver
.
swipe
(
100
,
100
,
200
,
200
)
await
driver
.
swipe
(
100
,
100
,
200
,
200
)
}
}
```
```
### UiDriver.drag<sup>9+</sup>
drag(startx: number, starty: number, endx: number, endy: number): Promise
\<
void>
UiDriver对象采取如下操作:从给出的起始坐标点拖拽至给出的目的坐标点。
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------------------- |
| startx | number | 是 | 以number的形式传入起始点的横坐标信息。 |
| starty | number | 是 | 以number的形式传入起始点的纵坐标信息。 |
| endx | number | 是 | 以number的形式传入目的点的横坐标信息。 |
| endy | number | 是 | 以number的形式传入目的点的纵坐标信息。 |
**示例:**
```
js
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
await
driver
.
drag
(
100
,
100
,
200
,
200
)
}
```
### UiDriver.screenCap
### UiDriver.screenCap
screenCap(savePath:
string):Promise
<bool>
;
screenCap(savePath:
string): Promise
\<
bool>
UiDriver对象采取如下操作:捕获当前屏幕,并保存为PNG格式的图片至给出的保存路径中。
UiDriver对象采取如下操作:捕获当前屏幕,并保存为PNG格式的图片至给出的保存路径中。
**需要权限**
:NA
**系统能力**
:SystemCapability.Test.UiTest
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------ |
| -------- | ------ | ---- | -------------- |
| savePath | string | 是 | 文件保存路径 |
| savePath | string | 是 | 文件保存路径。 |
**返回值:**
| 类型 | 说明 |
| -------------- | -------------------------------------- |
| Promise
\<
bool> | 截图操作是否成功完成。成功完成为true。 |
**示例:**
**示例:**
```
```
js
async
function
demo
()
{
async
function
demo
()
{
let
driver
=
UiDriver
.
create
()
let
driver
=
UiDriver
.
create
()
await
driver
.
screenCap
(
'
/local/tmp/
'
)
await
driver
.
screenCap
(
'
/local/tmp/
'
)
}
}
```
```
## MatchPattern
控件属性支持的匹配模式。
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Test.UiTest
| 名称 | 值 | 说明 |
| ----------- | ---- | -------------- |
| EQUALS | 0 | 等于给定值。 |
| CONTAINS | 1 | 包含给定值。 |
| STARTS_WITH | 2 | 从给定值开始。 |
| ENDS_WITH | 3 | 以给定值结束。 |
###
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录