• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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
16
17import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
18
19function translateParamsToString(parameters) {
20    const keySet = new Set([
21        '-s class', '-s notClass', '-s suite', '-s itName',
22        '-s level', '-s testType', '-s size', '-s timeout',
23        '-s package', '-s dryRun'
24    ])
25    let targetParams = '';
26    for (const key in parameters) {
27        if (keySet.has(key)) {
28            targetParams += ' ' + key + ' ' + parameters[key]
29        }
30    }
31    return targetParams.trim()
32}
33
34 export default {
35    onPrepare() {
36        console.info('OpenHarmonyTestRunner OnPrepare')
37    },
38    onRun() {
39        console.log('OpenHarmonyTestRunner onRun run')
40        var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
41        var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
42
43        var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
44        var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
45        cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters)
46        var debug = abilityDelegatorArguments.parameters["-D"]
47        console.info('debug value : '+debug)
48        if (debug == 'true')
49        {
50            cmd += ' -D'
51        }
52        console.info('cmd : '+cmd)
53        abilityDelegator.executeShellCommand(cmd, (err, data) => {
54            console.info('executeShellCommand : err : ' + JSON.stringify(err));
55            console.info('executeShellCommand : data : ' + data.stdResult);
56            console.info('executeShellCommand : data : ' + data.exitCode);
57        })
58    }
59};