• 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_TransitionAnimation]'
23const DOMAIN = 0xF811
24const BUNDLE = 'TransitionAnimation_'
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.transitionanimation",
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     * 页面间转场:底部滑入
46     */
47    it(BUNDLE + 'PageTransitionBottomFunction_001', 0, async function () {
48      // create UiDriver
49      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionBottomFunction_001 begin')
50      let driver = await UiDriver.create()
51      await driver.delayMs(1000)
52      // PageTransitionBottom
53      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionBottomFunction_001 PageTransitionBottom')
54      await driver.assertComponentExist(BY.text('底部滑入', MatchPattern.CONTAINS))
55      let bottom = await driver.findComponent(BY.text('底部滑入', MatchPattern.CONTAINS))
56      await bottom.click()
57      await driver.delayMs(1000)
58      // 返回上一级
59      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionBottomFunction_001 back')
60      await driver.assertComponentExist(BY.key('backImg'))
61      let backImg = await driver.findComponent(BY.key('backImg'))
62      await backImg.click()
63      await driver.delayMs(1000)
64      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionBottomFunction_001 end')
65    })
66
67    /**
68     * 页面间转场:自定义1
69     */
70    it(BUNDLE + 'PageTransitionCustomFirstFunction_001', 0, async function () {
71      // create UiDriver
72      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionCustomFirstFunction_001 begin')
73      let driver = await UiDriver.create()
74      await driver.delayMs(1000)
75      // PageTransitionCustomFirst
76      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionCustomFirstFunction_001 PageTransitionCustomFirst')
77      await driver.assertComponentExist(BY.text('自定义1', MatchPattern.CONTAINS))
78      let customFirst = await driver.findComponent(BY.text('自定义1', MatchPattern.CONTAINS))
79      await customFirst.click()
80      await driver.delayMs(1000)
81      // 返回上一级
82      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionCustomFirstFunction_001 back')
83      await driver.assertComponentExist(BY.key('backImg'))
84      let backImg = await driver.findComponent(BY.key('backImg'))
85      await backImg.click()
86      await driver.delayMs(1000)
87      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionCustomFirstFunction_001 end')
88    })
89
90    /**
91     * 页面间转场:自定义2
92     */
93    it(BUNDLE + 'PageTransitionCustomSecondFunction_001', 0, async function () {
94      // create UiDriver
95      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionCustomSecondFunction_001 begin')
96      let driver = await UiDriver.create()
97      await driver.delayMs(1000)
98      // PageTransitionCustomFirst
99      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionCustomSecondFunction_001 PageTransitionCustomFirst')
100      await driver.assertComponentExist(BY.text('自定义2', MatchPattern.CONTAINS))
101      let customSecond = await driver.findComponent(BY.text('自定义2', MatchPattern.CONTAINS))
102      await customSecond.click()
103      await driver.delayMs(1000)
104      // 返回上一级
105      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionCustomSecondFunction_001 back')
106      await driver.assertComponentExist(BY.key('backImg'))
107      let backImg = await driver.findComponent(BY.key('backImg'))
108      await backImg.click()
109      await driver.delayMs(1000)
110      hilog.info(DOMAIN, TAG, BUNDLE + 'PageTransitionCustomSecondFunction_001 end')
111    })
112
113    /**
114     * 组件内转场
115     */
116    it(BUNDLE + 'ComponentTransitionFunction_001', 0, async function () {
117      // create UiDriver
118      hilog.info(DOMAIN, TAG, BUNDLE + 'ComponentTransitionFunction_001 begin')
119      let driver = await UiDriver.create()
120      await driver.delayMs(1000)
121      // ComponentTransition
122      hilog.info(DOMAIN, TAG, BUNDLE + 'ComponentTransitionFunction_001 ComponentTransition')
123      await driver.assertComponentExist(BY.text('组件内转场', MatchPattern.CONTAINS))
124      let componentTransition = await driver.findComponent(BY.text('组件内转场', MatchPattern.CONTAINS))
125      await componentTransition.click()
126      await driver.delayMs(1000)
127      // show
128      hilog.info(DOMAIN, TAG, BUNDLE + 'ComponentTransitionFunction_001 show')
129      await driver.assertComponentExist(BY.key('show'))
130      let showBtn = await driver.findComponent(BY.key('show'))
131      await showBtn.click()
132      await driver.delayMs(1000)
133      // hide
134      hilog.info(DOMAIN, TAG, BUNDLE + 'ComponentTransitionFunction_001 hide')
135      await showBtn.click()
136      await driver.delayMs(1000)
137      // 返回上一级
138      hilog.info(DOMAIN, TAG, BUNDLE + 'ComponentTransitionFunction_001 back')
139      await driver.assertComponentExist(BY.key('backImg'))
140      let backImg = await driver.findComponent(BY.key('backImg'))
141      await backImg.click()
142      await driver.delayMs(1000)
143      hilog.info(DOMAIN, TAG, BUNDLE + 'ComponentTransitionFunction_001 end')
144    })
145
146    /**
147     * 共享元素转场
148     */
149    it(BUNDLE + 'ShareTransitionFunction_001', 0, async function () {
150      // create UiDriver
151      hilog.info(DOMAIN, TAG, BUNDLE + 'ShareTransitionFunction_001 begin')
152      let driver = await UiDriver.create()
153      await driver.delayMs(1000)
154      // ComponentTransition
155      hilog.info(DOMAIN, TAG, BUNDLE + 'ShareTransitionFunction_001 ComponentTransition')
156      await driver.assertComponentExist(BY.text('共享元素转场', MatchPattern.CONTAINS))
157      let shareTransition = await driver.findComponent(BY.text('共享元素转场', MatchPattern.CONTAINS))
158      await shareTransition.click()
159      await driver.delayMs(1000)
160      // shareItem1
161      hilog.info(DOMAIN, TAG, BUNDLE + 'ShareTransitionFunction_001 shareItem1')
162      await driver.assertComponentExist(BY.key('shareItem1'))
163      let shareItem1 = await driver.findComponent(BY.key('shareItem1'))
164      await shareItem1.click()
165      await driver.delayMs(1000)
166      // 返回上一级
167      hilog.info(DOMAIN, TAG, BUNDLE + 'ShareTransitionFunction_001 back1')
168      await driver.assertComponentExist(BY.key('backImg'))
169      let backImg = await driver.findComponent(BY.key('backImg'))
170      await backImg.click()
171      await driver.delayMs(1000)
172      // shareItem2
173      hilog.info(DOMAIN, TAG, BUNDLE + 'ShareTransitionFunction_001 shareItem2')
174      await driver.assertComponentExist(BY.key('shareItem2'))
175      let shareItem2 = await driver.findComponent(BY.key('shareItem2'))
176      await shareItem2.click()
177      await driver.delayMs(1000)
178      // 返回上一级
179      hilog.info(DOMAIN, TAG, BUNDLE + 'ShareTransitionFunction_001 back2')
180      await backImg.click()
181      await driver.delayMs(1000)
182      // 返回上一级
183      hilog.info(DOMAIN, TAG, BUNDLE + 'ShareTransitionFunction_001 back3')
184      await backImg.click()
185      await driver.delayMs(1000)
186      hilog.info(DOMAIN, TAG, BUNDLE + 'ShareTransitionFunction_001 end')
187    })
188  })
189}