• 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_ServiceAbility]'
22const DOMAIN = 0xF811
23const BUNDLE = 'ServiceAbility_'
24
25export default function appTest() {
26  describe('appTest', function () {
27    it(BUNDLE + 'StartAbilityFunction_001', 0, async function (done) {
28      hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbilityFunction_001 begin')
29      let parameter = {
30        "want": {
31          bundleName: "ohos.samples.etsserviceability",
32          abilityName: "ohos.samples.etsserviceability.MainAbility"
33        }
34      }
35      featureAbility.startAbility(parameter, (err, data) => {
36        hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbilityFunction_001,err.code:' + err.code)
37        expect(0).assertEqual(err.code)
38        done()
39        hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbilityFunction_001 end')
40      })
41    })
42    /**
43     * 连接服务
44     */
45    it(BUNDLE + 'ConnectServiceFunction_001', 0, async function () {
46      hilog.info(DOMAIN, TAG, BUNDLE + 'ConnectServiceFunction_001 begin')
47      let driver = await UiDriver.create()
48      await driver.delayMs(1000)
49      hilog.info(DOMAIN, TAG, BUNDLE + 'ConnectServiceFunction_001 clickConnectServiceBtn')
50      // 点击连接服务
51      await driver.assertComponentExist(BY.text('连接服务'))
52      let btnConnectService = await driver.findComponent(BY.text('连接服务'))
53      await driver.delayMs(1000)
54      await btnConnectService.click()
55      hilog.info(DOMAIN, TAG, BUNDLE + 'ConnectServiceFunction_001 end')
56    })
57    /**
58     * 输入字符串进行排序
59     */
60    it(BUNDLE + 'StringSortFunction_001', 0, async function () {
61      hilog.info(DOMAIN, TAG, BUNDLE + 'StringSortFunction_001 begin')
62      let driver = await UiDriver.create()
63      await driver.delayMs(1000)
64      hilog.info(DOMAIN, TAG, BUNDLE + 'StringSortFunction_001 inputString')
65      // 输入字符串
66      await driver.assertComponentExist(BY.key('textAreaInput'))
67      let textArea = await driver.findComponent(BY.key('textAreaInput'))
68      await driver.delayMs(1000)
69      await textArea.inputText('anghjdek')
70      let inputValue = await textArea.getText()
71      hilog.info(DOMAIN, TAG, BUNDLE + 'StringSortFunction_001 inputValue')
72      expect('anghjdek').assertEqual(inputValue)
73      await driver.delayMs(1000)
74      hilog.info(DOMAIN, TAG, BUNDLE + 'StringSortFunction_001 clickStringSortBtn')
75      // 点击字符串排序
76      await driver.assertComponentExist(BY.text('字符串排序'))
77      let btnStringSort = await driver.findComponent(BY.text('字符串排序'))
78      await driver.delayMs(1000)
79      await btnStringSort.click()
80      hilog.info(DOMAIN, TAG, BUNDLE + 'StringSortFunction_001 end')
81    })
82    /**
83     * 断开服务
84     */
85    it(BUNDLE + 'DisconnectServiceFunction_001', 0, async function () {
86      hilog.info(DOMAIN, TAG, BUNDLE + 'DisconnectServiceFunction_001 begin')
87      let driver = await UiDriver.create()
88      await driver.delayMs(1000)
89      hilog.info(DOMAIN, TAG, BUNDLE + 'DisconnectServiceFunction_001 clickDisconnectServiceBtn')
90      // 点击断开服务
91      await driver.assertComponentExist(BY.text('断开服务'))
92      let btnDisconnectService = await driver.findComponent(BY.text('断开服务'))
93      await driver.delayMs(1000)
94      await btnDisconnectService.click()
95      hilog.info(DOMAIN, TAG, BUNDLE + 'DisconnectServiceFunction_001 end')
96    })
97  })
98}