From 4acd1cb703dd040ce77c71e2f4eac049dcec7dbb Mon Sep 17 00:00:00 2001 From: haoxiaohui Date: Fri, 28 Apr 2023 10:54:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Sensor=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: haoxiaohui --- .../src/ohosTest/ets/test/Ability.test.ets | 67 +++++++++++++++++-- .../resources/base/element/string.json | 8 +++ .../resources/en_US/element/string.json | 24 +++++++ .../resources/zh_CN/element/string.json | 24 +++++++ .../DeviceManagement/Sensor/ohosTest.md | 12 ++++ 5 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/en_US/element/string.json create mode 100644 code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/zh_CN/element/string.json create mode 100644 code/BasicFeature/DeviceManagement/Sensor/ohosTest.md diff --git a/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/ets/test/Ability.test.ets b/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/ets/test/Ability.test.ets index 209e6b7513..9c1f9889f5 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/ets/test/Ability.test.ets @@ -14,14 +14,24 @@ */ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import { UiDriver, BY, UiComponent, MatchPattern } from '@ohos.uitest' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Driver, ON, Component, MatchPattern, DisplayRotation } from '@ohos.UiTest' +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry' import hilog from '@ohos.hilog' const TAG = '[Sample_Sensor]' const DOMAIN = 0xF811 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() { describe('appTest', function () { it(BUNDLE + 'StartAbility_001', 0, async function (done) { @@ -30,9 +40,11 @@ export default function appTest() { bundleName: "ohos.samples.sensor", abilityName: "EntryAbility" } - AbilityDelegatorRegistry.getAbilityDelegator().startAbility(parameter, (err, data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,err.code:' + err.code) - expect(0).assertEqual(err.code) + abilityDelegatorRegistry.getAbilityDelegator().startAbility(parameter, (err, data) => { + if (err !== null) { + 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') }) @@ -44,9 +56,52 @@ export default function appTest() { it(BUNDLE + 'BringSensorFunction_001', 0, async function () { // create UiDriver hilog.info(DOMAIN, TAG, BUNDLE + 'BringSensorFunction_001 begin') - let driver = await UiDriver.create() + let driver = await Driver.create() await driver.delayMs(1000) 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') + }) }) } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/base/element/string.json b/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/base/element/string.json index 65d8fa5a7c..1796725ebc 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/base/element/string.json +++ b/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/base/element/string.json @@ -11,6 +11,14 @@ { "name": "TestAbility_label", "value": "test label" + }, + { + "name": "directionNorth", + "value": "north" + }, + { + "name": "angle", + "value": "0°" } ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/en_US/element/string.json b/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/en_US/element/string.json new file mode 100644 index 0000000000..1796725ebc --- /dev/null +++ b/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/en_US/element/string.json @@ -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°" + } + ] +} \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/zh_CN/element/string.json b/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/zh_CN/element/string.json new file mode 100644 index 0000000000..24450270e2 --- /dev/null +++ b/code/BasicFeature/DeviceManagement/Sensor/entry/src/ohosTest/resources/zh_CN/element/string.json @@ -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°" + } + ] +} \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Sensor/ohosTest.md b/code/BasicFeature/DeviceManagement/Sensor/ohosTest.md new file mode 100644 index 0000000000..7b83db8562 --- /dev/null +++ b/code/BasicFeature/DeviceManagement/Sensor/ohosTest.md @@ -0,0 +1,12 @@ +# FileManager 测试用例归档 + +## 用例表 + +|测试功能|预置条件|输入|预期输出|测试结果| +|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------| +|拉起应用| 设备正常运行| |成功拉起应用|Pass| +|检查UI是否正常显示| 位于主页| |UI正常显示|Pass| +|切换横屏| 位于主页| 旋转90°| 主页转为横屏显示|Pass| +|检查UI是否正常显示| 位于主页| | UI正常显示|Pass| +|切回竖屏| 位于主页| 往回旋转90°| 主页转为竖屏显示|Pass| +|检查UI是否正常显示| 位于主页| | UI正常显示|Pass|