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 */ 15import Core from './src/core' 16import Constant from './src/Constant' 17import DataDriver from './src/module/config/DataDriver' 18import ExpectExtend from './src/module/assert/ExpectExtend' 19import OhReport from './src/module/report/OhReport' 20import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from './src/interface' 21 22class Hypium { 23 static setData (data) { 24 const core = Core.getInstance() 25 const dataDriver = new DataDriver({ data }) 26 core.addService('dataDriver', dataDriver) 27 } 28 29 static hypiumTest (abilityDelegator, abilityDelegatorArguments, testsuite) { 30 const core = Core.getInstance() 31 const expectExtend = new ExpectExtend({ 32 'id': 'extend' 33 }) 34 core.addService('expect', expectExtend) 35 const ohReport = new OhReport({ 36 'delegator': abilityDelegator 37 }) 38 core.addService('report', ohReport) 39 core.init() 40 core.subscribeEvent('spec', ohReport) 41 core.subscribeEvent('suite', ohReport) 42 core.subscribeEvent('task', ohReport) 43 const configService = core.getDefaultService("config") 44 let testParameters = configService.translateParams(abilityDelegatorArguments.parameters) 45 console.info('parameters:'+JSON.stringify(testParameters)) 46 configService.setConfig(testParameters) 47 testsuite() 48 if (Object.prototype.hasOwnProperty.call(globalThis, 'setupUiTestEnvironment')) { 49 globalThis.setupUiTestEnvironment().then(() => { 50 console.info('UiTestKit::after run uitest setup, start run testcases') 51 core.execute() 52 }).catch((error) => { 53 console.error('UiTestKit:: call setupUiTestEnvironment failure:' + error) 54 core.execute() 55 }) 56 } else { 57 console.info('UiTestKit:: no need to setup uitest, start run testcases') 58 core.execute() 59 } 60 } 61} 62 63export { 64 Hypium, 65 Constant, 66 describe, beforeAll, beforeEach, afterEach, afterAll, it, expect 67} 68