From 7b99ec605400c5f799b20c1ca3db07f7d84502b2 Mon Sep 17 00:00:00 2001 From: chengxingzhen Date: Thu, 12 Jan 2023 14:09:32 +0800 Subject: [PATCH] =?UTF-8?q?xts-=E6=96=B0=E5=A2=9E=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chengxingzhen --- .../main/ets/Application/MyAbilityStage.ts | 2 +- .../src/main/ets/MainAbility/MainAbility.ts | 30 ++++++++--------- .../ets/TestRunner/OpenHarmonyTestRunner.ts | 32 +++++++++---------- .../ets/test/ShellCommandControl.test.ets | 21 ++++++------ 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/Application/MyAbilityStage.ts b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/Application/MyAbilityStage.ts index 32d8c583c..f66afd586 100644 --- a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/Application/MyAbilityStage.ts +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/Application/MyAbilityStage.ts @@ -18,6 +18,6 @@ import AbilityStage from "@ohos.app.ability.AbilityStage" export default class MyAbilityStage extends AbilityStage { onCreate() { console.info("MyAbilityStageMonitor onCreate") - globalThis.abilityStageContext = this.context + globalThis.abilityStageContext = this.context; } } \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/MainAbility/MainAbility.ts index 5ac1c8fb5..7cdfc5138 100644 --- a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -20,42 +20,42 @@ import testsuite from '../test/List.test' export default class MainAbility extends Ability { onCreate(want, launchParam) { // Ability is creating, initialize resources for this ability - console.log("ActsShellCommandControlTest MainAbility onCreate") + console.log("ActsShellCommandControlTest MainAbility onCreate"); globalThis.abilityWant = want; - globalThis.abilityContext = this.context - let abilityDelegator: any - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - let abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - console.info('start run testcase!!!') - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + globalThis.abilityContext = this.context; + let abilityDelegator: any; + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let abilityDelegatorArguments: any; + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + console.info('start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); } onDestroy() { // Ability is destroying, release resources for this ability - console.log("ActsShellCommandControlTest MainAbility onDestroy") + console.log("ActsShellCommandControlTest MainAbility onDestroy"); } onWindowStageCreate(windowStage) { // Main window is created, set main page for this ability - console.log("ActsShellCommandControlTest MainAbility onWindowStageCreate") + console.log("ActsShellCommandControlTest MainAbility onWindowStageCreate"); - windowStage.setUIContent(this.context, "pages/index/index", null) - console.log("ActsShellCommandControlTest MainAbility onWindowStageCreate finish") + windowStage.setUIContent(this.context, "pages/index/index", null); + console.log("ActsShellCommandControlTest MainAbility onWindowStageCreate finish"); } onWindowStageDestroy() { // Main window is destroyed, release UI related resources - console.log("ActsShellCommandControlTest MainAbility onWindowStageDestroy") + console.log("ActsShellCommandControlTest MainAbility onWindowStageDestroy"); } onForeground() { // Ability has brought to foreground - console.log("ActsShellCommandControlTest MainAbility onForeground") + console.log("ActsShellCommandControlTest MainAbility onForeground"); } onBackground() { // Ability has back to background - console.log("ActsShellCommandControlTest MainAbility onBackground") + console.log("ActsShellCommandControlTest MainAbility onBackground"); } }; \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts index 5e01ca059..0ddb2de42 100644 --- a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -16,8 +16,8 @@ import TestRunner from '@ohos.application.testRunner' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -let abilityDelegator = undefined -let abilityDelegatorArguments = undefined +let abilityDelegator = undefined; +let abilityDelegatorArguments = undefined; function translateParamsToString(parameters) { const keySet = new Set([ @@ -28,10 +28,10 @@ function translateParamsToString(parameters) { let targetParams = ''; for (const key in parameters) { if (keySet.has(key)) { - targetParams = `${targetParams} ${key} ${parameters[key]}` + targetParams = `${targetParams} ${key} ${parameters[key]}`; } } - return targetParams.trim() + return targetParams.trim(); } async function onAbilityCreateCallback() { @@ -39,7 +39,7 @@ async function onAbilityCreateCallback() { } async function addAbilityMonitorCallback(err: any) { - console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)); } export default class OpenHarmonyTestRunner implements TestRunner { @@ -47,29 +47,29 @@ export default class OpenHarmonyTestRunner implements TestRunner { } onPrepare() { - console.info("OpenHarmonyTestRunner OnPrepare ") + console.info("OpenHarmonyTestRunner OnPrepare "); } async onRun() { - console.log('OpenHarmonyTestRunner onRun run') - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - globalThis.abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - let testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility' + console.log('OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + globalThis.abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'; let lMonitor = { abilityName: testAbilityName, onAbilityCreate: onAbilityCreateCallback, }; - abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) - let cmd = 'aa start -d 0 -a MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName - cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) - console.info('cmd : '+cmd) + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback); + let cmd = 'aa start -d 0 -a MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName; + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters); + console.info('cmd : '+cmd); abilityDelegator.executeShellCommand(cmd, (err: any, d: any) => { console.info('executeShellCommand : err : ' + JSON.stringify(err)); console.info('executeShellCommand : data : ' + d.stdResult); console.info('executeShellCommand : data : ' + d.exitCode); }) - console.info('OpenHarmonyTestRunner onRun end') + console.info('OpenHarmonyTestRunner onRun end'); } }; \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/test/ShellCommandControl.test.ets b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/test/ShellCommandControl.test.ets index 01b39f837..dc86ce23c 100644 --- a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/test/ShellCommandControl.test.ets +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/test/ShellCommandControl.test.ets @@ -27,14 +27,14 @@ export default function shellCommandControlTest() { */ it('Acts_Ability_ShellCommandControl__0100', 0, async function (done) { TAG = 'Acts_Ability_ShellCommandControl__0100'; - console.log(`${TAG} --- start`) + console.log(`${TAG} --- start`); let cmd = 'aa help' globalThis.abilityDelegator.executeShellCommand(cmd, (err, data) => { - console.log(`${TAG} stdResult = ${data.stdResult}`) - console.log(`${TAG} stdResult = ${JSON.stringify(err)}`) + console.log(`${TAG} stdResult = ${data.stdResult}`); + console.log(`${TAG} stdResult = ${JSON.stringify(err)}`); expect(data.exitCode).assertEqual(0); - console.log(`${TAG} --- end`) - done() + console.log(`${TAG} --- end`); + done(); }) }) @@ -46,16 +46,15 @@ export default function shellCommandControlTest() { */ it('Acts_Ability_ShellCommandControl__0200', 0, async function (done) { TAG = 'Acts_Ability_ShellCommandControl__0200'; - console.log(`${TAG} --- start`) + console.log(`${TAG} --- start`); let cmd = 'ls -l'; globalThis.abilityDelegator.executeShellCommand(cmd, (err, data) => { - console.log(`${TAG} stdResult = ${data.stdResult}`) - console.log(`${TAG} stdResult = ${JSON.stringify(err)}`) + console.log(`${TAG} stdResult = ${data.stdResult}`); + console.log(`${TAG} stdResult = ${JSON.stringify(err)}`); expect(data.exitCode).assertEqual(-1); - console.log(`${TAG} --- end`) - done() + console.log(`${TAG} --- end`); + done(); }) }) - }) } \ No newline at end of file -- GitLab