• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 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 hilog from '@ohos.hilog';
17import TestRunner from '@ohos.application.testRunner';
18import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
19
20var abilityDelegator = undefined
21var abilityDelegatorArguments = undefined
22
23async function onAbilityCreateCallback() {
24    hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
25}
26
27async function addAbilityMonitorCallback(err: any) {
28    hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
29}
30
31export default class OpenHarmonyTestRunner implements TestRunner {
32    constructor() {
33    }
34
35    onPrepare() {
36        hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
37    }
38
39    async onRun() {
40        hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
41        abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
42        abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
43        const bundleName = abilityDelegatorArguments.bundleName;
44        const testAbilityName = 'TestAbility';
45        let lMonitor = {
46            abilityName: testAbilityName,
47            onAbilityCreate: onAbilityCreateCallback,
48        };
49        abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
50        const want = {
51            bundleName: bundleName,
52            abilityName: testAbilityName
53        };
54        abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
55        abilityDelegator.startAbility(want, (err : any, data : any) => {
56            hilog.info(0x0000, 'testTag', 'startAbility : err : %{public}s', JSON.stringify(err) ?? '');
57            hilog.info(0x0000, 'testTag', 'startAbility : data : %{public}s',JSON.stringify(data) ?? '');
58        })
59        hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
60    }
61}