From 0810440db2e7fe5e93fed76f5d5504ff02e0d63d Mon Sep 17 00:00:00 2001 From: yeyedeshen Date: Fri, 21 Mar 2025 11:56:37 +0800 Subject: [PATCH] =?UTF-8?q?Bluetooth\FlipClock=E6=B5=8B=E8=AF=95=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yeyedeshen --- .../src/ohosTest/ets/test/Ability.test.ets | 14 +++--- .../ohosTest/ets/testability/TestAbility.ets | 14 +++--- .../entry/src/ohosTest/ets/test/Main.test.ets | 16 +++---- .../src/ohosTest/ets/test/Ability.test.ets | 43 ++++++++++++------- .../resources/base/element/string.json | 32 ++++++++++++++ 5 files changed, 81 insertions(+), 38 deletions(-) diff --git a/code/BasicFeature/Connectivity/Bluetooth/advertiser/src/ohosTest/ets/test/Ability.test.ets b/code/BasicFeature/Connectivity/Bluetooth/advertiser/src/ohosTest/ets/test/Ability.test.ets index 2bd31e1d68..99f998b73e 100644 --- a/code/BasicFeature/Connectivity/Bluetooth/advertiser/src/ohosTest/ets/test/Ability.test.ets +++ b/code/BasicFeature/Connectivity/Bluetooth/advertiser/src/ohosTest/ets/test/Ability.test.ets @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Copyright (c) 2023-2025 Hunan OpenValley Digital Industry Development 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 @@ -17,27 +17,27 @@ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' export default function abilityTest() { - describe('ActsAbilityTest', function () { + describe('ActsAbilityTest', () => { // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(function () { + beforeAll( () => { // Presets an action, which is performed only once before all test cases of the test suite start. // This API supports only one parameter: preset action function. }) - beforeEach(function () { + beforeEach( () => { // Presets an action, which is performed before each unit test case starts. // The number of execution times is the same as the number of test cases defined by **it**. // This API supports only one parameter: preset action function. }) - afterEach(function () { + afterEach( () => { // Presets a clear action, which is performed after each unit test case ends. // The number of execution times is the same as the number of test cases defined by **it**. // This API supports only one parameter: clear action function. }) - afterAll(function () { + afterAll( () => { // Presets a clear action, which is performed after all test cases of the test suite end. // This API supports only one parameter: clear action function. }) - it('assertContain', 0, function () { + it('assertContain', 0, () => { // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); let a = 'abc' diff --git a/code/BasicFeature/Connectivity/Bluetooth/advertiser/src/ohosTest/ets/testability/TestAbility.ets b/code/BasicFeature/Connectivity/Bluetooth/advertiser/src/ohosTest/ets/testability/TestAbility.ets index 5add8b1e31..6bbd533d82 100644 --- a/code/BasicFeature/Connectivity/Bluetooth/advertiser/src/ohosTest/ets/testability/TestAbility.ets +++ b/code/BasicFeature/Connectivity/Bluetooth/advertiser/src/ohosTest/ets/testability/TestAbility.ets @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Copyright (c) 2023-2025 Hunan OpenValley Digital Industry Development 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 @@ -19,18 +19,18 @@ import hilog from '@ohos.hilog'; import { Hypium } from '@ohos/hypium'; import testsuite from '../test/List.test'; import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; export default class TestAbility extends UIAbility { - onCreate(want, launchParam) { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility 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() + let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let abilityDelegatorArguments:AbilityDelegatorRegistry.AbilityDelegatorArgs = AbilityDelegatorRegistry.getArguments(); hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); } onDestroy() { diff --git a/code/BasicFeature/Connectivity/Bluetooth/entry/src/ohosTest/ets/test/Main.test.ets b/code/BasicFeature/Connectivity/Bluetooth/entry/src/ohosTest/ets/test/Main.test.ets index 369c51d45b..3aefb0faf6 100644 --- a/code/BasicFeature/Connectivity/Bluetooth/entry/src/ohosTest/ets/test/Main.test.ets +++ b/code/BasicFeature/Connectivity/Bluetooth/entry/src/ohosTest/ets/test/Main.test.ets @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Copyright (c) 2023-2025 Hunan OpenValley Digital Industry Development 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 @@ -13,30 +13,30 @@ * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; export default function MainTest() { - describe('MainTest', function () { + describe('MainTest', () => { // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(function () { + beforeAll(() => { // Presets an action, which is performed only once before all test cases of the test suite start. // This API supports only one parameter: preset action function. }) - beforeEach(function () { + beforeEach(() => { // Presets an action, which is performed before each unit test case starts. // The number of execution times is the same as the number of test cases defined by **it**. // This API supports only one parameter: preset action function. }) - afterEach(function () { + afterEach(() => { // Presets a clear action, which is performed after each unit test case ends. // The number of execution times is the same as the number of test cases defined by **it**. // This API supports only one parameter: clear action function. }) - afterAll(function () { + afterAll(() => { // Presets a clear action, which is performed after all test cases of the test suite end. // This API supports only one parameter: clear action function. }) - it('assertEqual', 0, function () { + it('assertEqual', 0, () => { // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. let a = 'test' // Defines a variety of assertion methods, which are used to declare expected boolean conditions. diff --git a/code/Solutions/Tools/FlipClock/entry/src/ohosTest/ets/test/Ability.test.ets b/code/Solutions/Tools/FlipClock/entry/src/ohosTest/ets/test/Ability.test.ets index 01368c5b64..abc2d52729 100644 --- a/code/Solutions/Tools/FlipClock/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/code/Solutions/Tools/FlipClock/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -14,11 +14,19 @@ */ import hilog from '@ohos.hilog'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { describe, it, expect } from '@ohos/hypium'; import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; import { Driver, ON } from '@ohos.UiTest'; const DRIVER = Driver.create(); +let abilityDelegatorRegistry = AbilityDelegatorRegistry.getAbilityDelegator(); + +// 资源本地化 +async function getResourceString(resource: T): Promise { + let manage = abilityDelegatorRegistry.getAppContext().resourceManager; + let text = await manage.getStringValue(resource); + return text; +} export default function abilityTest() { describe('ActsAbilityTest', () => { @@ -52,9 +60,12 @@ export default function abilityTest() { await driver.delayMs(2000); // 获取发送通知权限 hilog.info(0x0000, 'testTag', 'RequestPermission requestPermission'); - await driver.assertComponentExist(ON.text('允许')); - let btnStart = await driver.findComponent(ON.text('允许')); - await btnStart.click(); + for (let i = 0; i < 2; i++) { + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.allow')))); + let btnStart = await driver.findComponent(ON.text(await getResourceString($r('app.string.allow')))); + await btnStart.click(); + await driver.delayMs(1000); + } hilog.info(0x0000, 'testTag', 'RequestPermission end'); }) @@ -73,8 +84,8 @@ export default function abilityTest() { */ it('ToAlarmClock_001', 0, async () => { hilog.info(0x0000, 'testTag', 'ToAlarmClock_001 begin'); - await DRIVER.assertComponentExist(ON.text('闹钟')); - let alarmClock = await DRIVER.findComponent(ON.text('闹钟')); + await DRIVER.assertComponentExist(ON.text(await getResourceString($r('app.string.alarm_clock')))); + let alarmClock = await DRIVER.findComponent(ON.text(await getResourceString($r('app.string.alarm_clock')))); await alarmClock.click(); await DRIVER.delayMs(1000); await DRIVER.assertComponentExist(ON.id('add')); @@ -94,8 +105,8 @@ export default function abilityTest() { let point = await timePicker.getBoundsCenter(); await DRIVER.swipe(point.x + 20, point.y, point.x + 20, point.y - 40); await DRIVER.delayMs(1000); - await DRIVER.assertComponentExist(ON.text('是')); - let confirmBtn = await DRIVER.findComponent(ON.text('是')); + await DRIVER.assertComponentExist(ON.text(await getResourceString($r('app.string.yes')))); + let confirmBtn = await DRIVER.findComponent(ON.text(await getResourceString($r('app.string.yes')))); await confirmBtn.click(); await DRIVER.delayMs(1000); await DRIVER.assertComponentExist(ON.id('deleteAlarmClock')); @@ -120,8 +131,8 @@ export default function abilityTest() { */ it('ToCountDown_001', 0, async () => { hilog.info(0x0000, 'testTag', 'ToCountDown_001 begin'); - await DRIVER.assertComponentExist(ON.text('倒计时')); - let countdown = await DRIVER.findComponent(ON.text('倒计时')); + await DRIVER.assertComponentExist(ON.text(await getResourceString($r('app.string.countdown')))); + let countdown = await DRIVER.findComponent(ON.text(await getResourceString($r('app.string.countdown')))); await countdown.click(); await DRIVER.delayMs(1000); await DRIVER.assertComponentExist(ON.id('countdownCanvas')); @@ -213,17 +224,17 @@ export default function abilityTest() { it('ToSetPage_001', 0, async () => { hilog.info(0x0000, 'testTag', 'ToSetPage_001 begin'); // 底部tabBar的设置菜单 - await DRIVER.assertComponentExist(ON.text('设置')); - let setBtn = await DRIVER.findComponent(ON.text('设置')); + await DRIVER.assertComponentExist(ON.text(await getResourceString($r('app.string.setting')))); + let setBtn = await DRIVER.findComponent(ON.text(await getResourceString($r('app.string.setting')))); await setBtn.click(); await DRIVER.delayMs(1000); // 设置页面上的设置按钮 await DRIVER.assertComponentExist(ON.id('Setting')); let settingBtn = await DRIVER.findComponent(ON.id('Setting')); await settingBtn.click(); - await DRIVER.assertComponentExist(ON.text('全屏')); - await DRIVER.assertComponentExist(ON.text('屏幕常亮')); - await DRIVER.assertComponentExist(ON.text('亮度')); + await DRIVER.assertComponentExist(ON.text(await getResourceString($r('app.string.full_screen')))); + await DRIVER.assertComponentExist(ON.text(await getResourceString($r('app.string.keep_screen_on')))); + await DRIVER.assertComponentExist(ON.text(await getResourceString($r('app.string.brightness')))); hilog.info(0x0000, 'testTag', 'ToSetPage_001 end'); }) }) diff --git a/code/Solutions/Tools/FlipClock/entry/src/ohosTest/resources/base/element/string.json b/code/Solutions/Tools/FlipClock/entry/src/ohosTest/resources/base/element/string.json index 65d8fa5a7c..8b04a7a967 100644 --- a/code/Solutions/Tools/FlipClock/entry/src/ohosTest/resources/base/element/string.json +++ b/code/Solutions/Tools/FlipClock/entry/src/ohosTest/resources/base/element/string.json @@ -11,6 +11,38 @@ { "name": "TestAbility_label", "value": "test label" + }, + { + "name": "allow", + "value": "允许" + }, + { + "name": "alarm_clock", + "value": "闹钟" + }, + { + "name": "yes", + "value": "是" + }, + { + "name": "countdown", + "value": "倒计时" + }, + { + "name": "setting", + "value": "设置" + }, + { + "name": "full_screen", + "value": "全屏" + }, + { + "name": "keep_screen_on", + "value": "屏幕常亮" + }, + { + "name": "brightness", + "value": "亮度" } ] } \ No newline at end of file -- Gitee