• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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 Core from './src/core';
17import {DEFAULT, TestType, Size, Level} from './src/Constant';
18import DataDriver from './src/module/config/DataDriver';
19import ExpectExtend from './src/module/assert/ExpectExtend';
20import OhReport from './src/module/report/OhReport';
21import SysTestKit from './src/module/kit/SysTestKit';
22import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from './src/interface';
23import {MockKit, when} from './src/module/mock/MockKit';
24import ArgumentMatchers from './src/module/mock/ArgumentMatchers';
25
26class Hypium {
27    static setData(data) {
28        const core = Core.getInstance();
29        const dataDriver = new DataDriver({data});
30        core.addService('dataDriver', dataDriver);
31    }
32
33    static setTimeConfig(systemTime) {
34        SysTestKit.systemTime = systemTime;
35    }
36
37    static hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) {
38        const core = Core.getInstance();
39        const expectExtend = new ExpectExtend({
40            'id': 'extend'
41        });
42        core.addService('expect', expectExtend);
43        const ohReport = new OhReport({
44            'delegator': abilityDelegator
45        });
46        SysTestKit.delegator = abilityDelegator;
47        core.addService('report', ohReport);
48        core.init();
49        core.subscribeEvent('spec', ohReport);
50        core.subscribeEvent('suite', ohReport);
51        core.subscribeEvent('task', ohReport);
52        const configService = core.getDefaultService('config');
53        let testParameters = configService.translateParams(abilityDelegatorArguments.parameters);
54        console.info('parameters:' + JSON.stringify(testParameters));
55        configService.setConfig(testParameters);
56        testsuite();
57        if (Object.prototype.hasOwnProperty.call(globalThis, 'setupUiTestEnvironment')) {
58            globalThis.setupUiTestEnvironment().then(() => {
59                console.info('UiTestKit::after run uitest setup, start run testcases');
60                core.execute(abilityDelegator);
61            }).catch((error) => {
62                console.error('UiTestKit:: call setupUiTestEnvironment failure:' + error);
63                core.execute(abilityDelegator);
64            });
65        } else {
66            console.info('UiTestKit:: no need to setup uitest, start run testcases');
67            core.execute(abilityDelegator);
68        }
69    }
70}
71
72export {
73    Hypium,
74    Core,
75    DEFAULT,
76    TestType,
77    Size,
78    Level,
79    DataDriver,
80    ExpectExtend,
81    OhReport,
82    SysTestKit,
83    describe, beforeAll, beforeEach, afterEach, afterAll, it, expect,
84    MockKit, when,
85    ArgumentMatchers
86};