未验证 提交 2d89fafd 编写于 作者: O openharmony_ci 提交者: Gitee

!4715 Adapt to the new framework

Merge pull request !4715 from jiyong/local-20220730-0002
{ {
"description": "Configuration for hjunit demo Tests", "description": "Configuration for hjunit demo Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "OHJSUnitTest",
"test-timeout": "300000", "test-timeout": "300000",
"package": "com.example.systemcalltest", "bundle-name": "com.example.systemcalltest",
"shell-timeout": "60000" "module-name": "com.example.systemcalltest",
"shell-timeout": "600000",
"testcase-timeout": 70000
}, },
"kits": [ "kits": [
{ {
......
...@@ -71,7 +71,7 @@ export default class MainAbility extends Ability { ...@@ -71,7 +71,7 @@ export default class MainAbility extends Ability {
// Main window is created, set main page for this ability // Main window is created, set main page for this ability
console.log("SystemCallTest MainAbility onWindowStageCreate") console.log("SystemCallTest MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null) windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null)
} }
onWindowStageDestroy() { onWindowStageDestroy() {
......
...@@ -12,10 +12,9 @@ ...@@ -12,10 +12,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import file from '@system.file'; import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index" import testsuite from '../../../test/List.test'
import testsuite from "../../test/List.test.ets"
@Entry @Entry
...@@ -24,22 +23,12 @@ struct Index { ...@@ -24,22 +23,12 @@ struct Index {
aboutToAppear(){ aboutToAppear(){
console.info("start run testcase!!!!") console.info("start run testcase!!!!")
const core = Core.getInstance() var abilityDelegator: any
const expectExtend = new ExpectExtend({ abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
'id': 'extend' var abilityDelegatorArguments: any
}) abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
core.addService('expect', expectExtend) console.info('start run testcase!!!')
const reportExtend = new ReportExtend(file) Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
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()
} }
build() { build() {
......
/*
* 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
/*
* 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
/*
* 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
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 commonEvent from '@ohos.commonEvent'
import missionManager from '@ohos.application.missionManager' import missionManager from '@ohos.application.missionManager'
import appManager from '@ohos.application.appManager' import appManager from '@ohos.application.appManager'
...@@ -129,7 +129,7 @@ function clearDepProcess(bundleNames, callback, undoneCallBack) { ...@@ -129,7 +129,7 @@ function clearDepProcess(bundleNames, callback, undoneCallBack) {
} }
} }
export default function abilityTest(abilityContext) { export default function abilityTest() {
describe('ActsAbilityTest', function () { describe('ActsAbilityTest', function () {
beforeEach(async (done) => { beforeEach(async (done) => {
...@@ -195,7 +195,7 @@ export default function abilityTest(abilityContext) { ...@@ -195,7 +195,7 @@ export default function abilityTest(abilityContext) {
subscriber = await commonEvent.createSubscriber(subscriberInfo); subscriber = await commonEvent.createSubscriber(subscriberInfo);
commonEvent.subscribe(subscriber, subscribeCallBack); commonEvent.subscribe(subscriber, subscribeCallBack);
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -224,7 +224,7 @@ export default function abilityTest(abilityContext) { ...@@ -224,7 +224,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -280,7 +280,7 @@ export default function abilityTest(abilityContext) { ...@@ -280,7 +280,7 @@ export default function abilityTest(abilityContext) {
subscriber = await commonEvent.createSubscriber(subscriberInfo); subscriber = await commonEvent.createSubscriber(subscriberInfo);
commonEvent.subscribe(subscriber, subscribeCallBack); commonEvent.subscribe(subscriber, subscribeCallBack);
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: systemAppCalleeABundleName, bundleName: systemAppCalleeABundleName,
abilityName: systemAppCalleeAMainAbilityName, abilityName: systemAppCalleeAMainAbilityName,
}); });
...@@ -310,7 +310,7 @@ export default function abilityTest(abilityContext) { ...@@ -310,7 +310,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: systemAppCalleeABundleName, bundleName: systemAppCalleeABundleName,
abilityName: systemAppCalleeAMainAbilityName, abilityName: systemAppCalleeAMainAbilityName,
}); });
...@@ -369,12 +369,12 @@ export default function abilityTest(abilityContext) { ...@@ -369,12 +369,12 @@ export default function abilityTest(abilityContext) {
subscriber = await commonEvent.createSubscriber(subscriberInfo); subscriber = await commonEvent.createSubscriber(subscriberInfo);
commonEvent.subscribe(subscriber, subscribeCallBack); commonEvent.subscribe(subscriber, subscribeCallBack);
caller1 = await globalThis.abilityContext.startAbilityByCall({ caller1 = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: systemAppCalleeABundleName, bundleName: systemAppCalleeABundleName,
abilityName: systemAppCalleeAMainAbilityName, abilityName: systemAppCalleeAMainAbilityName,
}); });
caller2 = await globalThis.abilityContext.startAbilityByCall({ caller2 = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: systemAppCalleeABundleName, bundleName: systemAppCalleeABundleName,
abilityName: systemAppCalleeASecondAbilityName, abilityName: systemAppCalleeASecondAbilityName,
}); });
...@@ -405,11 +405,11 @@ export default function abilityTest(abilityContext) { ...@@ -405,11 +405,11 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller1 = await globalThis.abilityContext.startAbilityByCall({ let caller1 = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: systemAppCalleeABundleName, bundleName: systemAppCalleeABundleName,
abilityName: systemAppCalleeAMainAbilityName, abilityName: systemAppCalleeAMainAbilityName,
}); });
let caller2 = await globalThis.abilityContext.startAbilityByCall({ let caller2 = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: systemAppCalleeABundleName, bundleName: systemAppCalleeABundleName,
abilityName: systemAppCalleeASecondAbilityName, abilityName: systemAppCalleeASecondAbilityName,
}); });
...@@ -457,7 +457,7 @@ export default function abilityTest(abilityContext) { ...@@ -457,7 +457,7 @@ export default function abilityTest(abilityContext) {
expect(data).assertEqual('release'); expect(data).assertEqual('release');
console.log('ACTS_CommonComponent_Call_0700 releaseCallBack1' + data); console.log('ACTS_CommonComponent_Call_0700 releaseCallBack1' + data);
setTimeout(() => { setTimeout(() => {
globalThis.abilityContext.startAbilityByCall({ globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: systemAppCalleeABundleName, bundleName: systemAppCalleeABundleName,
abilityName: systemAppCalleeASecondAbilityName, abilityName: systemAppCalleeASecondAbilityName,
}).then(data => { }).then(data => {
...@@ -488,7 +488,7 @@ export default function abilityTest(abilityContext) { ...@@ -488,7 +488,7 @@ export default function abilityTest(abilityContext) {
subscriber = await commonEvent.createSubscriber(subscriberInfo); subscriber = await commonEvent.createSubscriber(subscriberInfo);
commonEvent.subscribe(subscriber, subscribeCallBack); commonEvent.subscribe(subscriber, subscribeCallBack);
globalThis.abilityContext.startAbilityByCall({ globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: systemAppCalleeABundleName, bundleName: systemAppCalleeABundleName,
abilityName: systemAppCalleeASecondAbilityName, abilityName: systemAppCalleeASecondAbilityName,
}).then(data => { }).then(data => {
...@@ -519,7 +519,7 @@ export default function abilityTest(abilityContext) { ...@@ -519,7 +519,7 @@ export default function abilityTest(abilityContext) {
expect(data).assertEqual('release'); expect(data).assertEqual('release');
console.log('ACTS_CommonComponent_Call_0800 releaseCallBack' + data); console.log('ACTS_CommonComponent_Call_0800 releaseCallBack' + data);
setTimeout(() => { setTimeout(() => {
globalThis.abilityContext.startAbilityByCall({ globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: systemAppCalleeABundleName, bundleName: systemAppCalleeABundleName,
abilityName: systemAppCalleeASecondAbilityName, abilityName: systemAppCalleeASecondAbilityName,
}).then(data => { }).then(data => {
...@@ -543,7 +543,7 @@ export default function abilityTest(abilityContext) { ...@@ -543,7 +543,7 @@ export default function abilityTest(abilityContext) {
}, 100); }, 100);
} }
globalThis.abilityContext.startAbilityByCall({ globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: systemAppCalleeABundleName, bundleName: systemAppCalleeABundleName,
abilityName: systemAppCalleeASecondAbilityName, abilityName: systemAppCalleeASecondAbilityName,
}).then(data => { }).then(data => {
...@@ -588,7 +588,7 @@ export default function abilityTest(abilityContext) { ...@@ -588,7 +588,7 @@ export default function abilityTest(abilityContext) {
subscriber = await commonEvent.createSubscriber(subscriberInfo); subscriber = await commonEvent.createSubscriber(subscriberInfo);
commonEvent.subscribe(subscriber, subscribeCallBack); commonEvent.subscribe(subscriber, subscribeCallBack);
caller = await globalThis.abilityContext.startAbilityByCall({ caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: thirdAppABundleName, bundleName: thirdAppABundleName,
abilityName: thirdAppAMainAbilityName, abilityName: thirdAppAMainAbilityName,
}); });
...@@ -619,7 +619,7 @@ export default function abilityTest(abilityContext) { ...@@ -619,7 +619,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
caller = await globalThis.abilityContext.startAbilityByCall({ caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: thirdAppABundleName, bundleName: thirdAppABundleName,
abilityName: thirdAppAMainAbilityName, abilityName: thirdAppAMainAbilityName,
}); });
...@@ -652,7 +652,7 @@ export default function abilityTest(abilityContext) { ...@@ -652,7 +652,7 @@ export default function abilityTest(abilityContext) {
var exceptionFlag = false; var exceptionFlag = false;
try { try {
caller = await globalThis.abilityContext.startAbilityByCall({ caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: systemAppCalleeABundleName, bundleName: systemAppCalleeABundleName,
abilityName: systemAppCalleeAThirdAbilityName, abilityName: systemAppCalleeAThirdAbilityName,
}); });
...@@ -712,7 +712,7 @@ export default function abilityTest(abilityContext) { ...@@ -712,7 +712,7 @@ export default function abilityTest(abilityContext) {
subscriber = await commonEvent.createSubscriber(subscriberInfo); subscriber = await commonEvent.createSubscriber(subscriberInfo);
commonEvent.subscribe(subscriber, subscribeCallBack); commonEvent.subscribe(subscriber, subscribeCallBack);
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -768,7 +768,7 @@ export default function abilityTest(abilityContext) { ...@@ -768,7 +768,7 @@ export default function abilityTest(abilityContext) {
bundleName: bundleNameCallee, bundleName: bundleNameCallee,
abilityName: abilityNameCallee, abilityName: abilityNameCallee,
} }
let caller = await globalThis.abilityContext.startAbilityByCall(want); let caller = await globalThis.globalThis.abilityContext.startAbilityByCall(want);
if (typeof caller !== "object" || caller == null) { if (typeof caller !== "object" || caller == null) {
console.log('ACTS_CommonComponent_Call_2000 startAbilityByCall fail'); console.log('ACTS_CommonComponent_Call_2000 startAbilityByCall fail');
expect().assertFail(); expect().assertFail();
...@@ -803,7 +803,7 @@ export default function abilityTest(abilityContext) { ...@@ -803,7 +803,7 @@ export default function abilityTest(abilityContext) {
bundleName: bundleNameCallee, bundleName: bundleNameCallee,
abilityName: abilityNameCallee, abilityName: abilityNameCallee,
} }
let caller = await globalThis.abilityContext.startAbilityByCall(want); let caller = await globalThis.globalThis.abilityContext.startAbilityByCall(want);
if (typeof caller !== "object" || caller == null) { if (typeof caller !== "object" || caller == null) {
console.log('ACTS_CommonComponent_Call_2300 startAbilityByCall fail'); console.log('ACTS_CommonComponent_Call_2300 startAbilityByCall fail');
expect().assertFail(); expect().assertFail();
...@@ -849,7 +849,7 @@ export default function abilityTest(abilityContext) { ...@@ -849,7 +849,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -893,7 +893,7 @@ export default function abilityTest(abilityContext) { ...@@ -893,7 +893,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -924,7 +924,7 @@ export default function abilityTest(abilityContext) { ...@@ -924,7 +924,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -955,7 +955,7 @@ export default function abilityTest(abilityContext) { ...@@ -955,7 +955,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -986,7 +986,7 @@ export default function abilityTest(abilityContext) { ...@@ -986,7 +986,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -1017,7 +1017,7 @@ export default function abilityTest(abilityContext) { ...@@ -1017,7 +1017,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -1048,7 +1048,7 @@ export default function abilityTest(abilityContext) { ...@@ -1048,7 +1048,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -1217,7 +1217,7 @@ export default function abilityTest(abilityContext) { ...@@ -1217,7 +1217,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -1249,7 +1249,7 @@ export default function abilityTest(abilityContext) { ...@@ -1249,7 +1249,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -1281,7 +1281,7 @@ export default function abilityTest(abilityContext) { ...@@ -1281,7 +1281,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
let caller = await globalThis.abilityContext.startAbilityByCall({ let caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}); });
...@@ -1313,7 +1313,7 @@ export default function abilityTest(abilityContext) { ...@@ -1313,7 +1313,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
globalThis.abilityContext.startAbilityByCall({ globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}).then((data) => { }).then((data) => {
...@@ -1346,7 +1346,7 @@ export default function abilityTest(abilityContext) { ...@@ -1346,7 +1346,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
globalThis.abilityContext.startAbilityByCall({ globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}).then((data) => { }).then((data) => {
...@@ -1379,7 +1379,7 @@ export default function abilityTest(abilityContext) { ...@@ -1379,7 +1379,7 @@ export default function abilityTest(abilityContext) {
done(); done();
} }
globalThis.abilityContext.startAbilityByCall({ globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}).then((data) => { }).then((data) => {
...@@ -1479,7 +1479,7 @@ export default function abilityTest(abilityContext) { ...@@ -1479,7 +1479,7 @@ export default function abilityTest(abilityContext) {
bundleName: bundleNameCallee, bundleName: bundleNameCallee,
abilityName: abilityNameCallee, abilityName: abilityNameCallee,
} }
let caller = await globalThis.abilityContext.startAbilityByCall(want); let caller = await globalThis.globalThis.abilityContext.startAbilityByCall(want);
if (typeof caller !== "object" || caller == null) { if (typeof caller !== "object" || caller == null) {
console.log('ACTS_CommonComponent_Call_4800 startAbilityByCall fail'); console.log('ACTS_CommonComponent_Call_4800 startAbilityByCall fail');
expect().assertFail(); expect().assertFail();
...@@ -1534,7 +1534,7 @@ export default function abilityTest(abilityContext) { ...@@ -1534,7 +1534,7 @@ export default function abilityTest(abilityContext) {
}) })
} }
globalThis.abilityContext.startAbilityByCall({ globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: sysABundleName, bundleName: sysABundleName,
abilityName: sysASecondAbilityName, abilityName: sysASecondAbilityName,
}).then((data) => { }).then((data) => {
...@@ -1635,7 +1635,7 @@ export default function abilityTest(abilityContext) { ...@@ -1635,7 +1635,7 @@ export default function abilityTest(abilityContext) {
let exceptionFlag = false; let exceptionFlag = false;
try { try {
caller = await globalThis.abilityContext.startAbilityByCall(null); caller = await globalThis.globalThis.abilityContext.startAbilityByCall(null);
console.log('ACTS_CommonComponent_Call_5200 startAbilityByCall' + JSON.stringify(caller)) console.log('ACTS_CommonComponent_Call_5200 startAbilityByCall' + JSON.stringify(caller))
} catch(err) { } catch(err) {
console.log('ACTS_CommonComponent_Call_5200 exception' + err); console.log('ACTS_CommonComponent_Call_5200 exception' + err);
...@@ -1658,7 +1658,7 @@ export default function abilityTest(abilityContext) { ...@@ -1658,7 +1658,7 @@ export default function abilityTest(abilityContext) {
let exceptionFlag = false; let exceptionFlag = false;
try { try {
caller = await globalThis.abilityContext.startAbilityByCall({ caller = await globalThis.globalThis.abilityContext.startAbilityByCall({
bundleName: "", bundleName: "",
abilityName: "", abilityName: "",
}); });
...@@ -1684,7 +1684,7 @@ export default function abilityTest(abilityContext) { ...@@ -1684,7 +1684,7 @@ export default function abilityTest(abilityContext) {
let exceptionFlag = false; let exceptionFlag = false;
try { try {
caller = await globalThis.abilityContext.startAbilityByCall(undefined); caller = await globalThis.globalThis.abilityContext.startAbilityByCall(undefined);
console.log('ACTS_CommonComponent_Call_5400 startAbilityByCall' + JSON.stringify(caller)) console.log('ACTS_CommonComponent_Call_5400 startAbilityByCall' + JSON.stringify(caller))
} catch(err) { } catch(err) {
console.log('ACTS_CommonComponent_Call_5400 exception' + err); console.log('ACTS_CommonComponent_Call_5400 exception' + err);
...@@ -1710,7 +1710,7 @@ export default function abilityTest(abilityContext) { ...@@ -1710,7 +1710,7 @@ export default function abilityTest(abilityContext) {
bundleName: bundleNameCallee, bundleName: bundleNameCallee,
abilityName: abilityNameCallee, abilityName: abilityNameCallee,
} }
let caller = await globalThis.abilityContext.startAbilityByCall(want); let caller = await globalThis.globalThis.abilityContext.startAbilityByCall(want);
if (typeof caller !== "object" || caller == null) { if (typeof caller !== "object" || caller == null) {
console.log('ACTS_CommonComponent_Call_5700 startAbilityByCall fail'); console.log('ACTS_CommonComponent_Call_5700 startAbilityByCall fail');
expect().assertFail(); expect().assertFail();
...@@ -1757,7 +1757,7 @@ export default function abilityTest(abilityContext) { ...@@ -1757,7 +1757,7 @@ export default function abilityTest(abilityContext) {
bundleName: bundleNameCallee, bundleName: bundleNameCallee,
abilityName: abilityNameCallee, abilityName: abilityNameCallee,
} }
let caller = await globalThis.abilityContext.startAbilityByCall(want); let caller = await globalThis.globalThis.abilityContext.startAbilityByCall(want);
if (typeof caller !== "object" || caller == null) { if (typeof caller !== "object" || caller == null) {
console.log('ACTS_CommonComponent_Call_5800 startAbilityByCall fail'); console.log('ACTS_CommonComponent_Call_5800 startAbilityByCall fail');
expect().assertFail(); expect().assertFail();
...@@ -1773,7 +1773,7 @@ export default function abilityTest(abilityContext) { ...@@ -1773,7 +1773,7 @@ export default function abilityTest(abilityContext) {
} }
await sleep(1000); await sleep(1000);
await globalThis.abilityContext.startAbility(want, startAbilityCallback); await globalThis.globalThis.abilityContext.startAbility(want, startAbilityCallback);
async function releaseCallback(data) { async function releaseCallback(data) {
console.log('ACTS_CommonComponent_Call_5800 releaseCallBack:' + data); console.log('ACTS_CommonComponent_Call_5800 releaseCallBack:' + data);
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
import abilityTest from './Ability.test.ets' import abilityTest from './Ability.test.ets'
export default function testsuite(context) { export default function testsuite() {
abilityTest(context) abilityTest()
} }
\ No newline at end of file
{ {
"src": [ "src": [
"pages/index/index", "MainAbility/pages/index/index",
"pages/second/second" "MainAbility/pages/second/second"
] ]
} }
\ No newline at end of file
{ {
"description": "Configuration for hjunit demo Tests", "description": "Configuration for hjunit demo Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "OHJSUnitTest",
"test-timeout": "600000", "test-timeout": "600000",
"package": "com.example.myapplication", "bundle-name": "com.example.myapplication",
"shell-timeout": "600000" "module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
}, },
"kits": [ "kits": [
{ {
......
/*
* 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 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 { export default class MainAbility extends Ability {
onCreate(want,launchParam){ onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability // Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate") console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want; 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() { onDestroy() {
...@@ -18,7 +41,7 @@ export default class MainAbility extends Ability { ...@@ -18,7 +41,7 @@ export default class MainAbility extends Ability {
//globalThis.windowStage = windowStage //globalThis.windowStage = windowStage
//globalThis.abilityStorage = this.storage //globalThis.abilityStorage = this.storage
globalThis.abilityContext = this.context globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null) windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null)
} }
onWindowStageDestroy() { onWindowStageDestroy() {
......
...@@ -12,10 +12,7 @@ ...@@ -12,10 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import router from '@ohos.router';
import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test"
@Entry @Entry
@Component @Component
...@@ -24,22 +21,6 @@ struct Index { ...@@ -24,22 +21,6 @@ struct Index {
aboutToAppear(){ aboutToAppear(){
console.info("start run testcase!!!!"); 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() { build() {
......
/*
* 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
/*
* 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
/*
* 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
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 commonEvent from '@ohos.commonEvent'
const passStr = 'pass'; const passStr = 'pass';
...@@ -28,7 +28,7 @@ function publishCaseExecute(caseName: string) { ...@@ -28,7 +28,7 @@ function publishCaseExecute(caseName: string) {
}); });
} }
export default function abilityTest(abilityContext) { export default function abilityTest() {
describe('AccessibilityElementTest', function () { describe('AccessibilityElementTest', function () {
let subScriber = undefined; let subScriber = undefined;
let isConnect = false; let isConnect = false;
...@@ -48,7 +48,7 @@ export default function abilityTest(abilityContext) { ...@@ -48,7 +48,7 @@ export default function abilityTest(abilityContext) {
} }
}); });
await abilityContext.startAbility({ await globalThis.abilityContext.startAbility({
deviceId: '', deviceId: '',
bundleName: 'com.example.acetest', bundleName: 'com.example.acetest',
abilityName: 'MainAbility', abilityName: 'MainAbility',
......
...@@ -14,6 +14,6 @@ ...@@ -14,6 +14,6 @@
*/ */
import abilityTest from './AccessibilityElement.test.ets' import abilityTest from './AccessibilityElement.test.ets'
export default function testsuite(abilityContext) { export default function testsuite() {
abilityTest(abilityContext) abilityTest()
} }
\ No newline at end of file
{ {
"src": [ "src": [
"pages/index/index" "MainAbility/pages/index/index"
] ]
} }
\ No newline at end of file
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
import("//test/xts/tools/build/suite.gni") import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsAccessibilityEventTest") { ohos_js_hap_suite("ActsAccessibilityEventTest") {
hap_profile = "entry/src/main/module.json" hap_profile = "./entry/src/main/module.json"
js_build_mode = "debug" js_build_mode = "debug"
deps = [ deps = [
":accessibilityevent_js_assets", ":accessibilityevent_js_assets",
...@@ -31,11 +31,11 @@ ohos_app_scope("accessibilityevent_app_profile") { ...@@ -31,11 +31,11 @@ ohos_app_scope("accessibilityevent_app_profile") {
} }
ohos_js_assets("accessibilityevent_js_assets") { ohos_js_assets("accessibilityevent_js_assets") {
source_dir = "entry/src/main/ets" source_dir = "./entry/src/main/ets"
} }
ohos_resources("accessibilityevent_resources") { ohos_resources("accessibilityevent_resources") {
sources = [ "entry/src/main/resources" ] sources = [ "./entry/src/main/resources" ]
deps = [ ":accessibilityevent_app_profile" ] deps = [ ":accessibilityevent_app_profile" ]
hap_profile = "entry/src/main/module.json" hap_profile = "./entry/src/main/module.json"
} }
{ {
"description": "Configuration for hjunit demo Tests", "description": "Configuration for hjunit demo Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "OHJSUnitTest",
"test-timeout": "180000", "test-timeout": "180000",
"package": "com.example.myapplication", "bundle-name": "com.example.myapplication",
"shell-timeout": "600000" "module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
}, },
"kits": [ "kits": [
{ {
......
/*
* 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 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 { export default class MainAbility extends Ability {
onCreate(want,launchParam){ onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability // Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate") console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want; 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() { onDestroy() {
...@@ -18,7 +41,7 @@ export default class MainAbility extends Ability { ...@@ -18,7 +41,7 @@ export default class MainAbility extends Ability {
//globalThis.windowStage = windowStage //globalThis.windowStage = windowStage
//globalThis.abilityStorage = this.storage //globalThis.abilityStorage = this.storage
globalThis.abilityContext = this.context globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null) windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null)
} }
onWindowStageDestroy() { onWindowStageDestroy() {
......
...@@ -12,10 +12,7 @@ ...@@ -12,10 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import router from '@ohos.router';
import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test"
@Entry @Entry
@Component @Component
...@@ -24,22 +21,6 @@ struct Index { ...@@ -24,22 +21,6 @@ struct Index {
aboutToAppear(){ aboutToAppear(){
console.info("start run testcase!!!!"); 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() { build() {
......
/*
* 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
/*
* 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
/*
* 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
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 accessibility from '@ohos.accessibility'
import commonEvent from '@ohos.commonEvent' import commonEvent from '@ohos.commonEvent'
export default function abilityTest(abilityContext) { export default function abilityTest() {
let targetBundleName = 'com.example.myapplication'; let targetBundleName = 'com.example.myapplication';
let subScriber = undefined; let subScriber = undefined;
let isConnected: boolean = false; let isConnected: boolean = false;
...@@ -38,7 +38,7 @@ export default function abilityTest(abilityContext) { ...@@ -38,7 +38,7 @@ export default function abilityTest(abilityContext) {
}); });
setTimeout(async () => { setTimeout(async () => {
await abilityContext.startAbility({ await globalThis.abilityContext.startAbility({
deviceId: "", deviceId: "",
bundleName: "com.example.acetest", bundleName: "com.example.acetest",
abilityName: "MainAbility", abilityName: "MainAbility",
......
...@@ -14,6 +14,6 @@ ...@@ -14,6 +14,6 @@
*/ */
import abilityTest from './AccessibilityEventTest.test.ets' import abilityTest from './AccessibilityEventTest.test.ets'
export default function testsuite(abilityContext) { export default function testsuite() {
abilityTest(abilityContext) abilityTest()
} }
\ No newline at end of file
{ {
"src": [ "src": [
"pages/index/index" "MainAbility/pages/index/index"
] ]
} }
\ No newline at end of file
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
import("//test/xts/tools/build/suite.gni") import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsAccessibilityExtensionTest") { ohos_js_hap_suite("ActsAccessibilityExtensionTest") {
hap_profile = "entry/src/main/module.json" hap_profile = "./entry/src/main/module.json"
js_build_mode = "debug" js_build_mode = "debug"
deps = [ deps = [
":accessibilityextension_js_assets", ":accessibilityextension_js_assets",
...@@ -31,11 +31,11 @@ ohos_app_scope("accessibilityextension_app_profile") { ...@@ -31,11 +31,11 @@ ohos_app_scope("accessibilityextension_app_profile") {
} }
ohos_js_assets("accessibilityextension_js_assets") { ohos_js_assets("accessibilityextension_js_assets") {
source_dir = "entry/src/main/ets" source_dir = "./entry/src/main/ets"
} }
ohos_resources("accessibilityextension_resources") { ohos_resources("accessibilityextension_resources") {
sources = [ "entry/src/main/resources" ] sources = [ "./entry/src/main/resources" ]
deps = [ ":accessibilityextension_app_profile" ] deps = [ ":accessibilityextension_app_profile" ]
hap_profile = "entry/src/main/module.json" hap_profile = "./entry/src/main/module.json"
} }
{ {
"description": "Configuration for hjunit demo Tests", "description": "Configuration for hjunit demo Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "OHJSUnitTest",
"test-timeout": "60000", "test-timeout": "180000",
"package": "com.example.myapplication", "bundle-name": "com.example.myapplication",
"shell-timeout": "60000" "module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
}, },
"kits": [ "kits": [
{ {
......
import Ability from '@ohos.application.Ability' 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 { export default class MainAbility extends Ability {
onCreate(want,launchParam){ onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability // Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate") console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want; 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() { onDestroy() {
...@@ -18,7 +27,7 @@ export default class MainAbility extends Ability { ...@@ -18,7 +27,7 @@ export default class MainAbility extends Ability {
//globalThis.windowStage = windowStage //globalThis.windowStage = windowStage
//globalThis.abilityStorage = this.storage //globalThis.abilityStorage = this.storage
globalThis.abilityContext = this.context globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null) windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null)
} }
onWindowStageDestroy() { onWindowStageDestroy() {
......
...@@ -12,10 +12,7 @@ ...@@ -12,10 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import router from '@ohos.router';
import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test"
@Entry @Entry
@Component @Component
...@@ -24,22 +21,6 @@ struct Index { ...@@ -24,22 +21,6 @@ struct Index {
aboutToAppear(){ aboutToAppear(){
console.info("start run testcase!!!!"); 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() { build() {
......
/*
* 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
/*
* 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
/*
* 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
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 commonEvent from '@ohos.commonEvent'
export default function abilityTest(abilityContext) { export default function abilityTest() {
let isCalled: boolean = false; let isCalled: boolean = false;
let subScriber = undefined; let subScriber = undefined;
...@@ -57,7 +57,7 @@ export default function abilityTest(abilityContext) { ...@@ -57,7 +57,7 @@ export default function abilityTest(abilityContext) {
*/ */
it('AccessibilityExtensionTest_Connect_0100', 0, async function (done) { it('AccessibilityExtensionTest_Connect_0100', 0, async function (done) {
console.info('AccessibilityExtensionTest_Connect_0100: start'); console.info('AccessibilityExtensionTest_Connect_0100: start');
await abilityContext.startAbility({ await globalThis.abilityContext.startAbility({
deviceId: "", deviceId: "",
bundleName: "com.example.acetest", bundleName: "com.example.acetest",
abilityName: "MainAbility", abilityName: "MainAbility",
......
...@@ -14,6 +14,6 @@ ...@@ -14,6 +14,6 @@
*/ */
import abilityTest from './AccessibilityExtension.test.ets' import abilityTest from './AccessibilityExtension.test.ets'
export default function testsuite(abilityContext) { export default function testsuite() {
abilityTest(abilityContext) abilityTest()
} }
\ No newline at end of file
{ {
"src": [ "src": [
"pages/index/index" "MainAbility/pages/index/index"
] ]
} }
\ No newline at end of file
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
import("//test/xts/tools/build/suite.gni") import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsAccessibilityExtensionContextTest") { ohos_js_hap_suite("ActsAccessibilityExtensionContextTest") {
hap_profile = "entry/src/main/module.json" hap_profile = "./entry/src/main/module.json"
js_build_mode = "debug" js_build_mode = "debug"
deps = [ deps = [
":accessibilityextensioncontext_js_assets", ":accessibilityextensioncontext_js_assets",
...@@ -31,11 +31,11 @@ ohos_app_scope("accessibilityextensioncontext_app_profile") { ...@@ -31,11 +31,11 @@ ohos_app_scope("accessibilityextensioncontext_app_profile") {
} }
ohos_js_assets("accessibilityextensioncontext_js_assets") { ohos_js_assets("accessibilityextensioncontext_js_assets") {
source_dir = "entry/src/main/ets" source_dir = "./entry/src/main/ets"
} }
ohos_resources("accessibilityextensioncontext_resources") { ohos_resources("accessibilityextensioncontext_resources") {
sources = [ "entry/src/main/resources" ] sources = [ "./entry/src/main/resources" ]
deps = [ ":accessibilityextensioncontext_app_profile" ] deps = [ ":accessibilityextensioncontext_app_profile" ]
hap_profile = "entry/src/main/module.json" hap_profile = "./entry/src/main/module.json"
} }
{ {
"description": "Configuration for hjunit demo Tests", "description": "Configuration for hjunit demo Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "OHJSUnitTest",
"test-timeout": "360000", "test-timeout": "360000",
"package": "com.example.myapplication", "bundle-name": "com.example.myapplication",
"shell-timeout": "360000" "module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
}, },
"kits": [ "kits": [
{ {
......
import Ability from '@ohos.application.Ability' 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 { export default class MainAbility extends Ability {
onCreate(want,launchParam){ onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability // Ability is creating, initialize resources for this ability
console.log("[Demo] MainAbility onCreate") console.log("[Demo] MainAbility onCreate")
globalThis.abilityWant = want; 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() { onDestroy() {
...@@ -18,7 +27,7 @@ export default class MainAbility extends Ability { ...@@ -18,7 +27,7 @@ export default class MainAbility extends Ability {
//globalThis.windowStage = windowStage //globalThis.windowStage = windowStage
//globalThis.abilityStorage = this.storage //globalThis.abilityStorage = this.storage
globalThis.abilityContext = this.context globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null) windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null)
} }
onWindowStageDestroy() { onWindowStageDestroy() {
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
*/ */
import file from '@system.file'; import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test"
@Entry @Entry
@Component @Component
...@@ -24,22 +22,6 @@ struct Index { ...@@ -24,22 +22,6 @@ struct Index {
aboutToAppear(){ aboutToAppear(){
console.info("start run testcase!!!!"); 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() { build() {
......
/*
* 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
/*
* 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
/*
* 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
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 commonEvent from '@ohos.commonEvent'
const passStr = 'pass'; const passStr = 'pass';
...@@ -28,7 +28,7 @@ function publishCaseExecute(caseName: string) { ...@@ -28,7 +28,7 @@ function publishCaseExecute(caseName: string) {
}); });
} }
export default function abilityTest(abilityContext) { export default function abilityTest() {
describe('AccessibilityExtensionContextTest', function () { describe('AccessibilityExtensionContextTest', function () {
let subScriber = undefined; let subScriber = undefined;
let isConnect = false; let isConnect = false;
...@@ -48,7 +48,7 @@ export default function abilityTest(abilityContext) { ...@@ -48,7 +48,7 @@ export default function abilityTest(abilityContext) {
} }
}); });
await abilityContext.startAbility({ await globalThis.abilityContext.startAbility({
deviceId: '', deviceId: '',
bundleName: 'com.example.acetest', bundleName: 'com.example.acetest',
abilityName: 'MainAbility', abilityName: 'MainAbility',
......
...@@ -14,6 +14,6 @@ ...@@ -14,6 +14,6 @@
*/ */
import abilityTest from './AccessibilityExtensionContext.test.ets' import abilityTest from './AccessibilityExtensionContext.test.ets'
export default function testsuite(abilityContext) { export default function testsuite() {
abilityTest(abilityContext) abilityTest()
} }
\ No newline at end of file
{ {
"src": [ "src": [
"pages/index/index" "MainAbility/pages/index/index"
] ]
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册