diff --git a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/Test.json b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/Test.json index 3fc9e19ad6b75568322c6fabafec85d5b0af7dc0..676c36bb18420fe5a496a117d222cde73d4839de 100644 --- a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/Test.json +++ b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/Test.json @@ -1,10 +1,12 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", - "test-timeout": "120000", - "package": "com.example.startabilityforresult", - "shell-timeout": "60000" + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.example.startabilityforresult", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 }, "kits": [ { diff --git a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility/MainAbility.ts index 10dd9a1eaff7ad67843219facba7f8aea7b5a1a5..5d9cb94eb1b16f32da7f1ba0b9896c87323bca11 100644 --- a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -30,7 +30,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/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/pages/index/index.ets b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility/pages/index/index.ets similarity index 61% rename from ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/pages/index/index.ets rename to ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility/pages/index/index.ets index b0a2df289574a6549c8e3128f714c5b1bb8763e0..102626507c52819532978509d89bd74837367ee8 100644 --- a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/pages/index/index.ets +++ b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility/pages/index/index.ets @@ -12,10 +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' var testTime = 0; @Entry @@ -25,22 +25,12 @@ struct Index { aboutToAppear(){ console.info("start run testcase!!!!") if(testTime++==0){ - 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) } } diff --git a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/pages/second/second.ets b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility/pages/second/second.ets similarity index 100% rename from ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/pages/second/second.ets rename to ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility/pages/second/second.ets diff --git a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility2/MainAbility2.ts b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility2/MainAbility2.ts index a31169f2d6b5809fefca35db484f44872cb94c0a..c47793cc75426eb2dd74eeb659dd757468ac50ab 100644 --- a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility2/MainAbility2.ts +++ b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/MainAbility2/MainAbility2.ts @@ -51,7 +51,7 @@ export default class MainAbility extends Ability { // Main window is created, set main page for this ability console.log("MainAbility2 onWindowStageCreate") globalThis.abilityContext = this.context - windowStage.setUIContent(this.context, "pages/second/second", null) + windowStage.setUIContent(this.context, "MainAbility/pages/second/second", null) } onWindowStageDestroy() { diff --git a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/TestAbility/TestAbility.ts b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..89a84730505783ba229175ab4b55d37f91a16266 --- /dev/null +++ b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/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/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/TestAbility/pages/index.ets b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /dev/null +++ b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/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/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..38779df14216625211a80c45b821bdeaae599077 --- /dev/null +++ b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/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.startabilityforresult.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/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/test/Ability.test.ets index 76fc2011d6350643cea9fd6e32cacb47bf49671c..6b0bb23c9d513aff487f19f028cfea3681f47cc8 100644 --- a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/test/Ability.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 "deccjsunit/index" +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium" import commonEvent from '@ohos.commonEvent' var subscriberInfo_MainAbility = { @@ -21,7 +21,7 @@ var subscriberInfo_MainAbility = { const START_ABILITY_TIMEOUT = 5000; console.debug("====>in Ability.test====>"); -export default function abilityTest(abilityContext) { +export default function abilityTest() { describe('ActsGetDisplayIdStartAbilityForResultTest', function () { console.debug("====>in ActsGetDisplayIdStartAbilityForResultTest====>"); @@ -57,7 +57,7 @@ export default function abilityTest(abilityContext) { console.debug("====>ACTS_startAbilityForResult_0100 Create Subscriber====>"); subscriber = data; commonEvent.subscribe(subscriber, subscribeCallBack); - await abilityContext.startAbilityForResult( + await globalThis.abilityContext.startAbilityForResult( { bundleName: 'com.example.startabilityforresult', abilityName: 'com.example.startabilityforresult.MainAbility2', @@ -115,7 +115,7 @@ export default function abilityTest(abilityContext) { console.debug("====>ACTS_startAbilityForResult_0200 Create Subscriber====>"); subscriber = data; commonEvent.subscribe(subscriber, subscribeCallBack); - await abilityContext.startAbilityForResult( + await globalThis.abilityContext.startAbilityForResult( { bundleName: 'com.example.startabilityforresult', abilityName: 'com.example.startabilityforresult.MainAbility2', @@ -176,7 +176,7 @@ export default function abilityTest(abilityContext) { console.debug("====>ACTS_startAbilityForResult_0300 Create Subscriber====>"); subscriber = data; commonEvent.subscribe(subscriber, subscribeCallBack); - await abilityContext.startAbilityForResult( + await globalThis.abilityContext.startAbilityForResult( { bundleName: 'com.example.startabilityforresult', abilityName: 'com.example.startabilityforresult.MainAbility2', @@ -235,7 +235,7 @@ export default function abilityTest(abilityContext) { console.debug("====>ACTS_startAbilityForResult_0400_Create Subscriber====>"); subscriber = data; await commonEvent.subscribe(subscriber, subscribeCallBack); - connId = await abilityContext.connectAbility( + connId = await globalThis.abilityContext.connectAbility( { bundleName: "com.example.startabilityforresult", abilityName: "com.example.startabilityforresult.ServiceAbility", @@ -246,7 +246,7 @@ export default function abilityTest(abilityContext) { }) function unSubscribeCallback() { - abilityContext.disconnectAbility( + globalThis.abilityContext.disconnectAbility( connId, (error, data) => { console.log('startAbilityForResult_0400 Disconnect result errCode : ' + error.code + " data: " + data) @@ -258,7 +258,7 @@ export default function abilityTest(abilityContext) { function timeout() { expect().assertFail(); - abilityContext.disconnectAbility( + globalThis.abilityContext.disconnectAbility( connId, (error, data) => { console.log('DisconnectAbility_0400 result errCode : ' + error.code + " data: " + data) diff --git a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/test/List.test.ets b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/test/List.test.ets index 882f978e77b1a8fbbf843ccb4dd73c47ed460305..f6a5bd8d95cac42bcdc862e9976dfc58d4cef99b 100644 --- a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/test/List.test.ets +++ b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/ets/test/List.test.ets @@ -15,8 +15,8 @@ import abilityTest from './Ability.test.ets' -export default function testsuite(context) { +export default function testsuite() { - abilityTest(context) + abilityTest() } \ No newline at end of file diff --git a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/resources/base/profile/main_pages.json index 6898b31d2085f478ee1ed9d933a5910cbf901d92..02221db61d317863114ff0ca4dd2b33586abff12 100644 --- a/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/entry/src/main/resources/base/profile/main_pages.json +++ b/ability/ability_runtime/amsdisplayIdtest/actsamsstartabilityforresulttest/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/ability/ability_runtime/newwant/actsnewwanttest/Test.json b/ability/ability_runtime/newwant/actsnewwanttest/Test.json index 6ffb225f0c54d65cf88fdde373e2e747653fe03d..e49bd512be4c05fbd4b558e8466b145161438e5f 100644 --- a/ability/ability_runtime/newwant/actsnewwanttest/Test.json +++ b/ability/ability_runtime/newwant/actsnewwanttest/Test.json @@ -1,10 +1,12 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", - "test-timeout": "120000", - "package": "com.example.newwanttest", - "shell-timeout": "60000" + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.example.newwanttest", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 }, "kits": [ { diff --git a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/MainAbility/MainAbility.ts index a573c393727b6ddbbc0e5269b57333ba91ab58db..2e7d00667eda224bc5e25c2eab34ad1987b1aa56 100644 --- a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -32,7 +32,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/newwant/actsnewwanttest/entry/src/main/ets/pages/index/index.ets b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/MainAbility/pages/index/index.ets similarity index 60% rename from ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/pages/index/index.ets rename to ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/MainAbility/pages/index/index.ets index dedc8cbede8045f84aef2a9d49b44b7291709894..b2438dfdf6b68001495268bff1bc2cdb5ab6c01d 100644 --- a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/pages/index/index.ets +++ b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/MainAbility/pages/index/index.ets @@ -13,10 +13,10 @@ * 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 @@ -25,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/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/pages/second/second.ets b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/MainAbility/pages/second/second.ets similarity index 100% rename from ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/pages/second/second.ets rename to ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/MainAbility/pages/second/second.ets diff --git a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/TestAbility/TestAbility.ts b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..89a84730505783ba229175ab4b55d37f91a16266 --- /dev/null +++ b/ability/ability_runtime/newwant/actsnewwanttest/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/newwant/actsnewwanttest/entry/src/main/ets/TestAbility/pages/index.ets b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /dev/null +++ b/ability/ability_runtime/newwant/actsnewwanttest/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/newwant/actsnewwanttest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..c072ffa540ad0e9bf34b52647de20d6e0288d937 --- /dev/null +++ b/ability/ability_runtime/newwant/actsnewwanttest/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.newwanttest.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/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets index 9c9d001cd26b5f06f0ab17323544529c3842114b..5cc6c752a544020ebf4a6219ae2e9c5a955330dd 100644 --- a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/Ability.test.ets @@ -13,7 +13,7 @@ * 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 commonEvent from '@ohos.commonEvent' let subscriberInfo = { @@ -35,7 +35,7 @@ let subscriberInfo = { let flagNewWant = false; -export default function abilityTest(abilityContext) { +export default function abilityTest() { describe('ActsNewWantTest', function () { /** @@ -57,7 +57,7 @@ export default function abilityTest(abilityContext) { await commonEvent.subscribe(Subscriber, SubscribeCallBack); }) - abilityContext.startAbility({ + globalThis.abilityContext.startAbility({ bundleName: "com.example.newwanthap", abilityName: "com.example.newwanthapa.MainAbility" }, (error, data) => { @@ -127,7 +127,7 @@ export default function abilityTest(abilityContext) { await commonEvent.subscribe(Subscriber, SubscribeCallBack); }) - abilityContext.startAbility({ + globalThis.abilityContext.startAbility({ bundleName: "com.example.newwanthap", abilityName: "com.example.newwanthapa.SecondAbility" }, (error, data) => { @@ -196,7 +196,7 @@ export default function abilityTest(abilityContext) { await commonEvent.subscribe(Subscriber, SubscribeCallBack); }) - abilityContext.startAbility({ + globalThis.abilityContext.startAbility({ bundleName: "com.example.newwanthap", abilityName: "com.example.newwanthapa.MainAbility", action: "startStandard0300" @@ -266,7 +266,7 @@ export default function abilityTest(abilityContext) { await commonEvent.subscribe(Subscriber, SubscribeCallBack); }) - abilityContext.startAbility({ + globalThis.abilityContext.startAbility({ bundleName: "com.example.newwanthap", abilityName: "com.example.newwanthapa.SecondAbility", action: "startSingleton0400" @@ -338,7 +338,7 @@ export default function abilityTest(abilityContext) { await commonEvent.subscribe(Subscriber, SubscribeCallBack); }) - abilityContext.startAbility({ + globalThis.abilityContext.startAbility({ bundleName: "com.example.newwanthap", abilityName: "com.example.newwanthapb.MainAbility", action: "startHapB" @@ -410,7 +410,7 @@ export default function abilityTest(abilityContext) { await commonEvent.subscribe(Subscriber, SubscribeCallBack); }) - abilityContext.startAbility({ + globalThis.abilityContext.startAbility({ bundleName: "com.example.newwanthapa", abilityName: "com.example.newwanthapc.MainAbility", action: "startHapC" @@ -482,7 +482,7 @@ export default function abilityTest(abilityContext) { await commonEvent.subscribe(Subscriber, SubscribeCallBack); }) - abilityContext.startAbility({ + globalThis.abilityContext.startAbility({ bundleName: "com.example.newwanthap", abilityName: "com.example.newwanthapa.SecondAbility", action: "startSecondAbility0700" @@ -553,7 +553,7 @@ export default function abilityTest(abilityContext) { await commonEvent.subscribe(Subscriber, SubscribeCallBack); }) - abilityContext.startAbility({ + globalThis.abilityContext.startAbility({ bundleName: "com.example.newwanthap", abilityName: "com.example.newwanthapa.MainAbility", action: "startMainAbility0800" diff --git a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/List.test.ets b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/List.test.ets index ecda46da39a99063bac759287cbb994c0cb13b1b..98c01ac1703452c2e67d55a2b7e4644f8fc007db 100644 --- a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/List.test.ets +++ b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/ets/test/List.test.ets @@ -16,8 +16,8 @@ import abilityTest from './Ability.test.ets' -export default function testsuite(context) { +export default function testsuite() { - abilityTest(context) + abilityTest() } \ No newline at end of file diff --git a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/resources/base/profile/main_pages.json index 6898b31d2085f478ee1ed9d933a5910cbf901d92..02221db61d317863114ff0ca4dd2b33586abff12 100644 --- a/ability/ability_runtime/newwant/actsnewwanttest/entry/src/main/resources/base/profile/main_pages.json +++ b/ability/ability_runtime/newwant/actsnewwanttest/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