提交 09fd7bd7 编写于 作者: Z zhangyushuai

add tests

Signed-off-by: Nzhangyushuai <zhangyushuai1@huawei.com>
上级 f947a505
# 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")
group("inputmethod") {
testonly = true
deps = [
"InputMethodTest_Stage:ActsImeAbilityTest",
"InputMethodTest_ets:ActsInputMethodEtsTest",
]
}
{
"app":{
"bundleName":"com.acts.imeability.test",
"vendor":"huawei",
"versionCode":1000000,
"versionName":"1.0.0",
"debug":false,
"icon":"$media:icon",
"label":"$string:app_name",
"description":"$string:description_application",
"distributedNotificationEnabled":true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":8,
"targetAPIVersion":8,
"car":{
"apiCompatibleVersion":8,
"singleUser":false
}
}
}
{
"string":[
{
"name":"app_name",
"value":"ohosProject"
}
]
}
\ 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsImeAbilityTest") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":IMExtAbility_ets_assets",
":IMExtAbility_resources",
]
ets2abc = true
certificate_profile = "signature/ActInputMethodStageAPITest.p7b"
hap_name = "ActsImeAbilityTest"
subsystem_name = "inputmethod"
part_name = "imf"
}
ohos_app_scope("IMExtAbility_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("IMExtAbility_ets_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("IMExtAbility_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":IMExtAbility_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "com.acts.imeability.test",
"module-name": "phone",
"shell-timeout": "600000",
"testcase-timeout": 10000
},
"kits": [{
"test-file-name": [
"ActsImeAbilityTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}]
}
/*
* 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.app.ability.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage onCreate");
globalThis.stageOnCreateRun = 1;
globalThis.stageContext = this.context;
}
}
/*
* 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 inputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility'
export default class ImExtAbility extends inputMethodExtensionAbility {
onCreate(want) {
console.info("inputMethodExtensionAbility onCreate");
let options = {
windowMode: 0
}
console.info("inputMethodExtensionAbility want.bundleName is: " + want.bundleName);
console.info("inputMethodExtensionAbility want.moduleName is: " + want.moduleName);
console.info("inputMethodExtensionAbility want.abilityName is: " + want.abilityName);
console.info("---------------------------1-----------------------------");
try{
this.context.destroy((err, data)=>{
if(err){
console.info('destroy001 destroy fail: ' + JSON.stringify(err));
}
console.info("destroy001 inputMethodExtensionAbility destroy successfully." + JSON.stringify(data));
})
}catch(error){
console.info('destroy001 destroy catch error: ' + JSON.stringify(error));
}
try{
this.context.destroy().then((data) => {
console.info("destroy002 terminateSelf success:." + JSON.stringify(data));
}).catch((err) => {
console.info('destroy002 terminateSelf fail: ' + JSON.stringify(err));
})
}catch(error){
console.info('destroy002 destroy catch error: ' + JSON.stringify(error));
}
}
onDestroy() {
console.info("onDestroy: inputMethodExtensionAbility destroy.");
}
}
/*
* 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.app.ability.UIAbility'
export default class MainAbility extends Ability {
onCreate(want,launchParam){
// Ability is creating, initialize resources for this ability
console.info("ImExtAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.info("ImExtAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.info("ImExtAbility onWindowStageCreate")
globalThis.abilityContext = this.context
windowStage.setUIContent(this.context, "pages/index/index", null)
console.info("ImExtAbility onWindowStageCreate finish")
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.info("ImExtAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.info("ImExtAbility onForeground")
}
onBackground() {
// Ability has back to background
console.info("ImExtAbility 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 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.acts.imeability.test.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
/*
* 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'
@Entry
@Component
struct Index {
build() {
Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {})
}
.width('100%')
.height('100%')
}
aboutToAppear(){
let abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
}
\ 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 '@system.router';
@Entry
@Component
struct Second {
private content: string = "Second Page"
build() {
Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('back to index')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
router.back()
})
}
.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 imeAbilityTest from './imeAbilityTest.test'
import inputMethodStageJSUnit from './inputMethodStageJSUnit';
export default function testsuite() {
imeAbilityTest(globalThis.abilityContext);
inputMethodStageJSUnit();
}
\ 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "@ohos/hypium"
import inputMethod from '@ohos.inputMethod'
export default function imeAbilityTest(abilityContext) {
describe('imeAbilityTest', function () {
var prop = {
packageName: '',
methodId: '',
name:'',
id:'',
extra:{}
}
/**
* sleep function.
*/
function sleep(date, time){
while(Date.now() - date <= time);
}
/**
* beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.
*/
beforeAll(function () {
let inputM = inputMethod.getCurrentInputMethod()
console.info("====>beforeAll: switchInputMethod to: " + JSON.stringify(inputM));
prop.packageName = inputM.packageName;
prop.methodId = inputM.methodId;
prop.name = inputM.packageName;
prop.id = inputM.methodId;
});
/**
* afterEach: Test case-level clearance conditions, which are executed after each test case is executed.
*/
afterAll(async function () {
console.info('====>afterAll: switchInputMethod to origionInput.' + JSON.stringify(prop));
await inputMethod.switchInputMethod(prop).then((data)=>{
console.info('====>afterAll switchInputMethod to origionInput :' + data);
expect(data == true).assertTrue();
}).catch(err =>{
console.info('====>afterAll switchInputMethod to origionInput error: ' + err);
})
});
/**
* @tc.number SUB_InputMethod_IMEAbility_0001
* @tc.desc Start a inputMethodExtension ability session.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_InputMethod_IMEAbility_0001', 0, async function (done) {
console.info('====>----------SUB_InputMethod_IMEAbility_0001 start-------------');
let imExtAbilityProperty = {
packageName : "com.acts.imeability.test",
methodId : "com.acts.imeability.test.ImExtAbility",
name:"com.acts.imeability.test",
id:"com.acts.imeability.test.ImExtAbility",
extra:{}
}
inputMethod.switchInputMethod(imExtAbilityProperty).then((data)=>{
console.info('====>SUB_InputMethod_IMEAbility_0004 switchInputMethod to IME :' + data);
expect(data == true).assertTrue();
});
sleep(Date.now(), 3000);
console.info('====>----------SUB_InputMethod_IMEAbility_0001 end-------------');
done();
})
/**
* @tc.number SUB_InputMethod_IMEAbility_0002
* @tc.desc Start a inputMethodExtension ability session
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 1
*/
it('SUB_InputMethod_IMEAbility_0002', 0, async function (done) {
console.info('====>-----------SUB_InputMethod_IMEAbility_0002 start-------------');
let imExtAbilityProperty = {
packageName : "com.acts.imeability.test",
methodId : "com.acts.imeability.test.ImExtAbility",
name:"com.acts.imeability.test",
id:"com.acts.imeability.test.ImExtAbility",
extra:{}
}
inputMethod.switchInputMethod(imExtAbilityProperty).then((data)=>{
console.info('====>SUB_InputMethod_IMEAbility_0002 switchInputMethod to IME :' + data);
expect(data == true).assertTrue();
});
sleep(Date.now(), 2500);
console.info('====>-----------SUB_InputMethod_IMEAbility_0002 end-------------');
done();
})
})
}
{
"module": {
"name": "phone",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:phone_entry_dsc",
"mainElement": "MainAbility",
"deviceTypes": [
"tablet",
"default",
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"uiSyntax": "ets",
"pages": "$profile:main_pages",
"metadata": [
{
"name": "ArkTSPartialUpdate",
"value": "false"
}
],
"abilities": [
{
"name": "com.acts.imeability.test.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:phone_entry_main",
"icon": "$media:icon",
"label": "$string:entry_label",
"visible": true,
"orientation": "portrait",
"launchType": "singleton",
"skills": [
{
"actions": [
"action.system.home"
],
"entities":[
"entity.system.home"
]
}
]
}
],
"extensionAbilities": [
{
"name": "com.acts.imeability.test.ImExtAbility",
"srcEntrance": "./ets/ImExtAbility/ImExtAbility.ets",
"label": "$string:ime_label",
"description": "$string:ime_description",
"type": "inputMethod"
}
],
"requestPermissions": [
{
"name":"ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
"reason":"need use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.CONNECT_IME_ABILITY"
}
]
}
}
{
"string": [
{
"name": "phone_entry_dsc",
"value": "i am an entry for phone"
},
{
"name": "phone_entry_main",
"value": "the phone entry ability"
},
{
"name": "entry_label",
"value": "ActsImeAbilityTest"
},
{
"name": "ime_description",
"value": "input method extension ability."
},
{
"name": "ime_label",
"value": "inputMethod extension ability services."
},
{
"name": "ime_label_1",
"value": "inputMethod extension ability services_1."
},
{
"name": "description_application",
"value": "demo for test"
},
{
"name": "app_name",
"value": "Demo"
}
]
}
{
"src": [
"pages/index/index",
"pages/second/second"
]
}
\ 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsInputMethodEtsTest") {
hap_profile = "./entry/src/main/config.json"
deps = [
":inputMethod_ets_assets",
":inputMethod_ets_resources",
":inputMethod_ets_test_assets",
]
ets2abc = true
subsystem_name = "inputmethod"
part_name = "imf"
certificate_profile = "./signature/ActInputMethodEtsAPITest.p7b"
hap_name = "ActsInputMethodEtsTest"
}
ohos_js_assets("inputMethod_ets_assets") {
source_dir = "./entry/src/main/ets/MainAbility"
}
ohos_js_assets("inputMethod_ets_test_assets") {
source_dir = "./entry/src/main/ets/TestAbility"
}
ohos_resources("inputMethod_ets_resources") {
sources = [ "./entry/src/main/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for inputMethod Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"bundle-name": "com.acts.inputmethodtest",
"package-name": "com.acts.inputmethodtest",
"shell-timeout": "600000"
},
"kits": [
{
"test-file-name": [
"ActsInputMethodEtsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "com.acts.inputmethodtest",
"vendor": "open",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 7,
"releaseType": "Release",
"target": 9
}
},
"deviceConfig": {},
"module": {
"package": "com.acts.inputmethodtest",
"name": ".MyApplication",
"mainAbility": "com.acts.inputmethodtest.MainAbility",
"deviceType": [
"tablet",
"default",
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "MainAbility",
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:description_mainability",
"formsEnabled": false,
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
},
{
"orientation": "unspecified",
"visible": true,
"srcPath": "TestAbility",
"name": ".TestAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"formsEnabled": false,
"label": "$string:TestAbility_label",
"type": "page",
"launchType": "standard"
}
],
"reqPermissions": [
{
"name": "ohos.permission.CONNECT_IME_ABILITY"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index",
"pages/input"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
/**
* 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'
export default {
onCreate() {
console.info('Application onCreate')
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info('Application onDestroy')
},
}
\ No newline at end of file
// @ts-nocheck
/**
* 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 MyComponent {
aboutToAppear() {
}
build() {
Flex({
direction: FlexDirection.Column,
alignItems: ItemAlign.Center,
justifyContent: FlexAlign.Center
}) {
Text('ACE ETS TEST')
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
.height('100%')
}
}
// @ts-nocheck
/**
* 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 TextInputTest {
@State text: string = '';
build() {
Column() {
TextInput({ placeholder: 'input your word' })
.type(InputType.Normal)
.key('TextInput')
.placeholderColor(Color.Blue)
.placeholderFont({ size: 40, weight: FontWeight.Normal, family: "sans-serif", style: FontStyle.Normal })
.enterKeyType(EnterKeyType.Search)
.caretColor(Color.Green)
.height(60)
.fontSize(30)
.fontWeight(FontWeight.Bold)
.fontFamily("cursive")
.fontStyle(FontStyle.Italic)
.fontColor(Color.Red)
.maxLength(20)
.onChange((value: string) => {
this.text = value
})
Text(this.text)
}
}
}
/*
* 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'
export default {
onCreate() {
console.info('Application onCreate')
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info('Application onDestroy')
},
}
\ 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 '@system.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 itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
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')
}
onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.MainAbility'
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -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 call abilityDelegator.getAppContext')
var context = abilityDelegator.getAppContext()
console.info('getAppContext : ' + JSON.stringify(context))
console.info('OpenHarmonyTestRunner onRun end')
}
};
\ 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 inputMethodJSUnit from './inputMethodJSUnit';
import inputMethodEngineJSUnit from './inputMethodEngineJSUnit';
export default function testsuite() {
inputMethodJSUnit();
inputMethodEngineJSUnit();
}
\ No newline at end of file
// @ts-nocheck
/**
* 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.
*/
export default class Utils {
static rect_left;
static rect_top;
static rect_right;
static rect_bottom;
static rect_value;
static sleep(time) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, time)
}).then(() => {
console.info(`sleep ${time} over...`)
})
}
static getComponentRect(key) {
let strJson = getInspectorByKey(key);
let obj = JSON.parse(strJson);
console.info("====>[getInspectorByKey] current component obj is: " + JSON.stringify(obj));
let rectInfo = JSON.parse('[' + obj.$rect + ']')
console.info("====>[getInspectorByKey] rectInfo is: " + rectInfo);
this.rect_left = JSON.parse('[' + rectInfo[0] + ']')[0]
this.rect_top = JSON.parse('[' + rectInfo[0] + ']')[1]
this.rect_right = JSON.parse('[' + rectInfo[1] + ']')[0]
this.rect_bottom = JSON.parse('[' + rectInfo[1] + ']')[1]
return this.rect_value = {
"left": this.rect_left, "top": this.rect_top, "right": this.rect_right, "bottom": this.rect_bottom
}
}
static async swipe(downX, downY, upX, upY, steps) {
console.info('====>start to swipe')
this.drags(downX, downY, upX, upY, steps, false)
}
static async drag(downX, downY, upX, upY, steps) {
console.info('====>start to drag')
this.drags(downX, downY, upX, upY, steps, true)
}
static async drags(downX, downY, upX, upY, steps, drag) {
let xStep;
let yStep;
let swipeSteps;
let ret;
xStep = 0;
yStep = 0;
ret = false;
swipeSteps = steps;
if (swipeSteps == 0) {
swipeSteps = 1;
}
xStep = (upX - downX) / swipeSteps;
yStep = (upY - downY) / swipeSteps;
console.info('====>move step is: ' + 'xStep: ' + xStep + ' yStep: ' + yStep)
let downPonit: TouchObject = {
id: 1,
x: downX,
y: downY,
type: TouchType.Down,
}
console.info('====>down touch started: ' + JSON.stringify(downPonit))
sendTouchEvent(downPonit);
console.info('====>start to move')
if (drag) {
await this.sleep(500)
}
for (let i = 1;i <= swipeSteps; i++) {
let movePoint: TouchObject = {
id: 1,
x: downX + (xStep * i),
y: downY + (yStep * i),
type: TouchType.Move
}
console.info('====>move touch started: ' + JSON.stringify(movePoint))
ret = sendTouchEvent(movePoint)
if (ret == false) {
break;
}
await this.sleep(5)
}
console.info('====>start to up')
if (drag) {
await this.sleep(100)
}
let upPoint: TouchObject = {
id: 1,
x: upX,
y: upY,
type: TouchType.Up,
}
console.info('====>up touch started: ' + JSON.stringify(upPoint))
sendTouchEvent(upPoint)
await this.sleep(500)
}
}
/**
* 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 inputMethod from '@ohos.inputMethod';
export default function inputMethodJSUnit() {
describe('appInfoTest_input_2', function () {
console.info("====>************* settings Test start*************");
it('inputmethoh_test_001', 0, async function (done) {
let inputMethodSetting = inputMethod.getInputMethodSetting();
console.info("====>inputmethoh_test_001 result:" + JSON.stringify(inputMethodSetting));
inputMethodSetting.listInputMethod((arr) => {
console.info("====>appInfoTest_input_2 listInputMethod result---" + JSON.stringify(arr));
expect(1 == 1).assertTrue();
done();
});
});
it('inputmethoh_test_002', 0, async function (done) {
let inputMethodSetting = inputMethod.getInputMethodSetting();
console.info("====>inputmethoh_test_002 result:" + JSON.stringify(inputMethodSetting));
inputMethodSetting.listInputMethod().then(inputMethodProperty => {
if (inputMethodProperty.length > 0) {
let obj = inputMethodProperty[0]
console.info("====>inputmethoh_test_002 listInputMethod obj---" + JSON.stringify(obj));
expect(obj.packageName != null).assertTrue();
expect(obj.methodId != null).assertTrue();
} else {
console.info("====>inputmethoh_test_002 listInputMethod is null");
expect().assertFail()
}
done();
}).catch(err => {
console.info("====>inputmethoh_test_002 listInputMethod is err: " + JSON.stringify(err));
done();
});
});
it('inputmethoh_test_003', 0, async function (done) {
let inputMethodSetting = inputMethod.getInputMethodSetting();
console.info("====>inputmethoh_test_003 result:" + JSON.stringify(inputMethodSetting));
setTimeout(() => {
inputMethodSetting.displayOptionalInputMethod((err) => {
try {
if (err) {
console.info("====>inputmethoh_test_003 displayOptionalInputMethod err:" + JSON.stringify(err));
expect().assertFail();
done();
}
expect(true).assertTrue();
console.info("====>inputmethoh_test_003 displayOptionalInputMethod---");
done();
} catch (err) {
console.info("====>inputmethoh_test_004 displayOptionalInputMethod throw_err: " + JSON.stringify(err));
done();
}
});
}, 500)
});
it('inputmethoh_test_004', 0, async function (done) {
let inputMethodSetting = inputMethod.getInputMethodSetting();
console.info("====>inputmethoh_test_004 result:" + JSON.stringify(inputMethodSetting));
setTimeout(() => {
inputMethodSetting.displayOptionalInputMethod().then(() => {
console.info("====>inputmethoh_test_004 displayOptionalInputMethod is called");
expect(true).assertTrue()
done();
}).catch(err => {
console.info("====>inputmethoh_test_004 displayOptionalInputMethod is err: " + JSON.stringify(err));
expect().assertFail()
done();
});
}, 500)
});
it('inputmethoh_test_005', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController();
console.info("====>inputmethoh_test_005 result:" + JSON.stringify(inputMethodCtrl));
inputMethodCtrl.stopInput((res) => {
console.info("====>inputmethoh_test_005 stopInput result----" + res);
done();
});
});
it('inputmethoh_test_006', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController();
console.info("====>inputmethoh_test_006 result:" + JSON.stringify(inputMethodCtrl));
inputMethodCtrl.stopInput().then(() => {
expect().assertFail();
done();
}).catch((err) => {
console.info("====>inputmethoh_test_006 stopInput is err: " + JSON.stringify(err));
expect().assertEqual();
done();
});
});
/*
* @tc.number: inputmethod_test_MAX_TYPE_NUM_001
* @tc.name: inputMethod::MAX_TYPE_NUM
* @tc.desc: Verify Max_ TYPE_ NUM
*/
it('inputmethod_test_MAX_TYPE_NUM_001', 0, async function (done) {
console.info("====>************* inputmethod_test_MAX_TYPE_NUM_001 Test start*************");
let inputMethodSetting = inputMethod.MAX_TYPE_NUM;
console.info("====>inputmethod_test_001 result:" + inputMethodSetting);
expect(inputMethodSetting !== null).assertTrue();
console.info("====>************* inputmethod_test_MAX_TYPE_NUM_001 Test end*************");
done();
});
/*
* @tc.number inputmethod_test_switchInputMethod_001
* @tc.name Test Indicates the input method which will replace the current one.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_switchInputMethod_001', 0, async function (done) {
console.info("====>************* inputmethod_test_switchInputMethod_001 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputmethod_test_switchInputMethod_001 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName: inputM.packageName,
methodId: inputM.methodId,
name: inputM.packageName,
id: inputM.methodId,
extra: {}
}
inputMethod.switchInputMethod(inputMethodProperty).then(data => {
console.info("====>inputmethod_test_switchInputMethod_001 data:" + data)
expect(data == true).assertTrue();
console.info("====>************* inputmethod_test_switchInputMethod_001 Test end*************");
done();
}).catch(err => {
console.info("====>inputmethod_test_switchInputMethod_001 err:" + err)
expect().assertFail();
done();
});
});
/*
* @tc.number inputmethod_test_switchInputMethod_002
* @tc.name Test Indicates the input method which will replace the current one.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_switchInputMethod_002', 0, async function (done) {
console.info("====>************* inputmethod_test_switchInputMethod_002 Test start*************");
let inputM = inputMethod.getCurrentInputMethod()
console.info("inputmethod_test_switchInputMethod_002 getCurrentInputMethod: " + JSON.stringify(inputM));
let inputMethodProperty = {
packageName: inputM.packageName,
methodId: inputM.methodId,
name: inputM.packageName,
id: inputM.methodId,
extra: {}
}
inputMethod.switchInputMethod(inputMethodProperty, (err, data) => {
try {
if (err) {
console.info("====>inputmethod_test_switchInputMethod_002 error:" + err);
expect().assertFail();
done();
}
console.info("====>inputmethod_test_switchInputMethod_002 data:" + data)
console.info("====>************* inputmethod_test_switchInputMethod_002 Test end*************");
expect(data == true).assertTrue();
done();
} catch (err) {
console.info("====>inputmethod_test_switchInputMethod_002 catch error:" + err);
done();
}
});
});
/*
* @tc.number inputmethod_test_showSoftKeyboard_001
* @tc.name Test Indicates the input method which will show softboard with calback.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_showSoftKeyboard_001', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.showSoftKeyboard((err) => {
try {
expect(err.code).assertEqual(12800003)
console.info("====>************* inputmethod_test_showSoftKeyboard_001 Test end*************");
done();
} catch (err) {
expect().assertFail()
done();
}
});
});
/*
* @tc.number inputmethod_test_showSoftKeyboard_002
* @tc.name Test Indicates the input method which will show softboard with Promise.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_showSoftKeyboard_002', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.showSoftKeyboard().then(() => {
expect().assertFail()
done();
}).catch((err) => {
console.info('====>showSoftKeyboard promise failed : ' + JSON.stringify(err))
console.info('====>showSoftKeyboard typeof(err.code): ' + typeof(err.code))
console.info('====>showSoftKeyboard typeof(err.code): ' + err.code)
expect(err.code).assertEqual(12800003)
console.info("====>************* inputmethod_test_showSoftKeyboard_002 Test end*************");
done();
})
});
/*
* @tc.number inputmethod_test_hideSoftKeyboard_001
* @tc.name Test Indicates the input method which will hide softboard with calback.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_hideSoftKeyboard_001', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.hideSoftKeyboard((err) => {
try {
console.info('====>hideSoftKeyboard callbacek failed : ' + JSON.stringify(err))
expect(err.code).assertEqual(12800003)
console.info("====>************* inputmethod_test_hideSoftKeyboard_001 Test end*************");
done();
} catch (err) {
expect().assertFail();
done();
}
})
});
/*
* @tc.number inputmethod_test_hideSoftKeyboard_002
* @tc.name Test Indicates the input method which will hide softboard with Promise.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_hideSoftKeyboard_002', 0, async function (done) {
let inputMethodCtrl = inputMethod.getInputMethodController()
inputMethodCtrl.hideSoftKeyboard().then(() => {
expect().assertFail();
done();
}).catch((err) => {
console.info('====>hideSoftKeyboard promise failed : ' + JSON.stringify(err))
expect(err.code).assertEqual(12800003);
console.info("====>************* inputmethod_test_hideSoftKeyboard_002 Test end*************");
done();
})
});
/*
* @tc.number inputmethod_test_getCurrentInputMethod_001
* @tc.name return The InputMethodProperty object of the current input method.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_getCurrentInputMethod_001', 0, async function (done) {
let currentIme = inputMethod.getCurrentInputMethod();
console.info("====>inputmethod_test_getCurrentInputMethod_001 currentIme---" + JSON.stringify(currentIme));
console.info(currentIme.packageName);
console.info(currentIme.methodId);
expect(currentIme.packageName !== null).assertTrue();
expect(currentIme.methodId !== null).assertTrue();
console.info("====>************* inputmethod_test_getCurrentInputMethod_001 Test end*************");
done();
});
/*
* @tc.number inputmethod_test_getInputMethods_001
* @tc.name param enable :
* if true, collect enabled input methods.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_getInputMethods_001', 0, async function (done) {
let inputMethodSetting = inputMethod.getInputMethodSetting();
console.info("====>inputmethod_test_getInputMethods_001 result:" + JSON.stringify(inputMethodSetting));
inputMethodSetting.getInputMethods(true, (err, arr) => {
try {
if (err) {
console.error("inputmethod_test_getInputMethods_001 failed because: " + JSON.stringify(err));
expect().assertFail();
done();
}
;
console.info("====>inputmethod_test_getInputMethods_001 listInputMethod result---" + JSON.stringify(arr));
expect(arr != null).assertTrue();
console.info("====>************* inputmethod_test_getInputMethods_001 Test end*************");
done();
} catch (err) {
console.error("inputmethod_test_getInputMethods_001 catch error: " + err);
done();
}
});
});
/*
* @tc.number inputmethod_test_getInputMethods_002
* @tc.name param enable :
* if false, collect disabled input methods.
* @tc.desc Function test
* @tc.level 2
*/
it('inputmethod_test_getInputMethods_002', 0, async function (done) {
let inputMethodSetting = inputMethod.getInputMethodSetting();
console.info("====>inputmethod_test_getInputMethods_002 result:" + JSON.stringify(inputMethodSetting));
inputMethodSetting.getInputMethods(false, (err, arr) => {
try {
if (err) {
console.error("inputmethod_test_getInputMethods_002 failed because: " + JSON.stringify(err));
expect().assertFail();
}
;
console.info("====>inputmethod_test_getInputMethods_002 listInputMethod result---" + JSON.stringify(arr));
expect(arr != null).assertTrue();
done();
} catch (err) {
console.error("inputmethod_test_getInputMethods_002 catch error: " + err);
done();
}
});
});
});
};
{
"string": [
{
"name": "entry_MainAbility",
"value": "entry_MainAbility"
},
{
"name": "description_mainability",
"value": "ETS_Empty Ability"
},
{
"name":"string_hello",
"value":"Hello"
},
{
"name":"string_world",
"value":"World"
},
{
"name":"message_arrive",
"value":"We will arrive at %s."
},
{
"name": "TestAbility_desc",
"value": "description"
},
{
"name": "TestAbility_label",
"value": "label"
}
]
}
\ 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("//build/ohos_var.gni")
group("request") {
testonly = true
deps = [
"RequestTest_Stage:ActsRequestStageTest",
"RequestTest_ets:ActsRequestETSApiTest",
]
}
{
"app": {
"bundleName": "com.acts.request.test",
"vendor": "huawei",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":9,
"targetAPIVersion":9
}
}
{
"string": [
{
"name": "app_name",
"value": "ActsTimeAPITest"
}
]
}
# 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("ActsRequestStageTest") {
deps = [
":requestStage_ets_assets",
":requestStage_resources",
]
ets2abc = true
js_build_mode = "debug"
part_name = "request"
subsystem_name = "request"
hap_name = "ActsRequestStageTest"
hap_profile = "entry/src/main/module.json"
certificate_profile = "signature/actsRequestStageTest.p7b"
}
ohos_app_scope("requestStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("requestStage_ets_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("requestStage_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":requestStage_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "com.acts.request.test",
"module-name": "entry_test",
"shell-timeout": "180000",
"testcase-timeout": 600000
},
"kits": [{
"test-file-name": [
"ActsRequestStageTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}]
}
import hilog from '@ohos.hilog';
import AbilityStage from "@ohos.app.ability.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'AbilityStage onCreate');
}
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import Window from '@ohos.window';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import Ability from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
var abilityDelegator: any;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var abilityDelegatorArguments: any;
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
if (abilityDelegator != undefined && abilityDelegatorArguments != undefined) {
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
} else {
hilog.info(0x0000, 'testTag', '%{public}s', 'abilityDelegator or abilityDelegatorArguments is undefined!!!');
}
}
onDestroy() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: Window.WindowStage) {
// Main window is created, set main page for this ability
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
globalThis.abilityContext = this.context;
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
}
import hilog from '@ohos.hilog';
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() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', '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 MainAbility ' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand("echo \"123456\" > /data/app/el2/100/base/com.acts.requesttest.test/haps/entry_test/cache/test.txt",
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ 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 hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
}
@State message: string = 'REQUEST TEST'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.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 requestUploadJSUnit from './requestUpload.test';
import requestDownloadJSUnit from './requestDownload.test';
export default function testsuite() {
requestDownloadJSUnit()
requestUploadJSUnit()
}
\ 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 request from "@ohos.request";
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function requestUploadJSUnit() {
describe('requestUploadJSUnit', function () {
console.info('====>################################request upload Test start');
/**
* beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.
*/
beforeAll(function () {
console.info('====>beforeAll: Prerequisites are executed.');
});
/**
* beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.
*/
beforeEach(function () {
console.info('====>beforeEach: Prerequisites is executed.');
});
/**
* afterEach: Test case-level clearance conditions, which are executed after each test case is executed.
*/
afterEach(function () {
console.info('====>afterEach: Test case-level clearance conditions is executed.');
});
/**
* afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed.
*/
afterAll(function () {
console.info('====>afterAll: Test suite-level cleanup condition is executed');
});
/**
* sleep function.
*/
function sleep(date, time){
while(Date.now() - date <= time);
}
let uploadTask;
let RequestData = {
name: 'name',
value: '123'
}
let File = {
filename: 'test',
name: 'test',
uri: 'internal://cache/test.txt',
type: 'txt'
}
let uploadConfig = {
url: 'http://127.0.0.1',
header: {
headers: 'http'
},
method: 'POST',
files: [File],
data: [RequestData]
};
/**
* @tc.number SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001
* @tc.desc Starts a upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 is starting-----------------------");
try {
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data)=>{
uploadTask = data;
console.info("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 uploadFile: " + uploadTask);
try{
expect(true).assertEqual(uploadTask != undefined);
}catch(e){
console.info("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 except error: " + e);
}
});
} catch (err) {
console.error("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 error: " + err);
};
setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 end-----------------------");
done();
}, 10000);
});
/**
* @tc.number SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001
* @tc.desc Starts a upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001', 0, async function (done) {
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 is starting-----------------------");
try{
request.uploadFile(globalThis.abilityContext, uploadConfig).then(data => {
uploadTask = data;
console.info("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 uploadFile: " + uploadTask);
try{
expect(true).assertEqual(uploadTask != undefined);
}catch(e){
console.info("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 except error: " + e);
}
}).catch(err => {
console.error("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 error: " + err);
expect().assertFail();
})
}catch(err){
console.error("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 catch error: " + err);
}
setTimeout(()=>{
console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 end-----------------------");
done();
}, 10000);
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_DELETE_0001
* @tc.desc Delete the upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_UPLOAD_API_DELETE_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => {
try{
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask);
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete((err, data) => {
try{
if (err) {
console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 Failed to delete the uploadTask task.');
expect().assertFail();
done();
}
console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask task delete success.');
expect(typeof data == "boolean").assertTrue();
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 end-----------------------");
done();
}catch(err){
console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 delete error' + err);
done();
}
});
} catch (error) {
console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 delete catch error' + error);
done();
}
})
});
/**
* @tc.number SUB_REQUEST_UPLOAD_API_DELETE_0002
* @tc.desc Delete the upload task.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_REQUEST_UPLOAD_API_DELETE_0002', 0, async function (done) {
console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0002 is starting-----------------------");
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => {
uploadTask = data;
console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask);
try{
expect(uploadTask != undefined).assertEqual(true);
uploadTask.delete().then(data => {
console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0002 delete data:' + JSON.stringify(data));
expect(data).assertEqual(true);
done();
}).catch((err) => {
console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0002 Failed to delete the uploadTask task.');
expect().assertFail();
done();
})
}catch(err){
console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0002 delete catch err');
done();
}
})
});
})
}
{
"module": {
"name": "entry_test",
"type": "entry",
"srcEntrance": "./ets/Application/MyAbilityStage.ts",
"description": "$string:entry_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"tablet",
"default",
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"metadata": [
{
"name": "ArkTSPartialUpdate",
"value": "false"
}
],
"abilities": [
{
"name": "MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:MainAbility_desc",
"icon": "$media:icon",
"label": "$string:MainAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:white",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name":"ohos.permission.INTERNET",
"reason":"need use ohos.permission.INTERNET."
},
{"name": "ohos.permission.WRITE_MEDIA",
"reason": "need use ohos.permission.WRITE_MEDIA",
"usedScene": {
"ability": [
"com.acts.request.test.MainAbility"
],
"when":"always"
}
},
{"name": "ohos.permission.READ_MEDIA",
"reason": "need use ohos.permission.WRITE_MEDIA",
"usedScene": {
"ability": [
"com.acts.request.test.MainAbility"
],
"when":"always"
}
}
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "entry_desc",
"value": "description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "ActsTimeAPITest"
}
]
}
\ 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("//build/ohos.gni")
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsRequestETSApiTest") {
hap_profile = "./entry/src/main/config.json"
deps = [
":request_ets_assets",
":request_ets_resources",
":request_ets_test_assets",
]
ets2abc = true
subsystem_name = "request"
part_name = "request"
certificate_profile = "./signature/ActsRequestETSApiTest.p7b"
hap_name = "ActsRequestETSApiTest"
}
ohos_js_assets("request_ets_assets") {
source_dir = "./entry/src/main/ets/MainAbility"
}
ohos_js_assets("request_ets_test_assets") {
source_dir = "./entry/src/main/ets/TestAbility"
}
ohos_resources("request_ets_resources") {
sources = [ "./entry/src/main/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for MiscservicesRequestJSApiTest js api Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"bundle-name": "com.acts.requesttest",
"package-name": "com.acts.requesttest",
"shell-timeout": "600000"
},
"kits": [
{
"test-file-name": ["ActsRequestETSApiTest.hap"],
"type": "AppInstallKit",
"cleanup-apps": true
},
{
"type": "ShellKit",
"run-command": [
]
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "com.acts.requesttest",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 7,
"target": 9,
"releaseType": "Release"
}
},
"deviceConfig": {},
"module": {
"package": "com.acts.requesttest",
"name": ".MyApplication",
"mainAbility": "com.acts.requesttest.MainAbility",
"deviceType": [
"tablet",
"default",
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": true
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "MainAbility",
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:description_mainability",
"formsEnabled": false,
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
},
{
"orientation": "unspecified",
"visible": true,
"srcPath": "TestAbility",
"name": ".TestAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"formsEnabled": false,
"label": "$string:TestAbility_label",
"type": "page",
"launchType": "standard"
}
],
"reqPermissions": [
{
"name": "ohos.permission.INTERNET",
"reason": "need use ohos.permission.INTERNET",
"usedScene": {
"ability": [
"com.acts.request.test.MainAbility"
],
"when": "inuse"
}
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
// @ts-nocheck
/**
* 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 'hypium/index'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('Application onCreate')
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info('Application onDestroy')
},
}
\ No newline at end of file
// @ts-nocheck
/**
* 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 MyComponent {
aboutToAppear() {
}
build() {
Flex({
direction: FlexDirection.Column,
alignItems: ItemAlign.Center,
justifyContent: FlexAlign.Center
}) {
Text('REQUEST TEST')
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
.height('100%')
}
}
// @ts-nocheck
/**
* 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'
export default {
onCreate() {
console.info('Application onCreate')
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info('Application onDestroy')
},
}
\ No newline at end of file
// @ts-nocheck
/**
* 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 '@system.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
// @ts-nocheck
/**
* 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 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 itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
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')
}
onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.MainAbility'
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
abilityDelegator.executeShellCommand("echo 123456 > /data/app/el2/100/base/com.acts.requesttest/haps/entry/cache/test.txt",
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -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 call abilityDelegator.getAppContext')
var context = abilityDelegator.getAppContext()
console.info('getAppContext : ' + JSON.stringify(context))
console.info('OpenHarmonyTestRunner onRun end')
}
};
\ 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 requestUploadJSUnit from './requestUpload.test';
import requestDownloadJSUnit from './requestDownload.test';
import requestSystemJSUnit from './requestSystem.test';
export default function testsuite() {
requestUploadJSUnit()
requestDownloadJSUnit()
requestSystemJSUnit()
}
\ 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 request from '@system.request';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index";
export default function requestSystemJSUnit() {
describe('requestSystemJSUnit', function () {
console.info('====>****************start requestSystemTest*****************')
/**
* @tc.name: ohos.SUB_REQUESTSYSTEM_UPLOAD_API_0001
* @tc.desc: Upload files.
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 1
*/
it('SUB_REQUESTSYSTEM_UPLOAD_API_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUESTSYSTEM_UPLOAD_API_0001 start-----------------------");
let UploadResponse = {
code: 200,
data: '',
headers: {RequestMethod: 'POST',
StatusCode: 200 }
}
let UploadRequestOptions = {
url: 'http://www.path.com',
method: 'POST',
files: [
{
uri: 'internal://cache/path/to/file.txt',
name: 'file',
filename: 'file.txt',
},
],
data:[
{
name: 'name1',
value: 'value',
},
],
success: function(UploadResponse) {
console.info('====>SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload success, code:' + UploadResponse.code);
},
fail: function(data, code) {
console.info('====>SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload fail');
},
complete: function (){
console.info('====>SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload complete');
}
}
try{
let result = request.upload(UploadRequestOptions);
console.info('====>SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload err:' + result);
expect(true).assertEqual(true);
}catch(err){
console.info('====>SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload err:' + err);
}
console.info("====>-----------------------SUB_REQUESTSYSTEM_UPLOAD_API_0001 end-----------------------");
done();
});
/**
* @tc.name: ohos.SUB_REQUESTSYSTEM_DOWNLOAD_API_0001
* @tc.desc: This API is used to download files.
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 1
*/
it('SUB_REQUESTSYSTEM_DOWNLOAD_API_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 start-----------------------");
let DownloadResponse = {
token: "Hm_lpvt_1d6c34c1bc067f5746a5fca18d1c24ab"
}
let DownloadRequestOptions = {
url: 'http://www.path.com',
filename: 'requestSystenTest',
header: '',
description: 'this is requeSystem download response',
success: function(DownloadResponse) {
console.info('====>SUB_REQUESTSYSTEM_DOWNLOAD_API_0001call success callback success: ' + DownloadResponse.token);
},
fail: function(data, code) {
console.info('====>SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 handling fail');
},
complete: function (){
console.info('====>SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 download complete');
}
}
try{
let result = request.download(DownloadRequestOptions);
console.info('====>SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 upload err:' + result);
expect(result == null).assertEqual(true);
}catch(err){
console.info('====>SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 download complete' + err);
}
console.info("====>-----------------------SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 end-----------------------");
done();
});
/**
* @tc.name: ohos.SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001
* @tc.desc: Listens to download task status.
* @tc.size: MediumTest
* @tc.type: Function
* @tc.level: Level 1
*/
it('SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001', 0, async function (done) {
console.info("====>-----------------------SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 start-----------------------");
let OnDownloadCompleteResponse = {
uri: "http://www.path.com"
}
let OnDownloadCompleteOptions = {
token: 'token-index',
success: function(OnDownloadCompleteResponse) {
console.info('====>SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 download success,uri:'
+ OnDownloadCompleteResponse.uri);
},
fail: function(data, code) {
console.info('====>SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 download fail');
},
complete: function (){
console.info('====>SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 download complete');
}
}
let result = request.onDownloadComplete(OnDownloadCompleteOptions);
console.info('====>SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 upload err:' + result);
expect(result == null).assertEqual(true);
console.info("====>-----------------------SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 end-----------------------");
done();
});
})
}
{
"string": [
{
"name": "entry_MainAbility",
"value": "entry_MainAbility"
},
{
"name": "description_mainability",
"value": "ETS_Empty Ability"
},
{
"name": "TestAbility_desc",
"value": "description"
},
{
"name": "TestAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
# 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")
group("theme") {
testonly = true
deps = [
"screenlock_ets:ActsScreenLockETSApiTest",
"wallpaper_ets:ActsWallpaperETSApiTest",
]
}
# 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("//build/ohos.gni")
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsScreenLockETSApiTest") {
hap_profile = "./entry/src/main/config.json"
deps = [
":screenLock_ets_assets",
":screenLock_ets_resources",
":screenLock_ets_test_assets",
]
ets2abc = true
subsystem_name = "theme"
part_name = "screenlock_mgr"
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsScreenLockETSApiTest"
}
ohos_js_assets("screenLock_ets_assets") {
source_dir = "./entry/src/main/ets/MainAbility"
}
ohos_js_assets("screenLock_ets_resources") {
source_dir = "./entry/src/main/ets/TestAbility"
}
ohos_resources("screenLock_ets_test_assets") {
sources = [ "./entry/src/main/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for screenlock js api Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "600000",
"bundle-name": "com.acts.theme.screenlocktest",
"package-name": "com.acts.theme.screenlocktest",
"shell-timeout": "600000"
},
"kits": [
{
"test-file-name": [
"ActsScreenLockETSApiTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"bundleName": "com.acts.theme.screenlocktest",
"vendor": "open",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 7,
"releaseType": "Release",
"target": 9
}
},
"deviceConfig": {},
"module": {
"package": "com.acts.theme.screenlocktest",
"name": ".MyApplication",
"mainAbility": "com.acts.theme.screenlocktest.MainAbility",
"deviceType": [
"tablet",
"default",
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "MainAbility",
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:description_mainability",
"formsEnabled": false,
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
},
{
"orientation": "unspecified",
"visible": true,
"srcPath": "TestAbility",
"name": ".TestAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"formsEnabled": false,
"label": "$string:TestAbility_label",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册