diff --git a/test_packages.gni b/test_packages.gni index f8779d2db9b2cd33132547fd847f5ab19d8996ce..2034c072ca717838bf33cfee6ac8f87667fd15ab 100644 --- a/test_packages.gni +++ b/test_packages.gni @@ -47,6 +47,7 @@ _all_test_packages = [ "${ACTS_ROOT}/settingsdata:settingsdata", "${ACTS_ROOT}/barrierfree:barrierfree", "${ACTS_ROOT}/applications:applications", + "${ACTS_ROOT}/wukong:wukong", ] _all_test_packages_ivi = [ diff --git a/wukong/BUILD.gn b/wukong/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2ec0e992987912468e414c1218dc00e781f91b78 --- /dev/null +++ b/wukong/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") +import("//test/xts/tools/build/suite.gni") + +group("wukong") { + testonly = true + if (is_standard_system) { + deps = [ + "actswukongtest:ActsWukongTest" + ] + } +} diff --git a/wukong/actswukongtest/AppScope/app.json b/wukong/actswukongtest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..0fa085ed14967b974ed0e782ebc302681b7dcdee --- /dev/null +++ b/wukong/actswukongtest/AppScope/app.json @@ -0,0 +1,19 @@ +{ + "app": { + "bundleName": "com.example.ActsWukongTest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true, + "keepAlive": true, + "singleUser": true, + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/wukong/actswukongtest/AppScope/resources/base/element/string.json b/wukong/actswukongtest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cb89829df4eb31a7a382f8e9c2f5c0b39a5f3635 --- /dev/null +++ b/wukong/actswukongtest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ActsWukongTest" + } + ] +} diff --git a/wukong/actswukongtest/AppScope/resources/base/media/app_icon.png b/wukong/actswukongtest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/wukong/actswukongtest/AppScope/resources/base/media/app_icon.png differ diff --git a/wukong/actswukongtest/BUILD.gn b/wukong/actswukongtest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8ee3263037cf0de8e8793f13ed31817f7d5723dd --- /dev/null +++ b/wukong/actswukongtest/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsWukongTest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":wukong_js_assets", + ":wukong_resources" + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsWukongTest" + subsystem_name = "wukong" + part_name = "wukong" +} + +ohos_app_scope("wukong_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("wukong_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("wukong_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":wukong_app_profile" ] + hap_profile = "entry/src/main/module.json" +} + diff --git a/wukong/actswukongtest/Test.json b/wukong/actswukongtest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..2f54d195085232f9a2356358d8aeaa232ff12929 --- /dev/null +++ b/wukong/actswukongtest/Test.json @@ -0,0 +1,31 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "280000", + "bundle-name": "com.example.ActsWukongTest", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 70000 + }, + "kits": [ + { + "test-file-name": [ + "ActsWukongTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + "power-shell wakeup", + "power-shell setmode 602", + "param set persist.ace.testmode.enabled 1" + ], + "teardown-command":[ + "bm uninstall -n com.example.ActsWukongTest" + ] + } + ] +} diff --git a/wukong/actswukongtest/entry/src/main/ets/Application/AbilityStage.ts b/wukong/actswukongtest/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..8d437d73a82bd94a6ef7c8a68a5b1e437ae41586 --- /dev/null +++ b/wukong/actswukongtest/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,24 @@ +/* + * 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[wukongTest] MyAbilityStage onCreate") + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} \ No newline at end of file diff --git a/wukong/actswukongtest/entry/src/main/ets/MainAbility/MainAbility.ts b/wukong/actswukongtest/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..eb03ab5e6d6eb668c4b9b09aabb2cd0b8cc98346 --- /dev/null +++ b/wukong/actswukongtest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,58 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' +import Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "MainAbility/pages/index", null) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; diff --git a/wukong/actswukongtest/entry/src/main/ets/MainAbility/pages/index.ets b/wukong/actswukongtest/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b67402613b387dc5408e2bab479945c5b5cf783c --- /dev/null +++ b/wukong/actswukongtest/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ +@Entry +@Component +struct Index { + @State message: string = 'wukongtest' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/wukong/actswukongtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/wukong/actswukongtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..de0edc2010d5ac40595591a360dfd22aaaae6d4f --- /dev/null +++ b/wukong/actswukongtest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -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') + } +}; diff --git a/wukong/actswukongtest/entry/src/main/ets/test/Ability.test.ets b/wukong/actswukongtest/entry/src/main/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7ef46761331ffe0d6e45b7848a97f5006614e7f2 --- /dev/null +++ b/wukong/actswukongtest/entry/src/main/ets/test/Ability.test.ets @@ -0,0 +1,77 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import { UiDriver } from '@ohos.uitest' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import prompt from '@ohos.prompt' + +var abilityDelegator = undefined; +var abilityDelegator1 = undefined; +var driver; +var cmd; + +function sleep(time) { + return new Promise < void> ((resolve, reject) => { + setTimeout(() => { + resolve(); + }, time) + }) +} + +export default function abilityTest() { + describe('ActsWukongTest', function () { + beforeAll(async (done) => { + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + abilityDelegator1 = AbilityDelegatorRegistry.getAbilityDelegator(); + driver = await UiDriver.create() + await sleep(2000); + done(); + }) + + afterAll(async function (done) { + prompt.showToast({ + message: 'CASE All End' + }) + done() + }) + + /** + * @tc.number: wukongtest_0010 + * @tc.name: getAbilityLists callback API. + * @tc.desc: getAbilityLists callback API abilityType is spoken, stateType is install. + */ + it('wukongtest_0010', 1, async function (done) { + cmd = "wukong exec -T 0.5 &"; + await abilityDelegator.executeShellCommand("pkill accessibility"); + abilityDelegator.executeShellCommand(cmd, + async (err: any, d: any) => { + console.log('hyr-----------ACTS_AppSelectorTest cmdUninstall executeShellCommand : err : ' + JSON.stringify(err)); + console.log('hyr-----------ACTS_AppSelectorTest cmdUninstall executeShellCommand : stdResult : ' + d.stdResult); + console.log('hyr-----------ACTS_AppSelectorTest cmdUninstall executeShellCommand : exitCode : ' + d.exitCode); + }); + await sleep(10000); + abilityDelegator1.executeShellCommand("ps -ef|grep 'wukong exec -T 0.5'|grep -c -v grep ",async (error: any, date: any) => { + console.log('hyr1-----------ACTS_AppSelectorTest cmdUninstall executeShellCommand : err1 : ' + JSON.stringify(error)); + console.log('hyr1-----------ACTS_AppSelectorTest cmdUninstall executeShellCommand : stdResult1 : ' + date.stdResult); + console.log('hyr1-----------ACTS_AppSelectorTest cmdUninstall executeShellCommand : exitCode1 : ' + date.exitCode); + let i = date.stdResult.indexOf('1'); + if(i == -1){ + expect().assertFail(); + } + done(); + }); + }) + }) +} diff --git a/wukong/actswukongtest/entry/src/main/ets/test/List.test.ets b/wukong/actswukongtest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb35098ac281d443c7add6de76cee00a268ce092 --- /dev/null +++ b/wukong/actswukongtest/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * 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 abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} \ No newline at end of file diff --git a/wukong/actswukongtest/entry/src/main/module.json b/wukong/actswukongtest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..7d42336bf1f3032babde9287a9e91ea77d9ab92b --- /dev/null +++ b/wukong/actswukongtest/entry/src/main/module.json @@ -0,0 +1,53 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "tablet", + "default", + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "com.example.ActsWukongTest.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.SET_ABILITY_CONTROLLER", + "reason": "need use ohos.permission.SET_ABILITY_CONTROLLER" + }, + { + "name": "ohos.permission.CAPTURE_SCREEN", + "reason": "need use ohos.permission.CAPTURE_SCREEN" + }, + { + "name": "ohos.permission.INPUT_MONITORING", + "reason": "need use ohos.permission.INPUT_MONITORING" + } + ] + } +} diff --git a/wukong/actswukongtest/entry/src/main/resources/base/element/string.json b/wukong/actswukongtest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..dfa429e6ed614decc3bee008fa9728cfd7959edd --- /dev/null +++ b/wukong/actswukongtest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "AbilityListTest entry" + }, + { + "name": "MainAbility_desc", + "value": "AbilityListTest MainAbility" + }, + { + "name": "MainAbility_label", + "value": "AbilityList" + } + ] +} \ No newline at end of file diff --git a/wukong/actswukongtest/entry/src/main/resources/base/media/icon.png b/wukong/actswukongtest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/wukong/actswukongtest/entry/src/main/resources/base/media/icon.png differ diff --git a/wukong/actswukongtest/entry/src/main/resources/base/profile/main_pages.json b/wukong/actswukongtest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..c1858c216308ad312862a877139a8ba6908ec3c6 --- /dev/null +++ b/wukong/actswukongtest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "MainAbility/pages/index" + ] +} diff --git a/wukong/actswukongtest/signature/openharmony_sx.p7b b/wukong/actswukongtest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..7ffcdc78527c5c1aa24520ab7e913c5f47c703f0 Binary files /dev/null and b/wukong/actswukongtest/signature/openharmony_sx.p7b differ