!1301 International、QRCode、MultiMedia添加自动化测试用例

Merge pull request !1301 from zhongyuyan/master
This commit is contained in:
openharmony_ci 2022-08-30 09:51:58 +00:00 committed by Gitee
commit b632ad9dcc
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
44 changed files with 1209 additions and 12 deletions

View File

@ -4,7 +4,7 @@
},
"targets": [
{
"name": "default",
"name": "default"
},
{
"name": "ohosTest",

View File

@ -71,6 +71,7 @@ struct CreateQRCode {
.aspectRatio(1)
.margin(40)
TextInput({ placeholder: $r('app.string.input_placeholder'), text: this.codeStr })
.key('createQRCodeInput')
.width('90%')
.height(60)
.placeholderColor(Color.Gray)
@ -86,6 +87,7 @@ struct CreateQRCode {
.fontSize(30)
.fontColor(Color.White)
}
.key('save')
.width('90%')
.height(70)
.backgroundColor('#0D9FFB')

View File

@ -0,0 +1,22 @@
/*
* 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 TestAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] TestAbilityStage onCreate")
}
}

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Ability from '@ohos.application.Ability'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default class TestAbility extends Ability {
onCreate(want, launchParam) {
console.log('TestAbility onCreate')
}
onDestroy() {
console.log('TestAbility onDestroy')
}
onWindowStageCreate(windowStage) {
console.log('TestAbility onWindowStageCreate')
windowStage.loadContent("TestAbility/pages/index", (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err))
return
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
})
globalThis.abilityContext = this.context
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onWindowStageDestroy() {
console.log('TestAbility onWindowStageDestroy')
}
onForeground() {
console.log('TestAbility onForeground')
}
onBackground() {
console.log('TestAbility onBackground')
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@ohos.router'
@Entry
@Component
struct Index {
aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(() => {
})
}
.width('100%')
}
.height('100%')
}
}

View File

@ -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 + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
}
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -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')
}
}

View File

@ -0,0 +1,20 @@
/*
* 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 appTest from './app.test'
export default function testsuite() {
appTest()
}

View File

@ -0,0 +1,86 @@
/*
* 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, BY, UiComponent, MatchPattern } from '@ohos.uitest'
import featureAbility from '@ohos.ability.featureAbility'
import hilog from '@ohos.hilog'
const TAG = '[Sample_QRCode]'
const DOMAIN = 0xF811
const BUNDLE = 'QRCode_'
export default function appTest() {
describe('appTest', function () {
it(BUNDLE + 'StartAbility_001', 0, async function (done) {
hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin')
let want = {
bundleName: "ohos.samples.qrcode",
abilityName: "MainAbility"
}
await globalThis.abilityContext.startAbility(want, (err, data) => {
hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,err.code:' + err.code)
expect(0).assertEqual(err.code)
done()
hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end')
})
})
/**
* 进入应用
*/
it(BUNDLE + 'EnterFunction_001', 0, async function () {
hilog.info(DOMAIN, TAG, BUNDLE + 'EnterFunction_001 begin')
let driver = await UiDriver.create()
await driver.delayMs(2000)
// 进入应用
hilog.info(DOMAIN, TAG, BUNDLE + 'EnterFunction_001 enter')
await driver.assertComponentExist(BY.text('允许', MatchPattern.CONTAINS))
let btnEnter = await driver.findComponent(BY.text('允许', MatchPattern.CONTAINS))
await btnEnter.click()
hilog.info(DOMAIN, TAG, BUNDLE + 'EnterFunction_001 end')
})
/**
* 生成并保存二维码
*/
it(BUNDLE + 'CreateFunction_001', 0, async function () {
hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 begin')
let driver = await UiDriver.create()
await driver.delayMs(2000)
// 点击生成二维码
hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 createClick')
await driver.assertComponentExist(BY.text('生成二维码', MatchPattern.CONTAINS))
let btnCreate = await driver.findComponent(BY.text('生成二维码', MatchPattern.CONTAINS))
await btnCreate.click()
await driver.delayMs(1000)
// 输入二维码内容
hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 createQRCodeInput')
await driver.assertComponentExist(BY.key('createQRCodeInput'))
let CreateQRCodeInput = await driver.findComponent(BY.key('createQRCodeInput'))
await CreateQRCodeInput.inputText('helloWorld')
let val = await CreateQRCodeInput.getText()
hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 inputValue')
expect('helloWorld').assertEqual(val)
await driver.delayMs(1000)
hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 saveClick')
await driver.assertComponentExist(BY.key('save'))
let btnSave = await driver.findComponent(BY.key('save'))
await btnSave.click()
await driver.delayMs(1000)
hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 end')
})
})
}

