From b6fea1bd580e2a69ffd629d1722ebf3253b9d51d Mon Sep 17 00:00:00 2001 From: jiyong_sd Date: Sat, 30 Jul 2022 10:34:17 +0800 Subject: [PATCH] Adapt to the new framework Signed-off-by: jiyong_sd Change-Id: I2ab725e9d4e9ad0ebe9a0337dd41cc3e0913ded0 --- .../systemcallentrytest/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 | 44 ++++++++++ .../src/main/ets/TestAbility/pages/index.ets | 48 +++++++++++ .../ets/TestRunner/OpenHarmonyTestRunner.ts | 72 ++++++++++++++++ .../entry/src/main/ets/test/Ability.test.ets | 82 +++++++++---------- .../entry/src/main/ets/test/List.test.ets | 4 +- .../resources/base/profile/main_pages.json | 4 +- barrierfree/accessibilityelement/Test.json | 8 +- .../src/main/ets/MainAbility/MainAbility.ts | 25 +++++- .../{ => MainAbility}/pages/index/index.ets | 21 +---- .../src/main/ets/TestAbility/TestAbility.ts | 50 +++++++++++ .../src/main/ets/TestAbility/pages/index.ets | 48 +++++++++++ .../ets/TestRunner/OpenHarmonyTestRunner.ts | 78 ++++++++++++++++++ .../ets/test/AccessibilityElement.test.ets | 6 +- .../entry/src/main/ets/test/List.test.ets | 4 +- .../resources/base/profile/main_pages.json | 2 +- barrierfree/accessibilityevent/BUILD.gn | 8 +- barrierfree/accessibilityevent/Test.json | 8 +- .../src/main/ets/MainAbility/MainAbility.ts | 25 +++++- .../{ => MainAbility}/pages/index/index.ets | 21 +---- .../src/main/ets/TestAbility/TestAbility.ts | 50 +++++++++++ .../src/main/ets/TestAbility/pages/index.ets | 48 +++++++++++ .../ets/TestRunner/OpenHarmonyTestRunner.ts | 78 ++++++++++++++++++ .../ets/test/AccessibilityEventTest.test.ets | 6 +- .../entry/src/main/ets/test/List.test.ets | 4 +- .../resources/base/profile/main_pages.json | 2 +- barrierfree/accessibilityextension/BUILD.gn | 8 +- barrierfree/accessibilityextension/Test.json | 10 ++- .../src/main/ets/MainAbility/MainAbility.ts | 11 ++- .../{ => MainAbility}/pages/index/index.ets | 21 +---- .../src/main/ets/TestAbility/TestAbility.ts | 50 +++++++++++ .../src/main/ets/TestAbility/pages/index.ets | 48 +++++++++++ .../ets/TestRunner/OpenHarmonyTestRunner.ts | 78 ++++++++++++++++++ .../ets/test/AccessibilityExtension.test.ets | 6 +- .../entry/src/main/ets/test/List.test.ets | 4 +- .../resources/base/profile/main_pages.json | 2 +- .../accessibilityextensioncontext/BUILD.gn | 10 +-- .../accessibilityextensioncontext/Test.json | 8 +- .../src/main/ets/MainAbility/MainAbility.ts | 11 ++- .../{ => MainAbility}/pages/index/index.ets | 18 ---- .../src/main/ets/TestAbility/TestAbility.ts | 50 +++++++++++ .../src/main/ets/TestAbility/pages/index.ets | 48 +++++++++++ .../ets/TestRunner/OpenHarmonyTestRunner.ts | 78 ++++++++++++++++++ .../AccessibilityExtensionContext.test.ets | 6 +- .../entry/src/main/ets/test/List.test.ets | 4 +- .../resources/base/profile/main_pages.json | 2 +- 49 files changed, 1057 insertions(+), 201 deletions(-) rename ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/{ => MainAbility}/pages/index/index.ets (60%) rename ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/{ => MainAbility}/pages/second/second.ets (100%) create mode 100644 ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/TestAbility/TestAbility.ts create mode 100644 ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/TestAbility/pages/index.ets create mode 100644 ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts rename barrierfree/accessibilityelement/entry/src/main/ets/{ => MainAbility}/pages/index/index.ets (53%) create mode 100644 barrierfree/accessibilityelement/entry/src/main/ets/TestAbility/TestAbility.ts create mode 100644 barrierfree/accessibilityelement/entry/src/main/ets/TestAbility/pages/index.ets create mode 100644 barrierfree/accessibilityelement/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts rename barrierfree/accessibilityevent/entry/src/main/ets/{ => MainAbility}/pages/index/index.ets (54%) create mode 100644 barrierfree/accessibilityevent/entry/src/main/ets/TestAbility/TestAbility.ts create mode 100644 barrierfree/accessibilityevent/entry/src/main/ets/TestAbility/pages/index.ets create mode 100644 barrierfree/accessibilityevent/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts rename barrierfree/accessibilityextension/entry/src/main/ets/{ => MainAbility}/pages/index/index.ets (54%) create mode 100644 barrierfree/accessibilityextension/entry/src/main/ets/TestAbility/TestAbility.ts create mode 100644 barrierfree/accessibilityextension/entry/src/main/ets/TestAbility/pages/index.ets create mode 100644 barrierfree/accessibilityextension/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts rename barrierfree/accessibilityextensioncontext/entry/src/main/ets/{ => MainAbility}/pages/index/index.ets (55%) create mode 100644 barrierfree/accessibilityextensioncontext/entry/src/main/ets/TestAbility/TestAbility.ts create mode 100644 barrierfree/accessibilityextensioncontext/entry/src/main/ets/TestAbility/pages/index.ets create mode 100644 barrierfree/accessibilityextensioncontext/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts diff --git a/ability/ability_runtime/actscalltest/systemcallentrytest/Test.json b/ability/ability_runtime/actscalltest/systemcallentrytest/Test.json index 87ac89c4f..f5428dc79 100644 --- a/ability/ability_runtime/actscalltest/systemcallentrytest/Test.json +++ b/ability/ability_runtime/actscalltest/systemcallentrytest/Test.json @@ -1,10 +1,12 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", + "type": "OHJSUnitTest", "test-timeout": "300000", - "package": "com.example.systemcalltest", - "shell-timeout": "60000" + "bundle-name": "com.example.systemcalltest", + "module-name": "com.example.systemcalltest", + "shell-timeout": "600000", + "testcase-timeout": 70000 }, "kits": [ { diff --git a/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/MainAbility/MainAbility.ts index 694daa7d8..e8ec2b0a6 100644 --- a/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -71,7 +71,7 @@ export default class MainAbility extends Ability { // Main window is created, set main page for this ability console.log("SystemCallTest 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/actscalltest/systemcallentrytest/entry/src/main/ets/pages/index/index.ets b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/MainAbility/pages/index/index.ets similarity index 60% rename from ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/pages/index/index.ets rename to ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/MainAbility/pages/index/index.ets index 7de8d97bf..57871ab8a 100644 --- a/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/pages/index/index.ets +++ b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/MainAbility/pages/index/index.ets @@ -12,10 +12,9 @@ * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../../../test/List.test' @Entry @@ -24,22 +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)) - globalThis.abilityWant.parameters.timeout = 10000; - 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/actscalltest/systemcallentrytest/entry/src/main/ets/pages/second/second.ets b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/MainAbility/pages/second/second.ets similarity index 100% rename from ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/pages/second/second.ets rename to ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/MainAbility/pages/second/second.ets diff --git a/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/TestAbility/TestAbility.ts b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 000000000..083827445 --- /dev/null +++ b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,44 @@ +/* + * 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.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/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/TestAbility/pages/index.ets b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 000000000..e29d33fb1 --- /dev/null +++ b/ability/ability_runtime/actscalltest/systemcallentrytest/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/actscalltest/systemcallentrytest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..cf6b400b4 --- /dev/null +++ b/ability/ability_runtime/actscalltest/systemcallentrytest/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 + '.MainAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a com.example.systemcalltest.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/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/test/Ability.test.ets index d7c7f4573..1f0330a2b 100644 --- a/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/actscalltest/systemcallentrytest/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' import missionManager from '@ohos.application.missionManager' import appManager from '@ohos.application.appManager' @@ -129,7 +129,7 @@ function clearDepProcess(bundleNames, callback, undoneCallBack) { } } -export default function abilityTest(abilityContext) { +export default function abilityTest() { describe('ActsAbilityTest', function () { beforeEach(async (done) => { @@ -195,7 +195,7 @@ export default function abilityTest(abilityContext) { subscriber = await commonEvent.createSubscriber(subscriberInfo); commonEvent.subscribe(subscriber, subscribeCallBack); - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -224,7 +224,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -280,7 +280,7 @@ export default function abilityTest(abilityContext) { subscriber = await commonEvent.createSubscriber(subscriberInfo); commonEvent.subscribe(subscriber, subscribeCallBack); - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: systemAppCalleeABundleName, abilityName: systemAppCalleeAMainAbilityName, }); @@ -310,7 +310,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: systemAppCalleeABundleName, abilityName: systemAppCalleeAMainAbilityName, }); @@ -369,12 +369,12 @@ export default function abilityTest(abilityContext) { subscriber = await commonEvent.createSubscriber(subscriberInfo); commonEvent.subscribe(subscriber, subscribeCallBack); - caller1 = await globalThis.abilityContext.startAbilityByCall({ + caller1 = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: systemAppCalleeABundleName, abilityName: systemAppCalleeAMainAbilityName, }); - caller2 = await globalThis.abilityContext.startAbilityByCall({ + caller2 = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: systemAppCalleeABundleName, abilityName: systemAppCalleeASecondAbilityName, }); @@ -405,11 +405,11 @@ export default function abilityTest(abilityContext) { done(); } - let caller1 = await globalThis.abilityContext.startAbilityByCall({ + let caller1 = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: systemAppCalleeABundleName, abilityName: systemAppCalleeAMainAbilityName, }); - let caller2 = await globalThis.abilityContext.startAbilityByCall({ + let caller2 = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: systemAppCalleeABundleName, abilityName: systemAppCalleeASecondAbilityName, }); @@ -457,7 +457,7 @@ export default function abilityTest(abilityContext) { expect(data).assertEqual('release'); console.log('ACTS_CommonComponent_Call_0700 releaseCallBack1' + data); setTimeout(() => { - globalThis.abilityContext.startAbilityByCall({ + globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: systemAppCalleeABundleName, abilityName: systemAppCalleeASecondAbilityName, }).then(data => { @@ -488,7 +488,7 @@ export default function abilityTest(abilityContext) { subscriber = await commonEvent.createSubscriber(subscriberInfo); commonEvent.subscribe(subscriber, subscribeCallBack); - globalThis.abilityContext.startAbilityByCall({ + globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: systemAppCalleeABundleName, abilityName: systemAppCalleeASecondAbilityName, }).then(data => { @@ -519,7 +519,7 @@ export default function abilityTest(abilityContext) { expect(data).assertEqual('release'); console.log('ACTS_CommonComponent_Call_0800 releaseCallBack' + data); setTimeout(() => { - globalThis.abilityContext.startAbilityByCall({ + globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: systemAppCalleeABundleName, abilityName: systemAppCalleeASecondAbilityName, }).then(data => { @@ -543,7 +543,7 @@ export default function abilityTest(abilityContext) { }, 100); } - globalThis.abilityContext.startAbilityByCall({ + globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: systemAppCalleeABundleName, abilityName: systemAppCalleeASecondAbilityName, }).then(data => { @@ -588,7 +588,7 @@ export default function abilityTest(abilityContext) { subscriber = await commonEvent.createSubscriber(subscriberInfo); commonEvent.subscribe(subscriber, subscribeCallBack); - caller = await globalThis.abilityContext.startAbilityByCall({ + caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: thirdAppABundleName, abilityName: thirdAppAMainAbilityName, }); @@ -619,7 +619,7 @@ export default function abilityTest(abilityContext) { done(); } - caller = await globalThis.abilityContext.startAbilityByCall({ + caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: thirdAppABundleName, abilityName: thirdAppAMainAbilityName, }); @@ -652,7 +652,7 @@ export default function abilityTest(abilityContext) { var exceptionFlag = false; try { - caller = await globalThis.abilityContext.startAbilityByCall({ + caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: systemAppCalleeABundleName, abilityName: systemAppCalleeAThirdAbilityName, }); @@ -712,7 +712,7 @@ export default function abilityTest(abilityContext) { subscriber = await commonEvent.createSubscriber(subscriberInfo); commonEvent.subscribe(subscriber, subscribeCallBack); - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -768,7 +768,7 @@ export default function abilityTest(abilityContext) { bundleName: bundleNameCallee, abilityName: abilityNameCallee, } - let caller = await globalThis.abilityContext.startAbilityByCall(want); + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall(want); if (typeof caller !== "object" || caller == null) { console.log('ACTS_CommonComponent_Call_2000 startAbilityByCall fail'); expect().assertFail(); @@ -803,7 +803,7 @@ export default function abilityTest(abilityContext) { bundleName: bundleNameCallee, abilityName: abilityNameCallee, } - let caller = await globalThis.abilityContext.startAbilityByCall(want); + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall(want); if (typeof caller !== "object" || caller == null) { console.log('ACTS_CommonComponent_Call_2300 startAbilityByCall fail'); expect().assertFail(); @@ -849,7 +849,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -893,7 +893,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -924,7 +924,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -955,7 +955,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -986,7 +986,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -1017,7 +1017,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -1048,7 +1048,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -1217,7 +1217,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -1249,7 +1249,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -1281,7 +1281,7 @@ export default function abilityTest(abilityContext) { done(); } - let caller = await globalThis.abilityContext.startAbilityByCall({ + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }); @@ -1313,7 +1313,7 @@ export default function abilityTest(abilityContext) { done(); } - globalThis.abilityContext.startAbilityByCall({ + globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }).then((data) => { @@ -1346,7 +1346,7 @@ export default function abilityTest(abilityContext) { done(); } - globalThis.abilityContext.startAbilityByCall({ + globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }).then((data) => { @@ -1379,7 +1379,7 @@ export default function abilityTest(abilityContext) { done(); } - globalThis.abilityContext.startAbilityByCall({ + globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }).then((data) => { @@ -1479,7 +1479,7 @@ export default function abilityTest(abilityContext) { bundleName: bundleNameCallee, abilityName: abilityNameCallee, } - let caller = await globalThis.abilityContext.startAbilityByCall(want); + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall(want); if (typeof caller !== "object" || caller == null) { console.log('ACTS_CommonComponent_Call_4800 startAbilityByCall fail'); expect().assertFail(); @@ -1534,7 +1534,7 @@ export default function abilityTest(abilityContext) { }) } - globalThis.abilityContext.startAbilityByCall({ + globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: sysABundleName, abilityName: sysASecondAbilityName, }).then((data) => { @@ -1635,7 +1635,7 @@ export default function abilityTest(abilityContext) { let exceptionFlag = false; try { - caller = await globalThis.abilityContext.startAbilityByCall(null); + caller = await globalThis.globalThis.abilityContext.startAbilityByCall(null); console.log('ACTS_CommonComponent_Call_5200 startAbilityByCall' + JSON.stringify(caller)) } catch(err) { console.log('ACTS_CommonComponent_Call_5200 exception' + err); @@ -1658,7 +1658,7 @@ export default function abilityTest(abilityContext) { let exceptionFlag = false; try { - caller = await globalThis.abilityContext.startAbilityByCall({ + caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ bundleName: "", abilityName: "", }); @@ -1684,7 +1684,7 @@ export default function abilityTest(abilityContext) { let exceptionFlag = false; try { - caller = await globalThis.abilityContext.startAbilityByCall(undefined); + caller = await globalThis.globalThis.abilityContext.startAbilityByCall(undefined); console.log('ACTS_CommonComponent_Call_5400 startAbilityByCall' + JSON.stringify(caller)) } catch(err) { console.log('ACTS_CommonComponent_Call_5400 exception' + err); @@ -1710,7 +1710,7 @@ export default function abilityTest(abilityContext) { bundleName: bundleNameCallee, abilityName: abilityNameCallee, } - let caller = await globalThis.abilityContext.startAbilityByCall(want); + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall(want); if (typeof caller !== "object" || caller == null) { console.log('ACTS_CommonComponent_Call_5700 startAbilityByCall fail'); expect().assertFail(); @@ -1757,7 +1757,7 @@ export default function abilityTest(abilityContext) { bundleName: bundleNameCallee, abilityName: abilityNameCallee, } - let caller = await globalThis.abilityContext.startAbilityByCall(want); + let caller = await globalThis.globalThis.abilityContext.startAbilityByCall(want); if (typeof caller !== "object" || caller == null) { console.log('ACTS_CommonComponent_Call_5800 startAbilityByCall fail'); expect().assertFail(); @@ -1773,7 +1773,7 @@ export default function abilityTest(abilityContext) { } await sleep(1000); - await globalThis.abilityContext.startAbility(want, startAbilityCallback); + await globalThis.globalThis.abilityContext.startAbility(want, startAbilityCallback); async function releaseCallback(data) { console.log('ACTS_CommonComponent_Call_5800 releaseCallBack:' + data); diff --git a/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/test/List.test.ets b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/test/List.test.ets index 882f978e7..f6a5bd8d9 100644 --- a/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/test/List.test.ets +++ b/ability/ability_runtime/actscalltest/systemcallentrytest/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/actscalltest/systemcallentrytest/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/resources/base/profile/main_pages.json index 6898b31d2..02221db61 100644 --- a/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/resources/base/profile/main_pages.json +++ b/ability/ability_runtime/actscalltest/systemcallentrytest/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/barrierfree/accessibilityelement/Test.json b/barrierfree/accessibilityelement/Test.json index 3e17f7e7f..844b2d14b 100644 --- a/barrierfree/accessibilityelement/Test.json +++ b/barrierfree/accessibilityelement/Test.json @@ -1,10 +1,12 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", + "type": "OHJSUnitTest", "test-timeout": "600000", - "package": "com.example.myapplication", - "shell-timeout": "600000" + "bundle-name": "com.example.myapplication", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 }, "kits": [ { diff --git a/barrierfree/accessibilityelement/entry/src/main/ets/MainAbility/MainAbility.ts b/barrierfree/accessibilityelement/entry/src/main/ets/MainAbility/MainAbility.ts index 1894466ab..cd47e0225 100644 --- a/barrierfree/accessibilityelement/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/barrierfree/accessibilityelement/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,10 +1,33 @@ +/* + * 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 '@ohos/hypium' +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("[Demo] MainAbility onCreate") globalThis.abilityWant = want; + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) } onDestroy() { @@ -18,7 +41,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/accessibilityelement/entry/src/main/ets/pages/index/index.ets b/barrierfree/accessibilityelement/entry/src/main/ets/MainAbility/pages/index/index.ets similarity index 53% rename from barrierfree/accessibilityelement/entry/src/main/ets/pages/index/index.ets rename to barrierfree/accessibilityelement/entry/src/main/ets/MainAbility/pages/index/index.ets index 9bd2846c0..83bb21248 100644 --- a/barrierfree/accessibilityelement/entry/src/main/ets/pages/index/index.ets +++ b/barrierfree/accessibilityelement/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/accessibilityelement/entry/src/main/ets/TestAbility/TestAbility.ts b/barrierfree/accessibilityelement/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 000000000..89a847305 --- /dev/null +++ b/barrierfree/accessibilityelement/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/barrierfree/accessibilityelement/entry/src/main/ets/TestAbility/pages/index.ets b/barrierfree/accessibilityelement/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 000000000..b93567f96 --- /dev/null +++ b/barrierfree/accessibilityelement/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/barrierfree/accessibilityelement/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/barrierfree/accessibilityelement/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..a4ee2f165 --- /dev/null +++ b/barrierfree/accessibilityelement/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.myapplication.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/barrierfree/accessibilityelement/entry/src/main/ets/test/AccessibilityElement.test.ets b/barrierfree/accessibilityelement/entry/src/main/ets/test/AccessibilityElement.test.ets index e1f9bf3ca..f1f956ea3 100644 --- a/barrierfree/accessibilityelement/entry/src/main/ets/test/AccessibilityElement.test.ets +++ b/barrierfree/accessibilityelement/entry/src/main/ets/test/AccessibilityElement.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' const passStr = 'pass'; @@ -28,7 +28,7 @@ function publishCaseExecute(caseName: string) { }); } -export default function abilityTest(abilityContext) { +export default function abilityTest() { describe('AccessibilityElementTest', function () { let subScriber = undefined; let isConnect = false; @@ -48,7 +48,7 @@ export default function abilityTest(abilityContext) { } }); - await abilityContext.startAbility({ + await globalThis.abilityContext.startAbility({ deviceId: '', bundleName: 'com.example.acetest', abilityName: 'MainAbility', diff --git a/barrierfree/accessibilityelement/entry/src/main/ets/test/List.test.ets b/barrierfree/accessibilityelement/entry/src/main/ets/test/List.test.ets index 0a7a9a2d3..5df9eb69f 100644 --- a/barrierfree/accessibilityelement/entry/src/main/ets/test/List.test.ets +++ b/barrierfree/accessibilityelement/entry/src/main/ets/test/List.test.ets @@ -14,6 +14,6 @@ */ import abilityTest from './AccessibilityElement.test.ets' -export default function testsuite(abilityContext) { - abilityTest(abilityContext) +export default function testsuite() { + abilityTest() } \ No newline at end of file diff --git a/barrierfree/accessibilityelement/entry/src/main/resources/base/profile/main_pages.json b/barrierfree/accessibilityelement/entry/src/main/resources/base/profile/main_pages.json index 821ecf235..ceb075cd8 100644 --- a/barrierfree/accessibilityelement/entry/src/main/resources/base/profile/main_pages.json +++ b/barrierfree/accessibilityelement/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,5 @@ { "src": [ - "pages/index/index" + "MainAbility/pages/index/index" ] } \ No newline at end of file diff --git a/barrierfree/accessibilityevent/BUILD.gn b/barrierfree/accessibilityevent/BUILD.gn index 9502a6f66..9d23279cf 100644 --- a/barrierfree/accessibilityevent/BUILD.gn +++ b/barrierfree/accessibilityevent/BUILD.gn @@ -14,7 +14,7 @@ import("//test/xts/tools/build/suite.gni") ohos_js_hap_suite("ActsAccessibilityEventTest") { - hap_profile = "entry/src/main/module.json" + hap_profile = "./entry/src/main/module.json" js_build_mode = "debug" deps = [ ":accessibilityevent_js_assets", @@ -31,11 +31,11 @@ ohos_app_scope("accessibilityevent_app_profile") { } ohos_js_assets("accessibilityevent_js_assets") { - source_dir = "entry/src/main/ets" + source_dir = "./entry/src/main/ets" } ohos_resources("accessibilityevent_resources") { - sources = [ "entry/src/main/resources" ] + sources = [ "./entry/src/main/resources" ] deps = [ ":accessibilityevent_app_profile" ] - hap_profile = "entry/src/main/module.json" + hap_profile = "./entry/src/main/module.json" } diff --git a/barrierfree/accessibilityevent/Test.json b/barrierfree/accessibilityevent/Test.json index a7606ed74..9d03dcbf6 100644 --- a/barrierfree/accessibilityevent/Test.json +++ b/barrierfree/accessibilityevent/Test.json @@ -1,10 +1,12 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", + "type": "OHJSUnitTest", "test-timeout": "180000", - "package": "com.example.myapplication", - "shell-timeout": "600000" + "bundle-name": "com.example.myapplication", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 }, "kits": [ { diff --git a/barrierfree/accessibilityevent/entry/src/main/ets/MainAbility/MainAbility.ts b/barrierfree/accessibilityevent/entry/src/main/ets/MainAbility/MainAbility.ts index 699be869c..83c05cfb5 100644 --- a/barrierfree/accessibilityevent/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/barrierfree/accessibilityevent/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,10 +1,33 @@ +/* + * 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 '@ohos/hypium' +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("[Demo] MainAbility onCreate") globalThis.abilityWant = want; + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) } onDestroy() { @@ -18,7 +41,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/accessibilityevent/entry/src/main/ets/pages/index/index.ets b/barrierfree/accessibilityevent/entry/src/main/ets/MainAbility/pages/index/index.ets similarity index 54% rename from barrierfree/accessibilityevent/entry/src/main/ets/pages/index/index.ets rename to barrierfree/accessibilityevent/entry/src/main/ets/MainAbility/pages/index/index.ets index c0162edef..ff6d68394 100644 --- a/barrierfree/accessibilityevent/entry/src/main/ets/pages/index/index.ets +++ b/barrierfree/accessibilityevent/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/accessibilityevent/entry/src/main/ets/TestAbility/TestAbility.ts b/barrierfree/accessibilityevent/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 000000000..89a847305 --- /dev/null +++ b/barrierfree/accessibilityevent/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/barrierfree/accessibilityevent/entry/src/main/ets/TestAbility/pages/index.ets b/barrierfree/accessibilityevent/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 000000000..b93567f96 --- /dev/null +++ b/barrierfree/accessibilityevent/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/barrierfree/accessibilityevent/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/barrierfree/accessibilityevent/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..a4ee2f165 --- /dev/null +++ b/barrierfree/accessibilityevent/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.myapplication.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/barrierfree/accessibilityevent/entry/src/main/ets/test/AccessibilityEventTest.test.ets b/barrierfree/accessibilityevent/entry/src/main/ets/test/AccessibilityEventTest.test.ets index cb2df2c1d..19f460fc7 100644 --- a/barrierfree/accessibilityevent/entry/src/main/ets/test/AccessibilityEventTest.test.ets +++ b/barrierfree/accessibilityevent/entry/src/main/ets/test/AccessibilityEventTest.test.ets @@ -12,11 +12,11 @@ * 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 accessibility from '@ohos.accessibility' import commonEvent from '@ohos.commonEvent' -export default function abilityTest(abilityContext) { +export default function abilityTest() { let targetBundleName = 'com.example.myapplication'; let subScriber = undefined; let isConnected: boolean = false; @@ -38,7 +38,7 @@ export default function abilityTest(abilityContext) { }); setTimeout(async () => { - await abilityContext.startAbility({ + await globalThis.abilityContext.startAbility({ deviceId: "", bundleName: "com.example.acetest", abilityName: "MainAbility", diff --git a/barrierfree/accessibilityevent/entry/src/main/ets/test/List.test.ets b/barrierfree/accessibilityevent/entry/src/main/ets/test/List.test.ets index e6a15953e..07a0ae9eb 100644 --- a/barrierfree/accessibilityevent/entry/src/main/ets/test/List.test.ets +++ b/barrierfree/accessibilityevent/entry/src/main/ets/test/List.test.ets @@ -14,6 +14,6 @@ */ import abilityTest from './AccessibilityEventTest.test.ets' -export default function testsuite(abilityContext) { - abilityTest(abilityContext) +export default function testsuite() { + abilityTest() } \ No newline at end of file diff --git a/barrierfree/accessibilityevent/entry/src/main/resources/base/profile/main_pages.json b/barrierfree/accessibilityevent/entry/src/main/resources/base/profile/main_pages.json index 821ecf235..ceb075cd8 100644 --- a/barrierfree/accessibilityevent/entry/src/main/resources/base/profile/main_pages.json +++ b/barrierfree/accessibilityevent/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,5 @@ { "src": [ - "pages/index/index" + "MainAbility/pages/index/index" ] } \ No newline at end of file diff --git a/barrierfree/accessibilityextension/BUILD.gn b/barrierfree/accessibilityextension/BUILD.gn index 5462a09b3..de09e3452 100644 --- a/barrierfree/accessibilityextension/BUILD.gn +++ b/barrierfree/accessibilityextension/BUILD.gn @@ -14,7 +14,7 @@ import("//test/xts/tools/build/suite.gni") ohos_js_hap_suite("ActsAccessibilityExtensionTest") { - hap_profile = "entry/src/main/module.json" + hap_profile = "./entry/src/main/module.json" js_build_mode = "debug" deps = [ ":accessibilityextension_js_assets", @@ -31,11 +31,11 @@ ohos_app_scope("accessibilityextension_app_profile") { } ohos_js_assets("accessibilityextension_js_assets") { - source_dir = "entry/src/main/ets" + source_dir = "./entry/src/main/ets" } ohos_resources("accessibilityextension_resources") { - sources = [ "entry/src/main/resources" ] + sources = [ "./entry/src/main/resources" ] deps = [ ":accessibilityextension_app_profile" ] - hap_profile = "entry/src/main/module.json" + hap_profile = "./entry/src/main/module.json" } diff --git a/barrierfree/accessibilityextension/Test.json b/barrierfree/accessibilityextension/Test.json index 0272039f7..0a5a554b6 100644 --- a/barrierfree/accessibilityextension/Test.json +++ b/barrierfree/accessibilityextension/Test.json @@ -1,10 +1,12 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", - "test-timeout": "60000", - "package": "com.example.myapplication", - "shell-timeout": "60000" + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.example.myapplication", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 }, "kits": [ { diff --git a/barrierfree/accessibilityextension/entry/src/main/ets/MainAbility/MainAbility.ts b/barrierfree/accessibilityextension/entry/src/main/ets/MainAbility/MainAbility.ts index 699be869c..905eef254 100644 --- a/barrierfree/accessibilityextension/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/barrierfree/accessibilityextension/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,10 +1,19 @@ import Ability from '@ohos.application.Ability' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +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("[Demo] MainAbility onCreate") globalThis.abilityWant = want; + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) } onDestroy() { @@ -18,7 +27,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/accessibilityextension/entry/src/main/ets/pages/index/index.ets b/barrierfree/accessibilityextension/entry/src/main/ets/MainAbility/pages/index/index.ets similarity index 54% rename from barrierfree/accessibilityextension/entry/src/main/ets/pages/index/index.ets rename to barrierfree/accessibilityextension/entry/src/main/ets/MainAbility/pages/index/index.ets index 06b7ba152..1e4619d11 100644 --- a/barrierfree/accessibilityextension/entry/src/main/ets/pages/index/index.ets +++ b/barrierfree/accessibilityextension/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/accessibilityextension/entry/src/main/ets/TestAbility/TestAbility.ts b/barrierfree/accessibilityextension/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 000000000..89a847305 --- /dev/null +++ b/barrierfree/accessibilityextension/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/barrierfree/accessibilityextension/entry/src/main/ets/TestAbility/pages/index.ets b/barrierfree/accessibilityextension/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 000000000..b93567f96 --- /dev/null +++ b/barrierfree/accessibilityextension/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/barrierfree/accessibilityextension/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/barrierfree/accessibilityextension/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..a4ee2f165 --- /dev/null +++ b/barrierfree/accessibilityextension/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.myapplication.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/barrierfree/accessibilityextension/entry/src/main/ets/test/AccessibilityExtension.test.ets b/barrierfree/accessibilityextension/entry/src/main/ets/test/AccessibilityExtension.test.ets index bc5db0fac..122c63b2c 100644 --- a/barrierfree/accessibilityextension/entry/src/main/ets/test/AccessibilityExtension.test.ets +++ b/barrierfree/accessibilityextension/entry/src/main/ets/test/AccessibilityExtension.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 commonEvent from '@ohos.commonEvent' -export default function abilityTest(abilityContext) { +export default function abilityTest() { let isCalled: boolean = false; let subScriber = undefined; @@ -57,7 +57,7 @@ export default function abilityTest(abilityContext) { */ it('AccessibilityExtensionTest_Connect_0100', 0, async function (done) { console.info('AccessibilityExtensionTest_Connect_0100: start'); - await abilityContext.startAbility({ + await globalThis.abilityContext.startAbility({ deviceId: "", bundleName: "com.example.acetest", abilityName: "MainAbility", diff --git a/barrierfree/accessibilityextension/entry/src/main/ets/test/List.test.ets b/barrierfree/accessibilityextension/entry/src/main/ets/test/List.test.ets index 90ace0ffe..2049c22d7 100644 --- a/barrierfree/accessibilityextension/entry/src/main/ets/test/List.test.ets +++ b/barrierfree/accessibilityextension/entry/src/main/ets/test/List.test.ets @@ -14,6 +14,6 @@ */ import abilityTest from './AccessibilityExtension.test.ets' -export default function testsuite(abilityContext) { - abilityTest(abilityContext) +export default function testsuite() { + abilityTest() } \ No newline at end of file diff --git a/barrierfree/accessibilityextension/entry/src/main/resources/base/profile/main_pages.json b/barrierfree/accessibilityextension/entry/src/main/resources/base/profile/main_pages.json index 821ecf235..ceb075cd8 100644 --- a/barrierfree/accessibilityextension/entry/src/main/resources/base/profile/main_pages.json +++ b/barrierfree/accessibilityextension/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,5 @@ { "src": [ - "pages/index/index" + "MainAbility/pages/index/index" ] } \ No newline at end of file diff --git a/barrierfree/accessibilityextensioncontext/BUILD.gn b/barrierfree/accessibilityextensioncontext/BUILD.gn index a8dd08140..bf970fbdc 100644 --- a/barrierfree/accessibilityextensioncontext/BUILD.gn +++ b/barrierfree/accessibilityextensioncontext/BUILD.gn @@ -9,12 +9,12 @@ # 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. +# limitations under the License. import("//test/xts/tools/build/suite.gni") ohos_js_hap_suite("ActsAccessibilityExtensionContextTest") { - hap_profile = "entry/src/main/module.json" + hap_profile = "./entry/src/main/module.json" js_build_mode = "debug" deps = [ ":accessibilityextensioncontext_js_assets", @@ -31,11 +31,11 @@ ohos_app_scope("accessibilityextensioncontext_app_profile") { } ohos_js_assets("accessibilityextensioncontext_js_assets") { - source_dir = "entry/src/main/ets" + source_dir = "./entry/src/main/ets" } ohos_resources("accessibilityextensioncontext_resources") { - sources = [ "entry/src/main/resources" ] + sources = [ "./entry/src/main/resources" ] deps = [ ":accessibilityextensioncontext_app_profile" ] - hap_profile = "entry/src/main/module.json" + hap_profile = "./entry/src/main/module.json" } diff --git a/barrierfree/accessibilityextensioncontext/Test.json b/barrierfree/accessibilityextensioncontext/Test.json index 0a3c2303a..0ed89639e 100644 --- a/barrierfree/accessibilityextensioncontext/Test.json +++ b/barrierfree/accessibilityextensioncontext/Test.json @@ -1,10 +1,12 @@ { "description": "Configuration for hjunit demo Tests", "driver": { - "type": "JSUnitTest", + "type": "OHJSUnitTest", "test-timeout": "360000", - "package": "com.example.myapplication", - "shell-timeout": "360000" + "bundle-name": "com.example.myapplication", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 }, "kits": [ { diff --git a/barrierfree/accessibilityextensioncontext/entry/src/main/ets/MainAbility/MainAbility.ts b/barrierfree/accessibilityextensioncontext/entry/src/main/ets/MainAbility/MainAbility.ts index d99a69a5a..40427aad1 100644 --- a/barrierfree/accessibilityextensioncontext/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/barrierfree/accessibilityextensioncontext/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,10 +1,19 @@ import Ability from '@ohos.application.Ability' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +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("[Demo] MainAbility onCreate") globalThis.abilityWant = want; + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) } onDestroy() { @@ -18,7 +27,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/accessibilityextensioncontext/entry/src/main/ets/pages/index/index.ets b/barrierfree/accessibilityextensioncontext/entry/src/main/ets/MainAbility/pages/index/index.ets similarity index 55% rename from barrierfree/accessibilityextensioncontext/entry/src/main/ets/pages/index/index.ets rename to barrierfree/accessibilityextensioncontext/entry/src/main/ets/MainAbility/pages/index/index.ets index 5b59712d5..bf2bfe045 100644 --- a/barrierfree/accessibilityextensioncontext/entry/src/main/ets/pages/index/index.ets +++ b/barrierfree/accessibilityextensioncontext/entry/src/main/ets/MainAbility/pages/index/index.ets @@ -14,8 +14,6 @@ */ import file from '@system.file'; -import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" -import testsuite from "../../test/List.test" @Entry @Component @@ -24,22 +22,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/accessibilityextensioncontext/entry/src/main/ets/TestAbility/TestAbility.ts b/barrierfree/accessibilityextensioncontext/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 000000000..89a847305 --- /dev/null +++ b/barrierfree/accessibilityextensioncontext/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/barrierfree/accessibilityextensioncontext/entry/src/main/ets/TestAbility/pages/index.ets b/barrierfree/accessibilityextensioncontext/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 000000000..b93567f96 --- /dev/null +++ b/barrierfree/accessibilityextensioncontext/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/barrierfree/accessibilityextensioncontext/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/barrierfree/accessibilityextensioncontext/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..a4ee2f165 --- /dev/null +++ b/barrierfree/accessibilityextensioncontext/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.myapplication.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/barrierfree/accessibilityextensioncontext/entry/src/main/ets/test/AccessibilityExtensionContext.test.ets b/barrierfree/accessibilityextensioncontext/entry/src/main/ets/test/AccessibilityExtensionContext.test.ets index 8a9adcafe..47bc0415c 100644 --- a/barrierfree/accessibilityextensioncontext/entry/src/main/ets/test/AccessibilityExtensionContext.test.ets +++ b/barrierfree/accessibilityextensioncontext/entry/src/main/ets/test/AccessibilityExtensionContext.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' const passStr = 'pass'; @@ -28,7 +28,7 @@ function publishCaseExecute(caseName: string) { }); } -export default function abilityTest(abilityContext) { +export default function abilityTest() { describe('AccessibilityExtensionContextTest', function () { let subScriber = undefined; let isConnect = false; @@ -48,7 +48,7 @@ export default function abilityTest(abilityContext) { } }); - await abilityContext.startAbility({ + await globalThis.abilityContext.startAbility({ deviceId: '', bundleName: 'com.example.acetest', abilityName: 'MainAbility', diff --git a/barrierfree/accessibilityextensioncontext/entry/src/main/ets/test/List.test.ets b/barrierfree/accessibilityextensioncontext/entry/src/main/ets/test/List.test.ets index bd2650fa6..e800c3c6b 100644 --- a/barrierfree/accessibilityextensioncontext/entry/src/main/ets/test/List.test.ets +++ b/barrierfree/accessibilityextensioncontext/entry/src/main/ets/test/List.test.ets @@ -14,6 +14,6 @@ */ import abilityTest from './AccessibilityExtensionContext.test.ets' -export default function testsuite(abilityContext) { - abilityTest(abilityContext) +export default function testsuite() { + abilityTest() } \ No newline at end of file diff --git a/barrierfree/accessibilityextensioncontext/entry/src/main/resources/base/profile/main_pages.json b/barrierfree/accessibilityextensioncontext/entry/src/main/resources/base/profile/main_pages.json index ae231ba6d..a99e380b1 100644 --- a/barrierfree/accessibilityextensioncontext/entry/src/main/resources/base/profile/main_pages.json +++ b/barrierfree/accessibilityextensioncontext/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,5 @@ { "src": [ - "pages/index/index" + "MainAbility/pages/index/index" ] } -- GitLab