• 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
18import { UiDriver, BY, UiComponent, MatchPattern } from '@ohos.uitest'
19import hilog from '@ohos.hilog'
20
21const TAG = '[Sample_Screenshot]'
22const DOMAIN = 0xF811
23const BUNDLE = 'Screenshot_'
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 want = {
30        bundleName: "ohos.samples.screenshot",
31        abilityName: "MainAbility"
32      }
33      var abilityDelegator: any
34      abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
35      abilityDelegator.startAbility(want, (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 + 'ClickAgreeFunction_001', 0, async () => {
46      hilog.info(DOMAIN, TAG, BUNDLE + 'ClickAgreeFunction_001 begin')
47      let driver = await UiDriver.create()
48      await driver.delayMs(1000)
49      // 点击允许
50      hilog.info(DOMAIN, TAG, BUNDLE + 'ClickAgreeFunction_001 clickAcceptBtn')
51      await driver.assertComponentExist(BY.text('允许'))
52      let btnAccept = await driver.findComponent(BY.text('允许'))
53      await btnAccept.click()
54      await driver.delayMs(1000)
55      hilog.info(DOMAIN, TAG, BUNDLE + 'ClickAgreeFunction_001 end')
56    })
57    /**
58     * 点击进行全屏截图
59     */
60    it(BUNDLE + 'FullScreenFunction_001', 0, async () => {
61      // 全屏截图
62      hilog.info(DOMAIN, TAG, BUNDLE + 'FullScreenFunction_001 begin')
63      let driver = await UiDriver.create()
64      await driver.delayMs(1000)
65      hilog.info(DOMAIN, TAG, BUNDLE + 'FullScreenFunction_001 clickFullScreenBtn')
66      await driver.assertComponentExist(BY.key('trueFullScreenShot'))
67      let fullScreen = await driver.findComponent(BY.key('trueFullScreenShot'))
68      await fullScreen.click()
69      await driver.delayMs(1000)
70      hilog.info(DOMAIN, TAG, BUNDLE + 'FullScreenFunction_001 end')
71    })
72    /**
73     * 点击进行固定大小截图
74     */
75    it(BUNDLE + 'FixedSizeScreenFunction_001', 0, async () => {
76      // 固定大小截图
77      hilog.info(DOMAIN, TAG, BUNDLE + 'FixedSizeScreenFunction_001 begin')
78      let driver = await UiDriver.create()
79      await driver.delayMs(1000)
80      hilog.info(DOMAIN, TAG, BUNDLE + 'FixedSizeScreenFunction_001 clickFixedScreenBtn')
81      await driver.assertComponentExist(BY.key('falseFullScreenShot'))
82      let fixedSize = await driver.findComponent(BY.key('falseFullScreenShot'))
83      await fixedSize.click()
84      await driver.delayMs(1000)
85      hilog.info(DOMAIN, TAG, BUNDLE + 'FixedSizeScreenFunction_001 end')
86    })
87  })
88}