From 33e91e15d4ef98125780113174c81924450b1163 Mon Sep 17 00:00:00 2001 From: shutao Date: Wed, 20 Sep 2023 17:10:12 +0800 Subject: [PATCH] =?UTF-8?q?scroll-view=E8=A1=A5=E5=85=85=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scroll-view/scroll-view-props.test.js | 85 +++++++++++++++++++ .../scroll-view/scroll-view-props.uvue | 34 ++++++-- 2 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 pages/component/scroll-view/scroll-view-props.test.js diff --git a/pages/component/scroll-view/scroll-view-props.test.js b/pages/component/scroll-view/scroll-view-props.test.js new file mode 100644 index 00000000..34990810 --- /dev/null +++ b/pages/component/scroll-view/scroll-view-props.test.js @@ -0,0 +1,85 @@ +// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ + +describe('component-native-scroll-view', () => { + + let page; + beforeAll(async () => { + page = await program.reLaunch('/pages/component/scroll-view/scroll-view-props'); + await page.waitFor(300); + }); + + //检测竖向可滚动区域 + it('check_scroll_height', async () => { + await page.setData({ + scrollX: false + }) + await page.waitFor(300); + const value = await page.callMethod('checkScrollHeight') + expect(value).toBe(true) + }) + + //检测竖向scrolltop属性赋值 + it('check_scroll_top', async () => { + await page.setData({ + scrollTop: 600 + }) + await page.waitFor(600) + const element = await page.$('#scrollViewY') + const scrollTop = await element.attribute("scrollTop") + console.log("check_scroll_top---"+scrollTop) + expect(scrollTop-600).toBeGreaterThanOrEqual(0) + }) + + //检测竖向scroll_into_view属性赋值 + it('check_scroll_into_view_top', async () => { + await page.setData({ + scrollIntoView: "item3" + }) + await page.waitFor(600) + const element = await page.$('#scrollViewY') + const scrollTop = await element.attribute("scrollTop") + console.log("check_scroll_into_view_top--"+scrollTop) + await page.setData({ + scrollIntoView: "" + }) + expect(scrollTop-690).toBeGreaterThanOrEqual(0) + }) + + //检测横向可滚动区域 + it('check_scroll_width', async () => { + await page.setData({ + scrollX: true + }) + await page.waitFor(300); + const value = await page.callMethod('checkScrollWidth') + expect(value).toBe(true) + }) + + //检测横向scrollLeft属性赋值 + it('check_scroll_left', async () => { + await page.setData({ + scrollLeft: 600 + }) + await page.waitFor(600) + const element = await page.$('#scrollViewX') + const scrollLeft = await element.attribute("scrollLeft") + console.log("check_scroll_left---"+scrollLeft) + expect(scrollLeft-600).toBeGreaterThanOrEqual(0) + }) + + //检测横向scroll_into_view属性赋值 + it('check_scroll_into_view_left', async () => { + await page.setData({ + scrollIntoView: "horizontal_item3" + }) + await page.waitFor(600) + const element = await page.$('#scrollViewX') + const scrollLeft = await element.attribute("scrollLeft") + console.log("check_scroll_into_view_left--"+scrollLeft) + await page.setData({ + scrollIntoView: "" + }) + expect(scrollLeft-1080).toBeGreaterThanOrEqual(0) + }) + +}); diff --git a/pages/component/scroll-view/scroll-view-props.uvue b/pages/component/scroll-view/scroll-view-props.uvue index 6ec4680e..9046f48f 100644 --- a/pages/component/scroll-view/scroll-view-props.uvue +++ b/pages/component/scroll-view/scroll-view-props.uvue @@ -5,11 +5,11 @@ - + @scrolltolower="scrolltolower" @scroll="scroll" @scrollend="scrollend" ref="scrollViewX" id="scrollViewX"> {{item.label}} @@ -18,7 +18,7 @@ :upper-threshold="upperThreshold" :lower-threshold="lowerThreshold" :scroll-into-view="scrollIntoView" :enable-back-to-top="enableBackToTop" :scroll-with-animation="scrollWithAnimation" :show-scrollbar="showScrollbar" :rebound="rebound" @scrolltoupper="scrolltoupper" - @scrolltolower="scrolltolower" @scroll="scroll" @scrollend="scrollend"> + @scrolltolower="scrolltolower" @scroll="scroll" @scrollend="scrollend" ref="scrollViewY" id="scrollViewY"> {{item.label}} @@ -161,7 +161,31 @@ }, scrollend() { console.log("滚动停止"); - } + }, + //自动化测试专用 + checkScrollHeight(): Boolean { + var element = this.$refs["scrollViewY"] + if(element != null) { + var scrollHeight = (element as Element).scrollHeight + console.log("checkScrollHeight"+scrollHeight) + if(scrollHeight > 1900) { + return true + } + } + return false + }, + //自动化测试专用 + checkScrollWidth(): Boolean { + var element = this.$refs["scrollViewX"] + if(element != null) { + var scrollWidth = (element as Element).scrollWidth + console.log("checkScrollWidth---"+scrollWidth) + if(scrollWidth > 1900) { + return true + } + } + return false + } } } @@ -206,4 +230,4 @@ padding: 30rpx; justify-content: center; } - \ No newline at end of file + -- GitLab