!2655 【Sample】增加Sensor自动化测试用例

Merge pull request !2655 from sephyrothcloud/master
This commit is contained in:
openharmony_ci 2023-05-13 09:27:51 +00:00 committed by Gitee
commit 0372ecb877
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 129 additions and 6 deletions

View File

@ -14,14 +14,24 @@
*/ */
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import { UiDriver, BY, UiComponent, MatchPattern } from '@ohos.uitest' import { Driver, ON, Component, MatchPattern, DisplayRotation } from '@ohos.UiTest'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'
import hilog from '@ohos.hilog' import hilog from '@ohos.hilog'
const TAG = '[Sample_Sensor]' const TAG = '[Sample_Sensor]'
const DOMAIN = 0xF811 const DOMAIN = 0xF811
const BUNDLE = 'Sensor_' const BUNDLE = 'Sensor_'
// 检查页面是否正常显示
async function checkPage(driver: Driver) {
hilog.info(DOMAIN, TAG, 'checkPage begin')
let resourceManager = abilityDelegatorRegistry.getAbilityDelegator().getAppContext().resourceManager
await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.directionNorth'))))
await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.angle'))))
await driver.assertComponentExist(ON.type('Image'))
hilog.info(DOMAIN, TAG, 'checkPage end')
}
export default function appTest() { export default function appTest() {
describe('appTest', function () { describe('appTest', function () {
it(BUNDLE + 'StartAbility_001', 0, async function (done) { it(BUNDLE + 'StartAbility_001', 0, async function (done) {
@ -30,9 +40,11 @@ export default function appTest() {
bundleName: "ohos.samples.sensor", bundleName: "ohos.samples.sensor",
abilityName: "EntryAbility" abilityName: "EntryAbility"
} }
AbilityDelegatorRegistry.getAbilityDelegator().startAbility(parameter, (err, data) => { abilityDelegatorRegistry.getAbilityDelegator().startAbility(parameter, (err, data) => {
if (err !== null) {
hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,err.code:' + err.code) hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,err.code:' + err.code)
expect(0).assertEqual(err.code) expect(0).assertEqual(err.code)
}
done() done()
hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end') hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end')
}) })
@ -44,9 +56,52 @@ export default function appTest() {
it(BUNDLE + 'BringSensorFunction_001', 0, async function () { it(BUNDLE + 'BringSensorFunction_001', 0, async function () {
// create UiDriver // create UiDriver
hilog.info(DOMAIN, TAG, BUNDLE + 'BringSensorFunction_001 begin') hilog.info(DOMAIN, TAG, BUNDLE + 'BringSensorFunction_001 begin')
let driver = await UiDriver.create() let driver = await Driver.create()
await driver.delayMs(1000) await driver.delayMs(1000)
hilog.info(DOMAIN, TAG, BUNDLE + 'BringSensorFunction_001 end') hilog.info(DOMAIN, TAG, BUNDLE + 'BringSensorFunction_001 end')
}) })
/**
* 检查页面控件是否正常显示
*/
it(BUNDLE + 'CheckSensorFunction_001', 0, async function () {
// create UiDriver
hilog.info(DOMAIN, TAG, BUNDLE + 'CheckSensorFunction_001 begin')
let driver = await Driver.create()
await driver.delayMs(500)
await checkPage(driver)
await driver.delayMs(500)
hilog.info(DOMAIN, TAG, BUNDLE + 'CheckSensorFunction_001 end')
})
/**
* 切换到横屏(转动90°)
*/
it(BUNDLE + 'RotateScreenLandscapeFunction_001', 0, async function () {
// create UiDriver
hilog.info(DOMAIN, TAG, BUNDLE + 'RotateScreenLandscapeFunction_001 begin')
let driver = await Driver.create()
await driver.delayMs(1000)
await driver.setDisplayRotation(DisplayRotation.ROTATION_90)
await driver.delayMs(1000)
await checkPage(driver)
await driver.delayMs(1000)
hilog.info(DOMAIN, TAG, BUNDLE + 'RotateScreenLandscapeFunction_001 end')
})
/**
* 切换回竖屏
*/
it(BUNDLE + 'RotateScreenPortraitFunction_001', 0, async function () {
// create UiDriver
hilog.info(DOMAIN, TAG, BUNDLE + 'RotateScreenPortraitFunction_001 begin')
let driver = await Driver.create()
await driver.delayMs(1000)
await driver.setDisplayRotation(DisplayRotation.ROTATION_0)
await driver.delayMs(1000)
await checkPage(driver)
await driver.delayMs(1000)
hilog.info(DOMAIN, TAG, BUNDLE + 'RotateScreenPortraitFunction_001 end')
})
}) })
} }

View File

@ -11,6 +11,14 @@
{ {
"name": "TestAbility_label", "name": "TestAbility_label",
"value": "test label" "value": "test label"
},
{
"name": "directionNorth",
"value": "north"
},
{
"name": "angle",
"value": "0°"
} }
] ]
} }

View File

@ -0,0 +1,24 @@
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
},
{
"name": "directionNorth",
"value": "north"
},
{
"name": "angle",
"value": "0°"
}
]
}

View File

@ -0,0 +1,24 @@
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
},
{
"name": "directionNorth",
"value": "北"
},
{
"name": "angle",
"value": "0°"
}
]
}

View File

@ -0,0 +1,12 @@
# FileManager 测试用例归档
## 用例表
|测试功能|预置条件|输入|预期输出|测试结果|
|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------|
|拉起应用| 设备正常运行| |成功拉起应用|Pass|
|检查UI是否正常显示| 位于主页| |UI正常显示|Pass|
|切换横屏| 位于主页| 旋转90°| 主页转为横屏显示|Pass|
|检查UI是否正常显示| 位于主页| | UI正常显示|Pass|
|切回竖屏| 位于主页| 往回旋转90°| 主页转为竖屏显示|Pass|
|检查UI是否正常显示| 位于主页| | UI正常显示|Pass|