From ecd3626a5d23805b4e1f207e748821a59078d18d Mon Sep 17 00:00:00 2001 From: caiminggang Date: Fri, 23 Sep 2022 14:25:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E4=BE=8B=E6=97=B6?= =?UTF-8?q?=E5=BA=8F=E9=97=AE=E9=A2=98=E5=92=8Cstage=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=A1=86=E6=9E=B6=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: caiminggang --- customization/edm_xts_stage/Test.json | 5 +- .../ets/TestRunner/OpenHarmonyTestRunner.ts | 72 +++++++++++++++++++ .../entry/src/main/ets/pages/index/index.ets | 30 +++----- .../src/main/ets/test/edmCallback.test.ets | 13 ++-- .../src/main/ets/test/edmPromise.test.ets | 2 +- 5 files changed, 90 insertions(+), 32 deletions(-) create mode 100644 customization/edm_xts_stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts diff --git a/customization/edm_xts_stage/Test.json b/customization/edm_xts_stage/Test.json index 2064ffd5d..bf9adadfa 100644 --- a/customization/edm_xts_stage/Test.json +++ b/customization/edm_xts_stage/Test.json @@ -1,9 +1,10 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", + "type": "OHJSUnitTest", "test-timeout": "180000", - "package": "com.example.myapplication", + "bundle-name": "com.example.myapplication", + "module-name": "phone", "shell-timeout": "600000" }, "kits": [ diff --git a/customization/edm_xts_stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/customization/edm_xts_stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..adcea6b8e --- /dev/null +++ b/customization/edm_xts_stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2022 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 TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var MainAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility' + let lMonitor = { + abilityName: MainAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a com.example.myapplication.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') + } +}; \ No newline at end of file diff --git a/customization/edm_xts_stage/entry/src/main/ets/pages/index/index.ets b/customization/edm_xts_stage/entry/src/main/ets/pages/index/index.ets index 59482e5ec..4c26b68c0 100644 --- a/customization/edm_xts_stage/entry/src/main/ets/pages/index/index.ets +++ b/customization/edm_xts_stage/entry/src/main/ets/pages/index/index.ets @@ -12,35 +12,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import file from '@system.file'; - -import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' import testsuite from "../../test/List.test.ets" - @Entry @Component struct Index { aboutToAppear(){ - console.info("start run testcase!!!!") - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - core.addService('expect', expectExtend) - const reportExtend = new ReportExtend(file) - - core.addService('report', reportExtend) - core.init() - core.subscribeEvent('task', reportExtend) - const configService = core.getDefaultService('config') - console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) - globalThis.abilityWant.parameters.timeout = 70000; - configService.setConfig(globalThis.abilityWant.parameters) - // testsuite(globalThis.abilityContext,globalThis.windowStage,globalThis.abilityStorage) - testsuite() - core.execute() + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) } build() { diff --git a/customization/edm_xts_stage/entry/src/main/ets/test/edmCallback.test.ets b/customization/edm_xts_stage/entry/src/main/ets/test/edmCallback.test.ets index 070788296..2f9e4c9b7 100644 --- a/customization/edm_xts_stage/entry/src/main/ets/test/edmCallback.test.ets +++ b/customization/edm_xts_stage/entry/src/main/ets/test/edmCallback.test.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "hypium/index" +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import { WANT1, ENTINFO1, SELFWANT, SELFHAPNAME, COMPANYNAME2, DESCRIPTION2, ENTINFO2, DEFAULT_USER_ID, TEST_USER_ID, ERR_USER_ID @@ -283,12 +283,11 @@ export default function edmCallbackTest() { let dsmgr = await enterpriseDeviceManager.getDeviceSettingsManager(); expect(dsmgr !== null).assertTrue(); console.log('before setDateTime'); - await dsmgr.setDateTime(SELFWANT, 1526003846000, (error, data) => { - console.log("setDateTime ===data: " + data); - console.log("setDateTime ===error: " + error); - }); - await enterpriseDeviceManager.disableSuperAdmin(SELFHAPNAME); - done(); + await dsmgr.setDateTime(SELFWANT, 1526003846000, OnReceiveEvent); + async function OnReceiveEvent() { + await enterpriseDeviceManager.disableSuperAdmin(SELFHAPNAME); + done(); + } }) }) } diff --git a/customization/edm_xts_stage/entry/src/main/ets/test/edmPromise.test.ets b/customization/edm_xts_stage/entry/src/main/ets/test/edmPromise.test.ets index f3a4810b6..cbf40152d 100644 --- a/customization/edm_xts_stage/entry/src/main/ets/test/edmPromise.test.ets +++ b/customization/edm_xts_stage/entry/src/main/ets/test/edmPromise.test.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "hypium/index" +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import { WANT1, ENTINFO1, SELFWANT, SELFHAPNAME, COMPANYNAME2, DESCRIPTION2, ENTINFO2, DEFAULT_USER_ID, TEST_USER_ID, ERR_USER_ID -- GitLab