1/* 2 * Copyright (c) 2024 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 AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; 16import { describe, it, expect } from '@ohos/hypium'; 17import { Driver, ON } from '@ohos.UiTest'; 18import { hilog } from '@kit.PerformanceAnalysisKit'; 19 20const TAG = '[Sample_NDKDrawingAPI]'; 21const DOMAIN = 0xF811 22const BUNDLE = 'NDKDrawingAPI_' 23 24export default function abilityTest() { 25 26 describe('ActsAbilityTest', () => { 27 /** 28 * 打开应用 29 */ 30 it(BUNDLE + 'StartAbility_001', 0, async (done: Function) => { 31 hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin') 32 let driver = Driver.create(); 33 let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 34 try { 35 await abilityDelegator.startAbility({ 36 bundleName: 'com.samples.cdrawing', 37 abilityName: 'EntryAbility' 38 }); 39 } catch (exception) { 40 hilog.info(DOMAIN, TAG, BUNDLE + `StartAbility_001 exception = ${JSON.stringify(exception)}`) 41 expect().assertFail(); 42 } 43 await driver.delayMs(1000); 44 await driver.assertComponentExist(ON.text('Draw Path')); 45 done(); 46 hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end') 47 }) 48 49 /** 50 * 点击按钮,绘制图形 51 */ 52 it(BUNDLE + 'DrawPath_001', 2, async () => { 53 hilog.info(DOMAIN, TAG, BUNDLE + 'DrawPath_001 begin') 54 let driver = Driver.create(); 55 let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 56 try { 57 await abilityDelegator.startAbility({ 58 bundleName: 'com.samples.cdrawing', 59 abilityName: 'EntryAbility' 60 }); 61 } catch (exception) { 62 hilog.info(DOMAIN, TAG, BUNDLE + `DrawPath_001 exception = ${JSON.stringify(exception)}`) 63 expect().assertFail(); 64 } 65 await driver.delayMs(1000); 66 await driver.assertComponentExist(ON.text('Draw Path')); 67 let drawPathBtn = await driver.findComponent(ON.text('Draw Path')); 68 // 点击'Draw Path'按钮 69 await drawPathBtn.click(); 70 await driver.delayMs(1000); 71 hilog.info(DOMAIN, TAG, BUNDLE + 'DrawPath_001 end') 72 }) 73 74 /** 75 * 点击按钮,绘制文字 76 */ 77 it(BUNDLE + 'DrawText_001', 2, async () => { 78 hilog.info(DOMAIN, TAG, BUNDLE + 'DrawText_001 begin') 79 let driver = Driver.create(); 80 let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 81 try { 82 await abilityDelegator.startAbility({ 83 bundleName: 'com.samples.cdrawing', 84 abilityName: 'EntryAbility' 85 }); 86 } catch (exception) { 87 hilog.info(DOMAIN, TAG, BUNDLE + `DrawText_001 exception = ${JSON.stringify(exception)}`) 88 expect().assertFail(); 89 } 90 await driver.delayMs(1000); 91 await driver.assertComponentExist(ON.text('Draw Text')); 92 let drawPathBtn = await driver.findComponent(ON.text('Draw Text')); 93 // 点击'Draw Text'按钮 94 await drawPathBtn.click(); 95 await driver.delayMs(1000); 96 hilog.info(DOMAIN, TAG, BUNDLE + 'DrawText_001 end') 97 }) 98 }) 99}