提交 5928ecd8 编写于 作者: J jiyong_sd

Adapt to the new framework

Signed-off-by: Njiyong_sd <jiyong@huawei.com>
Change-Id: I35e061b6637585c8c51b0bf3d530f6d9f014f66e
上级 a0a6561f
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "JSUnitTest",
"type": "OHJSUnitTest",
"test-timeout": "180000",
"package": "com.example.apicoverhaptest",
"shell-timeout": "600000"
"bundle-name": "com.example.apicoverhaptest",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
},
"kits": [
{
......
......@@ -30,7 +30,7 @@ export default class MainAbility extends Ability {
// Main window is created, set main page for this ability
console.log("[Demo] MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context;
windowStage.setUIContent(this.context, "pages/MainAbility_pages", null)
windowStage.setUIContent(this.context, "MainAbility/pages/MainAbility_pages", null)
}
onWindowStageDestroy() {
......
......@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import list from '../test/ListTest'
import router from '@ohos.router';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../test/List.test'
@Entry
@Component
......@@ -24,23 +25,12 @@ struct Index {
aboutToAppear() {
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend)
core.init()
globalThis.abilityWant.parameters.timeout = 20000;
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
configService.setConfig(globalThis.abilityWant.parameters)
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
list(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() {
......
/*
* 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.apicoverhaptest.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 @@
* 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 formProvider from '@ohos.application.formProvider';
import FormInfo from '@ohos.application.formInfo';
......@@ -24,7 +24,7 @@ var array = new Array();
function sleep(time) {
return new Promise((resolve)=>setTimeout(resolve,time));
}
export default function ApiCoverTest(abilityContext) {
export default function ApiCoverTest() {
describe('ApiCoverTestTest', function () {
/*
......@@ -39,7 +39,7 @@ export default function ApiCoverTest(abilityContext) {
bundleName: "com.example.extensionapitest",
abilityName: "FirstExtension1"
};
await abilityContext.startServiceExtensionAbility(want).then((data) => {
await globalThis.abilityContext.startServiceExtensionAbility(want).then((data) => {
console.log('Ability: startServiceExtensionAbility success:' + JSON.stringify(data));
expect("case execute failed").assertEqual(data);
}).catch((error) => {
......@@ -61,7 +61,7 @@ export default function ApiCoverTest(abilityContext) {
bundleName: "com.example.extensionapitest1",
abilityName: "FirstExtension"
};
await abilityContext.stopServiceExtensionAbility(want).then((data) => {
await globalThis.abilityContext.stopServiceExtensionAbility(want).then((data) => {
console.log(`Ability: stopServiceExtensionAbility success: ${JSON.stringify(data)}`);
expect("case execute failed").assertEqual(data);
}).catch((error) => {
......@@ -83,7 +83,7 @@ export default function ApiCoverTest(abilityContext) {
bundleName: "com.example.extensionapitest",
abilityName: "FirstExtension"
};
await abilityContext.startServiceExtensionAbilityWithAccount(want, 999).then((data) => {
await globalThis.abilityContext.startServiceExtensionAbilityWithAccount(want, 999).then((data) => {
console.log(`Ability: startServiceExtensionAbilityWithAccount success: ${JSON.stringify(data)}`);
expect("case execute failed").assertEqual("data");
}).catch((error) => {
......@@ -105,7 +105,7 @@ export default function ApiCoverTest(abilityContext) {
bundleName: "com.example.extensionapitest",
abilityName: "FirstExtension"
};
await abilityContext.stopServiceExtensionAbilityWithAccount(want, 999).then((data) => {
await globalThis.abilityContext.stopServiceExtensionAbilityWithAccount(want, 999).then((data) => {
console.log(`Ability: stopServiceExtensionAbilityWithAccount success: ${JSON.stringify(data)}`);
expect("case execute failed").assertEqual(data);
}).catch((error) => {
......@@ -127,7 +127,7 @@ export default function ApiCoverTest(abilityContext) {
bundleName: "com.example.extensionapitest",
abilityName: "FirstExtension1"
}
await abilityContext.startServiceExtensionAbility(want, (err, data) => {
await globalThis.abilityContext.startServiceExtensionAbility(want, (err, data) => {
if (err.code) {
console.error(`Ability: startServiceExtensionAbility failed: ${JSON.stringify(err)}`);
expect(EXTENSION_INFO_ERR).assertEqual(err.code);
......@@ -151,7 +151,7 @@ export default function ApiCoverTest(abilityContext) {
bundleName: "com.example.extensionapitest1",
abilityName: "FirstExtension"
};
await abilityContext.stopServiceExtensionAbility(want, (err, data) => {
await globalThis.abilityContext.stopServiceExtensionAbility(want, (err, data) => {
if (err.code) {
console.error(`Ability: stopServiceExtensionAbility failed: ${JSON.stringify(err)}`);
expect(EXTENSION_INFO_ERR).assertEqual(err.code);
......@@ -176,7 +176,7 @@ export default function ApiCoverTest(abilityContext) {
bundleName: "com.example.extensionapitest",
abilityName: "FirstExtension"
};
await abilityContext.startServiceExtensionAbilityWithAccount(want, 999, (err, data) => {
await globalThis.abilityContext.startServiceExtensionAbilityWithAccount(want, 999, (err, data) => {
if (err.code) {
console.error(`Ability: startServiceExtensionAbilityWithAccount failed: ${JSON.stringify(err)}`);
expect(USERID_ERR).assertEqual(err.code);
......@@ -200,7 +200,7 @@ export default function ApiCoverTest(abilityContext) {
bundleName: "com.example.extensionapitest",
abilityName: "FirstExtension"
};
abilityContext.stopServiceExtensionAbilityWithAccount(want, 999, (err, data) => {
globalThis.abilityContext.stopServiceExtensionAbilityWithAccount(want, 999, (err, data) => {
if (err.code) {
console.error(`Ability: stopServiceExtensionAbilityWithAccount failed: ${JSON.stringify(err)}`);
expect(USERID_ERR).assertEqual(err.code);
......@@ -219,17 +219,17 @@ export default function ApiCoverTest(abilityContext) {
* @tc.level 3
*/
it('SUB_AA_AMS_Context_0100', 0, async function (done) {
expect("/data/storage/el2/base/haps/phone/cache").assertEqual(abilityContext.cacheDir)
expect("/data/storage/el2/base/haps/phone/temp").assertEqual(abilityContext.tempDir)
expect("/data/storage/el2/base/haps/phone/files").assertEqual(abilityContext.filesDir)
expect("/data/storage/el2/database/phone").assertEqual(abilityContext.databaseDir)
expect("/data/storage/el2/base/haps/phone/preferences").assertEqual(abilityContext.preferencesDir)
expect("/data/storage/el1/bundle").assertEqual(abilityContext.bundleCodeDir)
expect("/data/storage/el2/distributedfiles").assertEqual(abilityContext.distributedFilesDir)
expect(1).assertEqual(abilityContext.area)
let moduleContext = abilityContext.createModuleContext("module1")
expect("/data/storage/el2/base/haps/phone/cache").assertEqual(globalThis.abilityContext.cacheDir)
expect("/data/storage/el2/base/haps/phone/temp").assertEqual(globalThis.abilityContext.tempDir)
expect("/data/storage/el2/base/haps/phone/files").assertEqual(globalThis.abilityContext.filesDir)
expect("/data/storage/el2/database/phone").assertEqual(globalThis.abilityContext.databaseDir)
expect("/data/storage/el2/base/haps/phone/preferences").assertEqual(globalThis.abilityContext.preferencesDir)
expect("/data/storage/el1/bundle").assertEqual(globalThis.abilityContext.bundleCodeDir)
expect("/data/storage/el2/distributedfiles").assertEqual(globalThis.abilityContext.distributedFilesDir)
expect(1).assertEqual(globalThis.abilityContext.area)
let moduleContext = globalThis.abilityContext.createModuleContext("module1")
expect("/data/storage/el2/base/cache").assertEqual(moduleContext.cacheDir)
abilityContext.resourceManager.getConfiguration((err, data) => {
globalThis.abilityContext.resourceManager.getConfiguration((err, data) => {
if(err == undefined){
console.log(`Ability: getConfiguration success: ${JSON.stringify(data)}`);
console.log(`Ability: getConfiguration success: JSON.stringify(data.direction)`);
......@@ -249,14 +249,14 @@ export default function ApiCoverTest(abilityContext) {
* @tc.level 3
*/
it('SUB_AA_AMS_Context_0200', 0, async function (done) {
await abilityContext.eventHub.on("contextEvent", func1)
abilityContext.eventHub.emit("contextEvent", "aa", "bb")
await globalThis.abilityContext.eventHub.on("contextEvent", func1)
globalThis.abilityContext.eventHub.emit("contextEvent", "aa", "bb")
await sleep(500)
expect("aa").assertEqual(array[0])
expect("bb").assertEqual(array[1])
array = []
await abilityContext.eventHub.off("contextEvent", func1)
abilityContext.eventHub.emit("contextEvent", "cc", "dd")
await globalThis.abilityContext.eventHub.off("contextEvent", func1)
globalThis.abilityContext.eventHub.emit("contextEvent", "cc", "dd")
await sleep(500)
expect(array.length).assertEqual(0)
array = [];
......
......@@ -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'
var TAG: string = ''
export default function ContextEnvironmentTest(applicationContext) {
......
......@@ -18,10 +18,10 @@ import verificationTest from './VerificationTest'
import wantAgentCover from './WantAgentCover.test'
import contextEnvironmentTest from './ContextEnvironmentTest.test';
export default function List(context) {
export default function List() {
apiCoverAbility(context)
verificationTest(context)
wantAgentCover(context)
apiCoverAbility()
verificationTest()
wantAgentCover()
contextEnvironmentTest(globalThis.applicationContext)
}
\ No newline at end of file
......@@ -12,14 +12,14 @@
* 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 AbilityConstant from "@ohos.application.AbilityConstant";
import appManager from "@ohos.application.appManager";
import wantConstant from '@ohos.ability.wantConstant';
var TAG
export default function verificationTest(abilityContext){
export default function verificationTest(){
describe('VerificationTestTest', function() {
......@@ -62,7 +62,7 @@ export default function verificationTest(abilityContext){
bundleName: 'ohos.acts.aafwk.test.fasupplement',
abilityName: 'ohos.acts.aafwk.test.fasupplement.MainAbility'
}
abilityContext.startAbility(wantNum).then((data) => {
globalThis.abilityContext.startAbility(wantNum).then((data) => {
console.info(TAG + "startAbility data = " + JSON.stringify(data));
}).catch((err) => {
console.info(TAG + "startAbility err = " + JSON.stringify(err));
......@@ -125,7 +125,7 @@ export default function verificationTest(abilityContext){
bundleName: 'ohos.acts.aafwk.test.stagesupplement',
abilityName: 'MainAbility3'
}
abilityContext.startAbility(wantNum).then((data) => {
globalThis.abilityContext.startAbility(wantNum).then((data) => {
console.info(TAG + "startAbility data = " + JSON.stringify(data));
}).catch((err) => {
console.info(TAG + "startAbility err = " + JSON.stringify(err));
......@@ -202,7 +202,7 @@ export default function verificationTest(abilityContext){
bundleName: 'ohos.acts.aafwk.test.stagesupplement',
abilityName: 'MainAbility4'
}
abilityContext.startAbility(wantNum).then((data) => {
globalThis.abilityContext.startAbility(wantNum).then((data) => {
console.info(TAG + "startAbility data = " + JSON.stringify(data));
}).catch((err) => {
console.info(TAG + "startAbility err = " + JSON.stringify(err));
......@@ -258,7 +258,7 @@ export default function verificationTest(abilityContext){
bundleName: 'ohos.acts.aafwk.test.fasupplement',
abilityName: 'ohos.acts.aafwk.test.fasupplement.MainAbility2'
}
abilityContext.startAbility(wantNum).then((data) => {
globalThis.abilityContext.startAbility(wantNum).then((data) => {
console.info(TAG + "startAbility data = " + JSON.stringify(data));
}).catch((err) => {
console.info(TAG + "startAbility err = " + JSON.stringify(err));
......@@ -285,14 +285,14 @@ export default function verificationTest(abilityContext){
let label = undefined
let code1 = 0
let code2 = 0
abilityContext.setMissionLabel(label).then((data) => {
globalThis.abilityContext.setMissionLabel(label).then((data) => {
console.info(TAG + "setMissionLabel data = " + JSON.stringify(data));
}).catch((err) => {
code1 = err.code
console.info(TAG + "setMissionLabel err = " + JSON.stringify(err));
});
abilityContext.setMissionLabel(label, (err, data) => {
globalThis.abilityContext.setMissionLabel(label, (err, data) => {
code2 = err.code
console.info(TAG + "setMissionLabel err = " + JSON.stringify(err));
console.info(TAG + "setMissionLabel data = " + JSON.stringify(data));
......@@ -352,7 +352,7 @@ export default function verificationTest(abilityContext){
bundleName: 'ohos.acts.aafwk.test.stagesupplement',
abilityName: 'MainAbility5'
}
abilityContext.startAbility(wantNum).then((data) => {
globalThis.abilityContext.startAbility(wantNum).then((data) => {
console.info(TAG + "startAbility data = " + JSON.stringify(data));
}).catch((err) => {
console.info(TAG + "startAbility err = " + JSON.stringify(err));
......@@ -415,8 +415,8 @@ export default function verificationTest(abilityContext){
bundleName: 'ohos.acts.aafwk.test.stagesupplement',
abilityName: 'MainAbility9'
}
abilityContext.startAbility(wantNum).then((data) => {
value = abilityContext.restoreWindowStage(undefined);
globalThis.abilityContext.startAbility(wantNum).then((data) => {
value = globalThis.abilityContext.restoreWindowStage(undefined);
console.info(TAG + "startAbility data = " + JSON.stringify(data) + ";" + JSON.stringify(data));
}).catch((err) => {
console.info(TAG + "startAbility err = " + JSON.stringify(err));
......@@ -475,7 +475,7 @@ export default function verificationTest(abilityContext){
bundleName: 'ohos.acts.aafwk.test.stagesupplement',
abilityName: 'MainAbility10'
}
abilityContext.startAbility(wantNum).then((data) => {
globalThis.abilityContext.startAbility(wantNum).then((data) => {
console.info(TAG + "startAbility data = " + JSON.stringify(data));
}).catch((err) => {
console.info(TAG + "startAbility err = " + JSON.stringify(err));
......
......@@ -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 wantAgent from '@ohos.wantAgent';
var TAG
export default function wantAgentCoverTest(abilityContext) {
export default function wantAgentCoverTest() {
describe('WantAgentTest', function () {
/*
......@@ -29,7 +29,7 @@ export default function wantAgentCoverTest(abilityContext) {
TAG = 'SUB_AA_OpenHarmony_WantAgentCover_0100 ==>';
try {
let status:any = abilityContext.stageMode
let status:any = globalThis.abilityContext.stageMode
let code1 = undefined
var wantAgentInfo = {
wants: [
......
{
"src": [
"pages/MainAbility_pages"
"MainAbility/pages/MainAbility_pages"
]
}
\ No newline at end of file
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "120000",
"package": "com.example.processmultiinstance",
"shell-timeout": "300000"
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "com.example.processmultiinstance",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 70000
},
"kits": [
{
......
......@@ -30,7 +30,7 @@ export default class MainAbility extends Ability {
// Main window is created, set main page for this ability
console.log("MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null)
windowStage.setUIContent(this.context, "MainAbility/pages/index/index", null)
}
onWindowStageDestroy() {
......
......@@ -12,10 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index"
import testsuite from "../../test/List.test.ets"
import router from '@ohos.router';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../../test/List.test'
@Entry
......@@ -24,22 +24,12 @@ struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
const reportExtend = new ReportExtend(file)
core.addService('report', reportExtend)
core.init()
core.subscribeEvent('task', reportExtend)
const configService = core.getDefaultService('config')
console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters))
globalThis.abilityWant.parameters.timeout = 70000;
configService.setConfig(globalThis.abilityWant.parameters)
testsuite(globalThis.abilityContext)
core.execute()
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
build() {
......
/*
* 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.processmultiinstance.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
......@@ -35,7 +35,7 @@ var processNameA = "com.example.multiinstancehapa";
var processNameB = "com.example.multiinstancehapb";
var processNameC = "com.example.multiinstancehapc";
export default function abilityTest(abilityContext) {
export default function abilityTest() {
describe('ActsProcessMultiInstanceTest', function () {
afterEach(async (done) => {
......@@ -138,14 +138,14 @@ export default function abilityTest(abilityContext) {
done();
}
}
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapb",
abilityName: "com.example.multiinstancehapba.MainAbility",
}, (err, data) => {
console.log('ACTS_Process_MultiInstance_0100 - startAbilityhapba: '
+ JSON.stringify(err) + ", " + JSON.stringify(data))
})
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapb",
abilityName: "com.example.multiinstancehapbb.MainAbility",
}, (err, data) => {
......@@ -247,14 +247,14 @@ export default function abilityTest(abilityContext) {
done();
}
}
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapb",
abilityName: "com.example.multiinstancehapbc.MainAbility",
}, (err, data) => {
console.log('ACTS_Process_MultiInstance_0200 - startAbilityhapbc: '
+ JSON.stringify(err) + ", " + JSON.stringify(data))
})
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapb",
abilityName: "com.example.multiinstancehapbd.MainAbility",
}, (err, data) => {
......@@ -361,14 +361,14 @@ export default function abilityTest(abilityContext) {
done();
}
}
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapb",
abilityName: "com.example.multiinstancehapbd.MainAbility",
}, (err, data) => {
console.log('ACTS_Process_MultiInstance_0300 - startAbilityhapbd: '
+ JSON.stringify(err) + ", " + JSON.stringify(data))
})
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapb",
abilityName: "com.example.multiinstancehapbe.MainAbility",
}, (err, data) => {
......@@ -472,14 +472,14 @@ export default function abilityTest(abilityContext) {
done();
}
}
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapb",
abilityName: "com.example.multiinstancehapba.MainAbility",
}, (err, data) => {
console.log('ACTS_Process_MultiInstance_0400 - startAbilityhapba: '
+ JSON.stringify(err) + ", " + JSON.stringify(data))
})
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapb",
abilityName: "com.example.multiinstancehapbf.MainAbility",
}, (err, data) => {
......@@ -583,14 +583,14 @@ export default function abilityTest(abilityContext) {
done();
}
}
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapa",
abilityName: "com.example.multiinstancehapaa.MainAbility",
}, (err, data) => {
console.log('ACTS_Process_MultiInstance_0500 - startAbilityhapaa: '
+ JSON.stringify(err) + ", " + JSON.stringify(data))
})
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapb",
abilityName: "com.example.multiinstancehapbe.MainAbility",
}, (err, data) => {
......@@ -697,14 +697,14 @@ export default function abilityTest(abilityContext) {
done();
}
}
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapa",
abilityName: "com.example.multiinstancehapaa.MainAbility",
}, (err, data) => {
console.log('ACTS_Process_MultiInstance_0600 - startAbilityhapaa: '
+ JSON.stringify(err) + ", " + JSON.stringify(data))
})
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapb",
abilityName: "com.example.multiinstancehapbf.MainAbility",
}, (err, data) => {
......@@ -810,14 +810,14 @@ export default function abilityTest(abilityContext) {
done();
}
}
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapa",
abilityName: "com.example.multiinstancehapab.MainAbility",
}, (err, data) => {
console.log('ACTS_Process_MultiInstance_0700 - startAbilityhapab: '
+ JSON.stringify(err) + ", " + JSON.stringify(data))
})
abilityContext.startAbility({
globalThis.abilityContext.startAbility({
bundleName: "com.example.multiinstancehapb",
abilityName: "com.example.multiinstancehapbc.MainAbility",
}, (err, data) => {
......
......@@ -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
{
"src": [
"pages/index/index",
"pages/second/second"
"MainAbility/pages/index/index",
"MainAbility/pages/second/second"
]
}
\ No newline at end of file
......@@ -14,7 +14,7 @@
*/
import Ability from '@ohos.application.Ability'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from 'hypium/index'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default class TestAbility extends Ability {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册