• 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_Cipher]'
22const DOMAIN = 0xF811
23const BUNDLE = 'Cipher_'
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.cipher",
32          abilityName: "ohos.samples.cipher.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 + 'EncryptionFunction_001', 0, async function () {
47      // create UiDriver
48      hilog.info(DOMAIN, TAG, BUNDLE + 'EncryptionFunction_001 begin')
49      let driver = await UiDriver.create()
50      await driver.delayMs(1000)
51      // 加密
52      hilog.info(DOMAIN, TAG, BUNDLE + 'EncryptionFunction_001 encryption')
53      await driver.assertComponentExist(BY.key('encryption'))
54      let encryption = await driver.findComponent(BY.key('encryption'))
55      await encryption.click()
56      await driver.delayMs(1000)
57      // 点击加密/解密
58      hilog.info(DOMAIN, TAG, BUNDLE + 'EncryptionFunction_001 encryptAndDecrypt')
59      await driver.assertComponentExist(BY.key('encryptAndDecrypt'))
60      let encryptAndDecrypt = await driver.findComponent(BY.key('encryptAndDecrypt'))
61      await encryptAndDecrypt.click()
62      await driver.delayMs(1000)
63      // 返回上一级
64      hilog.info(DOMAIN, TAG, BUNDLE + 'EncryptionFunction_001 back')
65      await driver.assertComponentExist(BY.key('back'))
66      let btnBack = await driver.findComponent(BY.key('back'))
67      await btnBack.click()
68      await driver.delayMs(1000)
69      hilog.info(DOMAIN, TAG, BUNDLE + 'EncryptionFunction_001 end')
70    })
71
72    /**
73     * 解密
74     */
75    it(BUNDLE + 'DecryptFunction_001', 0, async function () {
76      // create UiDriver
77      hilog.info(DOMAIN, TAG, BUNDLE + 'DecryptFunction_001 begin')
78      let driver = await UiDriver.create()
79      await driver.delayMs(1000)
80      // 解密
81      hilog.info(DOMAIN, TAG, BUNDLE + 'DecryptFunction_001 decrypt')
82      await driver.assertComponentExist(BY.key('decrypt'))
83      let decrypt = await driver.findComponent(BY.key('decrypt'))
84      await decrypt.click()
85      await driver.delayMs(1000)
86      // 点击加密/解密
87      hilog.info(DOMAIN, TAG, BUNDLE + 'DecryptFunction_001 Decrypt')
88      await driver.assertComponentExist(BY.key('encryptAndDecrypt'))
89      let encryptAndDecrypt = await driver.findComponent(BY.key('encryptAndDecrypt'))
90      await encryptAndDecrypt.click()
91      await driver.delayMs(1000)
92      // 返回上一级
93      hilog.info(DOMAIN, TAG, BUNDLE + 'DecryptFunction_001 back')
94      await driver.assertComponentExist(BY.key('back'))
95      let btnBack = await driver.findComponent(BY.key('back'))
96      await btnBack.click()
97      await driver.delayMs(1000)
98      hilog.info(DOMAIN, TAG, BUNDLE + 'DecryptFunction_001 end')
99    })
100  })
101}