• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 ON 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 hilog from '@ohos.hilog';
17import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium';
18import { Driver, ON } from '@ohos.UiTest';
19import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
20
21const DOMAIN = 0xF811;
22const TAG = '[Sample_jsAdaptiveCapabilities]';
23const BUNDLE = 'jsAdaptiveCapabilities_';
24
25let driver = Driver.create();
26
27// 通过 text 验证有没有这个组件 有的话点击一下
28async function checkButtonAndClickWithText(text) {
29  let textName = text;
30  await driver.assertComponentExist(ON.text(textName));
31  let button = await driver.findComponent(ON.text(textName));
32  await button.click();
33  await driver.delayMs(1000);
34}
35
36export default function abilityTest() {
37  describe('ActsAbilityTest', function () {
38    /**
39     * 拉起应用
40     */
41    it('StartAbility_001', 0, async () => {
42      hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin');
43      let abilityDelegatorRegistry = AbilityDelegatorRegistry.getAbilityDelegator();
44      try {
45        await abilityDelegatorRegistry.startAbility({
46          bundleName: 'ohos.samples.jsadaptivecapabilities',
47          abilityName: 'com.example.entry.MainAbility'
48        });
49      } catch (err) {
50        expect(0).assertEqual(err.code);
51      }
52      hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end');
53    })
54
55    /**
56     * 资源限定词
57     */
58    it(BUNDLE + 'clickResourceFunction_001', 0, async function () {
59      hilog.info(DOMAIN, TAG, BUNDLE + 'clickResourceFunction_001 begin');
60      let driver = Driver.create();
61      await driver.delayMs(1000);
62      // fa模型不支持资源本地化,故用中文
63      await checkButtonAndClickWithText('资源限定词');
64      // 跳转资源限定词页面
65      await driver.assertComponentExist(ON.id('clockFace'));
66      // 返回首页
67      await driver.pressBack();
68    })
69
70    /**
71     * 原子布局能力(目前坐标只适用于RK3568)
72     */
73    it(BUNDLE + 'clickAtomCapabilitiesFunction_001', 0, async function () {
74      hilog.info(DOMAIN, TAG, BUNDLE + 'clickAtomCapabilitiesFunction_001 begin');
75      let driver = Driver.create();
76      await driver.delayMs(1000);
77      // 点击原子布局能力
78      await checkButtonAndClickWithText('原子布局能力');
79      // 跳转原子布局能力页面
80      await checkButtonAndClickWithText('拉伸能力1');
81      // slider滑动
82      await driver.swipe(547, 1063, 360, 1065, 200);
83      await driver.delayMs(1000);
84      await driver.pressBack();
85      await driver.delayMs(500);
86      await checkButtonAndClickWithText('拉伸能力2');
87      // 打开switch
88      await driver.assertComponentExist(ON.type('switch'));
89      let swit = await driver.findComponent(ON.type('switch'));
90      await swit.click();
91      await driver.delayMs(1000);
92      // slider滑动
93      await driver.swipe(561, 1013, 360, 1013, 200);
94      await driver.delayMs(1000);
95      await driver.pressBack();
96      await checkButtonAndClickWithText('缩放能力');
97      // slider1滑动
98      await driver.swipe(507, 1025, 360, 1025, 200);
99      await driver.delayMs(1000);
100      // slider2滑动
101      await driver.swipe(507, 1085, 360, 1085, 200);
102      await driver.delayMs(1000);
103      await driver.pressBack();
104      await checkButtonAndClickWithText('隐藏能力');
105      // slider滑动
106      await driver.swipe(547, 1011, 360, 1011, 200);
107      await driver.delayMs(1000);
108      await driver.pressBack();
109      await checkButtonAndClickWithText('折行能力');
110      // slider滑动
111      await driver.swipe(547, 1063, 360, 1065, 200);
112      await driver.delayMs(1000);
113      await driver.pressBack();
114      await checkButtonAndClickWithText('均分能力');
115      // slider滑动
116      await driver.swipe(557, 1009, 360, 1009, 200);
117      await driver.delayMs(1000);
118      await driver.pressBack();
119      // 点击占比能力1按钮
120      await checkButtonAndClickWithText('占比能力');
121      // slider滑动
122      await driver.swipe(553, 1015, 360, 1015, 200);
123      await driver.delayMs(1000);
124      await driver.pressBack();
125      // 点击延伸能力1按钮
126      await checkButtonAndClickWithText('延伸能力1');
127      // scroll 应用滑动
128      await driver.swipe(360, 639, 0, 639, 200);
129      await driver.delayMs(1000);
130      // slider 滑动
131      await driver.swipe(410, 1017, 360, 1017, 200);
132      await driver.delayMs(1000);
133      await driver.pressBack();
134      await driver.delayMs(1000);
135      // 点击延伸能力2按钮
136      await checkButtonAndClickWithText('延伸能力2');
137      // scroll 应用滑动
138      await driver.swipe(360, 639, 0, 639, 200);
139      await driver.delayMs(1000);
140      // slider 滑动
141      await driver.swipe(410, 1017, 360, 1017, 200);
142      await driver.delayMs(1000);
143      await driver.pressBack();
144      await driver.delayMs(1000);
145      // 返回首页
146      await driver.pressBack();
147      await driver.delayMs(1000);
148      hilog.info(DOMAIN, TAG, BUNDLE + 'clickAtomCapabilitiesFunction_001 end');
149    })
150
151    /**
152     * 响应式布局
153     */
154    it(BUNDLE + 'clicAdaptiveCapabilitiesFunction_001', 0, async function () {
155      hilog.info(DOMAIN, TAG, BUNDLE + 'clickAdaptiveCapabilitiesFunction_001 begin');
156      let driver = Driver.create();
157      await driver.delayMs(1000);
158      // 点击响应式布局
159      await checkButtonAndClickWithText('响应式布局');
160      // 跳转响应式布局页面
161      await checkButtonAndClickWithText('栅格布局');
162      await driver.pressBack();
163      await driver.delayMs(500);
164      // 点击媒体查询
165      await checkButtonAndClickWithText('媒体查询');
166      await driver.pressBack();
167      await driver.delayMs(500);
168      // 点击典型场景
169      await checkButtonAndClickWithText('典型场景');
170      // 跳转典型场景页面
171      await checkButtonAndClickWithText('挪移布局');
172      await driver.pressBack();
173      await driver.delayMs(500);
174      // 点击缩进布局
175      await checkButtonAndClickWithText('缩进布局');
176      await driver.pressBack();
177      await driver.delayMs(500);
178      // 点击重复布局
179      await checkButtonAndClickWithText('重复布局');
180      await driver.pressBack();
181      await driver.delayMs(500);
182      // 回到响应式布局页面
183      await driver.pressBack();
184      await driver.delayMs(500);
185      // 回到首页
186      await driver.pressBack();
187      await driver.delayMs(500);
188      hilog.info(DOMAIN, TAG, BUNDLE + 'clickAdaptiveCapabilitiesFunction_001 end');
189    })
190  })
191}