From 780cbaf4b605510728eab907570f6056255bf444 Mon Sep 17 00:00:00 2001 From: GuangweiLi <213203228@seu.edu.cn> Date: Wed, 6 Mar 2024 17:59:41 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=B8=BA=E5=8F=AF=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=B7=BB=E5=8A=A0id=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8EUI=E6=B5=8B=E8=AF=95=EF=BC=9B=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=AF=E5=A4=8D=E7=94=A8=E6=8C=89=E9=92=AE=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GuangweiLi <213203228@seu.edu.cn> --- .../MyNews/entry/src/main/ets/pages/Index.ets | 68 +++++--- .../entry/src/main/ets/view/HomePage.ets | 160 +++++++++++------- .../main/ets/viewmodel/IndexBottomNavItem.ets | 11 +- 3 files changed, 149 insertions(+), 90 deletions(-) diff --git a/scenario/arkui/MyNews/entry/src/main/ets/pages/Index.ets b/scenario/arkui/MyNews/entry/src/main/ets/pages/Index.ets index e8ca73ff..4c949dd3 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/pages/Index.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/pages/Index.ets @@ -15,12 +15,23 @@ import { HomePage } from '../view/HomePage'; -import { MallPageBuilder } from '../view/MallPage' +import { MallPageBuilder } from '../view/MallPage'; import { ProfilePageBuilder } from '../view/ProfilePage'; import { TaskPageBuilder } from '../view/TaskPage'; import { VideoPageBuilder } from '../view/VideoPage'; import { IndexBottomNavItem } from '../viewmodel/IndexBottomNavItem'; -import { SearchPage } from '../view/SearchPage' + +// import { SearchPage } from '../view/SearchPage'; + + +/* 定义通用无底色、无按压效果按钮样式 */ +@Extend(Button) +function commonBtnStyle(handler?: (event: ClickEvent) => void) { + .type(ButtonType.Normal) + .stateEffect(false) + .backgroundColor(Color.Transparent) + .onClick(handler) +} /** @@ -29,23 +40,28 @@ import { SearchPage } from '../view/SearchPage' const bottomNavItemList: IndexBottomNavItem[] = [{ title: '首页', normalIcon: $r('app.media.ic_public_home'), - selectedIcon: $r('app.media.ic_public_home_filled') + selectedIcon: $r('app.media.ic_public_home_filled'), + btnId: 'indexHomePageBtn' }, { title: '视频', normalIcon: $r('app.media.ic_public_video'), - selectedIcon: $r('app.media.ic_public_video_filled') + selectedIcon: $r('app.media.ic_public_video_filled'), + btnId: 'indexVideoPageBtn' }, { title: '任务', normalIcon: $r('app.media.ic_public_calendar'), - selectedIcon: $r('app.media.ic_public_calendar_filled') + selectedIcon: $r('app.media.ic_public_calendar_filled'), + btnId: 'indexTaskPageBtn' }, { title: '商城', normalIcon: $r('app.media.ic_public_appstore'), - selectedIcon: $r('app.media.ic_public_appstore_filled') + selectedIcon: $r('app.media.ic_public_appstore_filled'), + btnId: 'indexMallPageBtn' }, { title: '个人', normalIcon: $r('app.media.ic_public_contacts'), - selectedIcon: $r('app.media.ic_public_contacts_filled') + selectedIcon: $r('app.media.ic_public_contacts_filled'), + btnId: 'indexProfilePageBtn' }] @@ -56,9 +72,10 @@ struct Index { private tabsController: TabsController = new TabsController() build() { - if(1) - SearchPage() - else + // TODO: 搜索页开发用 + // if (1) + // SearchPage() + // else Tabs({ barPosition: BarPosition.End, controller: this.tabsController }) { ForEach(bottomNavItemList, (item: IndexBottomNavItem, itemIndex: number) => { TabContent() { @@ -86,7 +103,7 @@ struct Index { .width('100%') .height('100%') .align(Alignment.Top) - .tabBar(this.TabBuilder(item.title, itemIndex, item.normalIcon, item.selectedIcon)) + .tabBar(this.TabBuilder(item.title, itemIndex, item.normalIcon, item.selectedIcon, item.btnId)) }) } .width('100%') @@ -101,20 +118,23 @@ struct Index { * 底部导航栏中自定义按钮样式(图标+文字) */ @Builder - TabBuilder(title: string, targetIndex: number, normalIcon: Resource, selectedIcon: Resource) { - Column() { - // 当被选中时变色,图标变为填充型 - Image(this.currentIndex === targetIndex ? selectedIcon : normalIcon) - .size({ width: 20, height: 20 }) - .fillColor(this.currentIndex === targetIndex ? $r('app.color.primary') : $r('app.color.light_fg')) - Text(title) - .fontSize(8) - .fontColor(this.currentIndex === targetIndex ? $r('app.color.primary') : $r('app.color.light_fg')) + TabBuilder(title: string, targetIndex: number, normalIcon: Resource, selectedIcon: Resource, btnId: string) { + Button() { + Column() { + // 当被选中时变色,图标变为填充型 + Image(this.currentIndex === targetIndex ? selectedIcon : normalIcon) + .size({ width: 20, height: 20 }) + .fillColor(this.currentIndex === targetIndex ? $r('app.color.primary') : $r('app.color.light_fg')) + Text(title) + .fontSize(8) + .fontColor(this.currentIndex === targetIndex ? $r('app.color.primary') : $r('app.color.light_fg')) + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) } - .width('100%') - .height('100%') - .justifyContent(FlexAlign.Center) - .onClick(() => { + .id(btnId) + .commonBtnStyle(() => { this.tabsController.changeIndex(targetIndex) this.currentIndex = targetIndex }) diff --git a/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets b/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets index 990b5fdd..528cce5d 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets @@ -19,6 +19,15 @@ import { FollowingTabContent } from './HomePageFollowingTab'; import { RecommendationTabContent } from './HomePageRecommendationTab'; +/* 定义通用无底色、无按压效果按钮样式 */ +@Extend(Button) +function commonBtnStyle(handler?: (event: ClickEvent) => void) { + .type(ButtonType.Normal) + .stateEffect(false) + .backgroundColor(Color.Transparent) + .onClick(handler) +} + /** * 上部选项卡内容 */ @@ -92,59 +101,67 @@ struct TopBar { build() { Row({ space: 4 }) { /* 左侧按钮 */ - Stack() { - Image($r('app.media.ic_public_appstore_filled')) - .padding(5) - .size({ width: 34, height: 34 }) - .fillColor($r('app.color.primary')) - .backgroundColor($r('app.color.primary_fg')) - .borderRadius(999) - Text('阅读赚金币') - .padding({ left: 2, right: 2, top: 1, bottom: 1 }) - .fontSize(7) - .fontColor($r('app.color.light_fg')) - .backgroundColor('#ffcc00') - .borderRadius(999) + Button() { + Stack() { + Image($r('app.media.ic_public_appstore_filled')) + .padding(5) + .size({ width: 34, height: 34 }) + .fillColor($r('app.color.primary')) + .backgroundColor($r('app.color.primary_fg')) + .borderRadius(999) + Text('阅读赚金币') + .padding({ left: 2, right: 2, top: 1, bottom: 1 }) + .fontSize(7) + .fontColor($r('app.color.light_fg')) + .backgroundColor('#ffcc00') + .borderRadius(999) + } + .height('100%') + .align(Alignment.Bottom) } - .height('100%') - .align(Alignment.Bottom) - .onClick(() => { + .commonBtnStyle(() => { // TODO: 按钮点击事件处理 - this.handleLeftBtnClk = !this.handleLeftBtnClk + this.handleLeftBtnClk = false + this.handleLeftBtnClk = true }) .bindPopup(this.handleLeftBtnClk, { message: 'TODO: 按钮点击事件处理', }) /* 搜索框 */ - Row() { - Image($r('app.media.ic_public_input_search')) - .margin({ left: 10 }) - .size({ width: 16, height: 16 }) - .fillColor($r('app.color.light_fg_shallow')) - Text() // TODO: 添加滚动热搜词条 + Button() { + Row() { + Image($r('app.media.ic_public_input_search')) + .margin({ left: 10 }) + .size({ width: 16, height: 16 }) + .fillColor($r('app.color.light_fg_shallow')) + Text() // TODO: 添加滚动热搜词条 + } + .width('100%') + .height('100%') + .borderRadius(999) + .backgroundColor($r('app.color.primary_fg')) } .width(0) - .height('100%') .flexGrow(1) - .borderRadius(999) - .backgroundColor($r('app.color.primary_fg')) - .onClick(() => { + .commonBtnStyle(() => { // 将搜索页压入页面栈 router.pushUrl({ url: 'view/SearchPage' }) }) /* 右侧发布按钮 */ - Column() { - Image($r("app.media.ic_public_add_norm_filled")) - .size({ width: 20, height: 20 }) - .fillColor($r("app.color.primary_fg")) - Text('发布').fontSize(9).fontColor($r("app.color.primary_fg")) + Button() { + Column() { + Image($r('app.media.ic_public_add_norm_filled')) + .size({ width: 20, height: 20 }) + .fillColor($r('app.color.primary_fg')) + Text('发布').fontSize(9).fontColor($r('app.color.primary_fg')) + } + .height('90%') + .margin({ left: 4, right: 4 }) + .justifyContent(FlexAlign.SpaceBetween) } - .height('90%') - .margin({ left: 4, right: 4 }) - .justifyContent(FlexAlign.SpaceBetween) - .onClick(() => { + .commonBtnStyle(() => { // 将发布页压入页面栈 router.pushUrl({ url: 'view/PublishPage' }) }) @@ -154,7 +171,7 @@ struct TopBar { .padding({ top: 18, bottom: 6, left: 10, right: 10 }) .alignItems(VerticalAlign.Bottom) .justifyContent(FlexAlign.SpaceBetween) - .backgroundColor($r("app.color.primary")) + .backgroundColor($r('app.color.primary')) } } @@ -164,6 +181,8 @@ struct TopBar { */ @Component struct TabSelector { + @State handleFilterBtnClk: boolean = false + @State handleEarphoneBtnClk: boolean = false @Link curIdx: number private scroller: Scroller = new Scroller() @@ -174,24 +193,26 @@ struct TabSelector { /* 可左右滑动的选项卡栏 */ Row({ space: 3 }) { ForEach(tabItemList, (item: string, itemIdx: number) => { - Column({ space: 4 }) { - Text(item) - .fontSize(14) - .fontWeight(this.curIdx === itemIdx ? FontWeight.Bold : FontWeight.Normal) - .fontColor(this.curIdx === itemIdx ? $r('app.color.primary') : $r('app.color.light_fg')) - - /* 文字下方线条 */ - Line() - .startPoint([0, 0]) - .endPoint([16, 0]) - .stroke(this.curIdx === itemIdx ? $r('app.color.primary') : Color.Transparent) - .strokeLineCap(LineCapStyle.Round) - .strokeWidth(2) + Button() { + Column({ space: 4 }) { + /* 选项卡文字 */ + Text(item) + .fontSize(14) + .fontWeight(this.curIdx === itemIdx ? FontWeight.Bold : FontWeight.Normal) + .fontColor(this.curIdx === itemIdx ? $r('app.color.primary') : $r('app.color.light_fg')) + /* 文字下方线条 */ + Line() + .startPoint([0, 0]) + .endPoint([16, 0]) + .stroke(this.curIdx === itemIdx ? $r('app.color.primary') : Color.Transparent) + .strokeLineCap(LineCapStyle.Round) + .strokeWidth(2) + } + .height('100%') + .padding({ left: 14, bottom: 1 }) + .justifyContent(FlexAlign.End) } - .height('100%') - .padding({ left: 14, bottom: 1 }) - .justifyContent(FlexAlign.End) - .onClick(() => { + .commonBtnStyle(() => { this.curIdx = itemIdx }) }) @@ -217,12 +238,20 @@ struct TabSelector { .flexGrow(1) .alignContent(Alignment.End) - /* 右侧的按钮 */ Row({ space: 8 }) { - Image($r("app.media.ic_public_view_list")) - .size({ width: 14, height: 14 }) - .fillColor($r('app.color.light_fg')) + Button() { + Image($r('app.media.ic_public_view_list')) + .size({ width: 14, height: 14 }) + .fillColor($r('app.color.light_fg')) + } + .commonBtnStyle(() => { + this.handleFilterBtnClk = false + this.handleFilterBtnClk = true + }) + .bindPopup(this.handleFilterBtnClk, { + message: 'TODO: 按钮点击事件处理' + }) Divider() .strokeWidth(2) @@ -230,9 +259,18 @@ struct TabSelector { .vertical(true) .color($r('app.color.light_border')) - Image($r("app.media.ic_device_earphone")) - .size({ width: 14, height: 14 }) - .fillColor($r('app.color.light_fg')) + Button() { + Image($r('app.media.ic_device_earphone')) + .size({ width: 14, height: 14 }) + .fillColor($r('app.color.light_fg')) + } + .commonBtnStyle(() => { + this.handleEarphoneBtnClk = false + this.handleEarphoneBtnClk = true + }) + .bindPopup(this.handleEarphoneBtnClk, { + message: 'TODO: 按钮点击事件处理' + }) } .height('100%') .padding({ left: 4, right: 14 }) diff --git a/scenario/arkui/MyNews/entry/src/main/ets/viewmodel/IndexBottomNavItem.ets b/scenario/arkui/MyNews/entry/src/main/ets/viewmodel/IndexBottomNavItem.ets index f0ddf5a4..4f1388ff 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/viewmodel/IndexBottomNavItem.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/viewmodel/IndexBottomNavItem.ets @@ -15,14 +15,15 @@ /** - * Type definition for the items in the bottom navigation bar. - * 应用底部导航栏中项的类型定义。 + * 应用底部导航栏中项的类型定义 */ export interface IndexBottomNavItem { - /* Text under the icon. */ + /* 图标下方文字 */ title: string - /* Display outlined icons when not clicked. */ + /* 未被选中时显示为轮廓型图标 */ normalIcon: Resource - /* Display filled icons after clicked. */ + /* 被选中时替换为填充型图标 */ selectedIcon: Resource + /* 对应的按钮id(测试用例中使用) */ + btnId: string } -- Gitee From f931912b3f08d93dffc3fd9e92a841a3b4c5c276 Mon Sep 17 00:00:00 2001 From: GuangweiLi <213203228@seu.edu.cn> Date: Wed, 6 Mar 2024 18:00:23 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0UI=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GuangweiLi <213203228@seu.edu.cn> --- .../src/ohosTest/ets/test/Ability.test.ets | 77 +++++++++++++++++-- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Ability.test.ets b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Ability.test.ets index f974452c..77db4fa9 100644 --- a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Ability.test.ets @@ -16,6 +16,25 @@ import hilog from '@ohos.hilog'; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { Driver, ON } from '@ohos.UiTest'; +import Want from '@ohos.app.ability.Want'; + + +const TAG = '[Scenario_MyNews_ActsAbilityTest]' +const DOMAIN = 0xF811 +const BUNDLE = 'MyApp_' + +let delegator = abilityDelegatorRegistry.getAbilityDelegator() +let driver = Driver.create() + +/* 通过id验证按钮是否存在,若存在则执行一次点击操作,返回按钮对象供后续操作 */ +const checkBtnIdAndClk = async (btnId: string) => { + await driver.assertComponentExist(ON.id(btnId)) + let btn = await driver.findComponent(ON.id(btnId)) + await btn.click() + await driver.delayMs(1000) +} export default function abilityTest() { describe('ActsAbilityTest', () => { @@ -38,14 +57,56 @@ export default function abilityTest() { // 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, () => { - // 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'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); + + /** + * 拉起应用 + */ + it('StartAbility_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin') + const want: Want = { + bundleName: 'com.samples.mynews', + abilityName: 'EntryAbility' + } + try { + await delegator.startAbility(want) + await driver.delayMs(1000) + done() + } catch (exception) { + hilog.info(DOMAIN, TAG, BUNDLE + `StartAbility_001 exception = ${JSON.stringify(exception)}`) + expect().assertFail() + done() + } + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end') + }) + + /** + * 底部导航栏按钮功能测试 + */ + it('IndexNavBtnFunction_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'IndexNavBtnFunction_001 begin') + /* 等待进入应用 */ + await driver.delayMs(1000) + + /* 从右到左,依次测试底部导航栏按钮功能 */ + const btnIdList: string[] = [ + 'indexProfilePageBtn', // `个人` + 'indexMallPageBtn', // `商城` + 'indexTaskPageBtn', // `任务` + 'indexVideoPageBtn', // `视频` + 'indexHomePageBtn' // `首页` + ] + for (let i = btnIdList.length - 1; i >= 0; i--) { + try { + await checkBtnIdAndClk(btnIdList[i]) + // TODO: 检测图标变化、颜色变化、页面元素 + + } catch (exception) { + hilog.info(DOMAIN, TAG, BUNDLE + `IndexNavBtnFunction_001 exception = ${JSON.stringify(exception)}`) + expect().assertFail() + done() + } + } + hilog.info(DOMAIN, TAG, BUNDLE + 'IndexNavBtnFunction_001 end') }) }) } \ No newline at end of file -- Gitee From 50ef6615cc409ec38ac2cf0f8f8007178bd09227 Mon Sep 17 00:00:00 2001 From: GuangweiLi <213203228@seu.edu.cn> Date: Thu, 7 Mar 2024 10:52:14 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=B8=BA=E6=AF=8F=E4=B8=AA=E4=B8=80?= =?UTF-8?q?=E7=BA=A7=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0id=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=B5=8B=E8=AF=95=E5=BA=95=E9=83=A8=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E6=A0=8F=E8=B7=B3=E8=BD=AC=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GuangweiLi <213203228@seu.edu.cn> --- scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets | 2 ++ scenario/arkui/MyNews/entry/src/main/ets/view/MallPage.ets | 1 + scenario/arkui/MyNews/entry/src/main/ets/view/ProfilePage.ets | 1 + scenario/arkui/MyNews/entry/src/main/ets/view/TaskPage.ets | 1 + scenario/arkui/MyNews/entry/src/main/ets/view/VideoPage.ets | 1 + 5 files changed, 6 insertions(+) diff --git a/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets b/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets index 528cce5d..33b075b1 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets @@ -28,6 +28,7 @@ function commonBtnStyle(handler?: (event: ClickEvent) => void) { .onClick(handler) } + /** * 上部选项卡内容 */ @@ -84,6 +85,7 @@ export struct HomePage { .height(0) .flexGrow(1) } + .id('homePage') .width('100%') .height('100%') } diff --git a/scenario/arkui/MyNews/entry/src/main/ets/view/MallPage.ets b/scenario/arkui/MyNews/entry/src/main/ets/view/MallPage.ets index a9567d23..6751dfd2 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/view/MallPage.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/view/MallPage.ets @@ -20,4 +20,5 @@ export function MallPageBuilder() { Column() { Text('商城页面内容') } + .id('mallPage') } diff --git a/scenario/arkui/MyNews/entry/src/main/ets/view/ProfilePage.ets b/scenario/arkui/MyNews/entry/src/main/ets/view/ProfilePage.ets index dc4acadf..43a409e9 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/view/ProfilePage.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/view/ProfilePage.ets @@ -20,4 +20,5 @@ export function ProfilePageBuilder() { Column() { Text('个人页面内容') } + .id('profilePage') } diff --git a/scenario/arkui/MyNews/entry/src/main/ets/view/TaskPage.ets b/scenario/arkui/MyNews/entry/src/main/ets/view/TaskPage.ets index b08b8625..6b922995 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/view/TaskPage.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/view/TaskPage.ets @@ -20,4 +20,5 @@ export function TaskPageBuilder() { Column() { Text('任务页面内容') } + .id('taskPage') } diff --git a/scenario/arkui/MyNews/entry/src/main/ets/view/VideoPage.ets b/scenario/arkui/MyNews/entry/src/main/ets/view/VideoPage.ets index 26bfefc1..a9ed5128 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/view/VideoPage.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/view/VideoPage.ets @@ -20,4 +20,5 @@ export function VideoPageBuilder() { Column() { Text('视频页面内容') } + .id('videoPage') } -- Gitee From d0adca394b45877f2915ab75a0a665376f5b28b7 Mon Sep 17 00:00:00 2001 From: GuangweiLi <213203228@seu.edu.cn> Date: Thu, 7 Mar 2024 10:53:08 +0800 Subject: [PATCH 04/10] =?UTF-8?q?UI=E6=B5=8B=E8=AF=95=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BA=95=E9=83=A8=E5=AF=BC=E8=88=AA=E6=A0=8F=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E5=8A=9F=E8=83=BD=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GuangweiLi <213203228@seu.edu.cn> --- .../src/ohosTest/ets/test/Ability.test.ets | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Ability.test.ets b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Ability.test.ets index 77db4fa9..892c12f1 100644 --- a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Ability.test.ets @@ -88,25 +88,27 @@ export default function abilityTest() { await driver.delayMs(1000) /* 从右到左,依次测试底部导航栏按钮功能 */ - const btnIdList: string[] = [ - 'indexProfilePageBtn', // `个人` - 'indexMallPageBtn', // `商城` - 'indexTaskPageBtn', // `任务` - 'indexVideoPageBtn', // `视频` - 'indexHomePageBtn' // `首页` + const btnIdList: string[][] = [ + ['indexProfilePageBtn', 'profilePage'], // `个人` + ['indexMallPageBtn', 'mallPage'], // `商城` + ['indexTaskPageBtn', 'taskPage'], // `任务` + ['indexVideoPageBtn', 'videoPage'], // `视频` + ['indexHomePageBtn', 'homePage'] // `首页` ] - for (let i = btnIdList.length - 1; i >= 0; i--) { - try { - await checkBtnIdAndClk(btnIdList[i]) - // TODO: 检测图标变化、颜色变化、页面元素 - - } catch (exception) { - hilog.info(DOMAIN, TAG, BUNDLE + `IndexNavBtnFunction_001 exception = ${JSON.stringify(exception)}`) - expect().assertFail() - done() + try { + for (let i = 0; i < btnIdList.length; i++) { + await checkBtnIdAndClk(btnIdList[i][0]) // 检查按钮是否存在并点击 + hilog.info(DOMAIN, TAG, BUNDLE + `IndexNavBtnFunction_001 button ${btnIdList[i][0]} is found and clicked`) + await driver.assertComponentExist(ON.id(btnIdList[i][1])) // 检查所跳转的页面内容是否匹配 + hilog.info(DOMAIN, TAG, BUNDLE + `IndexNavBtnFunction_001 button ${btnIdList[i][0]} function tst passed`) } + done() + } catch (exception) { + hilog.info(DOMAIN, TAG, BUNDLE + `IndexNavBtnFunction_001 exception = ${JSON.stringify(exception)}`) + expect().assertFail() + done() } hilog.info(DOMAIN, TAG, BUNDLE + 'IndexNavBtnFunction_001 end') }) }) -} \ No newline at end of file +} -- Gitee From 81dcf69461daf949640caac711f283666e126633 Mon Sep 17 00:00:00 2001 From: GuangweiLi <213203228@seu.edu.cn> Date: Thu, 7 Mar 2024 11:20:44 +0800 Subject: [PATCH 05/10] =?UTF-8?q?abilityTest=E6=8B=86=E5=88=86=E4=B8=BA?= =?UTF-8?q?=E5=85=B7=E4=BD=93=E7=9A=84indexTest=E5=8F=8A=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GuangweiLi <213203228@seu.edu.cn> --- .../test/{Ability.test.ets => Index.test.ets} | 26 +++---------------- .../entry/src/ohosTest/ets/test/List.test.ets | 5 ++-- 2 files changed, 6 insertions(+), 25 deletions(-) rename scenario/arkui/MyNews/entry/src/ohosTest/ets/test/{Ability.test.ets => Index.test.ets} (73%) diff --git a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Ability.test.ets b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Index.test.ets similarity index 73% rename from scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Ability.test.ets rename to scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Index.test.ets index 892c12f1..a9582471 100644 --- a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Index.test.ets @@ -15,7 +15,7 @@ import hilog from '@ohos.hilog'; -import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium'; +import { describe, expect, it } from '@ohos/hypium'; import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; import { Driver, ON } from '@ohos.UiTest'; import Want from '@ohos.app.ability.Want'; @@ -36,28 +36,8 @@ const checkBtnIdAndClk = async (btnId: string) => { await driver.delayMs(1000) } -export default function abilityTest() { - describe('ActsAbilityTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite 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(() => { - // 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(() => { - // 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(() => { - // 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. - }) - +export default function indexTest() { + describe('IndexTest', () => { /** * 拉起应用 */ diff --git a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/List.test.ets b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/List.test.ets index e59c8e47..c59d04aa 100644 --- a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/List.test.ets +++ b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/List.test.ets @@ -14,8 +14,9 @@ */ -import abilityTest from './Ability.test'; +import indexTest from './Index.test' + export default function testsuite() { - abilityTest(); + indexTest() } \ No newline at end of file -- Gitee From 3224d9e1d506aea3e4b116f5af3ff2c5ac3b4c78 Mon Sep 17 00:00:00 2001 From: GuangweiLi <213203228@seu.edu.cn> Date: Thu, 7 Mar 2024 11:42:55 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E9=A1=B5=E3=80=81=E5=8F=91=E5=B8=83=E9=A1=B5=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E7=BB=93=E6=9E=84=EF=BC=88=E5=BA=94=E4=B8=8EIndex=E5=90=8C?= =?UTF-8?q?=E7=BA=A7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GuangweiLi <213203228@seu.edu.cn> --- .../MyNews/entry/src/main/ets/{view => pages}/PublishPage.ets | 1 + .../MyNews/entry/src/main/ets/{view => pages}/SearchPage.ets | 3 ++- .../entry/src/main/resources/base/profile/main_pages.json | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) rename scenario/arkui/MyNews/entry/src/main/ets/{view => pages}/PublishPage.ets (99%) rename scenario/arkui/MyNews/entry/src/main/ets/{view => pages}/SearchPage.ets (99%) diff --git a/scenario/arkui/MyNews/entry/src/main/ets/view/PublishPage.ets b/scenario/arkui/MyNews/entry/src/main/ets/pages/PublishPage.ets similarity index 99% rename from scenario/arkui/MyNews/entry/src/main/ets/view/PublishPage.ets rename to scenario/arkui/MyNews/entry/src/main/ets/pages/PublishPage.ets index 4fd06376..bb833742 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/view/PublishPage.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/pages/PublishPage.ets @@ -58,6 +58,7 @@ struct PublishPage { .tabBar(this.TabBuilder(item, itemIndex)) }) } + .id('publishPage') .width('100%') .height('100%') .barHeight(64) diff --git a/scenario/arkui/MyNews/entry/src/main/ets/view/SearchPage.ets b/scenario/arkui/MyNews/entry/src/main/ets/pages/SearchPage.ets similarity index 99% rename from scenario/arkui/MyNews/entry/src/main/ets/view/SearchPage.ets rename to scenario/arkui/MyNews/entry/src/main/ets/pages/SearchPage.ets index 3002c7d2..8feed165 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/view/SearchPage.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/pages/SearchPage.ets @@ -29,6 +29,7 @@ const tabItemList: string[] = [ '品牌榜' ] + /** * `搜索` 页面内容。 */ @@ -36,7 +37,6 @@ const tabItemList: string[] = [ @Component export struct SearchPage { @State isPrivacyModeOn: boolean = false - private scroller: Scroller = new Scroller() build() { Column() { @@ -105,6 +105,7 @@ export struct SearchPage { /* 无痕搜索模式开关栏 */ PrivacyModeToggleBar({ isPrivacyModeOn: this.isPrivacyModeOn }) } + .id('searchPage') .width('100%') .height('100%') .justifyContent(FlexAlign.SpaceBetween) diff --git a/scenario/arkui/MyNews/entry/src/main/resources/base/profile/main_pages.json b/scenario/arkui/MyNews/entry/src/main/resources/base/profile/main_pages.json index 6dce140e..64148a78 100644 --- a/scenario/arkui/MyNews/entry/src/main/resources/base/profile/main_pages.json +++ b/scenario/arkui/MyNews/entry/src/main/resources/base/profile/main_pages.json @@ -1,7 +1,7 @@ { "src": [ "pages/Index", - "view/PublishPage", - "view/SearchPage" + "pages/PublishPage", + "pages/SearchPage" ] } \ No newline at end of file -- Gitee From bbbf60ae32e705eaa38a5e769eb19eb78655bfb3 Mon Sep 17 00:00:00 2001 From: GuangweiLi <213203228@seu.edu.cn> Date: Thu, 7 Mar 2024 14:52:19 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E4=B8=BA=E5=8F=91=E5=B8=83=E9=A1=B5?= =?UTF-8?q?=E3=80=81=E6=90=9C=E7=B4=A2=E9=A1=B5=E6=B7=BB=E5=8A=A0=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=8C=89=E9=92=AEID=EF=BC=8C=E7=94=A8=E4=BA=8EUI?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GuangweiLi <213203228@seu.edu.cn> --- .../entry/src/main/ets/pages/PublishPage.ets | 28 +++++++++--- .../entry/src/main/ets/pages/SearchPage.ets | 44 +++++++++++++------ 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/scenario/arkui/MyNews/entry/src/main/ets/pages/PublishPage.ets b/scenario/arkui/MyNews/entry/src/main/ets/pages/PublishPage.ets index bb833742..34aa8af7 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/pages/PublishPage.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/pages/PublishPage.ets @@ -17,6 +17,16 @@ import router from '@ohos.router'; +/* 定义通用无底色、无按压效果按钮样式 */ +@Extend(Button) +function commonBtnStyle(handler?: (event: ClickEvent) => void) { + .type(ButtonType.Normal) + .stateEffect(false) + .backgroundColor(Color.Transparent) + .onClick(handler) +} + + /** * All the items in the bottom tab bar. * 页面底部所有选项卡。 @@ -105,13 +115,17 @@ struct Article { Column() { /* Tool bar. */ Row() { - Text('取消') - .margin({ left: 20 }) - .fontSize(18) - .fontColor($r('app.color.light_fg')) - .onClick(() => { - router.back() - }) + Button() { + Text('取消') + .margin({ left: 20 }) + .fontSize(18) + .fontColor($r('app.color.light_fg')) + } + .id('publishPageReturnBtn') + .commonBtnStyle(() => { + router.back() + }) + Row({ space: 20 }) { Text('预览') .fontSize(18) diff --git a/scenario/arkui/MyNews/entry/src/main/ets/pages/SearchPage.ets b/scenario/arkui/MyNews/entry/src/main/ets/pages/SearchPage.ets index 8feed165..4f7bb708 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/pages/SearchPage.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/pages/SearchPage.ets @@ -19,6 +19,16 @@ import { HotBoardClass, HotBoardItem } from '../viewmodel/HotBoard'; import { HotBoardItemList } from '../../mock/HotBoardData'; +/* 定义通用无底色、无按压效果按钮样式 */ +@Extend(Button) +function commonBtnStyle(handler?: (event: ClickEvent) => void) { + .type(ButtonType.Normal) + .stateEffect(false) + .backgroundColor(Color.Transparent) + .onClick(handler) +} + + /** * 中部选项卡内容 */ @@ -126,12 +136,16 @@ struct TopBar { build() { Row() { /* 返回按钮 */ - Image($r('app.media.ic_public_arrow_left')) - .size({ width: 30, height: 30 }) - .fillColor($r('app.color.light_fg')) - .onClick(() => { - router.back() - }) + Button() { + Image($r('app.media.ic_public_arrow_left')) + .size({ width: 30, height: 30 }) + .fillColor($r('app.color.light_fg')) + } + .id('searchPageReturnBtn') + .commonBtnStyle(() => { + router.back() + }) + /* 搜索框 */ Search({ placeholder: '示例热搜词条' }) .width(0) @@ -141,14 +155,18 @@ struct TopBar { .placeholderFont({ size: 13 }) .borderRadius(999) .backgroundColor($r('app.color.index_tab_bg')) + /* 搜索按钮 */ - Text('搜索') - .margin({ left: 10 }) - .fontSize(14) - .fontColor($r('app.color.primary')) - .onClick(() => { - // TODO: 用户输入内容->搜索该内容 or 无输入->搜索当前词条 - }) + Button() { + Text('搜索') + .margin({ left: 10 }) + .fontSize(14) + .fontColor($r('app.color.primary')) + } + .id('searchPageSearchBtn') + .commonBtnStyle(() => { + // TODO: 用户输入内容->搜索该内容 or 无输入->搜索当前词条 + }) } .width('100%') .height(60) -- Gitee From 981208efbb094f3ac417f8d8a09beaf020fd6e0b Mon Sep 17 00:00:00 2001 From: GuangweiLi <213203228@seu.edu.cn> Date: Thu, 7 Mar 2024 14:53:09 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E3=80=81=E5=8F=98=E9=87=8F=E5=91=BD=E5=90=8D=EF=BC=9B=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BB=84=E4=BB=B6ID=EF=BC=8C=E7=94=A8=E4=BA=8EUI?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GuangweiLi <213203228@seu.edu.cn> --- .../MyNews/entry/src/main/ets/pages/Index.ets | 10 ++++----- .../entry/src/main/ets/view/HomePage.ets | 21 +++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/scenario/arkui/MyNews/entry/src/main/ets/pages/Index.ets b/scenario/arkui/MyNews/entry/src/main/ets/pages/Index.ets index 4c949dd3..17aff0a7 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/pages/Index.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/pages/Index.ets @@ -68,7 +68,7 @@ const bottomNavItemList: IndexBottomNavItem[] = [{ @Entry @Component struct Index { - @State currentIndex: number = 0 + @State curNavIdx: number = 0 private tabsController: TabsController = new TabsController() build() { @@ -122,12 +122,12 @@ struct Index { Button() { Column() { // 当被选中时变色,图标变为填充型 - Image(this.currentIndex === targetIndex ? selectedIcon : normalIcon) + Image(this.curNavIdx === targetIndex ? selectedIcon : normalIcon) .size({ width: 20, height: 20 }) - .fillColor(this.currentIndex === targetIndex ? $r('app.color.primary') : $r('app.color.light_fg')) + .fillColor(this.curNavIdx === targetIndex ? $r('app.color.primary') : $r('app.color.light_fg')) Text(title) .fontSize(8) - .fontColor(this.currentIndex === targetIndex ? $r('app.color.primary') : $r('app.color.light_fg')) + .fontColor(this.curNavIdx === targetIndex ? $r('app.color.primary') : $r('app.color.light_fg')) } .width('100%') .height('100%') @@ -136,7 +136,7 @@ struct Index { .id(btnId) .commonBtnStyle(() => { this.tabsController.changeIndex(targetIndex) - this.currentIndex = targetIndex + this.curNavIdx = targetIndex }) } diff --git a/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets b/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets index 33b075b1..bf674106 100644 --- a/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets +++ b/scenario/arkui/MyNews/entry/src/main/ets/view/HomePage.ets @@ -56,7 +56,7 @@ const tabItemList: string[] = [ */ @Component export struct HomePage { - @State currentTabIndex: number = 1 + @State curTabIdx: number = 1 build() { Column() { @@ -64,21 +64,21 @@ export struct HomePage { TopBar() /* 可左右滑动的选项卡+按钮 */ - TabSelector({ curIdx: this.currentTabIndex }) + TabSelector({ curIdx: this.curTabIdx }) Divider().strokeWidth(1).color($r('app.color.light_border')) /* 下方页面内容 */ Column() { - if (this.currentTabIndex === 0) { + if (this.curTabIdx === 0) { FollowingTabContent() // 默认显示推荐页 } - else if (this.currentTabIndex === 1) { + else if (this.curTabIdx === 1) { RecommendationTabContent() } // TODO: 添加其他选项卡对应的页面 else { - Text(this.currentTabIndex.toString()) + Text(this.curTabIdx.toString()) } } .width('100%') @@ -98,11 +98,10 @@ export struct HomePage { @Component struct TopBar { @State handleLeftBtnClk: boolean = false - @State curSearchTermIdx: number = 0 build() { Row({ space: 4 }) { - /* 左侧按钮 */ + /* 左侧奖励按钮 */ Button() { Stack() { Image($r('app.media.ic_public_appstore_filled')) @@ -121,6 +120,7 @@ struct TopBar { .height('100%') .align(Alignment.Bottom) } + .id('homePageTopBarRewardBtn') .commonBtnStyle(() => { // TODO: 按钮点击事件处理 this.handleLeftBtnClk = false @@ -144,11 +144,12 @@ struct TopBar { .borderRadius(999) .backgroundColor($r('app.color.primary_fg')) } + .id('homePageTopBarSearchBox') .width(0) .flexGrow(1) .commonBtnStyle(() => { // 将搜索页压入页面栈 - router.pushUrl({ url: 'view/SearchPage' }) + router.pushUrl({ url: 'pages/SearchPage' }) }) /* 右侧发布按钮 */ @@ -163,9 +164,10 @@ struct TopBar { .margin({ left: 4, right: 4 }) .justifyContent(FlexAlign.SpaceBetween) } + .id('homePageTopBarPublishBtn') .commonBtnStyle(() => { // 将发布页压入页面栈 - router.pushUrl({ url: 'view/PublishPage' }) + router.pushUrl({ url: 'pages/PublishPage' }) }) } .width('100%') @@ -221,6 +223,7 @@ struct TabSelector { } .height('100%') } + .id('homePageTabSelector') .width('100%') .height('100%') .scrollable(ScrollDirection.Horizontal) -- Gitee From 78b2a46b9de29d276127a627208eccc54d017388 Mon Sep 17 00:00:00 2001 From: GuangweiLi <213203228@seu.edu.cn> Date: Thu, 7 Mar 2024 14:53:49 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E5=AE=8C=E5=96=84indexTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GuangweiLi <213203228@seu.edu.cn> --- .../src/ohosTest/ets/test/Index.test.ets | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Index.test.ets b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Index.test.ets index a9582471..e340d7be 100644 --- a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Index.test.ets +++ b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/Index.test.ets @@ -17,21 +17,21 @@ import hilog from '@ohos.hilog'; import { describe, expect, it } from '@ohos/hypium'; import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import { Driver, ON } from '@ohos.UiTest'; +import { Component, Driver, ON } from '@ohos.UiTest'; import Want from '@ohos.app.ability.Want'; -const TAG = '[Scenario_MyNews_ActsAbilityTest]' -const DOMAIN = 0xF811 -const BUNDLE = 'MyApp_' +const TAG: string = '[Scenario_MyNews_IndexTest]' +const DOMAIN: number = 0xF811 +const BUNDLE: string = 'MyNews_' -let delegator = abilityDelegatorRegistry.getAbilityDelegator() -let driver = Driver.create() +let delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator() +let driver: Driver = Driver.create() /* 通过id验证按钮是否存在,若存在则执行一次点击操作,返回按钮对象供后续操作 */ -const checkBtnIdAndClk = async (btnId: string) => { - await driver.assertComponentExist(ON.id(btnId)) - let btn = await driver.findComponent(ON.id(btnId)) +const checkBtnIdAndClk = async (btnId: string): Promise => { + await driver.assertComponentExist(ON.type('Button').id(btnId)) + let btn: Component = await driver.findComponent(ON.type('Button').id(btnId)) await btn.click() await driver.delayMs(1000) } @@ -64,23 +64,21 @@ export default function indexTest() { */ it('IndexNavBtnFunction_001', 0, async (done: Function) => { hilog.info(DOMAIN, TAG, BUNDLE + 'IndexNavBtnFunction_001 begin') - /* 等待进入应用 */ - await driver.delayMs(1000) - /* 从右到左,依次测试底部导航栏按钮功能 */ - const btnIdList: string[][] = [ + // [0]: 待查找、点击的按钮ID;[1]: 点击后用于判断按钮功能是否正常的组件ID + const btnList: string[][] = [ ['indexProfilePageBtn', 'profilePage'], // `个人` ['indexMallPageBtn', 'mallPage'], // `商城` ['indexTaskPageBtn', 'taskPage'], // `任务` ['indexVideoPageBtn', 'videoPage'], // `视频` - ['indexHomePageBtn', 'homePage'] // `首页` + ['indexHomePageBtn', 'homePage']// `首页` ] try { - for (let i = 0; i < btnIdList.length; i++) { - await checkBtnIdAndClk(btnIdList[i][0]) // 检查按钮是否存在并点击 - hilog.info(DOMAIN, TAG, BUNDLE + `IndexNavBtnFunction_001 button ${btnIdList[i][0]} is found and clicked`) - await driver.assertComponentExist(ON.id(btnIdList[i][1])) // 检查所跳转的页面内容是否匹配 - hilog.info(DOMAIN, TAG, BUNDLE + `IndexNavBtnFunction_001 button ${btnIdList[i][0]} function tst passed`) + for (let i = 0; i < btnList.length; i++) { + await checkBtnIdAndClk(btnList[i][0]) // 检查按钮是否存在并点击 + hilog.info(DOMAIN, TAG, BUNDLE + `IndexNavBtnFunction_001 button ${btnList[i][0]} is found and clicked`) + await driver.assertComponentExist(ON.id(btnList[i][1])) // 检查所跳转的页面内容是否匹配 + hilog.info(DOMAIN, TAG, BUNDLE + `IndexNavBtnFunction_001 button ${btnList[i][0]} function test passed`) } done() } catch (exception) { -- Gitee From a8c262f80983cb26eb01a3275cb86c4366c0f146 Mon Sep 17 00:00:00 2001 From: GuangweiLi <213203228@seu.edu.cn> Date: Thu, 7 Mar 2024 14:54:57 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A6=96=E9=A1=B5UI?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=8C=E5=B7=B2=E5=AE=8C=E6=88=90=E9=A1=B6?= =?UTF-8?q?=E6=A0=8F=E3=80=81=E9=80=89=E9=A1=B9=E5=8D=A1=E6=A0=8F=EF=BC=88?= =?UTF-8?q?=E9=83=A8=E5=88=86=EF=BC=89=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GuangweiLi <213203228@seu.edu.cn> --- .../src/ohosTest/ets/test/HomePage.test.ets | 134 ++++++++++++++++++ .../entry/src/ohosTest/ets/test/List.test.ets | 2 + 2 files changed, 136 insertions(+) create mode 100644 scenario/arkui/MyNews/entry/src/ohosTest/ets/test/HomePage.test.ets diff --git a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/HomePage.test.ets b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/HomePage.test.ets new file mode 100644 index 00000000..5d8e20dd --- /dev/null +++ b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/HomePage.test.ets @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2023 Southeast University. + * 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 hilog from '@ohos.hilog'; +import { describe, expect, it } from '@ohos/hypium'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import { Component, Driver, ON } from '@ohos.UiTest'; +import Want from '@ohos.app.ability.Want'; + +const TAG: string = '[Scenario_MyNews_HomePageTest]' +const DOMAIN: number = 0xF811 +const BUNDLE: string = 'MyNews_' + +let delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator() +let driver: Driver = Driver.create() + +/* 通过id验证按钮是否存在,若存在则执行一次点击操作,返回按钮对象供后续操作 */ +const checkBtnIdAndClk = async (btnId: string): Promise => { + await driver.assertComponentExist(ON.type('Button').id(btnId)) + let btn: Component = await driver.findComponent(ON.type('Button').id(btnId)) + await btn.click() + await driver.delayMs(1000) +} + +export default function HomePageTest() { + describe('HomePageTest', () => { + /** + * 拉起应用,进入首页 + */ + it('StartAbility_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin') + const want: Want = { + bundleName: 'com.samples.mynews', + abilityName: 'EntryAbility' + } + try { + await delegator.startAbility(want) + await driver.delayMs(1000) + await checkBtnIdAndClk('indexHomePageBtn') + await driver.assertComponentExist(ON.id('homePage')) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 entered home page') + done() + } catch (exception) { + hilog.info(DOMAIN, TAG, BUNDLE + `StartAbility_001 exception = ${JSON.stringify(exception)}`) + expect().assertFail() + done() + } + hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end') + }) + + /** + * 顶栏按钮功能测试 + */ + it('HomePageTopBarBtnFunction_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'HomePageTopBarBtnFunction_001 begin') + /* 依次测试顶栏按钮功能 */ + // [0]:待查找、点击的按钮ID;[1]:点击后用于判断按钮功能是否正常的组件ID;[2]:返回首页的按钮ID + const btnList: string[][] = [ + // ['homePageTopBarRewardBtn', '', ''], // `阅读奖励`,暂未添加点击事件处理 + ['homePageTopBarSearchBox', 'searchPage', 'searchPageReturnBtn'], // `搜索框` + ['homePageTopBarPublishBtn', 'publishPage', 'publishPageReturnBtn']// `发布` + ] + try { + for (let i = 0; i < btnList.length; i++) { + await checkBtnIdAndClk(btnList[i][0]) // 检查按钮是否存在并点击 + hilog.info(DOMAIN, TAG, BUNDLE + `HomePageTopBarBtnFunction_001 button ${btnList[i][0]} is found and clicked`) + await driver.assertComponentExist(ON.id(btnList[i][1])) // 检查所跳转的页面内容是否匹配 + hilog.info(DOMAIN, TAG, BUNDLE + `HomePageTopBarBtnFunction_001 button ${btnList[i][0]} function test passed`) + await checkBtnIdAndClk(btnList[i][2]) // 返回首页 + } + done() + } catch (exception) { + hilog.info(DOMAIN, TAG, BUNDLE + `HomePageTopBarBtnFunction_001 exception = ${JSON.stringify(exception)}`) + expect().assertFail() + done() + } + hilog.info(DOMAIN, TAG, BUNDLE + 'HomePageTopBarBtnFunction_001 end') + }) + + /** + * 选项卡栏功能测试(是否正确加载及是否可滑动) + */ + it('HomePageTabSelectorFunction_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'HomePageTabSelectorFunction_001 begin') + /* 检查选项卡是否正确加载,测试左右滑动功能 */ + try { + await driver.assertComponentExist(ON.id('homePageTabSelector')) + let tabSelector = await driver.findComponent(ON.id('homePageTabSelector')) // 获取选项卡栏对象 + hilog.info(DOMAIN, TAG, BUNDLE + `HomePageTabSelectorFunction_001 tab selector is found`) + expect(await tabSelector.isScrollable()).assertTrue() // 检查是否可滑动(左右滑动没有提供API) + hilog.info(DOMAIN, TAG, BUNDLE + `HomePageTabSelectorFunction_001 tab selector is scrollable`) + done() + } catch (exception) { + hilog.info(DOMAIN, TAG, BUNDLE + `HomePageTabSelectorFunction_001 exception = ${JSON.stringify(exception)}`) + expect().assertFail() + done() + } + hilog.info(DOMAIN, TAG, BUNDLE + 'HomePageTabSelectorFunction_001 end') + }) + + /** + * 选项卡栏功能测试(页面切换功能) + */ + it('HomePageTabSelectorFunction_002', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'HomePageTabSelectorFunction_002 begin') + /* 检查选项卡是否正确加载,测试下方内容切换功能 */ + try { + await driver.assertComponentExist(ON.id('homePageTabSelector')) + let tabSelector = await driver.findComponent(ON.id('homePageTabSelector')) // 获取选项卡栏对象 + hilog.info(DOMAIN, TAG, BUNDLE + `HomePageTabSelectorFunction_002 tab selector is found`) + // TODO: 测试下方内容切换功能 + done() + } catch (exception) { + hilog.info(DOMAIN, TAG, BUNDLE + `HomePageTabSelectorFunction_002 exception = ${JSON.stringify(exception)}`) + expect().assertFail() + done() + } + hilog.info(DOMAIN, TAG, BUNDLE + 'HomePageTabSelectorFunction_002 end') + }) + }) +} diff --git a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/List.test.ets b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/List.test.ets index c59d04aa..b73bfd55 100644 --- a/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/List.test.ets +++ b/scenario/arkui/MyNews/entry/src/ohosTest/ets/test/List.test.ets @@ -1,3 +1,4 @@ +import HomePageTest from './HomePage.test' /* * Copyright (c) 2023 Southeast University. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,4 +20,5 @@ import indexTest from './Index.test' export default function testsuite() { indexTest() + HomePageTest() } \ No newline at end of file -- Gitee