1/** 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' 16import abilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; 17import { UiComponent, UiDriver, BY, Component, Driver, UiWindow, ON, MatchPattern, DisplayRotation, ResizeDirection, UiDirection, MouseButton, WindowMode, PointerMatrix, UIElementInfo, UIEventObserver } from '@ohos.UiTest' 18import ability_featureAbility from '@ohos.ability.featureAbility'; 19import { BusinessError } from '@ohos.base'; 20import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; 21 22const delegator : AbilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); 23const bundleName : string = abilityDelegatorRegistry.getArguments().bundleName; 24const waitUiReadyMs : number = 1000; 25 26async function startAbility(bundleName: string, abilityName: string) { 27 await delegator.executeShellCommand(`aa start -b ${bundleName} -a ${abilityName}`).then(result => { 28 console.info(`UiTestCase, start abilityFinished: ${result}`) 29 }).catch((err : BusinessError) => { 30 console.error(`UiTestCase, start abilityFailed: ${err}`) 31 }) 32} 33 34async function stopApplication(bundleName: string) { 35 await delegator.executeShellCommand(`aa force-stop ${bundleName} `).then(result => { 36 console.info(`UiTestCase, stop application finished: ${result}`) 37 }).catch((err : BusinessError) => { 38 console.error(`UiTestCase,stop application failed: ${err}`) 39 }) 40} 41 42export default function UiTest() { 43 describe('UiTest_API11', () => { 44 beforeEach(async () => { 45 await stopApplication('com.uitestScene.acts') 46 }) 47 48 /* 49 * @tc.number: uiTest_11001 50 * @tc.name: testMouseDoubleClick 51 * @tc.desc: doubleClick in the specified location on the screen by mouse. 52 */ 53 it('testMouseDoubleClick', 0, async () => { 54 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 55 let driver : Driver = Driver.create() 56 await driver.delayMs(waitUiReadyMs) 57 let Button = await driver.findComponent(ON.text('Click twice')) 58 let center = await Button.getBoundsCenter() 59 await driver.mouseDoubleClick(center, MouseButton.MOUSE_BUTTON_LEFT, 0, 0); 60 await driver.delayMs(waitUiReadyMs) 61 let button = await driver.findComponent(ON.text('doubleClick')) 62 let text = await button.getText() 63 expect(text == 'doubleClick').assertTrue() 64 }) 65 66 /* 67 * @tc.number: uiTest_11002 68 * @tc.name: testMouseLongClick 69 * @tc.desc: longClick in the specified location on the screen by mouse. 70 */ 71 it('testMouseLongClick', 0, async () => { 72 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 73 let driver = Driver.create() 74 await driver.delayMs(waitUiReadyMs) 75 let Button = await driver.findComponent(ON.text('next page')) 76 let center = await Button.getBoundsCenter() 77 await driver.mouseLongClick(center, MouseButton.MOUSE_BUTTON_LEFT, 0, 0) 78 await driver.delayMs(waitUiReadyMs) 79 let newButton = await driver.findComponent(ON.text('longClick')) 80 let text = await newButton.getText() 81 expect(text == 'longClick').assertTrue() 82 }) 83 84 /* 85 * @tc.number: uiTest_11003 86 * @tc.name: testMouseDrag 87 * @tc.desc: drag on the screen between the specified points by mouse. 88 */ 89 it('testMouseDrag', 0, async () => { 90 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 91 let driver = Driver.create() 92 await driver.delayMs(waitUiReadyMs) 93 let button = await driver.findComponent(ON.id('jump')) 94 let center = await button.getBoundsCenter(); 95 await driver.mouseLongClick(center, MouseButton.MOUSE_BUTTON_LEFT) 96 await driver.delayMs(waitUiReadyMs) 97 let text1 = await driver.findComponent(ON.text('two')) 98 let text2 = await driver.findComponent(ON.text('three')) 99 let point1 = await text1.getBoundsCenter() 100 let point2 = await text2.getBoundsCenter() 101 await driver.mouseDrag(point1, point2, 600) 102 await driver.delayMs(2000) 103 let text = await driver.findComponent(ON.text('one').isBefore(ON.text('two'))) 104 expect(text == null).assertTrue() 105 }) 106 107 /* 108 * @tc.number: uiTest_11004 109 * @tc.name: testMouseMoveWithTrack 110 * @tc.desc: swipe on the screen between the specified points with mouse. 111 */ 112 it('testMouseMoveWithTrack', 0, async () => { 113 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 114 let driver = Driver.create() 115 await driver.delayMs(waitUiReadyMs) 116 let Button1 = await driver.findComponent(ON.id('jump')) 117 let Button2 = await driver.findComponent(ON.text('next page')) 118 let center1 = await Button1.getBoundsCenter() 119 let center2 = await Button2.getBoundsCenter() 120 await driver.mouseMoveTo(center1) 121 await driver.delayMs(waitUiReadyMs) 122 await driver.mouseMoveWithTrack(center1, center2, 600) 123 await driver.delayMs(waitUiReadyMs) 124 let newButton = await driver.findComponent(ON.text('jump')) 125 expect(newButton == null).assertTrue() 126 }) 127 128 /* 129 * @tc.number: uiTest_11005 130 * @tc.name: testDriverInputText 131 * @tc.desc: inject text on the specified location. 132 */ 133 it('testDriverInputText', 0, async () => { 134 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 135 let driver = Driver.create() 136 await driver.delayMs(waitUiReadyMs) 137 let inputText = await driver.findComponent(ON.type('TextInput')) 138 await inputText.click() 139 await driver.delayMs(waitUiReadyMs) 140 let permissionBtn = await driver.findComponent(ON.text('同意')) 141 if (permissionBtn != null) { 142 await permissionBtn.click() 143 await driver.delayMs(waitUiReadyMs) 144 } 145 let input = await driver.findComponent(ON.type('TextInput')) 146 await input.clearText() 147 await driver.delayMs(waitUiReadyMs) 148 let center = await input.getBoundsCenter() 149 await driver.inputText(center, '123') 150 await driver.delayMs(2000) 151 let input_new = await driver.findComponent(ON.type('TextInput')) 152 let text = await input_new.getText() 153 console.info("testInputText result :" + text) 154 expect(text == '123').assertTrue() 155 }) 156 157 /* 158 * @tc.number: uiTest_11006 159 * @tc.name: testMouseScroll 160 * @tc.desc: scroll the mouse wheel at the specified location to specify the cell. 161 */ 162 it('testMouseScroll', 0, async () => { 163 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 164 let driver = Driver.create() 165 await driver.delayMs(waitUiReadyMs) 166 let btn = await driver.findComponent(ON.id('jump')) 167 await btn.click() 168 await driver.delayMs(waitUiReadyMs) 169 let img1 = await driver.findComponent(ON.id('test_pict')) 170 let bounds1 = await img1.getBounds() 171 let center1 = await img1.getBoundsCenter() 172 await driver.mouseScroll(center1,false,5,2072,0,20) 173 await driver.delayMs(waitUiReadyMs) 174 let img2 = await driver.findComponent(ON.id('test_pict')) 175 let bounds2 = await img2.getBounds() 176 expect(bounds1 != bounds2).assertTrue() 177 178 await driver.pressBack() 179 await driver.delayMs(waitUiReadyMs) 180 let Scroll = await driver.findComponent(ON.text('1')) 181 let center = await Scroll.getBoundsCenter() 182 await driver.mouseScroll(center,true,30) 183 await driver.delayMs(waitUiReadyMs) 184 let button1 = await driver.findComponent(ON.text('next page')) 185 expect(button1 == null).assertTrue() 186 }) 187 188 /* 189 * @tc.number: uiTest_11007 190 * @tc.name: testWindowAttr 191 * @tc.desc: find window by WindowFilter and get it's active status. 192 */ 193 it('testWindowAttr', 0, async () => { 194 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 195 let driver = Driver.create() 196 await driver.delayMs(waitUiReadyMs) 197 let window = await driver.findWindow({bundleName:'com.uitestScene.acts',focused:true,active:true,title:''}) 198 await window.focus() 199 let isActive = await window.isActive() 200 expect(isActive == true).assertTrue() 201 await stopApplication('com.uitestScene.acts') 202 }) 203 204 /* 205 * @tc.number: uiTest_11008 206 * @tc.name: testDescription 207 * @tc.desc: find UiComponent by description attribute and get it's description attribute. 208 */ 209 it('testDescription', 0, async () => { 210 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 211 let driver = Driver.create() 212 await driver.delayMs(waitUiReadyMs) 213 let text = await driver.findComponent(ON.type('Text').description('')) 214 let description = await text.getDescription() 215 expect(description == '').assertTrue() 216 await stopApplication('com.uitestScene.acts') 217 }) 218 }) 219 220 describe('UiTest_API10', () => { 221 afterEach(async () => { 222 await stopApplication('com.uitestScene.acts') 223 }) 224 225 /* 226 * @tc.number: uiTest_10001 227 * @tc.name: testWithIn 228 * @tc.desc: find UiComponent inside of the given UiComponent. 229 */ 230 it('testWithIn', 0, async () => { 231 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 232 let driver = Driver.create() 233 await driver.delayMs(waitUiReadyMs) 234 let scroll = await driver.findComponent(ON.type('Scroll')) 235 let btn = await driver.findComponent(ON.within(ON.type('Scroll')).text('next page')) 236 let bounds1 = await scroll.getBounds() 237 let bounds2 = await btn.getBounds() 238 expect(bounds1.top < bounds2.top).assertTrue() 239 expect(bounds1.bottom > bounds2.bottom).assertTrue() 240 expect(bounds1.left < bounds2.right).assertTrue() 241 expect(bounds1.right > bounds2.right).assertTrue() 242 }) 243 244 /* 245 * @tc.number: uiTest_10002 246 * @tc.name: testFling 247 * @tc.desc: inject fling on the device display. 248 */ 249 it('testFling', 0, async () => { 250 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 251 let driver = Driver.create() 252 await driver.delayMs(waitUiReadyMs) 253 let window = await driver.findWindow({bundleName: 'com.uitestScene.acts'}) 254 try { 255 await window.maximize() 256 await driver.delayMs(500) 257 } catch (error) { 258 console.info('It is already a Fullscreen window') 259 } 260 await driver.fling(UiDirection.DOWN, 39000) 261 await driver.delayMs(waitUiReadyMs) 262 let button = await driver.findComponents(ON.text('next page')) 263 expect (button).assertNull() 264 await driver.fling(UiDirection.LEFT, 39000) 265 await driver.delayMs(waitUiReadyMs) 266 let text = await driver.findComponents(ON.text('1')) 267 expect (text).assertNull() 268 await driver.fling(UiDirection.RIGHT, 39000) 269 await driver.delayMs(waitUiReadyMs) 270 let text2 = await driver.findComponents(ON.text('2')) 271 expect (text2).assertNull() 272 await driver.fling(UiDirection.UP, 39000) 273 await driver.delayMs(2000) 274 let button2 = await driver.findComponents(ON.text('next page')) 275 expect (button2 != null).assertTrue() 276 }) 277 278 /* 279 * @tc.number: uiTest_10003 280 * @tc.name: testScreenCapture 281 * @tc.desc: capture the specified area of current screen. 282 */ 283 it('testScreenCapture', 0, async () => { 284 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 285 let driver = Driver.create() 286 await driver.delayMs(waitUiReadyMs) 287 let savePath = '/data/storage/el2/base/cache/1.png' 288 let success = await driver.screenCapture(savePath, {left: 0, top: 0, right: 100, bottom: 100}) 289 expect(success == true).assertTrue() 290 await stopApplication('com.uitestScene.acts') 291 }) 292 293 /* 294 * @tc.number: uiTest_10004 295 * @tc.name: testMouseClick 296 * @tc.desc: click in the specified location on the screen by mouse. 297 */ 298 it('testMouseClick', 0, async () => { 299 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 300 let driver = Driver.create() 301 await driver.delayMs(waitUiReadyMs) 302 let Button = await driver.findComponent(ON.id('jump')) 303 let center = await Button.getBoundsCenter() 304 await driver.mouseClick({x:center.x, y:center.y}, MouseButton.MOUSE_BUTTON_RIGHT) 305 await driver.delayMs(waitUiReadyMs) 306 let Button1 = await driver.findComponent(ON.text('right')) 307 expect(Button1 != null).assertTrue() 308 await driver.mouseClick({x:center.x, y:center.y}, MouseButton.MOUSE_BUTTON_MIDDLE,2072,2045) 309 await driver.delayMs(waitUiReadyMs) 310 let Button2 = await driver.findComponent(ON.text('middle')) 311 expect(Button2 != null).assertTrue() 312 await driver.mouseClick({x:center.x, y:center.y}, MouseButton.MOUSE_BUTTON_LEFT) 313 await driver.delayMs(waitUiReadyMs) 314 let Button3 = await driver.findComponent(ON.id('jump')) 315 expect(Button3 == null).assertTrue() 316 await driver.click(center.x, center.y) 317 await stopApplication('com.uitestScene.acts') 318 }) 319 320 /* 321 * @tc.number: uiTest_10005 322 * @tc.name: testMouseMoveTo 323 * @tc.desc: move the mouse cursor to the specified location. 324 */ 325 it('testMouseMoveTo', 0, async () => { 326 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 327 let driver = Driver.create() 328 await driver.delayMs(waitUiReadyMs) 329 let Button = await driver.findComponent(ON.id('jump')) 330 let center = await Button.getBoundsCenter() 331 await driver.mouseMoveTo(center) 332 await driver.delayMs(waitUiReadyMs) 333 let newButton = await driver.findComponent(ON.text('hover')) 334 expect(newButton != null).assertTrue() 335 await stopApplication('com.uitestScene.acts') 336 }) 337 338 /* 339 * @tc.number: uiTest_10006 340 * @tc.name: testMouseScroll 341 * @tc.desc: scroll the mouse wheel at the specified location to specify the cell. 342 */ 343 it('testMouseScroll', 0, async () => { 344 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 345 let driver = Driver.create() 346 await driver.delayMs(waitUiReadyMs) 347 let btn = await driver.findComponent(ON.id('jump')) 348 await btn.click() 349 await driver.delayMs(waitUiReadyMs) 350 let img1 = await driver.findComponent(ON.type('Image').inWindow('com.uitestScene.acts')) 351 let bounds1 = await img1.getBounds() 352 let center1 = await img1.getBoundsCenter() 353 await driver.click(center1.x, center1.y) 354 await driver.delayMs(waitUiReadyMs) 355 await driver.mouseScroll(center1,false,5,2072,0) 356 await driver.delayMs(waitUiReadyMs) 357 let img2 = await driver.findComponent(ON.type('Image').inWindow('com.uitestScene.acts')) 358 let bounds2 = await img2.getBounds() 359 expect(bounds1 != bounds2).assertTrue() 360 361 await driver.pressBack() 362 await driver.delayMs(waitUiReadyMs) 363 let Scroll = await driver.findComponent(ON.text('1')) 364 let center = await Scroll.getBoundsCenter() 365 await driver.mouseScroll(center,true,30) 366 await driver.delayMs(waitUiReadyMs) 367 let button1 = await driver.findComponent(ON.text('next page')) 368 expect(button1 == null).assertTrue() 369 }) 370 371 /* 372 * @tc.number: uiTest_10007 373 * @tc.name: testInWindow 374 * @tc.desc: scroll the mouse wheel at the specified location to specify the cell. 375 */ 376 it('testInWindow', 0, async () => { 377 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 378 let driver = Driver.create() 379 await driver.delayMs(waitUiReadyMs) 380 let btn = await driver.findComponent(ON.inWindow('com.uitestScene.acts').text('next page')) 381 expect(btn != null).assertTrue() 382 await stopApplication('com.uitestScene.acts') 383 }) 384 385 /* 386 * @tc.number: uiTest_10008 387 * @tc.name: testMonitor1 388 * @tc.desc: monitor toast appearance. 389 */ 390 it('testMonitor1', 0, async () => { 391 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 392 let driver = Driver.create() 393 await driver.delayMs(waitUiReadyMs) 394 let observer = await driver.createUIEventObserver() 395 let callback = (UiElementInfo : UIElementInfo) => { 396 try { 397 console.info('UIElementInfo bundleName:'+ UiElementInfo.bundleName) 398 console.info('UIElementInfo text:'+ UiElementInfo.text) 399 console.info('UIElementInfo type:'+ UiElementInfo.type) 400 expect(UiElementInfo.bundleName == 'com.uitestScene.acts').assertTrue() 401 expect(UiElementInfo.text == 'toastShow').assertTrue() 402 expect(UiElementInfo.type == 'Toast').assertTrue() 403 } catch (err) { 404 console.info(err) 405 } 406 } 407 observer.once('toastShow', callback) 408 let btn = await driver.findComponent(ON.text('toast')) 409 await btn.click() 410 await driver.delayMs(waitUiReadyMs) 411 await stopApplication('com.uitestScene.acts') 412 }) 413 414 /* 415 * @tc.number: uiTest_10009 416 * @tc.name: testMonitor2 417 * @tc.desc: monitor dialog appearance. 418 */ 419 420 it('testMonitor2', 0, async () => { 421 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 422 let driver = Driver.create() 423 await driver.delayMs(waitUiReadyMs) 424 let observer = await driver.createUIEventObserver() 425 let callback = (UiElementInfo : UIElementInfo) => { 426 try { 427 console.info('UIElementInfo bundleName:'+ UiElementInfo.bundleName) 428 console.info('UIElementInfo text:'+ UiElementInfo.text) 429 console.info('UIElementInfo type:'+ UiElementInfo.type) 430 expect(UiElementInfo.bundleName == 'com.uitestScene.acts').assertTrue() 431 expect(UiElementInfo.text == 'dialogShow').assertTrue() 432 expect(UiElementInfo.type == 'AlertDialog').assertTrue() 433 } catch (err) { 434 console.info(err) 435 } 436 } 437 observer.once('dialogShow', callback) 438 let btn = await driver.findComponent(ON.text('dialog')) 439 await btn.click() 440 await driver.delayMs(waitUiReadyMs) 441 await stopApplication('com.uitestScene.acts') 442 }) 443 }) 444 445 describe('UiTest_API8', () => { 446 afterEach(async () => { 447 await stopApplication('com.uitestScene.acts') 448 }) 449 450 /* 451 * @tc.number: uiTest_8001 452 * @tc.name: testInputText 453 * @tc.desc: inject text to the target UiComponent 454 */ 455 it('testInputText', 0, async () => { 456 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 457 let driver = UiDriver.create() 458 await driver.delayMs(waitUiReadyMs) 459 let input = await driver.findComponent(BY.type('TextInput')) 460 await input.inputText('123') 461 await driver.delayMs(2000) 462 let input_new = await driver.findComponent(BY.type('TextInput')) 463 let text = await input_new.getText() 464 console.info("testInputText result :" + text) 465 expect(text == '123').assertTrue() 466 await stopApplication('com.uitestScene.acts') 467 }) 468 469 /* 470 * @tc.number: uiTest_8002 471 * @tc.name: testMatchPattern 472 * @tc.desc: specifies the string value match pattern. 473 */ 474 it('testMatchPattern', 0, async () => { 475 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 476 let driver = UiDriver.create() 477 await driver.delayMs(waitUiReadyMs) 478 let Button1 = await driver.findComponent(BY.text('next page', MatchPattern.EQUALS)) 479 expect(await Button1.getText() == 'next page').assertTrue() 480 let Button2 = await driver.findComponent(BY.text('next', MatchPattern.STARTS_WITH)) 481 expect(await Button2.getText() == 'next page').assertTrue() 482 let Button3 = await driver.findComponent(BY.text('xt page', MatchPattern.ENDS_WITH)) 483 expect(await Button3.getText() == 'next page').assertTrue() 484 let Button4 = await driver.findComponent(BY.text('ext', MatchPattern.CONTAINS)) 485 expect(await Button4.getText() == 'next page').assertTrue() 486 await stopApplication('com.uitestScene.acts') 487 }) 488 489 /* 490 * @tc.number: uiTest_8003 491 * @tc.name: testUiComponentClick 492 * @tc.desc: click this UiComponentClick. 493 */ 494 it('testUiComponentClick', 0, async () => { 495 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 496 let driver = UiDriver.create() 497 await driver.delayMs(waitUiReadyMs) 498 let button = await driver.findComponent(BY.text('next page')) 499 await button.click() 500 await driver.delayMs(waitUiReadyMs) 501 let newButton = await driver.findComponent(BY.text('back to index')) 502 let text = await newButton.getText() 503 expect(text == 'back to index').assertTrue() 504 await newButton.click() 505 await stopApplication('com.uitestScene.acts') 506 }) 507 508 /* 509 * @tc.number: uiTest_8004 510 * @tc.name: testUiComponentDoubleClick 511 * @tc.desc: doubleClick this UiComponentClick. 512 */ 513 it('testUiComponentDoubleClick', 0, async () => { 514 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 515 let driver = UiDriver.create() 516 await driver.delayMs(waitUiReadyMs) 517 let button = await driver.findComponent(BY.text('Click twice')) 518 await button.doubleClick() 519 await driver.delayMs(waitUiReadyMs) 520 let newButton = await driver.findComponent(BY.text('doubleClick')) 521 let text = await newButton.getText() 522 expect(text == 'doubleClick').assertTrue() 523 await newButton.click() 524 await stopApplication('com.uitestScene.acts') 525 }) 526 527 /* 528 * @tc.number: uiTest_8005 529 * @tc.name: testUiComponentLongClick 530 * @tc.desc: longClick this UiComponentClick. 531 */ 532 it('testUiComponentLongClick', 0, async () => { 533 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 534 let driver = UiDriver.create() 535 await driver.delayMs(waitUiReadyMs) 536 let button = await driver.findComponent(BY.text('next page')) 537 await button.longClick() 538 await driver.delayMs(waitUiReadyMs) 539 let newButton = await driver.findComponent(BY.text('longClick')) 540 let text = await newButton.getText() 541 expect(text == 'longClick').assertTrue() 542 await newButton.click() 543 await stopApplication('com.uitestScene.acts') 544 }) 545 546 /* 547 * @tc.number: uiTest_8006 548 * @tc.name: testKey 549 * @tc.desc: find UiComponent by key attribute and get it's key attribute. 550 */ 551 it('testKey', 0, async () => { 552 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 553 let driver = UiDriver.create() 554 await driver.delayMs(waitUiReadyMs) 555 let button = await driver.findComponent(BY.key('my-key')) 556 expect(await button.getKey() == 'my-key').assertTrue() 557 await stopApplication('com.uitestScene.acts') 558 }) 559 560 /* 561 * @tc.number: uiTest_8007 562 * @tc.name: testId 563 * @tc.desc: find UiComponent by id attribute and get it's id attribute. 564 */ 565 it('testId', 0, async () => { 566 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 567 let driver = UiDriver.create() 568 await driver.delayMs(waitUiReadyMs) 569 let button = await driver.findComponent(BY.text('next page')) 570 let id = await button.getId() 571 let button2 = await driver.findComponent(BY.id(id)) 572 expect(await button2.getText() == 'next page').assertTrue() 573 await stopApplication('com.uitestScene.acts') 574 }) 575 576 /* 577 * @tc.number: uiTest_8008 578 * @tc.name: testType 579 * @tc.desc: find UiComponent by type attribute and get it's type attribute. 580 */ 581 it('testType', 0, async () => { 582 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 583 let driver = UiDriver.create() 584 await driver.delayMs(waitUiReadyMs) 585 let text = await driver.findComponent(BY.type('Text')) 586 let type = await text.getType() 587 expect(type == 'Text').assertTrue() 588 await stopApplication('com.uitestScene.acts') 589 }) 590 591 /* 592 * @tc.number: uiTest_8009 593 * @tc.name: testClickable 594 * @tc.desc: find UiComponent by clickable attribute and get it's clickable attribute. 595 */ 596 it('testClickable', 0, async () => { 597 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 598 let driver = UiDriver.create() 599 await driver.delayMs(waitUiReadyMs) 600 let button = await driver.findComponent(BY.text('next page').clickable(false)) 601 let clickable = await button.isClickable() 602 expect(clickable == false).assertTrue() 603 await stopApplication('com.uitestScene.acts') 604 }) 605 606 /* 607 * @tc.number: uiTest_8010 608 * @tc.name: testScrollable 609 * @tc.desc: find UiComponent by scrollable attribute and get it's scrollable attribute. 610 */ 611 it('testScrollable', 0, async () => { 612 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 613 let driver = UiDriver.create() 614 await driver.delayMs(waitUiReadyMs) 615 let scrollBar = await driver.findComponent(BY.type('Scroll')) 616 let scrollable = await scrollBar.isScrollable() 617 expect(scrollable == true).assertTrue() 618 await stopApplication('com.uitestScene.acts') 619 }) 620 621 /* 622 * @tc.number: uiTest_8011 623 * @tc.name: testEnabled 624 * @tc.desc: find UiComponent by enabled attribute and get it's enabled attribute. 625 */ 626 it('testEnabled', 0, async () => { 627 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 628 let driver = UiDriver.create() 629 await driver.delayMs(waitUiReadyMs) 630 let button = await driver.findComponent(BY.text('next page').enabled(true)) 631 let enable = await button.isEnabled() 632 expect(enable == true).assertTrue() 633 await stopApplication('com.uitestScene.acts') 634 }) 635 636 /* 637 * @tc.number: uiTest_8012 638 * @tc.name: testFocused 639 * @tc.desc: find UiComponent by focused attribute and get it's focused attribute. 640 */ 641 it('testFocused', 0, async () => { 642 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 643 let driver = UiDriver.create() 644 await driver.delayMs(waitUiReadyMs) 645 let button = await driver.findComponent(BY.text('next page').focused(false)) 646 let focused = await button.isFocused() 647 expect(focused == false).assertTrue() 648 await stopApplication('com.uitestScene.acts') 649 }) 650 651 /* 652 * @tc.number: uiTest_8013 653 * @tc.name: testSelected 654 * @tc.desc: find UiComponent by selected attribute and get it's selected attribute. 655 */ 656 it('testSelected', 0, async () => { 657 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 658 let driver = UiDriver.create() 659 await driver.delayMs(waitUiReadyMs) 660 let button = await driver.findComponent(BY.text('next page').selected(false)) 661 let selected = await button.isSelected() 662 expect(selected == false).assertTrue() 663 await stopApplication('com.uitestScene.acts') 664 }) 665 666 /* 667 * @tc.number: uiTest_8014 668 * @tc.name: testPressBack 669 * @tc.desc: Press the BACK key. 670 */ 671 it('testPressBack', 0, async () => { 672 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 673 let driver = UiDriver.create() 674 await driver.delayMs(waitUiReadyMs) 675 let button = await driver.findComponent(BY.text('next page')) 676 await button.click() 677 await driver.delayMs(waitUiReadyMs) 678 await driver.pressBack() 679 await driver.delayMs(waitUiReadyMs) 680 let button_ori = await driver.findComponent(BY.text('next page')) 681 expect(await button_ori.getText() == 'next page').assertTrue() 682 await stopApplication('com.uitestScene.acts') 683 }) 684 685 /* 686 * @tc.number: uiTest_8015 687 * @tc.name: testFindComponents 688 * @tc.desc: find all the matched UiComponents on current UI 689 */ 690 it('testFindComponents', 0, async () => { 691 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 692 let driver = UiDriver.create() 693 await driver.delayMs(waitUiReadyMs) 694 let buttons = await driver.findComponents(BY.type('Button')) 695 expect(await buttons[0].getText() != null).assertTrue() 696 await stopApplication('com.uitestScene.acts') 697 }) 698 699 /* 700 * @tc.number: uiTest_8016 701 * @tc.name: testTriggerKey 702 * @tc.desc: press the specified key. 703 */ 704 it('testTriggerKey', 0, async () => { 705 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 706 let driver = UiDriver.create() 707 await driver.delayMs(waitUiReadyMs) 708 let button = await driver.findComponent(BY.text('next page')) 709 await button.click() 710 await driver.delayMs(waitUiReadyMs) 711 let keyBack = 2 712 await driver.triggerKey(keyBack) 713 await driver.delayMs(waitUiReadyMs) 714 let button_ori = await driver.findComponent(BY.text('next page')) 715 expect(await button_ori.getText() == 'next page').assertTrue() 716 await stopApplication('com.uitestScene.acts') 717 }) 718 719 /* 720 * @tc.number: uiTest_8017 721 * @tc.name: testScreenCap 722 * @tc.desc: capture current screen. 723 */ 724 it('testScreenCap', 0, async () => { 725 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 726 let driver = UiDriver.create() 727 await driver.delayMs(waitUiReadyMs) 728 let savePath = '/data/storage/el2/base/cache/1.png' 729 let success = await driver.screenCap(savePath) 730 expect(success == true).assertTrue() 731 await stopApplication('com.uitestScene.acts') 732 }) 733 734 /* 735 * @tc.number: uiTest_8018 736 * @tc.name: testAssertComponentExist 737 * @tc.desc: Assert whether the matched UiComponent exists on current UI;. 738 */ 739 it('testAssertComponentExist', 0, async () => { 740 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 741 let driver = UiDriver.create() 742 await driver.delayMs(waitUiReadyMs) 743 await driver.assertComponentExist(BY.text('next page')) 744 await stopApplication('com.uitestScene.acts') 745 }) 746 747 /* 748 * @tc.number: uiTest_8019 749 * @tc.name: testIsBefore 750 * @tc.desc: find uiComponent which is before another UiComponent that specified by given. 751 */ 752 it('testIsBefore', 0, async () => { 753 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 754 let driver = UiDriver.create() 755 await driver.delayMs(waitUiReadyMs) 756 let button = await driver.findComponent(BY.isBefore(BY.text('Click twice')).type('Button')) 757 expect(await button.getType() == 'Button').assertTrue() 758 await stopApplication('com.uitestScene.acts') 759 }) 760 761 /* 762 * @tc.number: uiTest_8020 763 * @tc.name: testIsAfter 764 * @tc.desc: find uiComponent which is after another UiComponent that specified by given. 765 */ 766 it('testIsAfter', 0, async () => { 767 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 768 let driver = UiDriver.create() 769 await driver.delayMs(waitUiReadyMs) 770 let button = await driver.findComponent(BY.isAfter(BY.text('next page')).type('Text')) 771 expect(await button.getText() == 'Click twice').assertTrue() 772 await stopApplication('com.uitestScene.acts') 773 }) 774 775 /* 776 * @tc.number: uiTest_8021 777 * @tc.name: testSwipe 778 * @tc.desc: swipe on the screen between the specified points. 779 */ 780 it('testSwipe', 0, async () => { 781 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 782 let driver = UiDriver.create() 783 await driver.delayMs(waitUiReadyMs) 784 await driver.swipe(500, 1100, 500, 300) 785 let text = await driver.findComponent(BY.text('next page')) 786 expect(text == null).assertTrue() 787 await stopApplication('com.uitestScene.acts') 788 }) 789 790 /* 791 * @tc.number: uiTest_8022 792 * @tc.name: testScrollSearch 793 * @tc.desc: scroll on this UiComponent to find matched UiComponent. 794 */ 795 it('testScrollSearch', 0, async () => { 796 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 797 let driver = UiDriver.create() 798 await driver.delayMs(waitUiReadyMs) 799 let scrollBar = await driver.findComponent(BY.type('Scroll')) 800 let button = await scrollBar.scrollSearch(BY.text('next page')) 801 expect(await button.getText() == 'next page').assertTrue() 802 await stopApplication('com.uitestScene.acts') 803 }) 804 }) 805 806 describe('UiTest_API9', () => { 807 afterEach(async () => { 808 await stopApplication('com.uitestScene.acts') 809 }) 810 811 /* 812 * @tc.number: uiTest_9001 813 * @tc.name: testInputText 814 * @tc.desc: inject text to the target UiComponent 815 */ 816 it('testInputText', 0, async () => { 817 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 818 let driver = Driver.create() 819 await driver.delayMs(waitUiReadyMs) 820 let input = await driver.findComponent(ON.type('TextInput')) 821 await input.inputText('123') 822 await driver.delayMs(2000) 823 let input_new = await driver.findComponent(ON.type('TextInput')) 824 let text = await input_new.getText() 825 console.info("testInputText result :" + text) 826 expect(text == '123').assertTrue() 827 await stopApplication('com.uitestScene.acts') 828 }) 829 830 /* 831 * @tc.number: uiTest_9002 832 * @tc.name: testClearText 833 * @tc.desc: clear text of the target UiComponent 834 */ 835 it('testClearText', 0, async () => { 836 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 837 let driver = Driver.create() 838 await driver.delayMs(waitUiReadyMs) 839 let input1 = await driver.findComponent(ON.type('TextInput')) 840 await input1.inputText('abc') 841 await driver.delayMs(2000) 842 let input2 = await driver.findComponent(ON.type('TextInput')) 843 await input2.clearText() 844 await driver.delayMs(waitUiReadyMs) 845 let input_new = await driver.findComponent(ON.type('TextInput')) 846 let text = await input_new.getText() 847 console.info("testClearText result :" + text) 848 expect(text).assertEqual('') 849 await stopApplication('com.uitestScene.acts') 850 }) 851 852 /* 853 * @tc.number: uiTest_9003 854 * @tc.name: testCheckable 855 * @tc.desc: find UiComponent by checkable attribute and get it's checkable attribute. 856 */ 857 it('testCheckable', 0, async () => { 858 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 859 let driver = Driver.create() 860 await driver.delayMs(waitUiReadyMs) 861 let button = await driver.findComponent(ON.checkable(true).type('Checkbox')) 862 let checkable = await button.isCheckable() 863 expect(checkable == true).assertTrue() 864 await stopApplication('com.uitestScene.acts') 865 }) 866 867 /* 868 * @tc.number: uiTest_9004 869 * @tc.name: testChecked 870 * @tc.desc: find UiComponent by checked attribute and get it's checked attribute. 871 */ 872 it('testChecked', 0, async () => { 873 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 874 let driver = Driver.create() 875 await driver.delayMs(waitUiReadyMs) 876 let button = await driver.findComponent(ON.checked(false).type('Checkbox')) 877 let checked = await button.isChecked() 878 expect(checked == false).assertTrue() 879 await stopApplication('com.uitestScene.acts') 880 }) 881 882 /* 883 * @tc.number: uiTest_9005 884 * @tc.name: testMatchPattern 885 * @tc.desc: specifies the string value match pattern. 886 */ 887 it('testMatchPattern', 0, async () => { 888 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 889 let driver = Driver.create() 890 await driver.delayMs(waitUiReadyMs) 891 let Button1 = await driver.findComponent(ON.text('next page',MatchPattern.EQUALS)) 892 expect(await Button1.getText() == 'next page').assertTrue() 893 let Button2 = await driver.findComponent(ON.text('next',MatchPattern.STARTS_WITH)) 894 expect(await Button2.getText() == 'next page').assertTrue() 895 let Button3 = await driver.findComponent(ON.text('xt page',MatchPattern.ENDS_WITH)) 896 expect(await Button3.getText() == 'next page').assertTrue() 897 let Button4 = await driver.findComponent(ON.text('ext',MatchPattern.CONTAINS)) 898 expect(await Button4.getText() == 'next page').assertTrue() 899 await stopApplication('com.uitestScene.acts') 900 }) 901 902 /* 903 * @tc.number: uiTest_9006 904 * @tc.name: testDriverClick 905 * @tc.desc: click in the specified location on the screen. 906 */ 907 it('testDriverClick', 0, async () => { 908 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 909 let driver = Driver.create() 910 await driver.delayMs(waitUiReadyMs) 911 let Button = await driver.findComponent(ON.text('next page')) 912 let center = await Button.getBoundsCenter() 913 await driver.click(center.x, center.y) 914 await driver.delayMs(waitUiReadyMs) 915 let newButton = await driver.findComponent(ON.text('back to index')) 916 let text = await newButton.getText() 917 expect(text == 'back to index').assertTrue() 918 await newButton.click() 919 await stopApplication('com.uitestScene.acts') 920 }) 921 922 /* 923 * @tc.number: uiTest_9007 924 * @tc.name: testDriverDoubleClick 925 * @tc.desc: doubleClick in the specified location on the screen. 926 */ 927 it('testDriverDoubleClick', 0, async () => { 928 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 929 let driver = Driver.create() 930 await driver.delayMs(waitUiReadyMs) 931 let Button = await driver.findComponent(ON.text('Click twice')) 932 let center = await Button.getBoundsCenter() 933 await driver.doubleClick(center.x, center.y) 934 await driver.delayMs(waitUiReadyMs) 935 let button = await driver.findComponent(ON.text('doubleClick')) 936 let text = await button.getText() 937 expect(text == 'doubleClick').assertTrue() 938 await button.click() 939 await stopApplication('com.uitestScene.acts') 940 }) 941 942 /* 943 * @tc.number: uiTest_9008 944 * @tc.name: testDriverLongClick 945 * @tc.desc: longClick in the specified location on the screen. 946 */ 947 it('testDriverLongClick', 0, async () => { 948 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 949 let driver = Driver.create() 950 await driver.delayMs(waitUiReadyMs) 951 let Button = await driver.findComponent(ON.text('next page')) 952 let center = await Button.getBoundsCenter() 953 await driver.longClick(center.x, center.y) 954 await driver.delayMs(waitUiReadyMs) 955 let newButton = await driver.findComponent(ON.text('longClick')) 956 let text = await newButton.getText() 957 expect(text == 'longClick').assertTrue() 958 await newButton.click() 959 await stopApplication('com.uitestScene.acts') 960 }) 961 962 /* 963 * @tc.number: uiTest_9009 964 * @tc.name: testUiComponentClick 965 * @tc.desc: click this UiComponentClick. 966 */ 967 it('testUiComponentClick', 0, async () => { 968 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 969 let driver = Driver.create() 970 await driver.delayMs(waitUiReadyMs) 971 let button = await driver.findComponent(ON.text('next page')) 972 await button.click() 973 await driver.delayMs(waitUiReadyMs) 974 let newButton = await driver.findComponent(ON.text('back to index')) 975 let text = await newButton.getText() 976 expect(text == 'back to index').assertTrue() 977 await newButton.click() 978 await stopApplication('com.uitestScene.acts') 979 }) 980 981 /* 982 * @tc.number: uiTest_9010 983 * @tc.name: testUiComponentDoubleClick 984 * @tc.desc: doubleClick this UiComponentClick. 985 */ 986 it('testUiComponentDoubleClick', 0, async () => { 987 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 988 let driver = Driver.create() 989 await driver.delayMs(waitUiReadyMs) 990 let button = await driver.findComponent(ON.text('Click twice')) 991 await button.doubleClick() 992 await driver.delayMs(waitUiReadyMs) 993 let newButton = await driver.findComponent(ON.text('doubleClick')) 994 let text = await newButton.getText() 995 expect(text == 'doubleClick').assertTrue() 996 await newButton.click() 997 await stopApplication('com.uitestScene.acts') 998 }) 999 1000 /* 1001 * @tc.number: uiTest_9011 1002 * @tc.name: testUiComponentLongClick 1003 * @tc.desc: longClick this UiComponentClick. 1004 */ 1005 it('testUiComponentLongClick', 0, async () => { 1006 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1007 let driver = Driver.create() 1008 await driver.delayMs(waitUiReadyMs) 1009 let button = await driver.findComponent(ON.text('next page')) 1010 await button.longClick() 1011 await driver.delayMs(waitUiReadyMs) 1012 let newButton = await driver.findComponent(ON.text('longClick')) 1013 let text = await newButton.getText() 1014 expect(text == 'longClick').assertTrue() 1015 await newButton.click() 1016 await stopApplication('com.uitestScene.acts') 1017 }) 1018 1019 /* 1020 * @tc.number: uiTest_9012 1021 * @tc.name: testKey 1022 * @tc.desc: find UiComponent by key attribute and get it's key attribute. 1023 */ 1024 it('testKey', 0, async () => { 1025 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1026 let driver = Driver.create() 1027 await driver.delayMs(waitUiReadyMs) 1028 let button = await driver.findComponent(ON.id('my-key')) 1029 expect(await button.getId() == 'my-key').assertTrue() 1030 await stopApplication('com.uitestScene.acts') 1031 }) 1032 1033 /* 1034 * @tc.number: uiTest_9013 1035 * @tc.name: testType 1036 * @tc.desc: find UiComponent by type attribute and get it's type attribute. 1037 */ 1038 it('testType', 0, async () => { 1039 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1040 let driver = Driver.create() 1041 await driver.delayMs(waitUiReadyMs) 1042 let text = await driver.findComponent(ON.type('Text')) 1043 let type = await text.getType() 1044 expect(type == 'Text').assertTrue() 1045 await stopApplication('com.uitestScene.acts') 1046 }) 1047 1048 /* 1049 * @tc.number: uiTest_9014 1050 * @tc.name: testClickable 1051 * @tc.desc: find UiComponent by clickable attribute and get it's clickable attribute. 1052 */ 1053 it('testClickable', 0, async () => { 1054 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1055 let driver = Driver.create() 1056 await driver.delayMs(waitUiReadyMs) 1057 let button = await driver.findComponent(ON.text('next page').clickable(false)) 1058 let clickable = await button.isClickable() 1059 expect(clickable == false).assertTrue() 1060 await stopApplication('com.uitestScene.acts') 1061 }) 1062 1063 /* 1064 * @tc.number: uiTest_9015 1065 * @tc.name: testLongClickable 1066 * @tc.desc: find UiComponent by longClickable attribute and get it's longClickable attribute. 1067 */ 1068 it('testLongClickable', 0, async () => { 1069 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1070 let driver = Driver.create() 1071 await driver.delayMs(waitUiReadyMs) 1072 let button = await driver.findComponent(ON.text('next page').longClickable(false)) 1073 let longClickable = await button.isLongClickable() 1074 expect(longClickable== false).assertTrue() 1075 await stopApplication('com.uitestScene.acts') 1076 }) 1077 1078 /* 1079 * @tc.number: uiTest_9016 1080 * @tc.name: testScrollable 1081 * @tc.desc: find UiComponent by scrollable attribute and get it's scrollable attribute. 1082 */ 1083 it('testScrollable', 0, async () => { 1084 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1085 let driver = Driver.create() 1086 await driver.delayMs(waitUiReadyMs) 1087 let scrollBar = await driver.findComponent(ON.type('Scroll')) 1088 let scrollable = await scrollBar.isScrollable() 1089 expect(scrollable == true).assertTrue() 1090 await stopApplication('com.uitestScene.acts') 1091 }) 1092 1093 /* 1094 * @tc.number: uiTest_9017 1095 * @tc.name: testEnabled 1096 * @tc.desc: find UiComponent by enabled attribute and get it's enabled attribute. 1097 */ 1098 it('testEnabled', 0, async () => { 1099 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1100 let driver = Driver.create() 1101 await driver.delayMs(waitUiReadyMs) 1102 let button = await driver.findComponent(ON.text('next page').enabled(true)) 1103 let enable = await button.isEnabled() 1104 expect(enable == true).assertTrue() 1105 await stopApplication('com.uitestScene.acts') 1106 }) 1107 1108 /* 1109 * @tc.number: uiTest_9018 1110 * @tc.name: testFocused 1111 * @tc.desc: find UiComponent by focused attribute and get it's focused attribute. 1112 */ 1113 it('testFocused', 0, async () => { 1114 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1115 let driver = Driver.create() 1116 await driver.delayMs(waitUiReadyMs) 1117 let button = await driver.findComponent(ON.text('next page').focused(false)) 1118 let focused = await button.isFocused() 1119 expect(focused == false).assertTrue() 1120 await stopApplication('com.uitestScene.acts') 1121 }) 1122 1123 /* 1124 * @tc.number: uiTest_9019 1125 * @tc.name: testSelected 1126 * @tc.desc: find UiComponent by selected attribute and get it's selected attribute. 1127 */ 1128 it('testSelected', 0, async () => { 1129 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1130 let driver = Driver.create() 1131 await driver.delayMs(waitUiReadyMs) 1132 let button = await driver.findComponent(ON.text('next page').selected(false)) 1133 let selected = await button.isSelected() 1134 expect(selected == false).assertTrue() 1135 await stopApplication('com.uitestScene.acts') 1136 }) 1137 1138 /* 1139 * @tc.number: uiTest_9020 1140 * @tc.name: testPressBack 1141 * @tc.desc: Press the BACK key. 1142 */ 1143 it('testPressBack', 0, async () => { 1144 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1145 let driver = Driver.create() 1146 await driver.delayMs(waitUiReadyMs) 1147 let button = await driver.findComponent(ON.text('next page')) 1148 await button.click() 1149 await driver.delayMs(waitUiReadyMs) 1150 await driver.pressBack() 1151 await driver.delayMs(waitUiReadyMs) 1152 let button_ori = await driver.findComponent(ON.text('next page')) 1153 expect(await button_ori.getText() == 'next page').assertTrue() 1154 await stopApplication('com.uitestScene.acts') 1155 }) 1156 1157 /* 1158 * @tc.number: uiTest_9021 1159 * @tc.name: testFindComponents 1160 * @tc.desc: find all the matched UiComponents on current UI 1161 */ 1162 it('testFindComponents', 0, async () => { 1163 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1164 let driver = Driver.create() 1165 await driver.delayMs(waitUiReadyMs) 1166 let buttons = await driver.findComponents(ON.type('Button')) 1167 expect(await buttons[0].getText() != null).assertTrue() 1168 await stopApplication('com.uitestScene.acts') 1169 }) 1170 1171 /* 1172 * @tc.number: uiTest_9022 1173 * @tc.name: testTriggerKey 1174 * @tc.desc: press the specified key. 1175 */ 1176 it('testTriggerKey', 0, async () => { 1177 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1178 let driver = Driver.create() 1179 await driver.delayMs(waitUiReadyMs) 1180 let button = await driver.findComponent(ON.text('next page')) 1181 await button.click() 1182 await driver.delayMs(waitUiReadyMs) 1183 let keyBack = 2 1184 await driver.triggerKey(keyBack) 1185 await driver.delayMs(waitUiReadyMs) 1186 let button_ori = await driver.findComponent(ON.text('next page')) 1187 expect(await button_ori.getText() == 'next page').assertTrue() 1188 await stopApplication('com.uitestScene.acts') 1189 }) 1190 1191 /* 1192 * @tc.number: uiTest_9023 1193 * @tc.name: testTriggerCombineKeys 1194 * @tc.desc: press two or three key combinations 1195 */ 1196 it('testTriggerCombineKeys', 0, async () => { 1197 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1198 let driver = Driver.create() 1199 await driver.delayMs(2000) 1200 let text = await driver.findComponent(ON.type('TextInput')) 1201 let center = await text.getBoundsCenter() 1202 // set pasteBoard data 1203 await text.inputText('123') 1204 await driver.delayMs(2000) 1205 await driver.click(center.x, center.y) 1206 await driver.delayMs(waitUiReadyMs) 1207 await driver.triggerCombineKeys(2072, 2017) 1208 await driver.delayMs(waitUiReadyMs) 1209 await driver.triggerCombineKeys(2072, 2019) 1210 await driver.delayMs(waitUiReadyMs) 1211 // clear and paste 1212 let text2 = await driver.findComponent(ON.type('TextInput')) 1213 await text2.clearText() 1214 await driver.delayMs(waitUiReadyMs) 1215 await driver.triggerCombineKeys(2072, 2038) 1216 await driver.delayMs(4000) 1217 let text3 = await driver.findComponent(ON.type('TextInput')) 1218 expect(await text3.getText() == '123').assertTrue() 1219 await stopApplication('com.uitestScene.acts') 1220 }) 1221 1222 /* 1223 * @tc.number: uiTest_9024 1224 * @tc.name: testGetUiComponentBounds 1225 * @tc.desc: get the bounds of this UiComponent. 1226 */ 1227 it('testGetUiComponentBounds', 0, async () => { 1228 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1229 let driver = Driver.create() 1230 await driver.delayMs(waitUiReadyMs) 1231 let text = await driver.findComponent(ON.text('next page')) 1232 expect(text !== null).assertTrue() 1233 let bounds = await text.getBounds(); 1234 expect(bounds !== null).assertTrue() 1235 expect(bounds.right).assertLarger(bounds.left) 1236 expect(bounds.bottom).assertLarger(bounds.top) 1237 await stopApplication('com.uitestScene.acts') 1238 }) 1239 1240 /* 1241 * @tc.number: uiTest_9025 1242 * @tc.name: testGetUiComponentBoundsCenter 1243 * @tc.desc: get the boundsCenter of this @link UiComponent. 1244 */ 1245 it('testGetUiComponentBoundsCenter', 0, async () => { 1246 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1247 let driver = Driver.create() 1248 await driver.delayMs(waitUiReadyMs) 1249 let button = await driver.findComponent(ON.text('next page')) 1250 let point = await button.getBoundsCenter() 1251 expect(point!== null).assertTrue() 1252 await stopApplication('com.uitestScene.acts') 1253 }) 1254 1255 /* 1256 * @tc.number: uiTest_9026 1257 * @tc.name: testWaitForComponent 1258 * @tc.desc: Find the first matched UiComponent on current UI during the time given. 1259 */ 1260 it('testWaitForComponent', 0, async () => { 1261 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1262 let driver = Driver.create() 1263 await driver.delayMs(waitUiReadyMs) 1264 let button = await driver.waitForComponent(ON.text('next page'), waitUiReadyMs) 1265 expect(button !== null).assertTrue() 1266 await stopApplication('com.uitestScene.acts') 1267 }) 1268 1269 /* 1270 * @tc.number: uiTest_9027 1271 * @tc.name: testScreenCap 1272 * @tc.desc: capture current screen. 1273 */ 1274 it('testScreenCap', 0, async () => { 1275 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1276 let driver = Driver.create() 1277 await driver.delayMs(waitUiReadyMs) 1278 let savePath = '/data/storage/el2/base/cache/1.png' 1279 let success = await driver.screenCap(savePath) 1280 expect(success == true).assertTrue() 1281 await stopApplication('com.uitestScene.acts') 1282 }) 1283 1284 /* 1285 * @tc.number: uiTest_9028 1286 * @tc.name: testAssertComponentExist 1287 * @tc.desc: Assert whether the matched UiComponent exists on current UI;. 1288 */ 1289 it('testAssertComponentExist', 0, async () => { 1290 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1291 let driver = Driver.create() 1292 await driver.delayMs(waitUiReadyMs) 1293 await driver.assertComponentExist(ON.text('next page')) 1294 await stopApplication('com.uitestScene.acts') 1295 }) 1296 1297 /* 1298 * @tc.number: uiTest_9029 1299 * @tc.name: testIsBefore 1300 * @tc.desc: find uiComponent which is before another UiComponent that specified by given. 1301 */ 1302 it('testIsBefore', 0, async () => { 1303 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1304 let driver = Driver.create() 1305 await driver.delayMs(waitUiReadyMs) 1306 let button = await driver.findComponent(ON.isBefore(ON.text('Click twice')).type('Button')) 1307 expect(await button.getType() == 'Button').assertTrue() 1308 await stopApplication('com.uitestScene.acts') 1309 }) 1310 1311 /* 1312 * @tc.number: uiTest_9030 1313 * @tc.name: testIsAfter 1314 * @tc.desc: find uiComponent which is after another UiComponent that specified by given. 1315 */ 1316 it('testIsAfter', 0, async () => { 1317 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1318 let driver = Driver.create() 1319 await driver.delayMs(waitUiReadyMs) 1320 let button = await driver.findComponent(ON.isAfter(ON.text('next page')).type('Text')) 1321 expect(await button.getText() == 'Click twice').assertTrue() 1322 await stopApplication('com.uitestScene.acts') 1323 }) 1324 1325 /* 1326 * @tc.number: uiTest_9031 1327 * @tc.name: testSwipe 1328 * @tc.desc: swipe on the screen between the specified points. 1329 */ 1330 it('testSwipe', 0, async () => { 1331 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1332 let driver = Driver.create() 1333 await driver.delayMs(waitUiReadyMs) 1334 await driver.swipe(500,1100,500,300) 1335 let text = await driver.findComponent(ON.text('next page')) 1336 expect(text == null).assertTrue() 1337 let scrollBar = await driver.findComponent(ON.type('Scroll')) 1338 await scrollBar.scrollToTop() 1339 await stopApplication('com.uitestScene.acts') 1340 }) 1341 1342 /* 1343 * @tc.number: uiTest_9032 1344 * @tc.name: testFling 1345 * @tc.desc: inject fling on the device display. 1346 */ 1347 it('testFling', 0, async () => { 1348 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1349 let driver = Driver.create() 1350 await driver.delayMs(waitUiReadyMs) 1351 await driver.fling({x:500, y:1100},{x:500, y:300}, 20, 600) 1352 await driver.delayMs(1000) 1353 let text = await driver.findComponent(ON.text('next page')) 1354 expect(text == null).assertTrue() 1355 let scrollBar = await driver.findComponent(ON.type('Scroll')) 1356 await scrollBar.scrollToTop() 1357 await stopApplication('com.uitestScene.acts') 1358 }) 1359 1360 /* 1361 * @tc.number: uiTest_9033 1362 * @tc.name: testScrollSearch 1363 * @tc.desc: scroll on this UiComponent to find matched UiComponent. 1364 */ 1365 it('testScrollSearch', 0, async () => { 1366 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1367 let driver = Driver.create() 1368 await driver.delayMs(waitUiReadyMs) 1369 let scrollBar = await driver.findComponent(ON.type('Scroll')) 1370 let button = await scrollBar.scrollSearch(ON.text('next page')) 1371 expect(await button.getText() == 'next page').assertTrue() 1372 await stopApplication('com.uitestScene.acts') 1373 }) 1374 1375 /* 1376 * @tc.number: uiTest_9034 1377 * @tc.name: testScrollToBottom 1378 * @tc.desc: scroll on this UiComponent to the bottom. 1379 */ 1380 it('testScrollToBottom', 0, async () => { 1381 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1382 let driver = Driver.create() 1383 await driver.delayMs(waitUiReadyMs) 1384 let scrollBar = await driver.findComponent(ON.type('Scroll')) 1385 expect(scrollBar != null).assertTrue() 1386 await scrollBar.scrollToBottom() 1387 let button = await driver.findComponent(ON.text('bottom')) 1388 expect(await button.getText() == 'bottom').assertTrue() 1389 await scrollBar.scrollToTop() 1390 await stopApplication('com.uitestScene.acts') 1391 }) 1392 1393 /* 1394 * @tc.number: uiTest_9035 1395 * @tc.name: testScrollToTop 1396 * @tc.desc: scroll on this UiComponent to the top. 1397 */ 1398 it('testScrollToTop', 0, async () => { 1399 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1400 let driver = Driver.create() 1401 await driver.delayMs(waitUiReadyMs) 1402 let scrollBar = await driver.findComponent(ON.type('Scroll')) 1403 expect(scrollBar !== null).assertTrue() 1404 await scrollBar.scrollToBottom() 1405 await scrollBar.scrollToTop() 1406 let button = await driver.findComponent(ON.text('next page')) 1407 expect(await button.getText() == 'next page').assertTrue() 1408 await stopApplication('com.uitestScene.acts') 1409 }) 1410 1411 /* 1412 * @tc.number: uiTest_9036 1413 * @tc.name: testPinch 1414 * @tc.desc: pinch enlarge this UiComponent to the target scale. 1415 */ 1416 it('testPinch', 0, async () => { 1417 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1418 let driver = Driver.create() 1419 await driver.delayMs(waitUiReadyMs) 1420 let button = await driver.findComponent(ON.id('jump')) 1421 await button.click() 1422 await driver.delayMs(waitUiReadyMs) 1423 let image1 = await driver.findComponent(ON.id('test_pict')) 1424 let bounds1 = await image1.getBounds() 1425 await image1.pinchIn(0.5); 1426 await driver.delayMs(waitUiReadyMs) 1427 let image2 = await driver.findComponent(ON.id('test_pict')) 1428 let bounds2 = await image2.getBounds() 1429 expect(bounds2 != bounds1).assertTrue() 1430 await image2.pinchOut(1.2); 1431 let image3 = await driver.findComponent(ON.id('test_pict')) 1432 let bounds3 = await image3.getBounds() 1433 expect(bounds3 != bounds2).assertTrue() 1434 await driver.pressBack() 1435 await stopApplication('com.uitestScene.acts') 1436 }) 1437 1438 /* 1439 * @tc.number: uiTest_9037 1440 * @tc.name: testInjectMultiPointerAction 1441 * @tc.desc: inject multi-pointer action on the device display. 1442 */ 1443 it('testInjectMultiPointerAction', 0, async () => { 1444 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1445 let driver = Driver.create() 1446 await driver.delayMs(waitUiReadyMs) 1447 let button = await driver.findComponent(ON.id('jump')) 1448 await button.click() 1449 await driver.delayMs(waitUiReadyMs) 1450 let image1 = await driver.findComponent(ON.id('test_pict')) 1451 let bounds1 = await image1.getBounds() 1452 let left = bounds1.left 1453 let right = bounds1.right 1454 let centerY = Math.floor((bounds1.top + bounds1.bottom) / 2) 1455 let pointer = PointerMatrix.create(2,11) 1456 await driver.delayMs(300) 1457 for (let step = 0; step < 11; step++) { 1458 pointer.setPoint(0, step, {x: left + 200 - (step + 1) *20, y: centerY + step * 20}) 1459 } 1460 for (let step = 0; step < 11; step++) { 1461 pointer.setPoint(1, step, {x: right - 200 + (step + 1) *20, y: centerY - step * 20}) 1462 } 1463 await driver.injectMultiPointerAction(pointer, 400) 1464 await driver.delayMs(3000) 1465 let image2 = await driver.findComponent(ON.id('test_pict')) 1466 let bounds2= await image2.getBounds() 1467 expect(bounds2 != bounds1).assertTrue() 1468 await stopApplication('com.uitestScene.acts') 1469 }) 1470 1471 /* 1472 * @tc.number: uiTest_9038 1473 * @tc.name: testGetWindowMode 1474 * @tc.desc: get the window mode of this UiWindow. 1475 */ 1476 it('testGetWindowMode', 0, async () => { 1477 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1478 let driver = Driver.create() 1479 await driver.delayMs(waitUiReadyMs) 1480 let window1 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1481 let mode1 = await window1.getWindowMode() 1482 try { 1483 await window1.resume() 1484 let window2 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1485 let mode2 = await window2.getWindowMode() 1486 if (mode1 == WindowMode.FULLSCREEN) { 1487 expect(mode2 == WindowMode.FLOATING).assertTrue() 1488 expect(mode2 != WindowMode.SECONDARY).assertTrue() 1489 expect(mode2 != WindowMode.PRIMARY).assertTrue() 1490 } else { 1491 expect(mode2 == WindowMode.FULLSCREEN).assertTrue() 1492 } 1493 await stopApplication('com.uitestScene.acts') 1494 } 1495 catch (err) { 1496 if (err.message == 'this device can not support this action') { 1497 expect(window1 != null).assertTrue() 1498 } else { 1499 expect(false).assertTrue() 1500 } 1501 } 1502 }) 1503 1504 /* 1505 * @tc.number: uiTest_9039 1506 * @tc.name: testGetBundleName 1507 * @tc.desc: get the bundleName of this UiWindow. 1508 */ 1509 it('testGetBundleName', 0, async () => { 1510 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1511 let driver = Driver.create() 1512 await driver.delayMs(waitUiReadyMs) 1513 let window = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1514 let name = await window.getBundleName() 1515 expect(name == 'com.uitestScene.acts').assertTrue() 1516 await stopApplication('com.uitestScene.acts') 1517 }) 1518 1519 /* 1520 * @tc.number: uiTest_9040 1521 * @tc.name: testGetTitle 1522 * @tc.desc: get the title of this UiWindow. 1523 */ 1524 it('testGetTitle', 0, async () => { 1525 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1526 let driver = Driver.create() 1527 await driver.delayMs(waitUiReadyMs) 1528 let window = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1529 let title = await window.getTitle() 1530 expect(title == '').assertTrue() 1531 await stopApplication('com.uitestScene.acts') 1532 }) 1533 1534 /* 1535 * @tc.number: uiTest_9041 1536 * @tc.name: testWindowMoveTo 1537 * @tc.desc: move this UiWindow to the specified points. 1538 */ 1539 it('testWindowMoveTo', 0, async () => { 1540 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1541 let driver = Driver.create() 1542 await driver.delayMs(waitUiReadyMs) 1543 let window = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1544 try{ 1545 let windowMode = await window.getWindowMode() 1546 if (windowMode != WindowMode.FLOATING) { 1547 await window.resume() 1548 } 1549 await driver.delayMs(waitUiReadyMs) 1550 let window1 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1551 let bounds1 = await window1.getBounds() 1552 await window1.moveTo(100,100) 1553 await driver.delayMs(waitUiReadyMs) 1554 let window2 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1555 let bounds2 = await window2.getBounds() 1556 expect(bounds1 != bounds2).assertTrue() 1557 await stopApplication('com.uitestScene.acts') 1558 } 1559 catch (err) { 1560 if (err.message == 'this device can not support this action') { 1561 expect(window != null).assertTrue() 1562 } else { 1563 expect(false).assertTrue() 1564 } 1565 } 1566 }) 1567 1568 /* 1569 * @tc.number: uiTest_9042 1570 * @tc.name: testWindowResize 1571 * @tc.desc: resize this UiWindow to the specified size for the specified direction. 1572 */ 1573 it('testWindowResizeA', 0, async () => { 1574 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1575 let driver = Driver.create() 1576 await driver.delayMs(waitUiReadyMs) 1577 let window = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1578 try{ 1579 let windowMode = await window.getWindowMode() 1580 if (windowMode != WindowMode.FLOATING) { 1581 await window.resume() 1582 } 1583 await driver.delayMs(waitUiReadyMs) 1584 1585 let window1 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1586 let bounds1 = await window1.getBounds() 1587 await window1.resize(600,600,ResizeDirection.RIGHT_DOWN) 1588 await driver.delayMs(waitUiReadyMs) 1589 let window2 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1590 let bounds2 = await window2.getBounds() 1591 expect(bounds2 != bounds1).assertTrue() 1592 1593 await window2.resize(400,400,ResizeDirection.RIGHT_UP) 1594 let window3 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1595 let bounds3= await window3.getBounds() 1596 expect(bounds3 != bounds2).assertTrue() 1597 await window3.resize(300,300,ResizeDirection.LEFT_DOWN) 1598 let window4 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1599 let bounds4= await window4.getBounds() 1600 expect(bounds4 != bounds3).assertTrue() 1601 1602 await window4.resize(500,500,ResizeDirection.LEFT_UP) 1603 let window5 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1604 let bounds5= await window5.getBounds() 1605 expect(bounds5 != bounds4).assertTrue() 1606 await stopApplication('com.uitestScene.acts') 1607 } 1608 catch (err) { 1609 if (err.message == 'this device can not support this action') { 1610 expect(window != null).assertTrue() 1611 } else { 1612 expect(false).assertTrue() 1613 } 1614 } 1615 }) 1616 1617 it('testWindowResizeB', 0, async () => { 1618 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1619 let driver = Driver.create() 1620 await driver.delayMs(waitUiReadyMs) 1621 let window = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1622 try{ 1623 let windowMode = await window.getWindowMode() 1624 if (windowMode != WindowMode.FLOATING) { 1625 await window.resume() 1626 } 1627 await driver.delayMs(waitUiReadyMs) 1628 1629 let window5 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1630 let bounds5= await window5.getBounds() 1631 await window5.resize(bounds5.right - bounds5.left,300,ResizeDirection.DOWN) 1632 let window6 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1633 let bounds6= await window6.getBounds() 1634 expect(bounds6 != bounds5).assertTrue() 1635 1636 await window6.resize(bounds6.right - bounds6.left,500,ResizeDirection.UP) 1637 let window7 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1638 let bounds7 = await window7.getBounds() 1639 expect(bounds7 != bounds6).assertTrue() 1640 1641 await window7.resize(300,bounds7.bottom - bounds7.top,ResizeDirection.LEFT) 1642 let window8 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1643 let bounds8 = await window8.getBounds() 1644 expect(bounds8 != bounds7).assertTrue() 1645 1646 await window8.resize(500,bounds8.bottom - bounds8.top,ResizeDirection.RIGHT) 1647 let window9 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1648 let bounds9 = await window9.getBounds() 1649 expect(bounds9 != bounds8).assertTrue() 1650 1651 await stopApplication('com.uitestScene.acts') 1652 } 1653 catch (err) { 1654 if (err.message == 'this device can not support this action') { 1655 expect(window != null).assertTrue() 1656 } else { 1657 expect(false).assertTrue() 1658 } 1659 } 1660 }) 1661 1662 /* 1663 * @tc.number: uiTest_9043 1664 * @tc.name: testWindowAttr 1665 * @tc.desc: set the focused status of this UiWindow. 1666 */ 1667 it('testWindowAttr', 0, async () => { 1668 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1669 let driver = Driver.create() 1670 await driver.delayMs(waitUiReadyMs) 1671 let window = await driver.findWindow({bundleName:'com.uitestScene.acts',focused:true,actived:true,title:''}) 1672 await window.focus() 1673 let isFocused = await window.isFocused() 1674 let isActived = await window.isActived() 1675 expect(isFocused == true).assertTrue() 1676 expect(isActived == true).assertTrue() 1677 await stopApplication('com.uitestScene.acts') 1678 }) 1679 1680 /* 1681 * @tc.number: uiTest_9044 1682 * @tc.name: testWindowMaximize 1683 * @tc.desc: maximize this UiWindow. 1684 */ 1685 it('testWindowMaximize', 0, async () => { 1686 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1687 let driver = Driver.create() 1688 await driver.delayMs(waitUiReadyMs) 1689 let window = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1690 try{ 1691 let windowMode = await window.getWindowMode() 1692 if (windowMode != WindowMode.FLOATING) { 1693 await window.resume() 1694 } 1695 let window2 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1696 await window2.maximize() 1697 await driver.delayMs(waitUiReadyMs) 1698 let window3 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1699 let mode = await window3.getWindowMode() 1700 expect(mode == WindowMode.FULLSCREEN).assertTrue() 1701 await stopApplication('com.uitestScene.acts') 1702 } 1703 catch (err) { 1704 if (err.message == 'this device can not support this action') { 1705 expect(window != null).assertTrue() 1706 } else { 1707 expect(false).assertTrue() 1708 } 1709 } 1710 }) 1711 1712 /* 1713 * @tc.number: uiTest_9045 1714 * @tc.name: testWindowMinimize 1715 * @tc.desc: minimize this UiWindow. 1716 */ 1717 it('testWindowMinimize', 0, async () => { 1718 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1719 let driver = Driver.create() 1720 await driver.delayMs(waitUiReadyMs) 1721 let window = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1722 try{ 1723 await window.minimize() 1724 await driver.delayMs(waitUiReadyMs) 1725 let window1 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1726 expect(window1 == null).assertTrue() 1727 await stopApplication('com.uitestScene.acts') 1728 } 1729 catch (err) { 1730 if (err.message == 'this device can not support this action') { 1731 expect(window != null).assertTrue() 1732 } else { 1733 expect(false).assertTrue() 1734 } 1735 } 1736 }) 1737 1738 /* 1739 * @tc.number: uiTest_9046 1740 * @tc.name: testWindowClose 1741 * @tc.desc: close this UiWindow. 1742 */ 1743 it('testWindowClose', 0, async () => { 1744 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1745 let driver = Driver.create() 1746 await driver.delayMs(waitUiReadyMs) 1747 let window = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1748 try{ 1749 await window.close() 1750 await driver.delayMs(waitUiReadyMs) 1751 let window1 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1752 expect(window1 == null).assertTrue() 1753 } 1754 catch (err) { 1755 if (err.message == 'this device can not support this action') { 1756 expect(window != null).assertTrue() 1757 } else { 1758 expect(false).assertTrue() 1759 } 1760 } 1761 }) 1762 1763 /* 1764 * @tc.number: uiTest_9047 1765 * @tc.name: testGetDisplaySize 1766 * @tc.desc: get the size of the device display. 1767 */ 1768 it('testGetDisplaySize', 0, async () => { 1769 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1770 let driver = Driver.create() 1771 await driver.delayMs(waitUiReadyMs) 1772 let s = await driver.getDisplaySize() 1773 expect(s.x != 0).assertTrue() 1774 expect(s.y != 0).assertTrue() 1775 await stopApplication('com.uitestScene.acts') 1776 }) 1777 1778 /* 1779 * @tc.number: uiTest_9048 1780 * @tc.name: testGetDisplayDensity 1781 * @tc.desc: get the density of the device display. 1782 */ 1783 it('testGetDisplayDensity', 0, async () => { 1784 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1785 let driver = Driver.create() 1786 await driver.delayMs(waitUiReadyMs) 1787 let s = await driver.getDisplayDensity() 1788 expect(s.x != 0).assertTrue() 1789 expect(s.y != 0).assertTrue() 1790 await stopApplication('com.uitestScene.acts') 1791 }) 1792 1793 /* 1794 * @tc.number: uiTest_9049 1795 * @tc.name: testDisplayRotation 1796 * @tc.desc: get the rotation of the device display and set it. 1797 */ 1798 it('testDisplayRotation', 0, async () => { 1799 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1800 let driver = Driver.create() 1801 await driver.delayMs(waitUiReadyMs) 1802 await driver.setDisplayRotation(DisplayRotation.ROTATION_0) 1803 await driver.delayMs(waitUiReadyMs) 1804 let rotation = await driver.getDisplayRotation() 1805 if (rotation == DisplayRotation.ROTATION_90) { 1806 console.info('The device is displayed in horizontal on default') 1807 await driver.setDisplayRotation(DisplayRotation.ROTATION_90) 1808 await driver.delayMs(waitUiReadyMs) 1809 let rotation1 = await driver.getDisplayRotation() 1810 expect(rotation1 == DisplayRotation.ROTATION_0) 1811 1812 await driver.setDisplayRotation(DisplayRotation.ROTATION_180) 1813 await driver.delayMs(waitUiReadyMs) 1814 let rotation2 = await driver.getDisplayRotation() 1815 expect(rotation2 == DisplayRotation.ROTATION_270) 1816 1817 await driver.setDisplayRotation(DisplayRotation.ROTATION_270) 1818 await driver.delayMs(waitUiReadyMs) 1819 let rotation3 = await driver.getDisplayRotation() 1820 expect(rotation3 == DisplayRotation.ROTATION_180) 1821 1822 await driver.setDisplayRotation(DisplayRotation.ROTATION_90) 1823 } else if (rotation == DisplayRotation.ROTATION_0) { 1824 console.info('The device is displayed in vertical on default') 1825 await driver.setDisplayRotation(DisplayRotation.ROTATION_90) 1826 await driver.delayMs(waitUiReadyMs) 1827 let rotation1 = await driver.getDisplayRotation() 1828 expect(rotation1 == DisplayRotation.ROTATION_90) 1829 1830 await driver.setDisplayRotation(DisplayRotation.ROTATION_180) 1831 await driver.delayMs(waitUiReadyMs) 1832 let rotation2 = await driver.getDisplayRotation() 1833 expect(rotation2 == DisplayRotation.ROTATION_180) 1834 1835 await driver.setDisplayRotation(DisplayRotation.ROTATION_270) 1836 await driver.delayMs(waitUiReadyMs) 1837 let rotation3 = await driver.getDisplayRotation() 1838 expect(rotation3 == DisplayRotation.ROTATION_270) 1839 1840 await driver.setDisplayRotation(DisplayRotation.ROTATION_0) 1841 } 1842 await stopApplication('com.uitestScene.acts') 1843 }) 1844 1845 /* 1846 * @tc.number: uiTest_9050 1847 * @tc.name: testSetDisplayRotationEnabled 1848 * @tc.desc: enable/disable the rotation of device display. 1849 */ 1850 it('testSetDisplayRotationEnabled', 0, async () => { 1851 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1852 let driver = Driver.create() 1853 await driver.setDisplayRotationEnabled(true) 1854 await driver.delayMs(waitUiReadyMs) 1855 await driver.setDisplayRotation(DisplayRotation.ROTATION_0) 1856 await driver.delayMs(waitUiReadyMs) 1857 let rotation = await driver.getDisplayRotation() 1858 if (rotation == DisplayRotation.ROTATION_90) { 1859 console.info('The device is displayed in horizontal on default') 1860 await driver.setDisplayRotation(DisplayRotation.ROTATION_90) 1861 } else { 1862 console.info('The device is displayed in vertical on default') 1863 } 1864 await stopApplication('com.uitestScene.acts') 1865 }) 1866 1867 /* 1868 * @tc.number: uiTest_9051 1869 * @tc.name: testWakeUpDisplay 1870 * @tc.desc: wake up the device display. 1871 */ 1872 it('testWakeUpDisplay', 0, async () => { 1873 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1874 let driver = Driver.create() 1875 await driver.delayMs(waitUiReadyMs) 1876 await driver.wakeUpDisplay() 1877 await stopApplication('com.uitestScene.acts') 1878 }) 1879 1880 /* 1881 * @tc.number: uiTest_9052 1882 * @tc.name: testPressHome 1883 * @tc.desc: press the home key. 1884 */ 1885 it('testPressHome', 0, async () => { 1886 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1887 let driver = Driver.create() 1888 await driver.delayMs(waitUiReadyMs) 1889 await driver.pressHome() 1890 await driver.delayMs(1000) 1891 let button = await driver.findComponent(ON.text('next page')) 1892 expect(button == null).assertTrue() 1893 await stopApplication('com.uitestScene.acts') 1894 }) 1895 1896 /* 1897 * @tc.number: uiTest_9053 1898 * @tc.name: testWaitForIdle 1899 * @tc.desc: wait for the UI become idle. 1900 */ 1901 it('testWaitForIdle', 0, async () => { 1902 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1903 let driver = Driver.create() 1904 await driver.delayMs(2000) 1905 let idled = await driver.waitForIdle(4000,5000) 1906 expect(idled = true).assertTrue() 1907 await stopApplication('com.uitestScene.acts') 1908 }) 1909 1910 /* 1911 * @tc.number: uiTest_9054 1912 * @tc.name: testDrag 1913 * @tc.desc: drag on the screen between the specified points. 1914 */ 1915 it('testDrag', 0, async () => { 1916 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1917 let driver = Driver.create() 1918 await driver.delayMs(waitUiReadyMs) 1919 let button = await driver.findComponent(ON.id('jump')) 1920 await button.longClick() 1921 await driver.delayMs(waitUiReadyMs) 1922 let text1 = await driver.findComponent(ON.text('one')) 1923 let text2 = await driver.findComponent(ON.text('two')) 1924 let point1 = await text1.getBoundsCenter() 1925 let point2 = await text2.getBoundsCenter() 1926 await driver.drag(point1.x, point1.y, point2.x, point2.y) 1927 await driver.delayMs(waitUiReadyMs) 1928 let text = await driver.findComponent(ON.text('one').isBefore(ON.text('two'))) 1929 expect(text == null).assertTrue() 1930 await stopApplication('com.uitestScene.acts') 1931 }) 1932 1933 /* 1934 * @tc.number: uiTest_9055 1935 * @tc.name: testDragTos 1936 * @tc.desc: drag this UiComponent to the bounds rect of target UiComponent. 1937 */ 1938 it('testDragTo', 0, async () => { 1939 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1940 let driver = Driver.create() 1941 await driver.delayMs(waitUiReadyMs) 1942 let button = await driver.findComponent(ON.id('jump')) 1943 await button.longClick() 1944 await driver.delayMs(waitUiReadyMs) 1945 let text1 = await driver.findComponent(ON.text('one')) 1946 let text2 = await driver.findComponent(ON.text('two')) 1947 await text1.dragTo(text2) 1948 await driver.delayMs(waitUiReadyMs) 1949 let text = await driver.findComponent(ON.text('one').isBefore(ON.text('two'))) 1950 expect(text == null).assertTrue() 1951 await stopApplication('com.uitestScene.acts') 1952 }) 1953 1954 /* 1955 * @tc.number: uiTest_9056 1956 * @tc.name: testSplit 1957 * @tc.desc: change this UiWindow into split screen mode. 1958 */ 1959 it('testSplit', 0, async () => { 1960 await startAbility('com.uitestScene.acts', 'com.uitestScene.acts.MainAbility') 1961 let driver = Driver.create() 1962 await driver.delayMs(waitUiReadyMs) 1963 let window1 = await driver.findWindow({bundleName:'com.uitestScene.acts'}) 1964 try { 1965 await window1.split() 1966 await driver.delayMs(waitUiReadyMs) 1967 let bar = await driver.findComponent(ON.type('DecorBar')) 1968 expect(bar == null).assertTrue() 1969 } 1970 catch (err) { 1971 if (err.message == 'this device can not support this action') { 1972 expect(window1 != null).assertTrue() 1973 } else { 1974 expect(false).assertTrue() 1975 } 1976 } 1977 await stopApplication('com.uitestScene.acts') 1978 }) 1979 }) 1980} 1981