• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15
16import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
17import { UiDriver, BY, UiComponent, MatchPattern } from '@ohos.uitest'
18import featureAbility from '@ohos.ability.featureAbility'
19import hilog from '@ohos.hilog'
20
21const TAG = '[Sample_FlipClock]'
22const DOMAIN = 0xF811
23const BUNDLE = 'FlipClock_'
24
25export default function appTest() {
26  describe('appTest', function () {
27    it(BUNDLE + 'StartAbility_001', 0, async function (done) {
28      hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin')
29      let parameter = {
30        "want": {
31          bundleName: "ohos.samples.etsFlipClock",
32          abilityName: "ohos.samples.etsFlipClock.MainAbility"
33        }
34      }
35      await featureAbility.startAbility(parameter, (err, data) => {
36        hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,err.code:' + err.code)
37        expect(0).assertEqual(err.code)
38        done()
39        hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end')
40      })
41    })
42
43    /**
44     * 时钟
45     */
46    it(BUNDLE + 'CreateFunction_001', 0, async function () {
47      hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 begin')
48      let driver = await UiDriver.create()
49      await driver.delayMs(2000)
50      hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 end')
51    })
52
53    /**
54     * 闹钟
55     */
56    it(BUNDLE + 'ClockFunction_001', 0, async function () {
57      hilog.info(DOMAIN, TAG, BUNDLE + 'ClockFunction_001 begin')
58      let driver = await UiDriver.create()
59      await driver.delayMs(500)
60      hilog.info(DOMAIN, TAG, BUNDLE + 'ClockFunction_001 clockClick')
61      await driver.assertComponentExist(BY.text('闹钟', MatchPattern.CONTAINS))
62      let btnClock = await driver.findComponent(BY.text('闹钟', MatchPattern.CONTAINS))
63      await btnClock.click()
64      await driver.delayMs(500)
65      hilog.info(DOMAIN, TAG, BUNDLE + 'ClockFunction_001 end')
66    })
67
68    /**
69     * 倒计时
70     */
71    it(BUNDLE + 'CountdownFunction_001', 0, async function () {
72      hilog.info(DOMAIN, TAG, BUNDLE + 'CountdownFunction_001 begin')
73      let driver = await UiDriver.create()
74      await driver.delayMs(500)
75      hilog.info(DOMAIN, TAG, BUNDLE + 'CountdownFunction_001 timerClick')
76      await driver.assertComponentExist(BY.text('倒计时', MatchPattern.CONTAINS))
77      let btnTimer = await driver.findComponent(BY.text('倒计时', MatchPattern.CONTAINS))
78      await btnTimer.click()
79      await driver.delayMs(500)
80      hilog.info(DOMAIN, TAG, BUNDLE + 'CountdownFunction_001 end')
81    })
82
83    /**
84     * 设置
85     */
86    it(BUNDLE + 'SetFunction_001', 0, async function () {
87      hilog.info(DOMAIN, TAG, BUNDLE + 'SetFunction_001 begin')
88      let driver = await UiDriver.create()
89      await driver.delayMs(1000)
90      hilog.info(DOMAIN, TAG, BUNDLE + 'SetFunction_001 setting')
91      await driver.assertComponentExist(BY.text('设置', MatchPattern.CONTAINS))
92      let btnSettings = await driver.findComponent(BY.text('设置', MatchPattern.CONTAINS))
93      await btnSettings.click()
94      await driver.delayMs(1000)
95      // 全屏
96      hilog.info(DOMAIN, TAG, BUNDLE + 'SetFunction_001 fullScreen')
97      await driver.assertComponentExist(BY.type('Toggle'))
98      let btnFullScreen = await driver.findComponent(BY.type('Toggle'))
99      await btnFullScreen.click()
100      await driver.delayMs(1000)
101      // 屏幕常量
102      hilog.info(DOMAIN, TAG, BUNDLE + 'SetFunction_001 screenLight')
103      await driver.assertComponentExist(BY.key('screenLight'))
104      let btnScreenLight = await driver.findComponent(BY.key('screenLight'))
105      await btnScreenLight.click()
106      await driver.delayMs(1000)
107      // 亮度调节
108      hilog.info(DOMAIN, TAG, BUNDLE + 'SetFunction_001 brightness')
109      await driver.assertComponentExist(BY.key('brightness'))
110      let btnBrightness = await driver.findComponent(BY.key('brightness'))
111      await btnBrightness.click()
112      await driver.delayMs(1000)
113      hilog.info(DOMAIN, TAG, BUNDLE + 'SetFunction_001 end')
114    })
115  })
116}