Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
55b9befd
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看板
提交
55b9befd
编写于
5月 13, 2023
作者:
Z
zhouke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
uitest补充新接口说明.Signed-off-by: <zhouke35@huawei.com>.
Signed-off-by:
N
zhouke
<
zhouke35@huawei.com
>
上级
7d82c2bf
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
3 deletion
+82
-3
zh-cn/application-dev/reference/apis/js-apis-uitest.md
zh-cn/application-dev/reference/apis/js-apis-uitest.md
+82
-3
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-uitest.md
浏览文件 @
55b9befd
...
...
@@ -20,7 +20,7 @@ UiTest提供模拟UI操作的能力,供开发者在测试场景使用,主要
## 导入模块
```
js
import
{
UiComponent
,
UiDriver
,
Component
,
Driver
,
UiWindow
,
ON
,
BY
,
MatchPattern
,
DisplayRotation
,
ResizeDirection
,
WindowMode
,
PointerMatrix
,
UiDirection
,
MouseButton
}
from
'
@ohos.UiTest
'
;
import
{
UiComponent
,
UiDriver
,
Component
,
Driver
,
UiWindow
,
ON
,
BY
,
MatchPattern
,
DisplayRotation
,
ResizeDirection
,
WindowMode
,
PointerMatrix
,
UiDirection
,
MouseButton
,
UiElementInfo
,
UiEventObserver
}
from
'
@ohos.UiTest
'
;
```
## MatchPattern
...
...
@@ -141,6 +141,18 @@ import {UiComponent, UiDriver, Component, Driver, UiWindow, ON, BY, MatchPattern
| MOUSE_BUTTON_RIGHT | 1 | 鼠标右键。 |
| MOUSE_BUTTON_MIDDLE | 2 | 鼠标中间键。 |
## UiElementInfo<sup>10+</sup>
UI事件的相关信息。
**系统能力**
:SystemCapability.Test.UiTest
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ---------- | ------ | ---- | ---- | --------------------- |
| bundleName | string | 是 | 否 | 归属应用的包名。 |
| type | string | 是 | 否 | 控件/窗口类型。 |
| text | string | 是 | 否 | 控件/窗口的文本信息。 |
## On<sup>9+</sup>
UiTest框架在API 9中,通过On类提供了丰富的控件特征描述API,用于进行控件筛选来匹配/查找出目标控件。
<br>
...
...
@@ -899,7 +911,7 @@ isChecked(): Promise\<boolean>
async
function
demo
()
{
let
driver
=
Driver
.
create
();
let
checkBox
=
await
driver
.
findComponent
(
ON
.
type
(
'
Checkbox
'
));
if
(
await
checkBox
.
isChecked
)
{
if
(
await
checkBox
.
isChecked
()
)
{
console
.
info
(
'
This checkBox is checked
'
);
}
else
{
console
.
info
(
'
This checkBox is not checked
'
);
...
...
@@ -936,7 +948,7 @@ isCheckable(): Promise\<boolean>
async
function
demo
()
{
let
driver
=
Driver
.
create
();
let
checkBox
=
await
driver
.
findComponent
(
ON
.
type
(
'
Checkbox
'
));
if
(
await
checkBox
.
isCheckable
)
{
if
(
await
checkBox
.
isCheckable
()
)
{
console
.
info
(
'
This checkBox is checkable
'
);
}
else
{
console
.
info
(
'
This checkBox is not checkable
'
);
...
...
@@ -2389,6 +2401,37 @@ async function demo() {
}
```
### createUiEventObserver<sup>10+</sup>
createUiEventObserver(): UiEventObserver;
创建一个UI事件监听器。
**系统能力**
:SystemCapability.Test.UiTest
**返回值:**
| 类型 | 说明 |
| ----------------------------------------------- | ------------------------------------- |
| Promise
\<
[
UiEventObserver
](
#uieventobserver10
)
> | 以Promise形式返回找到的目标窗口对象。 |
**错误码:**
以下错误码的详细介绍请参见
[
uitest测试框架错误码
](
../errorcodes/errorcode-uitest.md
)
。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 17000002 | API does not allow calling concurrently. |
**示例:**
```
js
async
function
demo
()
{
let
driver
=
Driver
.
create
();
let
obeserver
=
await
driver
.
createUiEventObserve
();
}
```
## PointerMatrix<sup>9+</sup>
存储多指操作中每根手指每一步动作的坐标点及其行为的二维数组。
...
...
@@ -2893,6 +2936,42 @@ async function demo() {
}
```
## UiEventObserver<sup>10+</sup>
UI事件监听器。
### once<sup>10+</sup>
once(type: 'toastShow', callback: Callback
<UiElementInfo>
): void;
once(type: 'dialogShow', callback: Callback
<UiElementInfo>
): void;
监听事件,事件发生时执行对应的回调方法。
**系统能力**
:SystemCapability.Test.UiTest
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | -------------------- |
| type | string | 是 | 监听的事件名称 |
| callback | Callback
<
[
UiElementInfo
](
#uielementinfo10
)
>
| 是 | 事件发生时执行的回调 |
**示例:**
```
js
async
function
demo
()
{
let
observer
=
await
driver
.
createUiEventObserver
()
let
callback
=
(
UiElementInfo
)
=>
{
console
.
info
(
UiElementInfo
.
bundleName
)
console
.
info
(
UiElementInfo
.
text
)
console
.
info
(
UiElementInfo
.
type
)
}
observer
.
once
(
'
toastShow
'
,
callback
)
observer
.
once
(
'
dialogShow
'
,
callback
)
}
```
## By<sup>(deprecated)</sup>
UiTest框架通过By类提供了丰富的控件特征描述API,用于进行控件筛选来匹配/查找出目标控件。
<br>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录