• 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
19import featureAbility from '@ohos.ability.featureAbility'
20import hilog from '@ohos.hilog'
21
22const TAG = '[Sample_Observer]'
23const DOMAIN = 0xF811
24const BUNDLE = 'Observer _'
25
26export default function appTest() {
27  describe('appTest', function () {
28    it(BUNDLE + 'StartAbility_001', 0, async function (done) {
29      hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin')
30      let want = {
31        bundleName: "ohos.samples.observer",
32        abilityName: "MainAbility"
33      }
34      var abilityDelegator: any
35      abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
36      await abilityDelegator.startAbility(want, (err, data) => {
37        hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,err.code:' + err.code)
38        expect(0).assertEqual(err.code)
39        done()
40        hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end')
41      })
42    })
43
44    /**
45     * Observer
46     */
47    it(BUNDLE + 'ObserverFunction_001', 0, async function () {
48      // create UiDriver
49      hilog.info(DOMAIN, TAG, BUNDLE + 'ObserverFunction_001 begin')
50      let driver = await UiDriver.create()
51      await driver.delayMs(1000)
52      // 订阅网络状态变化事件
53      hilog.info(DOMAIN, TAG, BUNDLE + 'ObserverFunction_001 network_state_change')
54      await driver.assertComponentExist(BY.key('switch1'))
55      let switch1 = await driver.findComponent(BY.key('switch1'))
56      await switch1.click()
57      await driver.delayMs(1000)
58      // 订阅信号状态变化事件
59      hilog.info(DOMAIN, TAG, BUNDLE + 'ObserverFunction_001 signal_info_change')
60      await driver.assertComponentExist(BY.key('switch2'))
61      let switch2 = await driver.findComponent(BY.key('switch2'))
62      await switch2.click()
63      await driver.delayMs(1000)
64      // 订阅通话状态变化事件
65      hilog.info(DOMAIN, TAG, BUNDLE + 'ObserverFunction_001 callState_change')
66      await driver.assertComponentExist(BY.key('switch3'))
67      let switch3 = await driver.findComponent(BY.key('switch3'))
68      await switch3.click()
69      await driver.delayMs(1000)
70      // 订阅蜂窝数据链路连接状态
71      hilog.info(DOMAIN, TAG, BUNDLE + 'ObserverFunction_001 cellular_data_connection_state_change')
72      await driver.assertComponentExist(BY.key('switch4'))
73      let switch4 = await driver.findComponent(BY.key('switch4'))
74      await switch4.click()
75      await driver.delayMs(1000)
76      // 订阅蜂窝数据业务的数据流状态
77      hilog.info(DOMAIN, TAG, BUNDLE + 'ObserverFunction_001 cellular_data_flow_change')
78      await driver.assertComponentExist(BY.key('switch5'))
79      let switch5 = await driver.findComponent(BY.key('switch5'))
80      await switch5.click()
81      await driver.delayMs(1000)
82      // 订阅sim状态更改事件
83      hilog.info(DOMAIN, TAG, BUNDLE + 'ObserverFunction_001 sim_state_change')
84      await driver.assertComponentExist(BY.key('switch6'))
85      let switch6 = await driver.findComponent(BY.key('switch6'))
86      await switch6.click()
87      await driver.delayMs(1000)
88      // seeDetails
89      hilog.info(DOMAIN, TAG, BUNDLE + 'ObserverFunction_001 seeDetails')
90      await driver.assertComponentExist(BY.key('seeDetails'))
91      let btnDetail = await driver.findComponent(BY.key('seeDetails'))
92      await btnDetail.click()
93      await driver.delayMs(1000)
94      // 返回上一级
95      hilog.info(DOMAIN, TAG, BUNDLE + 'ObserverFunction_001 back')
96      await driver.assertComponentExist(BY.key('back'))
97      let back = await driver.findComponent(BY.key('back'))
98      await back.click()
99      await driver.delayMs(1000)
100      hilog.info(DOMAIN, TAG, BUNDLE + 'ObserverFunction_001 end')
101    })
102  })
103}