diff --git a/ability/ability_runtime/actscalltest/systemcallentrytest/Test.json b/ability/ability_runtime/actscalltest/systemcallentrytest/Test.json index 87ac89c4f63fc417d0c27cf4fb4831130b95ae32..f5428dc794d6fcc3f92f732e75eca69f4b86bc6e 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 694daa7d816cc0bdc722901d6aa30c3c15303f42..e8ec2b0a60581d84e314fecf70862e7f6a73a3ca 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 7de8d97bf41542a2e9722f2953ad5739feffbd0e..57871ab8aa670bfc12882687a33124a0e06cf97c 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 0000000000000000000000000000000000000000..0838274452af51408c691ad3c868210f484b59e0 --- /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 0000000000000000000000000000000000000000..e29d33fb1f74914762edf3a6b3abc01b92299ad3 --- /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 0000000000000000000000000000000000000000..cf6b400b4753293315080429d66fa399ac511eda --- /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 d7c7f45734ec4337f85fe951642451a05aec5e7b..1f0330a2bf120509340ddda2c47770a1f6337c40 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 882f978e77b1a8fbbf843ccb4dd73c47ed460305..f6a5bd8d95cac42bcdc862e9976dfc58d4cef99b 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 6898b31d2085f478ee1ed9d933a5910cbf901d92..02221db61d317863114ff0ca4dd2b33586abff12 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 3e17f7e7f3625d3f75e3b4d31e84b587293c6f3b..844b2d14bb8348292357929958759b8ba467b563 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 1894466ab9c018f438aa6bb45d80fed51c9e514d..cd47e022551551b3c393359b8cccafb7462c600a 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 9bd2846c0a7cf88a8ac7af708a6fc27dad8845d5..83bb21248c681d6ed9d5dfaa26b65e9d847895cd 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 0000000000000000000000000000000000000000..89a84730505783ba229175ab4b55d37f91a16266 --- /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 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /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 0000000000000000000000000000000000000000..a4ee2f1652b3d04ce83ece64ef70f8dfa62a2dc8 --- /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 e1f9bf3cac6d79635362826a3b86e4abe9207ea9..f1f956ea352e3958ca40cc635a11df6ba4319228 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 0a7a9a2d365a8751101b5f27f530533fb32c1354..5df9eb69fd9800d8d37490cc04264d1ef975ea66 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 821ecf2358ec52ffa8b0812267be3793be71896a..ceb075cd80946aade673d707aac904fb8998bce9 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 9502a6f66d5fc5ae96f0d40aabad1d0d19be91e9..9d23279cfac103e7e3d9aacc20a631c388761b19 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 a7606ed745a4538d346e08e5a4aef41b78b6b03d..9d03dcbf69da4bf9ef7843e57eff664c77169cb7 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 699be869c24384a16829d10f83abd19264a89e7d..83c05cfb5703f06d913d4bcc1ce45482f883f6d9 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 c0162edef1e6867f2be044948b3ead652aeb6fc3..ff6d68394f7ae767fc2a0f10e5205b8c2c0bc931 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 0000000000000000000000000000000000000000..89a84730505783ba229175ab4b55d37f91a16266 --- /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 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /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 0000000000000000000000000000000000000000..a4ee2f1652b3d04ce83ece64ef70f8dfa62a2dc8 --- /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 cb2df2c1d2a3b2d28946820025dc43711137d996..19f460fc71197795bd557fd4d4187b968ccfd89e 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 e6a15953e0321da02c67f83c07cec09232da6e39..07a0ae9eb00964cdd8036589ba0e2d40ffeeba99 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 821ecf2358ec52ffa8b0812267be3793be71896a..ceb075cd80946aade673d707aac904fb8998bce9 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 5462a09b344dcc7a602674368ae754f7b03ceb00..de09e3452833005ac9e3a0019baa7a58476de590 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 0272039f7638b890a2667c4ce212721ce4db879d..0a5a554b6faa8a03d9a82e85fe178d63a6eaa59e 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 699be869c24384a16829d10f83abd19264a89e7d..905eef2544ca4ebaeebf5ff059a0d4d32d1a6b73 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 06b7ba152d18e3f085397d59eafa3504a702b96a..1e4619d1153fb4eeb85a087cf6f0fb7f3f61ecfb 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 0000000000000000000000000000000000000000..89a84730505783ba229175ab4b55d37f91a16266 --- /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 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /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 0000000000000000000000000000000000000000..a4ee2f1652b3d04ce83ece64ef70f8dfa62a2dc8 --- /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 bc5db0fac7e4a28bf49aa1cdcb0289344682fbe8..122c63b2c0d2c1df1b9dfb7a09b5acc5b4068f1d 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 90ace0ffe68044fb4250a57b35aa9e479617a046..2049c22d7a90c8622e4b007f1d7e5256181881ff 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 821ecf2358ec52ffa8b0812267be3793be71896a..ceb075cd80946aade673d707aac904fb8998bce9 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 a8dd08140fc6773a0159c8b592f237d7cf7ea0ee..bf970fbdcf31d369769c1df8594a4040d9e9e6cc 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 0a3c2303a92c4988ada0af1b55581b6e702dc0b2..0ed89639e98d85d7fdf29c799dba90fb36df6185 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 d99a69a5a823f2eb8e447326af915497ddfb3d25..40427aad12dce08c70cf7f161e73b7d81c3f5377 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 5b59712d541ea9a3fc6a1f18c0c7a2a53b006d76..bf2bfe04597d272c2ca46893adf3b35ec6614416 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 0000000000000000000000000000000000000000..89a84730505783ba229175ab4b55d37f91a16266 --- /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 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /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 0000000000000000000000000000000000000000..a4ee2f1652b3d04ce83ece64ef70f8dfa62a2dc8 --- /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 8a9adcafe9456ffae333792910e3fe6b07e56199..47bc0415ca9f883f81a398c72aac8e167cbe87fd 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 bd2650fa6dbf24c6b805c780fd1f59d13897c7e6..e800c3c6bae719ec99a0694802b7a71a9b7ddde8 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 ae231ba6ddcfbdfdcb3648055e256939888a69af..a99e380b1101058975a15da3ddab9efc0f72972a 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" ] }