From df005cf6c717b03f3ac7134b90d1897952f39ab3 Mon Sep 17 00:00:00 2001 From: zhouke Date: Mon, 15 May 2023 18:09:03 +0800 Subject: [PATCH] modify.Signed-off-by: . Signed-off-by: zhouke --- .../reference/apis/js-apis-uitest.md | 294 ++++++++++-------- 1 file changed, 160 insertions(+), 134 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-uitest.md b/zh-cn/application-dev/reference/apis/js-apis-uitest.md index 01bf817f7b..f61b1bb6a9 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-uitest.md +++ b/zh-cn/application-dev/reference/apis/js-apis-uitest.md @@ -20,7 +20,7 @@ UiTest提供模拟UI操作的能力,供开发者在测试场景使用,主要 ## 导入模块 ```js -import {UiComponent, UiDriver, Component, Driver, UiWindow, ON, BY, MatchPattern, DisplayRotation, ResizeDirection, WindowMode, PointerMatrix, UiDirection, MouseButton, UiElementInfo, UiEventObserver} 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,7 +141,7 @@ import {UiComponent, UiDriver, Component, Driver, UiWindow, ON, BY, MatchPattern | MOUSE_BUTTON_RIGHT | 1 | 鼠标右键。 | | MOUSE_BUTTON_MIDDLE | 2 | 鼠标中间键。 | -## UiElementInfo10+ +## UIElementInfo10+ UI事件的相关信息。 @@ -576,8 +576,8 @@ click(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -603,8 +603,8 @@ doubleClick(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -630,8 +630,8 @@ longClick(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -663,8 +663,8 @@ getId(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -696,8 +696,8 @@ getText(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -729,8 +729,8 @@ getType(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -762,8 +762,8 @@ getBounds(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -795,8 +795,8 @@ getBoundsCenter(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -828,8 +828,8 @@ isClickable(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -865,8 +865,8 @@ isLongClickable(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -902,8 +902,8 @@ isChecked(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -939,8 +939,8 @@ isCheckable(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -976,8 +976,8 @@ isScrollable(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1014,8 +1014,8 @@ isEnabled(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1052,8 +1052,8 @@ isFocused(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1089,8 +1089,8 @@ isSelected(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1126,8 +1126,8 @@ inputText(text: string): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1151,8 +1151,8 @@ clearText(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1190,8 +1190,8 @@ scrollSearch(on: On): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1223,8 +1223,8 @@ scrollToTop(speed?: number): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1256,8 +1256,8 @@ scrollToBottom(speed?: number): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1289,8 +1289,8 @@ dragTo(target: Component): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1323,8 +1323,8 @@ pinchOut(scale: number): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1356,8 +1356,8 @@ pinchIn(scale: number): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -1424,7 +1424,7 @@ Driver对象在给定的时间内延时。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1461,7 +1461,7 @@ findComponent(on: On): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1498,7 +1498,7 @@ findComponents(on: On): Promise\> | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1535,7 +1535,7 @@ findWindow(filter: WindowFilter): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1573,7 +1573,7 @@ waitForComponent(on: On, time: number): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1604,7 +1604,7 @@ assertComponentExist(on: On): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | | 17000003 | Component existence assertion failed. | **示例:** @@ -1630,7 +1630,7 @@ Driver对象进行点击BACK键的操作。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1661,7 +1661,7 @@ Driver对象采取如下操作:传入key值实现模拟点击对应按键的 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1694,7 +1694,7 @@ Driver对象通过给定的key值,找到对应组合键并点击。例如,Ke | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1727,7 +1727,7 @@ Driver对象采取如下操作:在目标坐标点单击。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1759,7 +1759,7 @@ Driver对象采取如下操作:在目标坐标点双击。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1791,7 +1791,7 @@ Driver对象采取如下操作:在目标坐标点长按。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1826,7 +1826,7 @@ Driver对象采取如下操作:从起始坐标点滑向目的坐标点。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1861,7 +1861,7 @@ Driver对象采取如下操作:从起始坐标点拖拽至目的坐标点。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1898,7 +1898,7 @@ Driver对象采取如下操作:捕获当前屏幕,并保存为PNG格式的 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1929,7 +1929,7 @@ setDisplayRotation(rotation: DisplayRotation): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1960,7 +1960,7 @@ getDisplayRotation(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1991,7 +1991,7 @@ setDisplayRotationEnabled(enabled: boolean): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2022,7 +2022,7 @@ getDisplaySize(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2053,7 +2053,7 @@ getDisplayDensity(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2078,7 +2078,7 @@ wakeUpDisplay(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2103,7 +2103,7 @@ pressHome(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2141,7 +2141,7 @@ waitForIdle(idleTime: number, timeout: number): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2175,7 +2175,7 @@ fling(from: Point, to: Point, stepLen: number, speed: number): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2213,7 +2213,7 @@ injectMultiPointerAction(pointers: PointerMatrix, speed?: number): Promise\10+ -fling(direction: UiDirection, speed: number): Promise; +fling(direction: UiDirection, speed: number): Promise\; 指定方向和速度,模拟手指滑动后脱离屏幕的快速滑动操作。 @@ -2252,7 +2252,7 @@ fling(direction: UiDirection, speed: number): Promise; | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2265,7 +2265,7 @@ async function demo() { ### screenCapture10+ -screenCapture(savePath: string, rect?: Rect): Promise; +screenCapture(savePath: string, rect?: Rect): Promise\; 捕获当前屏幕的指定区域,并保存为PNG格式的图片至给出的保存路径中。 @@ -2290,7 +2290,7 @@ screenCapture(savePath: string, rect?: Rect): Promise; | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2303,7 +2303,7 @@ async function demo() { ### mouseClick10+ -mouseClick(p: Point, btnId: MouseButton, key1?: number, key2?: number): Promise; +mouseClick(p: Point, btnId: MouseButton, key1?: number, key2?: number): Promise\; 在指定坐标点注入鼠标点击动作,支持同时按下对应键盘组合键。例如,Key值为2072时,按下ctrl并进行鼠标点击动作。 @@ -2315,7 +2315,7 @@ mouseClick(p: Point, btnId: MouseButton, key1?: number, key2?: number): Promise< | ------ | ----------------------------- | ---- | ------------------- | | p | [Point](#point9) | 是 | 鼠标点击的坐标。 | | btnId | [MouseButton](#mousebutton10) | 是 | 按下的鼠标按钮。 | -| key1 | number | 是 | 指定的第一个key值。 | +| key1 | number | 否 | 指定的第一个key值。 | | key2 | number | 否 | 指定的第二个key值。 | **错误码:** @@ -2324,7 +2324,7 @@ mouseClick(p: Point, btnId: MouseButton, key1?: number, key2?: number): Promise< | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2337,7 +2337,7 @@ async function demo() { ### mouseScroll10+ -mouseScroll(p: Point, down: boolean, d: number, key1?: number, key2?: number): Promise; +mouseScroll(p: Point, down: boolean, d: number, key1?: number, key2?: number): Promise\; 在指定坐标点注入鼠标滚轮滑动动作,支持同时按下对应键盘组合键。例如,Key值为2072时,按下ctrl并进行鼠标滚轮滑动动作。 @@ -2350,7 +2350,7 @@ mouseScroll(p: Point, down: boolean, d: number, key1?: number, key2?: number): P | p | [Point](#point9) | 是 | 鼠标点击的坐标。 | | down | boolean | 是 | 滚轮滑动方向是否向下。 | | d | number | 是 | 鼠标滚轮滚动的格数,每格对应目标点位移120个像素点。 | -| key1 | number | 是 | 指定的第一个key值。 | +| key1 | number | 否 | 指定的第一个key值。 | | key2 | number | 否 | 指定的第二个key值。 | **错误码:** @@ -2359,7 +2359,7 @@ mouseScroll(p: Point, down: boolean, d: number, key1?: number, key2?: number): P | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2372,7 +2372,7 @@ async function demo() { ### mouseMoveTo10+ -mouseMoveTo(p: Point): Promise; +mouseMoveTo(p: Point): Promise\; 将鼠标光标移到目标点。 @@ -2390,7 +2390,7 @@ mouseMoveTo(p: Point): Promise; | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2401,9 +2401,9 @@ async function demo() { } ``` -### createUiEventObserver10+ +### createUIEventObserver10+ -createUiEventObserver(): UiEventObserver; +createUIEventObserver(): UIEventObserver; 创建一个UI事件监听器。 @@ -2413,7 +2413,7 @@ createUiEventObserver(): UiEventObserver; | 类型 | 说明 | | ----------------------------------------------- | ------------------------------------- | -| Promise\<[UiEventObserver](#uieventobserver10)> | 以Promise形式返回找到的目标窗口对象。 | +| Promise\<[UIEventObserver](#uieventobserver10)> | 以Promise形式返回找到的目标窗口对象。 | **错误码:** @@ -2421,7 +2421,7 @@ createUiEventObserver(): UiEventObserver; | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2520,8 +2520,8 @@ getBundleName(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -2553,8 +2553,8 @@ getBounds(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -2586,8 +2586,8 @@ getTitle(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -2619,8 +2619,8 @@ getWindowMode(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -2652,8 +2652,8 @@ isFocused(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -2685,8 +2685,8 @@ isActived(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -2712,8 +2712,8 @@ focus(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | **示例:** @@ -2746,8 +2746,8 @@ moveTo(x: number, y: number): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | | 17000005 | This operation is not supported. | **示例:** @@ -2782,8 +2782,8 @@ resize(wide: number, height: number, direction: ResizeDirection): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | | 17000005 | This operation is not supported. | **示例:** @@ -2810,8 +2810,8 @@ split(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | | 17000005 | This operation is not supported. | **示例:** @@ -2838,8 +2838,8 @@ maximize(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | | 17000005 | This operation is not supported. | **示例:** @@ -2866,8 +2866,8 @@ minimize(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | | 17000005 | This operation is not supported. | **示例:** @@ -2894,8 +2894,8 @@ resume(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | | 17000005 | This operation is not supported. | **示例:** @@ -2922,8 +2922,8 @@ close(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | -| 17000004 | Component lost/UiWindow lost. | +| 17000002 | if the async function was not called with await. | +| 17000004 | if the component is invisible or destroyed. | | 17000005 | This operation is not supported. | **示例:** @@ -2936,38 +2936,64 @@ async function demo() { } ``` -## UiEventObserver10+ +## UIEventObserver10+ UI事件监听器。 -### once10+ +### once('toastShow')10+ -once(type: 'toastShow', callback: Callback): void; +once(type: 'toastShow', callback: Callback\):void; -once(type: 'dialogShow', callback: Callback): void; - -监听事件,事件发生时执行对应的回调方法。 +开始监听toast控件出现的事件,使用callback的形式返回结果。 **系统能力**:SystemCapability.Test.UiTest **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------- | ---- | -------------------- | -| type | string | 是 | 监听的事件名称 | -| callback | Callback<[UiElementInfo](#uielementinfo10)> | 是 | 事件发生时执行的回调 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------------------------------- | ---- | --------------------------------- | +| type | string | 是 | 订阅的事件类型,取值为'toastShow' | +| 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) + let observer = await driver.createUIEventObserver() + let callback = (UIElementInfo)=>{ + console.info(UIElementInfo.bundleName) + console.info(UIElementInfo.text) + console.info(UIElementInfo.type) } observer.once('toastShow', callback) +} +``` + +### once('dialogShow')10+ + +once(type: 'dialogShow', callback: Callback\): void; + +开始监听dialog控件出现的事件,使用callback的形式返回结果。 + +**系统能力**:SystemCapability.Test.UiTest + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------------------------------- | ---- | ---------------------------------- | +| type | string | 是 | 订阅的事件类型,取值为'dialogShow' | +| 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('dialogShow', callback) } ``` -- GitLab