diff --git a/ability/ability_runtime/non_concurrent/acts_systemappa_test/Test.json b/ability/ability_runtime/non_concurrent/acts_systemappa_test/Test.json index f568cdbf05e4fd33f601eb344468e3f022ffce15..8e028c73e122376aa58c6b04a0252be93817813d 100644 --- a/ability/ability_runtime/non_concurrent/acts_systemappa_test/Test.json +++ b/ability/ability_runtime/non_concurrent/acts_systemappa_test/Test.json @@ -1,10 +1,12 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", + "type": "OHJSUnitTest", "test-timeout": "300000", - "package": "com.example.actsabilitypermissiontest", - "shell-timeout": "300000" + "bundle-name": "com.example.actsabilitypermissiontest", + "module-name": "com.example.actsabilitypermissiontest", + "shell-timeout": "600000", + "testcase-timeout": 70000 }, "kits": [ { diff --git a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility/MainAbility.ts index d88d073b2a98fb0a5c339bb3152c5f4ee7405511..21042c6b3c94bde0fbbd9c9b9529eeca6f267c80 100644 --- a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility/MainAbility.ts @@ -31,7 +31,7 @@ export default class MainAbility extends Ability { // Main window is created, set main page for this ability console.log("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/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/pages/index/index.ets b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility/pages/index/index.ets similarity index 56% rename from ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/pages/index/index.ets rename to ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility/pages/index/index.ets index 9684c6481bd50765a73977b94eb1f592953cfc83..1ce55a7aae38319f46b7b1b10fdc70e883414cdd 100644 --- a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/pages/index/index.ets +++ b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility/pages/index/index.ets @@ -12,9 +12,10 @@ * 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.ets" +import router from '@ohos.router'; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../../../test/List.test' @Entry @Component @@ -22,20 +23,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)) - 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/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/pages/index/index2.ets b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility/pages/index/index2.ets similarity index 100% rename from ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/pages/index/index2.ets rename to ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility/pages/index/index2.ets diff --git a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/pages/second/second.ets b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility/pages/second/second.ets similarity index 100% rename from ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/pages/second/second.ets rename to ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility/pages/second/second.ets diff --git a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility2/MainAbility2.ts b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility2/MainAbility2.ts index d96a855d995c637d4973a9890c2c06b01cce2e9b..e54a793c64342d9310f0210e7d4ce6e366b9509b 100644 --- a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility2/MainAbility2.ts +++ b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/MainAbility2/MainAbility2.ts @@ -35,7 +35,7 @@ export default class MainAbility2 extends Ability { onWindowStageCreate(windowStage) { // Main window is created, set main page for this ability console.log("MainAbility2 onWindowStageCreate") - windowStage.setUIContent(this.context, "pages/index/index2", null) + windowStage.setUIContent(this.context, "MainAbility/pages/index/index2", null) globalThis.ability2Context = this.context; commonEvent.publish("ACTS_AbilityPermission_0100_Start_CommonEvent", PublishCallBackOne1); } diff --git a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/TestAbility/TestAbility.ts b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..89a84730505783ba229175ab4b55d37f91a16266 --- /dev/null +++ b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,50 @@ +/* + * 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 TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.loadContent("TestAbility/pages/index", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }); + + 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/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/TestAbility/pages/index.ets b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /dev/null +++ b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,48 @@ +/* + * 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 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/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..5a6f38020383883bce44298f8add80762f263adc --- /dev/null +++ b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * 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', + '-s dryRun' + ]) + 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 com.example.actsabilitypermissiontest.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') + { + cmd += ' -D' + } + 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/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/test/AbilityPermission.test.ets b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/test/AbilityPermission.test.ets index e118d2046b70009a4d23cd285729b5d5db533d8e..552a99bcb589f266e17f11dfb4b684c9d4b12de9 100644 --- a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/test/AbilityPermission.test.ets +++ b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/test/AbilityPermission.test.ets @@ -14,7 +14,7 @@ */ // @ts-nocheck import osaccount from '@ohos.account.osAccount' -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index" +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import commonEvent from '@ohos.commonEvent' var AbilityPermission1 = { events: ["ACTS_AbilityPermission_0100_Start_CommonEvent"] @@ -29,7 +29,7 @@ var AbilityPermission6 = { events: ["ACTS_AbilityPermission_0600_Start_CommonEvent"] } const START_ABILITY_TIMEOUT = 3000; -export default function abilityPermissionTest(abilityContext) { +export default function abilityPermissionTest() { describe('ActsAbilityPermissionTest', function () { var osAccountManager = osaccount.getAccountManager(); var userA; @@ -72,7 +72,7 @@ export default function abilityPermissionTest(abilityContext) { Subscriber = data; commonEvent.subscribe(Subscriber, SubscribeCallBack); console.debug("====>start startAbility_100====>"); - await abilityContext.startAbilityWithAccount( + await globalThis.abilityContext.startAbilityWithAccount( { bundleName: 'com.example.actsabilitypermissiontest', abilityName: 'com.example.actsabilitypermissiontest.MainAbility2' @@ -118,7 +118,7 @@ export default function abilityPermissionTest(abilityContext) { Subscriber = data; commonEvent.subscribe(Subscriber, SubscribeCallBack); console.debug("====>start startAbility_0300====>"); - await abilityContext.startAbilityWithAccount( + await globalThis.abilityContext.startAbilityWithAccount( { bundleName: 'com.example.actssystemappuonehundredonerelytest', abilityName: 'com.example.actssystemappuonehundredonerelytest.MainAbility' @@ -158,7 +158,7 @@ export default function abilityPermissionTest(abilityContext) { function SubscribeCallBack(err, data) { expect(data.event == "ACTS_AbilityPermission_0400_Start_CommonEvent").assertTrue(); console.debug("====>0400 Subscribe CallBack data:====>" + JSON.stringify(data)); - abilityContext.disconnectAbility(globalThis.number).then((data) => { + globalThis.abilityContext.disconnectAbility(globalThis.number).then((data) => { console.debug("====>data is====>" + JSON.stringify(data)); }) console.log('====>disconnectAbility finish'); @@ -191,7 +191,7 @@ export default function abilityPermissionTest(abilityContext) { Subscriber = data; commonEvent.subscribe(Subscriber, SubscribeCallBack); console.debug("====>0400start connectAbility====>"); - globalThis.number = await abilityContext.connectAbilityWithAccount( + globalThis.number = await globalThis.abilityContext.connectAbilityWithAccount( { bundleName: 'com.example.actsabilitypermissiontest', abilityName: 'com.example.actsabilitypermissiontest.ServiceAbility', @@ -253,7 +253,7 @@ export default function abilityPermissionTest(abilityContext) { commonEvent.subscribe(Subscriber, SubscribeCallBackF); }) console.debug("====>0600start connectAbility====>"); - connId = await abilityContext.connectAbilityWithAccount( + connId = await globalThis.abilityContext.connectAbilityWithAccount( { bundleName: 'com.example.actssystemappuonehundredonerelytest', abilityName: 'com.example.actssystemappuonehundredonerelytest.ServiceAbility', diff --git a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/test/List.test.ets b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/test/List.test.ets index 998089c74699eb9ca50ec4180bdf675adadf6ad0..1c60435f0efe55d2075f48b6a2c3cc809b99171c 100644 --- a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/test/List.test.ets +++ b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/ets/test/List.test.ets @@ -14,6 +14,6 @@ */ import abilityPermissionText from './AbilityPermission.test.ets' -export default function testsuite(context) { - abilityPermissionText(context) +export default function testsuite() { + abilityPermissionText() } \ No newline at end of file diff --git a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/resources/base/profile/main_pages.json index 6898b31d2085f478ee1ed9d933a5910cbf901d92..02221db61d317863114ff0ca4dd2b33586abff12 100644 --- a/ability/ability_runtime/non_concurrent/acts_systemappa_test/entry/src/main/resources/base/profile/main_pages.json +++ b/ability/ability_runtime/non_concurrent/acts_systemappa_test/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