From b5ef136a3516fc7b56d8b6f9b3e94bfd56e27abf Mon Sep 17 00:00:00 2001 From: jiyong_sd Date: Thu, 28 Jul 2022 17:20:42 +0800 Subject: [PATCH] Adapt to the new framework Signed-off-by: jiyong_sd Change-Id: I353a66b0eb392f2fc6782c649bbac908d9115a88 --- barrierfree/accessibilityconfig/Test.json | 10 +-- .../src/main/ets/MainAbility/MainAbility.ts | 16 ++++- .../{ => MainAbility}/pages/index/index.ets | 21 +----- .../src/main/ets/TestAbility/TestAbility.ts | 53 ++++++++++++++ .../src/main/ets/TestAbility/pages/index.ets | 47 ++++++++++++ .../ets/TestRunner/OpenHarmonyTestRunner.ts | 72 +++++++++++++++++++ .../ets/test/AccessibilityConfig.test.ets | 4 +- .../entry/src/main/ets/test/List.test.ets | 4 +- .../entry/src/main/module.json | 4 +- .../resources/base/profile/main_pages.json | 2 +- .../actsbmsstageetstest/Test.json | 8 ++- .../src/main/ets/MainAbility/MainAbility.ts | 2 +- .../{ => MainAbility}/pages/index/index.ets | 29 +++----- .../{ => MainAbility}/pages/second/second.ets | 0 .../src/main/ets/TestAbility/TestAbility.ts | 30 ++++++++ .../src/main/ets/TestAbility/pages/index.ets | 34 +++++++++ .../ets/TestRunner/OpenHarmonyTestRunner.ts | 58 +++++++++++++++ .../ets/test/GetProfileByAbility.test.ets | 4 +- .../GetProfileByExtensionAbility.test.ets | 4 +- .../entry/src/main/ets/test/List.test.ets | 2 +- .../resources/base/profile/form_config.json | 4 +- .../resources/base/profile/main_pages.json | 4 +- .../base/profile/shortcuts_config.json | 4 +- 23 files changed, 350 insertions(+), 66 deletions(-) rename barrierfree/accessibilityconfig/entry/src/main/ets/{ => MainAbility}/pages/index/index.ets (52%) create mode 100644 barrierfree/accessibilityconfig/entry/src/main/ets/TestAbility/TestAbility.ts create mode 100644 barrierfree/accessibilityconfig/entry/src/main/ets/TestAbility/pages/index.ets create mode 100644 barrierfree/accessibilityconfig/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts rename bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/{ => MainAbility}/pages/index/index.ets (60%) rename bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/{ => MainAbility}/pages/second/second.ets (100%) create mode 100644 bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestAbility/TestAbility.ts create mode 100644 bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestAbility/pages/index.ets create mode 100644 bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts diff --git a/barrierfree/accessibilityconfig/Test.json b/barrierfree/accessibilityconfig/Test.json index c6b592b95..eea8e56d7 100644 --- a/barrierfree/accessibilityconfig/Test.json +++ b/barrierfree/accessibilityconfig/Test.json @@ -1,10 +1,12 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", - "test-timeout": "180000", - "package": "com.example.accessibilityconfig", - "shell-timeout": "180000" + "type": "OHJSUnitTest", + "test-timeout": "240000", + "bundle-name": "com.example.accessibilityconfig", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 }, "kits": [ { diff --git a/barrierfree/accessibilityconfig/entry/src/main/ets/MainAbility/MainAbility.ts b/barrierfree/accessibilityconfig/entry/src/main/ets/MainAbility/MainAbility.ts index e9c126eb7..f9014b87a 100644 --- a/barrierfree/accessibilityconfig/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/barrierfree/accessibilityconfig/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,3 +1,17 @@ +/* + * 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 Ability from '@ohos.application.Ability' export default class MainAbility extends Ability { @@ -18,7 +32,7 @@ export default class MainAbility extends Ability { //globalThis.windowStage = windowStage //globalThis.abilityStorage = this.storage globalThis.abilityContext = this.context - windowStage.setUIContent(this.context, "pages/index/index", null) + windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null) } onWindowStageDestroy() { diff --git a/barrierfree/accessibilityconfig/entry/src/main/ets/pages/index/index.ets b/barrierfree/accessibilityconfig/entry/src/main/ets/MainAbility/pages/index/index.ets similarity index 52% rename from barrierfree/accessibilityconfig/entry/src/main/ets/pages/index/index.ets rename to barrierfree/accessibilityconfig/entry/src/main/ets/MainAbility/pages/index/index.ets index d45c30711..51bf7178e 100644 --- a/barrierfree/accessibilityconfig/entry/src/main/ets/pages/index/index.ets +++ b/barrierfree/accessibilityconfig/entry/src/main/ets/MainAbility/pages/index/index.ets @@ -12,10 +12,7 @@ * 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 testsuite from "../../test/List.test" +import router from '@ohos.router'; @Entry @Component @@ -24,22 +21,6 @@ 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); - core.execute(); } build() { diff --git a/barrierfree/accessibilityconfig/entry/src/main/ets/TestAbility/TestAbility.ts b/barrierfree/accessibilityconfig/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 000000000..a8203eae9 --- /dev/null +++ b/barrierfree/accessibilityconfig/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,53 @@ +/* + * 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 Ability from '@ohos.application.Ability' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from 'hypium/index' +import testsuite from '../test/List.test' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.setUIContent(this.context, 'TestAbility/pages/index', null) + + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +}; \ No newline at end of file diff --git a/barrierfree/accessibilityconfig/entry/src/main/ets/TestAbility/pages/index.ets b/barrierfree/accessibilityconfig/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 000000000..70827e8f7 --- /dev/null +++ b/barrierfree/accessibilityconfig/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,47 @@ +/* + * 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. + */ + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/barrierfree/accessibilityconfig/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/barrierfree/accessibilityconfig/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..c56fa98f7 --- /dev/null +++ b/barrierfree/accessibilityconfig/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 testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -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/barrierfree/accessibilityconfig/entry/src/main/ets/test/AccessibilityConfig.test.ets b/barrierfree/accessibilityconfig/entry/src/main/ets/test/AccessibilityConfig.test.ets index a30566f31..71ead2c9d 100644 --- a/barrierfree/accessibilityconfig/entry/src/main/ets/test/AccessibilityConfig.test.ets +++ b/barrierfree/accessibilityconfig/entry/src/main/ets/test/AccessibilityConfig.test.ets @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import config from '@ohos.accessibility.config' -export default function abilityTest(abilityContext) { +export default function abilityTest() { describe('AccessibilityConfigTest', function () { beforeEach(async function (done) { diff --git a/barrierfree/accessibilityconfig/entry/src/main/ets/test/List.test.ets b/barrierfree/accessibilityconfig/entry/src/main/ets/test/List.test.ets index ee66692b5..8cfe3dd44 100644 --- a/barrierfree/accessibilityconfig/entry/src/main/ets/test/List.test.ets +++ b/barrierfree/accessibilityconfig/entry/src/main/ets/test/List.test.ets @@ -14,6 +14,6 @@ */ import abilityTest from './AccessibilityConfig.test.ets' -export default function testsuite(abilityContext) { - abilityTest(abilityContext) +export default function testsuite() { + abilityTest() } \ No newline at end of file diff --git a/barrierfree/accessibilityconfig/entry/src/main/module.json b/barrierfree/accessibilityconfig/entry/src/main/module.json index 69501f617..716634826 100644 --- a/barrierfree/accessibilityconfig/entry/src/main/module.json +++ b/barrierfree/accessibilityconfig/entry/src/main/module.json @@ -13,8 +13,8 @@ "uiSyntax": "ets", "pages": "$profile:main_pages", "abilities": [{ - "name": "com.example.accessibilityconfig.MainAbility", - "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "name": "TestAbility", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", "description": "$string:phone_entry_main", "icon": "$media:icon", "label": "$string:entry_label", diff --git a/barrierfree/accessibilityconfig/entry/src/main/resources/base/profile/main_pages.json b/barrierfree/accessibilityconfig/entry/src/main/resources/base/profile/main_pages.json index 360bf0b46..43f5bb10d 100644 --- a/barrierfree/accessibilityconfig/entry/src/main/resources/base/profile/main_pages.json +++ b/barrierfree/accessibilityconfig/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,5 @@ { "src": [ - "pages/index/index" + "TestAbility/pages/index" ] } \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/Test.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/Test.json index 3ede21fab..e565426f0 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/Test.json +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/Test.json @@ -1,10 +1,12 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", + "type": "OHJSUnitTest", "test-timeout": "180000", - "package": "ohos.acts.bundle.stage.test", - "shell-timeout": "600000" + "bundle-name": "ohos.acts.bundle.stage.test", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 }, "kits": [ { diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/MainAbility/MainAbility.ts b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/MainAbility/MainAbility.ts index 72b03d747..87b6463a2 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -16,7 +16,7 @@ export default class MainAbility extends Ability { // Main window is created, set main page for this ability console.log("[Demo] MainAbility onWindowStageCreate") globalThis.abilityContext = this.context - windowStage.setUIContent(this.context, "pages/index/index", null) + windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null) } onWindowStageDestroy() { diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/pages/index/index.ets b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/MainAbility/pages/index/index.ets similarity index 60% rename from bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/pages/index/index.ets rename to bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/MainAbility/pages/index/index.ets index 37b86f509..f172d89b0 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/pages/index/index.ets +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/MainAbility/pages/index/index.ets @@ -12,10 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import file from '@system.file'; +import router from '@ohos.router'; -import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" -import testsuite from "../../test/List.test.ets" +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../../../test/List.test' @Entry @@ -24,22 +25,12 @@ 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) - 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/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/pages/second/second.ets b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/MainAbility/pages/second/second.ets similarity index 100% rename from bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/pages/second/second.ets rename to bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/MainAbility/pages/second/second.ets diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestAbility/TestAbility.ts b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 000000000..fb7ef2b1e --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,30 @@ +import Ability from '@ohos.application.Ability' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.setUIContent(this.context, 'TestAbility/pages/index', null) + + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +}; \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestAbility/pages/index.ets b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 000000000..733600abc --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,34 @@ +import router from '@ohos.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..3149248af --- /dev/null +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,58 @@ +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 testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a ohos.acts.bundle.stage.test.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/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/GetProfileByAbility.test.ets b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/GetProfileByAbility.test.ets index 0e54eaaeb..4d53d13b0 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/GetProfileByAbility.test.ets +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/GetProfileByAbility.test.ets @@ -14,7 +14,7 @@ */ import bundle from '@ohos.bundle'; -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index" +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" const MODULE_NAME = "phone" const MODULE_NAME_TEST = "phone1" @@ -26,7 +26,7 @@ const METADATA_NAME1 = "ohos.ability.form1" const METADATA_NAME2 = "ohos.ability.form2" const METADATA_NAME3 = "ohos.ability.form3" const METADATA_NAME_TEST = "ohos.test.form" -const PROFILE_JSON_STRING = "{\"src\":[\"pages/index/index\",\"pages/second/second\"]}" +const PROFILE_JSON_STRING = "{\"src\":[\"MainAbility/pages/index/index\",\"MainAbility/pages/second/second\"]}" export default function getProfileByAbility() { describe('getProfileByAbility', function () { diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/GetProfileByExtensionAbility.test.ets b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/GetProfileByExtensionAbility.test.ets index cc9a2b7e6..1f9690489 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/GetProfileByExtensionAbility.test.ets +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/GetProfileByExtensionAbility.test.ets @@ -14,7 +14,7 @@ */ import bundle from '@ohos.bundle'; -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index" +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" const MODULE_NAME = "phone" const MODULE_NAME_TEST = "phone1" @@ -26,7 +26,7 @@ const METADATA_NAME1 = "ohos.extension.form1" const METADATA_NAME2 = "ohos.extension.form2" const METADATA_NAME3 = "ohos.extension.form3" const METADATA_NAME_TEST = "ohos.test.form" -const PROFILE_JSON_STRING = "{\"src\":[\"pages/index/index\",\"pages/second/second\"]}" +const PROFILE_JSON_STRING = "{\"src\":[\"MainAbility/pages/index/index\",\"MainAbility/pages/second/second\"]}" export default function getProfileByExtensionAbility() { describe('getProfileByExtensionAbility', function () { diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/List.test.ets b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/List.test.ets index 0f706c4b4..9f75ecfa4 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/List.test.ets +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/ets/test/List.test.ets @@ -16,7 +16,7 @@ import getProfileByAbility from './GetProfileByAbility.test.ets'; import getProfileByExtensionAbility from './GetProfileByExtensionAbility.test.ets'; -export default function testsuite(context) { +export default function testsuite() { getProfileByAbility(); getProfileByExtensionAbility(); } \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/form_config.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/form_config.json index 10d2c96da..e892d4472 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/form_config.json +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/form_config.json @@ -1,6 +1,6 @@ { "src": [ - "pages/index/index", - "pages/second/second" + "MainAbility/pages/index/index", + "MainAbility/pages/second/second" ] } \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/main_pages.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/main_pages.json index 6898b31d2..02221db61 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/main_pages.json +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/main_pages.json @@ -1,6 +1,6 @@ { "src": [ - "pages/index/index", - "pages/second/second" + "MainAbility/pages/index/index", + "MainAbility/pages/second/second" ] } \ No newline at end of file diff --git a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/shortcuts_config.json b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/shortcuts_config.json index 96b478210..010134e5c 100644 --- a/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/shortcuts_config.json +++ b/bundlemanager/bundle_standard/bundlemanager/actsbmsstageetstest/entry/src/main/resources/base/profile/shortcuts_config.json @@ -1,6 +1,6 @@ { "src": [ - "pages/index/index", - "pages/second/second" + "MainAbility/pages/index/index", + "MainAbility/pages/second/second" ] } \ No newline at end of file -- GitLab