提交 404d5e9a 编写于 作者: Z zhouke

增加uitest xts用例.Signed-off-by: <zhouke35@huawei.com>.

Signed-off-by: Nzhouke <zhouke35@huawei.com>
上级 6fa6d7a8
# 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("arkXtest") {
testonly = true
if (is_standard_system) {
deps = [
"uitest:uitest_xts",
]
}
}
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("uitest_xts") {
hap_profile = "./src/main/config.json"
deps = [
":uitest_ets_assets",
":uitest_ets_test_assets",
":uitest_ets_resources",
]
ets2abc = true
certificate_profile = "//test/xts/acts/arkXtest/uitest/signature/auto_ohos_default_com.uitest.test.p7b"
hap_name = "uitest_xts"
}
ohos_js_assets("uitest_ets_assets") {
source_dir = "./src/main/ets/MainAbility"
}
ohos_js_assets("uitest_ets_test_assets") {
source_dir = "./src/main/ets/TestAbility"
}
ohos_resources("uitest_ets_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
{
"description": "Configuration for uitest Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "1800000",
"bundle-name": "com.uitest.test",
"package-name": "com.uitest.test",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"$module.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"vendor": "open",
"bundleName": "com.uitest.test",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 7,
"releaseType": "Release",
"target": 8
}
},
"deviceConfig": {},
"module": {
"package": "com.uitest.test",
"name": ".MyApplication",
"mainAbility": ".MainAbility",
"srcPath": "MainAbility",
"deviceType": [
"phone"
],
"distro": {
"moduleType": "entry",
"installationFree": false,
"deliveryWithInstall": true,
"moduleName": "entry"
},
"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",
"formsEnabled": false,
"visible": true,
"srcPath": "TestAbility",
"name": ".TestAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index",
"pages/second",
"pages/third",
"pages/fourth"
],
"name": ".MainAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"mode": {
"syntax": "ets",
"type": "pageAbility"
},
"pages": [
"pages/index",
"pages/second",
"pages/third",
"pages/fourth"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}
\ 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.
*/
export default {
onCreate() {
console.info('Application onCreate')
},
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 Fourth
{
private content: string = "Fourth Page"
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('longClick')
.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 router from '@system.router';
import prompt from '@ohos.prompt';
@Entry
@Component
struct ScrollExample {
scroller: Scroller = new Scroller()
private arr: number[] = [1,2,3,4]
build() {
Stack({ alignContent: Alignment.TopStart }) {
Scroll(this.scroller) {
Column() {
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.key('my-key')
.type(ButtonType.Capsule)
.margin({ top: 20 })
.onClick(() => {
router.push({ uri: 'pages/second' })
})
.gesture(
LongPressGesture({repeat:false})
.onAction((event: GestureEvent)=>{
router.push({ uri: 'pages/fourth' })
})
)
Text('Click twice')
.margin({top:20})
.gesture(
TapGesture({ count: 2 })
.onAction(() => {
router.push({ uri: 'pages/third' })
})
)
Checkbox({name:'hi'})
.size({width:30,height:30})
TextInput({ placeholder: 'welcome', text: 'Hello World'})
.type(InputType.Normal)
.width(300)
.height(50)
.fontSize(40)
.enabled(true)
.margin({ top: 20 })
ForEach(this.arr, (item) => {
Text(item.toString())
.width('100%').height('30%').backgroundColor(0xFFFFFF)
.borderRadius(75).fontSize(80).textAlign(TextAlign.Center)
.margin({ top: 10 })
}, item => item)
Button() {
Text('bottom')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20, left: 150
})
.onClick(() => {
router.push({ uri: 'pages/second' })
})
}.width('100%')
}
.scrollable(ScrollDirection.Vertical).scrollBar(BarState.On)
.scrollBarColor(Color.Gray).scrollBarWidth(30)
.onScroll((xOffset: number, yOffset: number) => {
console.info(xOffset + ' ' + yOffset)
})
}.width('100%').height('100%').backgroundColor(0xDCDCDC)
}
}
/**
* 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 router from '@system.router';
@Entry
@Component
struct Third{
private content: string = "Third Page"
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('page_3')
.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 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!!!')
abilityDelegatorArguments.parameters['timeout'] = 3000000
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 Fourth
{
private content: string = "Fourth Page"
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('longClick')
.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 router from '@system.router';
import prompt from '@ohos.prompt';
@Entry
@Component
struct ScrollExample {
scroller: Scroller = new Scroller()
private arr: number[] = [1,2,3,4]
build() {
Stack({ alignContent: Alignment.TopStart }) {
Scroll(this.scroller) {
Column() {
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.key('my-key')
.type(ButtonType.Capsule)
.margin({ top: 20 })
.onClick(() => {
router.push({ uri: 'pages/second' })
})
.gesture(
LongPressGesture({repeat:false})
.onAction((event: GestureEvent)=>{
router.push({ uri: 'pages/fourth' })
})
)
Text('Click twice')
.margin({top:20})
.gesture(
TapGesture({ count: 2 })
.onAction(() => {
router.push({ uri: 'pages/third' })
})
)
Checkbox({name:'hi'})
.size({width:30,height:30})
TextInput({ placeholder: 'welcome', text: 'Hello World'})
.type(InputType.Normal)
.width(300)
.height(50)
.fontSize(40)
.enabled(true)
.margin({ top: 20 })
ForEach(this.arr, (item) => {
Text(item.toString())
.width('100%').height('30%').backgroundColor(0xFFFFFF)
.borderRadius(75).fontSize(80).textAlign(TextAlign.Center)
.margin({ top: 10 })
}, item => item)
Button() {
Text('bottom')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20, left: 150
})
.onClick(() => {
router.push({ uri: 'pages/second' })
})
}.width('100%')
}
.scrollable(ScrollDirection.Vertical).scrollBar(BarState.On)
.scrollBarColor(Color.Gray).scrollBarWidth(30)
.onScroll((xOffset: number, yOffset: number) => {
console.info(xOffset + ' ' + yOffset)
})
}.width('100%').height('100%').backgroundColor(0xDCDCDC)
}
}
/**
* 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 router from '@system.router';
@Entry
@Component
struct Third{
private content: string = "Third Page"
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text(`${this.content}`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('page_3')
.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 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)
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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import abilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
import { UiDriver, BY, ResizeDirection, MatchPattern } from '@ohos.uitest'
import ability_featureAbility from '@ohos.ability.featureAbility';
const delegator = abilityDelegatorRegistry.getAbilityDelegator();
const bundleName = abilityDelegatorRegistry.getArguments().bundleName;
const waitUiReadyMs = 1000;
async function startAbility(bundleName: string, abilityName: string) {
await delegator.executeShellCommand(`aa start -b ${bundleName} -a ${abilityName}`).then(result => {
console.info(`UiTestCase, start abilityFinished: ${result}`)
}).catch(err => {
console.error(`UiTestCase, start abilityFailed: ${err}`)
})
}
async function stopApplication(bundleName: string) {
await delegator.executeShellCommand(`aa force-stop ${bundleName} `).then(result => {
console.info(`UiTestCase, stop application finished: ${result}`)
}).catch(err => {
console.error(`UiTestCase,stop application failed: ${err}`)
})
}
export default function abilityTest() {
describe('UiTestCase', function () {
it('UiComponent.InputText', 0, async function () {
let driver = UiDriver.create()
//await startAbility('com.example.myapplication', 'com.example.entry.MainAbility')
await driver.delayMs(waitUiReadyMs)
let input = await driver.findComponent(BY.type('TextInput'))
await input.inputText('123')
await driver.delayMs(waitUiReadyMs)
let input_new = await driver.findComponent(BY.type('TextInput'))
let text = await input_new.getText()
expect(text == '123').assertTrue()
})
it('UiComponent.ClearText', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let input = await driver.findComponent(BY.type('TextInput'))
await input.clearText()
await driver.delayMs(waitUiReadyMs)
let input_new = await driver.findComponent(BY.type('TextInput'))
let text = await input_new.getText()
expect(text).assertEqual('')
})
it('checkable', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.checkable(true).type('Checkbox'))
let checkable = await button.isCheckable()
expect(typeof (checkable) == 'boolean').assertTrue()
})
it('checked', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.checked(false).type('Checkbox'))
let checked = await button.isChecked()
expect(typeof (checked) == 'boolean').assertTrue()
})
it('UiDriver.click', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
await driver.click(350, 90)
await driver.delayMs(waitUiReadyMs)
let newButton = await driver.findComponent(BY.text('back to index'))
let text = await newButton.getText()
expect(text == 'back to index').assertTrue()
await newButton.click()
})
it('UiDriver.LongClick', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
await driver.longClick(350, 90)
await driver.delayMs(waitUiReadyMs)
let newButton = await driver.findComponent(BY.text('longClick'))
let text = await newButton.getText()
expect(text == 'longClick').assertTrue()
await newButton.click()
})
it('key', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.key('my-key'))
expect(await button.getKey() == 'my-key').assertTrue()
})
it('UiComponent.Click', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('next page', MatchPattern.EQUALS))
await button.click()
await driver.delayMs(waitUiReadyMs)
let newButton = await driver.findComponent(BY.text('back to index'))
let text = await newButton.getText()
expect(text == 'back to index').assertTrue()
await newButton.click()
})
it('UiComponent.LongClick', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('next page'))
await button.longClick()
await driver.delayMs(waitUiReadyMs)
let newButton = await driver.findComponent(BY.text('longClick'))
let text = await newButton.getText()
expect(text == 'longClick').assertTrue()
await newButton.click()
})
it('UiComponent.getType', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let text = await driver.findComponent(BY.type('Text'))
let type = await text.getType()
expect(type == 'Text').assertTrue()
})
it('UiComponent.getText', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('next page'))
let text = await button.getText()
expect(text == 'next page').assertTrue()
})
it('UiComponent.isClickable', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('next page').clickable(false))
let clickable = await button.isClickable()
expect(typeof (clickable) == 'boolean').assertTrue()
})
it('UiComponent.isLongClickable', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('next page').longClickable(false))
let longClickable = await button.isLongClickable()
expect(typeof (longClickable) == 'boolean').assertTrue()
})
it('UiComponent.isScrollable', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let scrollBar = await driver.findComponent(BY.type('Scroll').scrollable(false))
let scrollable = await scrollBar.isScrollable()
expect(typeof (scrollable) == 'boolean').assertTrue()
})
it('UiComponent.isEnabled', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('next page').enabled(true))
let enable = await button.isEnabled()
expect(enable).assertEqual(true)
})
it('UiComponent.isFocused', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('next page').focused(false))
let focused = await button.isFocused()
expect(typeof (focused) == 'boolean').assertTrue()
})
it('UiComponent.isSelected', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('next page').selected(false))
let selected = await button.isSelected()
expect(typeof (selected) == 'boolean').assertTrue()
})
it('UiComponent.scrollToBottom', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let scrollBar = await driver.findComponent(BY.type('Scroll'))
expect(scrollBar != null).assertTrue()
await scrollBar.scrollToBottom()
let button = await driver.findComponent(BY.text('bottom'))
expect(await button.getText() == 'bottom').assertTrue()
await scrollBar.scrollToTop()
})
it('UiComponent.scrollToTop', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
await driver.swipe(100, 200, 100, 100)
await driver.delayMs(waitUiReadyMs)
let scrollBar = await driver.findComponent(BY.type('Scroll'))
expect(scrollBar !== null).assertTrue()
await scrollBar.scrollToTop()
let button = await driver.findComponent(BY.text('next page'))
expect(await button.getText() == 'next page').assertTrue()
})
it('UiDriver.assertComponentExist', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
await driver.assertComponentExist(BY.text('next page'))
})
it('UiDriver.pressBack', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('next page'))
await button.click()
await driver.delayMs(waitUiReadyMs)
await driver.pressBack()
await driver.delayMs(waitUiReadyMs)
let button_ori = await driver.findComponent(BY.text('next page'))
expect(await button_ori.getText() == 'next page').assertTrue()
})
it('UiDriver.findComponents', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let buttons = await driver.findComponents(BY.type('Button'))
expect(await buttons[0].getText() != null).assertTrue()
})
it('UiDriver.triggerKey', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('next page'))
await button.click()
await driver.delayMs(waitUiReadyMs)
await driver.triggerKey(2)
await driver.delayMs(waitUiReadyMs)
let button_ori = await driver.findComponent(BY.text('next page'))
expect(await button_ori.getText() == 'next page').assertTrue()
})
it('UiDriver.swipe', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
await driver.swipe(100, 500, 100, 100)
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('bottom'))
let text = await button.getText()
expect(text == 'bottom').assertTrue()
await driver.swipe(100, 100, 100, 600)
})
it('UiDriver.screenCap', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let path = '/data/local/tmp/1.png'
let success = await driver.screenCap(path)
expect(typeof (success) == 'boolean').assertTrue()
})
it('getUiComponentBounds', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let text = await driver.findComponent(BY.text('Hello World'))
expect(text !== null).assertTrue()
let bounds = await text.getBounds();
console.info(`UiTestCase, bounds=${bounds}, type=${typeof (bounds)}`)
console.info(bounds.rightX.toString())
console.info(bounds.leftX.toString())
console.info(bounds.topY.toString())
console.info(bounds.bottomY.toString())
expect(bounds !== null).assertTrue()
expect(bounds.rightX).assertLarger(bounds.leftX)
expect(bounds.bottomY).assertLarger(bounds.topY)
})
it('getUiComponentBoundsCenter', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('next page'))
let point = await button.getBoundsCenter()
expect(point!== null).assertTrue()
})
it('UiDriver.waitForComponent', 0, async function () {
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.waitForComponent(BY.text('next page'), waitUiReadyMs)
expect(button !== null).assertTrue()
})
it('By.isBefore', 0, async function () {
await startAbility('com.ohos.settings', 'com.ohos.settings.MainAbility')
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.isBefore(BY.text('显示与亮度')).text('移动数据'))
expect(await button.getText() == '移动数据').assertTrue()
})
it('By.isAfter', 0, async function () {
await startAbility('com.ohos.settings', 'com.ohos.settings.MainAbility')
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.isAfter(BY.text('显示与亮度')).text('声音'))
expect(await button.getText() == '声音').assertTrue()
})
it('window.test', 0, async function () {
await startAbility('com.example.windows', 'MainAbility')
let driver = UiDriver.create()
await driver.delayMs(200)
let window = await driver.findWindow({bundleName:'com.example.windows'})
await window.resume()
await driver.delayMs(200)
let window2 = await driver.findWindow({bundleName:'com.example.windows'})
await window2.moveTo(300, 300)
await driver.delayMs(200)
let button2 = await driver.findComponent(BY.text('Clock'))
await button2.click()
})
it('window.test_2', 0, async function () {
await startAbility('com.example.windows', 'MainAbility')
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let button = await driver.findComponent(BY.text('自由窗口创建'))
await button.click()
await driver.delayMs(waitUiReadyMs)
let window_2 = await driver.findWindow({bundleName:'com.example.windows'})
await window_2.resize(400, 400, 7)
let window = await driver.findWindow({bundleName:'com.example.windows'})
await window.resize(600, 600, 7)
await stopApplication('com.example.windows')
})
it('window.resize', 0, async function () {
await startAbility('com.example.windows', 'MainAbility')
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let window = await driver.findWindow({bundleName:'com.example.windows'})
await window.resume()
await driver.delayMs(waitUiReadyMs)
let window1 = await driver.findWindow({bundleName:'com.example.windows'})
await window1.moveTo(100,100)
await driver.delayMs(waitUiReadyMs)
let window2 = await driver.findWindow({bundleName:'com.example.windows'})
await window2.resize(600, 600,7)
await driver.delayMs(waitUiReadyMs)
})
it('window.maximize', 0, async function () {
await startAbility('com.example.windows', 'MainAbility')
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let window = await driver.findWindow({bundleName:'com.example.windows'})
await window.maximize()
})
it('window.minimize', 0, async function () {
await startAbility('com.example.windows', 'MainAbility')
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let window = await driver.findWindow({bundleName:'com.example.windows'})
await window.minimize()
})
it('window.close', 0, async function () {
await startAbility('com.example.windows', 'MainAbility')
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let window = await driver.findWindow({bundleName:'com.example.windows'})
await window.close()
})
it('window.split', 0, async function () {
await startAbility('com.example.windows', 'MainAbility')
let driver = UiDriver.create()
await driver.delayMs(waitUiReadyMs)
let window = await driver.findWindow({bundleName:'com.example.windows'})
await window.split()
})
})
afterAll(function () {
console.info(`uitestApiStatistic::Start runnig afterAll`)
try {
let mod = globalThis.requireInternal('uitest')
// collect all functions
let objects = {
'By': mod.By, 'UiDriver': mod.UiDriver, 'UiComponent': mod.UiComponent
}
let allApis = []
for (let name in objects) {
let object = objects[name]
Object.getOwnPropertyNames(object).forEach(pn => {
if (pn != 'constructor' && typeof (object[pn]) == 'function') {
allApis.push(name + '.' + pn)
}
})
Object.getOwnPropertyNames(object.prototype).forEach(pn => {
if (pn != 'constructor' && typeof (object.prototype[pn]) == 'function') {
allApis.push(name + '.' + pn)
}
})
}
let calledApis: Array<string> = mod.getCalledJsApis()
calledApis.forEach(name => console.info(`uitestApiStatistic::CoveredApi: ${name}`))
let missedApis = allApis.filter(value =>!calledApis.includes(value))
console.info(`uitestApiStatistic::Total ${allApis.length}, coverd ${calledApis.length}, missed ${missedApis.length}`)
missedApis.forEach(name => console.warn(`uitestApiStatistic::NotCoveredApi: ${name}`))
} catch (e) {
console.error(`uitestApiStatistic::Runnig afterAll failed: ${e}`)
} finally {
console.info(`uitestApiStatistic::End runnig afterAll`)
}
})
}
/**
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import abilityTest from './Ability.test'
export default function testsuite() {
abilityTest()
}
\ No newline at end of file
{
"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
......@@ -14,6 +14,7 @@
import("//test/xts/tools/build/suite.gni")
_all_test_packages = [
"${ACTS_ROOT}/arkXtest:arkXtest",
"${ACTS_ROOT}/global:global",
"${ACTS_ROOT}/security:security",
"${ACTS_ROOT}/useriam:useriam",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册