'use static';
/*
* Copyright (c) 2023-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import TestRunner from '@ohos.application.testRunner';
import hilog from '@ohos.hilog';
import { Hypium } from '../index';
import testsuite from '../test/List.test';
let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator;
let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs;
const jsonPath: string = 'mock/mock-config.json';
const domain: int = 0x0000; //日志标识,0x0000作为测试框架的业务标识
const tag: string = 'testTag'; //日志标识字符串,作为tag标识当前runner类下的测试行为
export class OpenHarmonyTestRunner implements TestRunner {
constructor() {}
public onPrepare: () => void = () => {
hilog.info(domain, tag, '%{public}s', 'OpenHarmonyTestRunner OnPrepare');
}
public onRun: () => void = () => {
hilog.info(domain, tag, '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = abilityDelegatorRegistry.getArguments();
abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator();
hilog.info(domain, tag, '%{public}s', 'start run testcase!!!');
let woker = abilityDelegatorArguments.parameters['-s worker']
if (woker) {
let workerNum : int = Number(woker) as int;
hilog.info(0x0000, 'testTag', '%{public}s', 'run in workers, woker number:' + workerNum);
Hypium.hypiumInitEAWorkers(abilityDelegator, abilityDelegatorArguments, workerNum, testsuite);
} else {
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
}
hilog.info(domain, tag, '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}