View File

@ -0,0 +1,54 @@
/*
* 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.
*/
{
"module": {
"name": "entry_test",
"type": "feature",
"srcEntrance": "./ets/Application/TestAbilityStage.ts",
"description": "$string:entry_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"uiSyntax": "ets",
"abilities": [
{
"name": "TestAbility",
"srcEntrance": "./ets/TestAbility/TestAbility.ts",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"visible": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:white",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}

View File

@ -0,0 +1,8 @@
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}

View File

@ -0,0 +1,16 @@
{
"string": [
{
"name": "entry_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -0,0 +1,5 @@
{
"src": [
"TestAbility/pages/index"
]
}

View File

@ -13,6 +13,7 @@
"dependencies": {
"@ohos/hypium": "1.0.1",
"@ohos/hvigor-ohos-plugin": "1.1.6",
"@ohos/hvigor": "1.1.6"
"@ohos/hvigor": "1.1.6",
"jsqr": "^1.4.0"
}
}

View File

@ -11,4 +11,4 @@
"repository": {},
"version": "1.0.0",
"dependencies": {}
}
}

View File

@ -45,7 +45,7 @@
"deliveryWithInstall": true,
"moduleName": "entry"
},
"package": "com.example.entry",
"package": "ohos.samples.international",
"srcPath": "",
"name": ".entry",
"js": [

View File

@ -169,6 +169,7 @@ struct EditPreferred {
.layoutWeight(1)
Blank()
Image($r('app.media.check'))
.key('check')
.width(60).height('100%')
.objectFit(ImageFit.Contain)
.onClick(() => {

View File

@ -205,6 +205,7 @@ struct Language {
.fontSize(22).fontColor(Color.Gray)
Blank()
Text($r('app.string.edit'))
.key('edit')
.fontSize(22).fontColor(Color.Blue)
.onClick(() => {
router.push({

View File

@ -0,0 +1,68 @@
{
"app": {
"bundleName": "ohos.samples.international",
"vendor": "samples",
"version": {
"code": 1000000,
"name": "1.0.0"
}
},
"deviceConfig": {},
"module": {
"package": "com.example.entry_test",
"name": ".entry_test",
"mainAbility": ".TestAbility",
"srcPath": "",
"deviceType": [
"default",
"tablet"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry_test",
"moduleType": "feature",
"installationFree": false
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "TestAbility",
"name": ".TestAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:description_TestAbility",
"formsEnabled": false,
"label": "$string:entry_TestAbility",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 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')
},
}

View File

@ -0,0 +1,52 @@
/*
* 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%')
}
}

View File

@ -0,0 +1,83 @@
/*
* 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'] + '.TestAbility'
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters)
console.info('cmd : ' + cmd)
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 call abilityDelegator.getAppContext')
var context = abilityDelegator.getAppContext()
console.info('getAppContext : ' + JSON.stringify(context))
console.info('OpenHarmonyTestRunner onRun end')
}
}

View File

@ -0,0 +1,20 @@
/*
* 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 appTest from './app.test'
export default function testsuite() {
appTest()
}

View File

@ -0,0 +1,144 @@
/*
* 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, BY, UiComponent, MatchPattern } from '@ohos.uitest'
import featureAbility from '@ohos.ability.featureAbility'
import hilog from '@ohos.hilog'
const TAG = '[Sample_International]'
const DOMAIN = 0xF811
const BUNDLE = 'International_'
export default function appTest() {
describe('appTest', function () {
it(BUNDLE + 'StartAbility_001', 0, async function (done) {
hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin')
let parameter = {
"want": {
bundleName: "ohos.samples.international",
abilityName: "ohos.samples.international.MainAbility"
}
}
await featureAbility.startAbility(parameter, (err, data) => {
hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,err.code:' + err.code)
expect(0).assertEqual(err.code)
done()
hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end')
})
})
/**
* 语言和地区
*/
it(BUNDLE + 'LanguageRegionFunction_001', 0, async function () {
hilog.info(DOMAIN, TAG, BUNDLE + 'LanguageRegionFunction_001 begin')
let driver = await UiDriver.create()
await driver.delayMs(1000)
// 点击语言和地区
hilog.info(DOMAIN, TAG, BUNDLE + 'LanguageRegionFunction_001 enter')
await driver.assertComponentExist(BY.text('语言和地区', MatchPattern.CONTAINS))
let languageRegion = await driver.findComponent(BY.text('语言和地区', MatchPattern.CONTAINS))
await languageRegion.click()
await driver.delayMs(1000)
// 添加语言
hilog.info(DOMAIN, TAG, BUNDLE + 'LanguageRegionFunction_001 add')
await driver.assertComponentExist(BY.text('添加语言', MatchPattern.CONTAINS))
let btnAdd = await driver.findComponent(BY.text('添加语言', MatchPattern.CONTAINS))
await btnAdd.click()
await driver.delayMs(1000)
await driver.pressBack()
await driver.delayMs(2000)
// 编辑
hilog.info(DOMAIN, TAG, BUNDLE + 'LanguageRegionFunction_001 edit')
await driver.assertComponentExist(BY.key('edit'))
let btnEdit = await driver.findComponent(BY.key('edit'))
await btnEdit.click()
await driver.delayMs(1000)
// 确认
hilog.info(DOMAIN, TAG, BUNDLE + 'LanguageRegionFunction_001 check')
await driver.assertComponentExist(BY.key('check'))
let btnCheck = await driver.findComponent(BY.key('check'))
await btnCheck.click()
await driver.delayMs(2000)
// 当前地区
hilog.info(DOMAIN, TAG, BUNDLE + 'LanguageRegionFunction_001 currentRegion')
await driver.assertComponentExist(BY.text('当前地区', MatchPattern.CONTAINS))
let btnCurrentRegion = await driver.findComponent(BY.text('当前地区', MatchPattern.CONTAINS))
await btnCurrentRegion.click()
await driver.delayMs(1000)
// 选择地区
hilog.info(DOMAIN, TAG, BUNDLE + 'LanguageRegionFunction_001 selectRegion')
await driver.assertComponentExist(BY.text('选择地区', MatchPattern.CONTAINS))
let btnSelectRegion = await driver.findComponent(BY.text('选择地区', MatchPattern.CONTAINS))
await btnSelectRegion.click()
await driver.delayMs(1000)
// 选择新加坡
hilog.info(DOMAIN, TAG, BUNDLE + 'LanguageRegionFunction_001 selected')
await driver.assertComponentExist(BY.text('新加坡', MatchPattern.CONTAINS))
let btnSelected = await driver.findComponent(BY.text('新加坡', MatchPattern.CONTAINS))
await btnSelected.click()
await driver.delayMs(500)
await driver.pressBack()
await driver.delayMs(1000)
await driver.pressBack()
await driver.delayMs(1000)
hilog.info(DOMAIN, TAG, BUNDLE + 'LanguageRegionFunction_001 end')
})
/**
* 日期和时间
*/
it(BUNDLE + 'DateTimeFunction_001', 0, async function () {
hilog.info(DOMAIN, TAG, BUNDLE + 'DateTimeFunction_001 begin')
let driver = await UiDriver.create()
await driver.delayMs(2000)
// 点击日期和时间
hilog.info(DOMAIN, TAG, BUNDLE + 'DateTimeFunction_001 enter')
await driver.assertComponentExist(BY.text('日期和时间', MatchPattern.CONTAINS))
let dateTime = await driver.findComponent(BY.text('日期和时间', MatchPattern.CONTAINS))
await dateTime.click()
await driver.delayMs(1000)
console.log("Sample_International 32")
// 开启24小时制
hilog.info(DOMAIN, TAG, BUNDLE + 'DateTimeFunction_001 toggleClick')
await driver.assertComponentExist(BY.type('Toggle'))
let btnHours24 = await driver.findComponent(BY.type('Toggle'))
await btnHours24.click()
await driver.delayMs(2000)
await driver.pressBack()
await driver.delayMs(1000)
hilog.info(DOMAIN, TAG, BUNDLE + 'DateTimeFunction_001 end')
})
/**
* 区域格式示例
*/
it(BUNDLE + 'FormatExampleFunction_001', 0, async function () {
hilog.info(DOMAIN, TAG, BUNDLE + 'FormatExampleFunction_001 begin')
let driver = await UiDriver.create()
await driver.delayMs(1000)
// 点击区域格式示例
hilog.info(DOMAIN, TAG, BUNDLE + 'FormatExampleFunction_001 enter')
await driver.assertComponentExist(BY.text('区域格式示例', MatchPattern.CONTAINS))
let formatExample = await driver.findComponent(BY.text('区域格式示例', MatchPattern.CONTAINS))
await formatExample.click()
await driver.delayMs(2000)
await driver.pressBack()
await driver.delayMs(1000)
hilog.info(DOMAIN, TAG, BUNDLE + 'FormatExampleFunction_001 end')
})
})
}

View File

@ -0,0 +1,12 @@
{
"string": [
{
"name": "description_TestAbility",
"value": "eTS_Empty Ability"
},
{
"name": "entry_TestAbility",
"value": "entry_TestAbility"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -16,4 +16,4 @@
"hypium": "^1.0.0",
"@ohos/hvigor": "1.1.6"
}
}
}

View File

@ -117,7 +117,7 @@ struct AlbumPage {
LazyForEach(this.mediaDataSource, (item, index) => {
ListItem() {
MediaItem({ media: item, index: index, btnAction: this.btnAction.bind(this) })
}
}.key('ListItem' + (index + 1))
.onClick(() => {
if (item.mediaType === mediaLibrary.MediaType.VIDEO) {
Logger.info(this.tag, `onClick,item.id=${item.id}`)

View File

@ -144,6 +144,7 @@ struct CameraPage {
Image(this.getCameraIcon())
.size({ width: 70, height: 70 })
.margin({ left: 50 })
.key('photo')
.onClick(() => {
if (this.curModel === CameraMode.MODE_PHOTO) {
Logger.info(this.tag, 'takePicture begin')

View File

@ -77,7 +77,7 @@ struct Record {
Row() {
Blank()
Button({ type: ButtonType.Circle, stateEffect: true }) {
Rect({ width: 25, height: 25 }).fill(Color.Red).radius(5)
Rect({ width: 25, height: 25 }).fill(Color.Red).radius(5).key('end')
}
.size({ width: 75, height: 75 })
.backgroundColor('#FFFFFF')
@ -93,11 +93,12 @@ struct Record {
Rect({ width: 5, height: 25 })
Rect({ width: 5, height: 25 })
.margin({ left: 10 })
}.width(20).height(25)
}.width(20).height(25).key('stop')
} else {
Polyline({ width: 20, height: 25 })
.points([[0, 0], [20, 12.5], [0, 25]])
.margin({ left: 5 })
.key('start')
}
}
.size({ width: 75, height: 75 })

View File

@ -81,6 +81,7 @@ export struct MediaItem {
.size({ width: 40, height: 40 })
}
}
.key('rename')
.size({ width: 50, height: 50 })
.backgroundColor('#F5F5F5')
.onClick(() => {
@ -94,6 +95,7 @@ export struct MediaItem {
.size({ width: 40, height: 40 })
}
}
.key('delete')
.size({ width: 50, height: 50 })
.margin({ left: 15, right: 10 })
.backgroundColor('#F5F5F5')

View File

@ -27,6 +27,7 @@ export struct RenameDialog {
.fontColor(Color.Black)
.fontWeight(FontWeight.Bold)
TextInput({ placeholder: 'input new name', text: this.title })
.key('inputRename')
.type(InputType.Normal)
.placeholderColor(Color.Gray)
.maxLength(20)

View File

@ -0,0 +1,22 @@
/*
* 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 TestAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] TestAbilityStage onCreate")
}
}

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Ability from '@ohos.application.Ability'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default class TestAbility extends Ability {
onCreate(want, launchParam) {
console.log('TestAbility onCreate')
}
onDestroy() {
console.log('TestAbility onDestroy')
}
onWindowStageCreate(windowStage) {
console.log('TestAbility onWindowStageCreate')
windowStage.loadContent("TestAbility/pages/index", (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err))
return
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
})
globalThis.abilityContext = this.context
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
onWindowStageDestroy() {
console.log('TestAbility onWindowStageDestroy')
}
onForeground() {
console.log('TestAbility onForeground')
}
onBackground() {
console.log('TestAbility onBackground')
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@ohos.router'
@Entry
@Component
struct Index {
aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(() => {
})
}
.width('100%')
}
.height('100%')
}
}

View File

@ -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 + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
}
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -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')
}
}

View File

@ -0,0 +1,20 @@
/*
* 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 appTest from './app.test'
export default function testsuite() {
appTest()
}

View File

@ -0,0 +1,59 @@
/*
* 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, BY, UiComponent, MatchPattern } from '@ohos.uitest'
import featureAbility from '@ohos.ability.featureAbility'
import hilog from '@ohos.hilog'
const TAG = '[Sample_MultiMedia]'
const DOMAIN = 0xF811
const BUNDLE = 'MultiMedia_'
export default function appTest() {
describe('appTest', function () {
it(BUNDLE + 'StartAbility_001', 0, async function (done) {
hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin')
let want = {
bundleName: "ohos.samples.multimedia",
abilityName: "MainAbility"
}
await globalThis.abilityContext.startAbility(want, (err, data) => {
hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,err.code:' + err.code)
expect(0).assertEqual(err.code)
done()
hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end')
})
})
/**
* 创建文件
*/
it(BUNDLE + 'CreateFunction_001', 0, async function () {
hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 begin')
let driver = await UiDriver.create()
await driver.delayMs(1000)
// enter
hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 enter')
await driver.assertComponentExist(BY.text('允许', MatchPattern.CONTAINS))
let btnEnter = await driver.findComponent(BY.text('允许', MatchPattern.CONTAINS))
await btnEnter.click()
await btnEnter.click()
await btnEnter.click()
await driver.delayMs(1000)
hilog.info(DOMAIN, TAG, BUNDLE + 'CreateFunction_001 end')
})
})
}

View File

@ -0,0 +1,54 @@
/*
* 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.
*/
{
"module": {
"name": "entry_test",
"type": "feature",
"srcEntrance": "./ets/TestAbility/TestAbility.ts",
"description": "$string:entry_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"uiSyntax": "ets",
"abilities": [
{
"name": "TestAbility",
"srcEntrance": "./ets/TestAbility/TestAbility.ts",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:white",
"visible": true,
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}

View File

@ -0,0 +1,8 @@
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}

View File

@ -0,0 +1,16 @@
{
"string": [
{
"name": "entry_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -0,0 +1,5 @@
{
"src": [
"TestAbility/pages/index"
]
}

View File

@ -11,8 +11,8 @@
"repository": {},
"version": "1.0.0",
"dependencies": {
"@ohos/hypium": "1.0.0",
"@ohos/hvigor-ohos-plugin": "1.1.3",
"@ohos/hvigor": "1.1.3"
"@ohos/hypium": "1.0.1",
"@ohos/hvigor-ohos-plugin": "1.1.6",
"@ohos/hvigor": "1.1.6"
}
}
}