1/* 2 * Copyright (c) 2023 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 */ 15 16import hilog from '@ohos.hilog'; 17import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; 18import { Driver, ON } from '@ohos.UiTest'; 19import logger from '../util/Logger'; 20import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; 21 22const TAG = '[Sample_CanvasGame]'; 23const BUNDLE = 'canvasGame_'; 24const DRIVER = Driver.create(); 25let abilityDelegatorRegistry = AbilityDelegatorRegistry.getAbilityDelegator(); 26 27export default function abilityTest() { 28 describe('ActsAbilityTest', () => { 29 30 /** 31 * 长按打开卡片列表 32 */ 33 it(BUNDLE + 'OpenFormList_001', 0, async (done: Function) => { 34 let ability = await abilityDelegatorRegistry.getCurrentTopAbility(); 35 let manager = ability.context.resourceManager; 36 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 37 logger.info(TAG, `${BUNDLE}OpenFormList_001 begin`); 38 // 点击退出 39 await DRIVER.pressBack(); 40 await DRIVER.delayMs(500); 41 // 检查桌面是否存在五子棋卡片应用 42 await DRIVER.assertComponentExist(ON.text(await manager.getStringValue($r('app.string.EntryAbility_label')))); 43 let app = await DRIVER.findComponent(ON.text(await manager.getStringValue($r('app.string.EntryAbility_label')))); 44 // 获取文字控件边框 45 let rect = await app.getBounds(); 46 // 计算文字控件高度 47 let height = rect.bottom - rect.top; 48 // 获取文字控件中心点 49 let point = await app.getBoundsCenter(); 50 await DRIVER.longClick(point.x, point.y - height); 51 await DRIVER.delayMs(500); 52 // 检查长按应用是否存在服务卡片弹窗 53 await DRIVER.assertComponentExist(ON.text(await manager.getStringValue($r('app.string.Card_Button')))); 54 let formBtn = await DRIVER.findComponent(ON.text(await manager.getStringValue($r('app.string.Card_Button')))); 55 await formBtn.click(); 56 done(); 57 logger.info(TAG, `${BUNDLE}OpenFormList_001 end`); 58 }) 59 60 /** 61 * 创建卡片 62 */ 63 it(BUNDLE + 'createForm_001', 0, async (done: Function) => { 64 // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. 65 logger.info(TAG, `${BUNDLE}createForm_001 begin`); 66 let resourceManager = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext().resourceManager; 67 await DRIVER.delayMs(500); 68 // 检查是否有添加到桌面按钮 69 await DRIVER.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.AddForm')))); 70 let addToDesk = await DRIVER.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.AddForm')))); 71 await addToDesk.click(); 72 await DRIVER.delayMs(500); 73 // 检查是否桌面上是否有五子棋卡片 74 await DRIVER.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')))); 75 let resultArray = await DRIVER.findComponents(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')))); 76 expect(resultArray.length).assertEqual(2); 77 done(); 78 logger.info(TAG, `${BUNDLE}createForm_001 end`); 79 }) 80 }) 81}