• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15
16import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
17import { describe, it, expect } from '@ohos/hypium';
18import { Driver, ON } from '@ohos.UiTest';
19import hilog from '@ohos.hilog';
20
21const TAG = '[Sample_ArkTSDrawingAPI]';
22const DOMAIN = 0xF811
23const BUNDLE = 'ArkTSDrawingAPI_'
24
25export default function abilityTest() {
26
27  describe('ActsAbilityTest', () => {
28    /**
29     * 打开应用
30     */
31    it(BUNDLE + 'StartAbility_001', 0, async (done: Function) => {
32      hilog.info(DOMAIN, TAG, BUNDLE + "StartAbility_001, begin")
33      let driver = Driver.create();
34      let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
35      try {
36        await abilityDelegator.startAbility({
37          bundleName: 'com.samples.drawing',
38          abilityName: 'EntryAbility'
39        });
40      } catch (exception) {
41        hilog.info(DOMAIN, TAG, BUNDLE + `StartAbility_001 exception = ${JSON.stringify(exception)}`)
42        expect().assertFail();
43      }
44      await driver.delayMs(1000);
45      await driver.assertComponentExist(ON.text('Draw Path'));
46      done();
47      hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end')
48    })
49
50    /**
51     * 点击按钮,绘制图形
52     */
53    it(BUNDLE + 'DrawPath_001', 2, async () => {
54      hilog.info(DOMAIN, TAG, BUNDLE + "DrawPath_001, begin")
55      let driver = Driver.create();
56      let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
57      try {
58        await abilityDelegator.startAbility({
59          bundleName: 'com.samples.drawing',
60          abilityName: 'EntryAbility'
61        });
62      } catch (exception) {
63        hilog.info(DOMAIN, TAG, BUNDLE + `DrawPath_001 exception = ${JSON.stringify(exception)}`)
64        expect().assertFail();
65      }
66      await driver.delayMs(1000);
67      await driver.assertComponentExist(ON.text('Draw Path'));
68      let drawPathBtn = await driver.findComponent(ON.text('Draw Path'));
69      // 点击'Draw Path'按钮
70      await drawPathBtn.click();
71      await driver.delayMs(1000);
72      hilog.info(DOMAIN, TAG, BUNDLE + 'DrawPath_001 end')
73    })
74
75    /**
76     * 点击按钮,绘制矩形
77     */
78    it(BUNDLE + 'DrawRect_001', 2, async () => {
79      hilog.info(DOMAIN, TAG, BUNDLE + 'DrawRect_001 begin')
80      let driver = Driver.create();
81      let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
82      try {
83        await abilityDelegator.startAbility({
84          bundleName: 'com.samples.drawing',
85          abilityName: 'EntryAbility'
86        });
87      } catch (exception) {
88        hilog.info(DOMAIN, TAG, BUNDLE + `DrawRect_001 exception = ${JSON.stringify(exception)}`)
89        expect().assertFail();
90      }
91      await driver.delayMs(1000);
92      await driver.assertComponentExist(ON.text('Draw Rect'));
93      let drawPathBtn = await driver.findComponent(ON.text('Draw Rect'));
94      // 点击'Draw Rect'按钮
95      await drawPathBtn.click();
96      await driver.delayMs(1000);
97      hilog.info(DOMAIN, TAG, BUNDLE + 'DrawRect_001 end')
98    })
99
100    /**
101     * 点击按钮,绘制文字
102     */
103    it(BUNDLE + 'DrawText_001', 2, async () => {
104      hilog.info(DOMAIN, TAG, BUNDLE + 'DrawText_001 begin')
105      let driver = Driver.create();
106      let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
107      try {
108        await abilityDelegator.startAbility({
109          bundleName: 'com.samples.drawing',
110          abilityName: 'EntryAbility'
111        });
112      } catch (exception) {
113        hilog.info(DOMAIN, TAG, BUNDLE + `DrawText_001 exception = ${JSON.stringify(exception)}`)
114        expect().assertFail();
115      }
116      await driver.delayMs(1000);
117      await driver.assertComponentExist(ON.text('Draw Text'));
118      let drawPathBtn = await driver.findComponent(ON.text('Draw Text'));
119      // 点击'Draw Text'按钮
120      await drawPathBtn.click();
121      await driver.delayMs(1000);
122      hilog.info(DOMAIN, TAG, BUNDLE + 'DrawText_001 end')
123    })
124  })
125}