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 84cb3f5d01d51e217035371df3e1e447103eaa8d..3532860d68579c99d8cb75709070ce54aacfb44a 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} 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 | 鼠标中间键。 | +## UIElementInfo10+ + +UI事件的相关信息。 + +**系统能力**:SystemCapability.Test.UiTest + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ---------- | ------ | ---- | ---- | --------------------- | +| bundleName | string | 是 | 否 | 归属应用的包名。 | +| type | string | 是 | 否 | 控件/窗口类型。 | +| text | string | 是 | 否 | 控件/窗口的文本信息。 | + ## On9+ UiTest框架在API 9中,通过On类提供了丰富的控件特征描述API,用于进行控件筛选来匹配/查找出目标控件。
@@ -564,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. | **示例:** @@ -591,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. | **示例:** @@ -618,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. | **示例:** @@ -651,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. | **示例:** @@ -684,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. | **示例:** @@ -717,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. | **示例:** @@ -750,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. | **示例:** @@ -783,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. | **示例:** @@ -816,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. | **示例:** @@ -853,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. | **示例:** @@ -890,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. | **示例:** @@ -899,7 +911,7 @@ isChecked(): Promise\ 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'); @@ -927,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. | **示例:** @@ -936,7 +948,7 @@ isCheckable(): Promise\ 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'); @@ -964,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. | **示例:** @@ -1002,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. | **示例:** @@ -1040,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. | **示例:** @@ -1077,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. | **示例:** @@ -1114,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. | **示例:** @@ -1139,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. | **示例:** @@ -1178,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. | **示例:** @@ -1211,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. | **示例:** @@ -1244,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. | **示例:** @@ -1277,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. | **示例:** @@ -1311,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. | **示例:** @@ -1344,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. | **示例:** @@ -1412,7 +1424,7 @@ Driver对象在给定的时间内延时。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1449,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. | **示例:** @@ -1486,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. | **示例:** @@ -1523,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. | **示例:** @@ -1561,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. | **示例:** @@ -1592,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. | **示例:** @@ -1618,7 +1630,7 @@ Driver对象进行点击BACK键的操作。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1649,7 +1661,7 @@ Driver对象采取如下操作:传入key值实现模拟点击对应按键的 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1682,7 +1694,7 @@ Driver对象通过给定的key值,找到对应组合键并点击。例如,Ke | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1715,7 +1727,7 @@ Driver对象采取如下操作:在目标坐标点单击。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1747,7 +1759,7 @@ Driver对象采取如下操作:在目标坐标点双击。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1779,7 +1791,7 @@ Driver对象采取如下操作:在目标坐标点长按。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1814,7 +1826,7 @@ Driver对象采取如下操作:从起始坐标点滑向目的坐标点。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1849,7 +1861,7 @@ Driver对象采取如下操作:从起始坐标点拖拽至目的坐标点。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1886,7 +1898,7 @@ Driver对象采取如下操作:捕获当前屏幕,并保存为PNG格式的 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1917,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. | **示例:** @@ -1948,7 +1960,7 @@ getDisplayRotation(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -1979,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. | **示例:** @@ -2010,7 +2022,7 @@ getDisplaySize(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2041,7 +2053,7 @@ getDisplayDensity(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2066,7 +2078,7 @@ wakeUpDisplay(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2091,7 +2103,7 @@ pressHome(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 17000002 | API does not allow calling concurrently. | +| 17000002 | if the async function was not called with await. | **示例:** @@ -2129,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. | **示例:** @@ -2163,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. | **示例:** @@ -2201,7 +2213,7 @@ injectMultiPointerAction(pointers: PointerMatrix, speed?: number): Promise\10+ -fling(direction: UiDirection, speed: number): Promise; +fling(direction: UiDirection, speed: number): Promise\; 指定方向和速度,模拟手指滑动后脱离屏幕的快速滑动操作。 @@ -2240,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. | **示例:** @@ -2253,7 +2265,7 @@ async function demo() { ### screenCapture10+ -screenCapture(savePath: string, rect?: Rect): Promise; +screenCapture(savePath: string, rect?: Rect): Promise\; 捕获当前屏幕的指定区域,并保存为PNG格式的图片至给出的保存路径中。 @@ -2278,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. | **示例:** @@ -2291,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并进行鼠标点击动作。 @@ -2303,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值。 | **错误码:** @@ -2312,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. | **示例:** @@ -2325,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并进行鼠标滚轮滑动动作。 @@ -2338,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值。 | **错误码:** @@ -2347,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. | **示例:** @@ -2360,7 +2372,7 @@ async function demo() { ### mouseMoveTo10+ -mouseMoveTo(p: Point): Promise; +mouseMoveTo(p: Point): Promise\; 将鼠标光标移到目标点。 @@ -2378,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. | **示例:** @@ -2389,6 +2401,37 @@ async function demo() { } ``` +### createUIEventObserver10+ + +createUIEventObserver(): UIEventObserver; + +创建一个UI事件监听器。 + +**系统能力**:SystemCapability.Test.UiTest + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------------------- | ------------------------------------- | +| Promise\<[UIEventObserver](#uieventobserver10)> | 以Promise形式返回找到的目标窗口对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[uitest测试框架错误码](../errorcodes/errorcode-uitest.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 17000002 | if the async function was not called with await. | + +**示例:** + +```js +async function demo() { + let driver = Driver.create(); + let obeserver = await driver.createUiEventObserve(); +} +``` + ## PointerMatrix9+ 存储多指操作中每根手指每一步动作的坐标点及其行为的二维数组。 @@ -2477,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. | **示例:** @@ -2510,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. | **示例:** @@ -2543,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. | **示例:** @@ -2576,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. | **示例:** @@ -2609,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. | **示例:** @@ -2642,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. | **示例:** @@ -2669,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. | **示例:** @@ -2703,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. | **示例:** @@ -2739,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. | **示例:** @@ -2767,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. | **示例:** @@ -2795,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. | **示例:** @@ -2823,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. | **示例:** @@ -2851,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. | **示例:** @@ -2879,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. | **示例:** @@ -2893,6 +2936,68 @@ async function demo() { } ``` +## UIEventObserver10+ + +UI事件监听器。 + +### once('toastShow') + +once(type: 'toastShow', callback: Callback\):void; + +开始监听toast控件出现的事件,使用callback的形式返回结果。 + +**系统能力**:SystemCapability.Test.UiTest + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------------------------------- | ---- | --------------------------------- | +| 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) + } + observer.once('toastShow', callback) +} +``` + +### once('dialogShow') + +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) +} +``` + ## By(deprecated) UiTest框架通过By类提供了丰富的控件特征描述API,用于进行控件筛选来匹配/查找出目标控件。