From 8a9a5c0769c1b2a5ccc9396e632831e0e0da242c Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Tue, 11 Jun 2024 20:45:38 +0800 Subject: [PATCH] =?UTF-8?q?test(pages):=20=E8=A1=A5=E5=85=85=E9=81=97?= =?UTF-8?q?=E6=BC=8F=E9=A1=B5=E9=9D=A2=E5=8F=8A=E6=9C=AA=E6=88=AA=E5=9B=BE?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/pages.test.js | 388 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 305 insertions(+), 83 deletions(-) diff --git a/pages/pages.test.js b/pages/pages.test.js index 1825192a..38ff592f 100755 --- a/pages/pages.test.js +++ b/pages/pages.test.js @@ -1,57 +1,192 @@ +const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() +const isAndroid = platformInfo.startsWith('android') +const isIos = platformInfo.startsWith('ios') +const isApp = isAndroid || isIos +const isWeb = platformInfo.startsWith('web') +const isAppWebview = !!process.env.UNI_AUTOMATOR_APP_WEBVIEW + let pageIndex = 0 const pages = [ + // tabBar //改动频繁,不再测试 + // '/pages/tabBar/component', + // '/pages/tabBar/API', + // '/pages/tabBar/CSS', + // '/pages/tabBar/template', + // component - '/pages/component/button/button', - '/pages/component/checkbox/checkbox', - '/pages/component/general-attribute/general-attribute', - '/pages/component/general-event/general-event', - '/pages/component/image/image-format', - // '/pages/component/image/image-large', // 截图过大 - // '/pages/component/image/image-mode', // 判断CPU类型,单独测试例截图 - // '/pages/component/image/image-path', // 网络资源加载,单独测试例截图 - '/pages/component/image/image', - // '/pages/component/input/input', // 自动获取焦点,单独测试例截图 - '/pages/component/list-view/list-view', - '/pages/component/scroll-view/scroll-view-custom-refresher-props', + '/pages/component/view/view', + // 单独测试例截图 + // 'pages/component/scroll-view/scroll-view', + // 单独测试例截图 + // '/pages/component/scroll-view/scroll-view-refresher', + // 单独测试例截图 + // '/pages/component/scroll-view/scroll-view-props', '/pages/component/scroll-view/scroll-view-refresher-props', - '/pages/component/navigator/navigate', - '/pages/component/navigator/navigator', - '/pages/component/navigator/redirect', - // '/pages/component/picker-view/picker-view', //动态内容 + '/pages/component/scroll-view/scroll-view-custom-refresher-props', + '/pages/component/swiper/swiper', + '/pages/component/list-view/list-view', + // 单独测试例截图 + // '/pages/component/list-view/list-view-refresh', + // 单独测试例截图 + // '/pages/component/list-view/list-view-multiplex', + '/pages/component/list-view/list-view-multiplex-input', + '/pages/component/list-view/list-view-multiplex-video', + '/pages/component/list-view/list-view-children-in-slot', + // 单独测试例截图 + // '/pages/component/sticky-section/sticky-section', + // 单独测试例截图 + // '/pages/component/sticky-header/sticky-header', + '/pages/component/text/text', + // 单独测试例截图 + // '/pages/component/text/text-props', + '/pages/component/rich-text/rich-text', + '/pages/component/rich-text/rich-text-tags', + '/pages/component/rich-text/rich-text-complex', '/pages/component/progress/progress', + '/pages/component/form/form', + '/pages/component/button/button', + '/pages/component/button/buttonstatus', '/pages/component/radio/radio', - '/pages/component/rich-text/rich-text-complex', - '/pages/component/rich-text/rich-text-tags', - '/pages/component/rich-text/rich-text', + '/pages/component/checkbox/checkbox', + // 自动获取焦点,单独测试例截图 + // '/pages/component/input/input', + '/pages/component/textarea/textarea', '/pages/component/slider/slider', + '/pages/component/slider/slider-in-swiper', + //动态内容 + // '/pages/component/picker-view/picker-view', '/pages/component/slider-100/slider-100', - '/pages/component/swiper/swiper', '/pages/component/switch/switch', - '/pages/component/text/text-props', - '/pages/component/text/text', - '/pages/component/textarea/textarea', - // '/pages/component/video/video', - '/pages/component/view/view', - // '/pages/component/web-view/web-view', // 动态内容 - // '/pages/component/web-view-local/web-view-local', // 依赖加载完成回调,单独测试例截图 + '/pages/component/image/image', + '/pages/component/image/image-format', + // 判断CPU类型,单独测试例截图 + // '/pages/component/image/image-mode', + // 网络资源加载,单独测试例截图 + // '/pages/component/image/image-path', + // 截图过大 + // '/pages/component/image/image-large', + '/pages/component/video/video', + '/pages/component/video/video-format', + '/pages/component/navigator/navigator', + '/pages/component/navigator/navigate', + '/pages/component/navigator/redirect', + // 动态内容 + // '/pages/component/web-view/web-view', + // 依赖加载完成回调,单独测试例截图 + // '/pages/component/web-view-local/web-view-local', + // 动态内容 + // '/pages/component/unicloud-db-contacts/list', + '/pages/component/unicloud-db-contacts/add', + // 动态内容 + // '/pages/component/unicloud-db-contacts/edit', + // 动态内容 + // '/pages/component/unicloud-db-contacts/detail', + '/pages/component/mixin-datacom/mixin-datacom', + // 单独测试例截图 + // '/pages/component/general-attribute/general-attribute', + '/pages/component/general-event/general-event', '/pages/component/general-event/transition-event', + '/pages/component/general-event/touch-event', + // 单独测试例截图 + // '/pages/component/nested-scroll-header/nested-scroll-header', + // 单独测试例截图 + // '/pages/component/nested-scroll-body/nested-scroll-body', + // 单独测试例截图 + // '/pages/component/swiper/swiper-list-view', + '/pages/component/list-view/list-view-refresh', + // 单独测试例截图 + // '/pages/component/list-view/issue-2199', + + // API + '/pages/API/get-app/get-app', + // 单独测试例截图 + // '/pages/API/get-current-pages/get-current-pages', + // 单独测试例截图 + // '/pages/API/get-current-pages/set-page-style-disable-pull-down-refresh', + '/pages/API/get-launch-options-sync/get-launch-options-sync', + '/pages/API/navigator/navigator', + // 单独测试例截图 + // '/pages/API/set-navigation-bar-color/set-navigation-bar-color', + // 单独测试例截图 + // '/pages/API/set-navigation-bar-title/set-navigation-bar-title', + // 单独测试例截图 + // '/pages/API/set-page-backgroundColorContent/set-page-backgroundColorContent', + // 单独测试例截图 + // '/pages/API/navigator/new-page/new-page-1', + '/pages/API/navigator/new-page/new-page-3', + '/pages/API/navigator/new-page/onLoad', + // 下拉刷新,不进行截图 + '/pages/API/pull-down-refresh/pull-down-refresh', + // 单独测试例截图 + // '/pages/API/get-element-by-id/get-element-by-id', + // 单独测试例截图 + // '/pages/API/get-element-by-id/get-element-by-id-multiple-root-node', + '/pages/API/nodes-info/nodes-info', + '/pages/API/storage/storage', + // 单独测试例截图 + // '/pages/API/action-sheet/action-sheet', + // 单独测试例截图 + // '/pages/API/modal/modal', + '/pages/API/loading/loading', + // 单独测试例截图 + // '/pages/API/toast/toast', + // 单独测试例截图 + // '/pages/API/load-font-face/load-font-face', + // 单独测试例截图 + // '/pages/API/load-font-face/load-font-face-child', + '/pages/API/get-location/get-location', + '/pages/API/interceptor/interceptor', + '/pages/API/interceptor/page1', + '/pages/API/interceptor/page2', + '/pages/API/request/request', + '/pages/API/upload-file/upload-file', + '/pages/API/download-file/download-file', + '/pages/API/websocket-socketTask/websocket-socketTask', + // 页面销毁时会关闭socket连接,所以规避 + // '/pages/API/websocket-global/websocket-global', + '/pages/API/unicloud-call-function/unicloud-call-function', + '/pages/API/unicloud-import-object/unicloud-import-object', + '/pages/API/get-system-info/get-system-info', + '/pages/API/get-device-info/get-device-info', + '/pages/API/get-app-base-info/get-app-base-info', + '/pages/API/preview-image/preview-image', + '/pages/API/choose-image/choose-image', + '/pages/API/choose-video/choose-video', + '/pages/API/get-network-type/get-network-type', + '/pages/API/page-scroll-to/page-scroll-to', + '/pages/API/event-bus/event-bus', + '/pages/API/unicloud-file-api/unicloud-file-api', + '/pages/API/unicloud-database/unicloud-database', + '/pages/API/get-battery-info/get-battery-info', + '/pages/API/get-window-info/get-window-info', + '/pages/API/rpx2px/rpx2px', + '/pages/API/request-payment-uni-pay/request-payment-uni-pay', + '/pages/API/request-payment-uni-pay/order-detail', + // 单独测试例截图 + // '/pages/API/resize-observer/resize-observer', + // 单独测试例截图 + // '/pages/API/map/map', // CSS '/pages/CSS/background/background-color', - '/pages/CSS/border/complex-border/complex-border', - '/pages/CSS/border/border-bottom', + // 单独测试例中截图 + // '/pages/CSS/background/background-image', + '/pages/CSS/border/border', '/pages/CSS/border/border-color', + '/pages/CSS/border/border-top', + '/pages/CSS/border/border-bottom', '/pages/CSS/border/border-left', - '/pages/CSS/border/border-radius', '/pages/CSS/border/border-right', + '/pages/CSS/border/border-radius', '/pages/CSS/border/border-style', - '/pages/CSS/border/border-top', '/pages/CSS/border/border-width', - '/pages/CSS/border/border', - '/pages/CSS/border/dynamic-border', - // '/pages/CSS/box-shadow/box-shadow', + '/pages/CSS/border/complex-border/complex-border', + // 单独测试例中截图 + // '/pages/CSS/border/dynamic-border', + '/pages/CSS/box-shadow/box-shadow', '/pages/CSS/display/flex', '/pages/CSS/display/none', + '/pages/CSS/flex/flex', '/pages/CSS/flex/align-content', '/pages/CSS/flex/align-items', '/pages/CSS/flex/flex-basis', @@ -59,78 +194,137 @@ const pages = [ '/pages/CSS/flex/flex-flow', '/pages/CSS/flex/flex-grow', '/pages/CSS/flex/flex-shrink', - '/pages/CSS/flex/flex', '/pages/CSS/flex/justify-content', '/pages/CSS/layout/height', - '/pages/CSS/layout/max-height', - '/pages/CSS/layout/max-width', '/pages/CSS/layout/min-height', + '/pages/CSS/layout/max-height', '/pages/CSS/layout/min-width', + '/pages/CSS/layout/max-width', '/pages/CSS/layout/position', - '/pages/CSS/layout/visibility', '/pages/CSS/layout/width', '/pages/CSS/layout/z-index', + '/pages/CSS/layout/visibility', + '/pages/CSS/margin/margin', + '/pages/CSS/margin/margin-top', '/pages/CSS/margin/margin-bottom', '/pages/CSS/margin/margin-left', '/pages/CSS/margin/margin-right', - '/pages/CSS/margin/margin-top', - '/pages/CSS/margin/margin', + '/pages/CSS/padding/padding', + '/pages/CSS/padding/padding-top', '/pages/CSS/padding/padding-bottom', '/pages/CSS/padding/padding-left', '/pages/CSS/padding/padding-right', - '/pages/CSS/padding/padding-top', - '/pages/CSS/padding/padding', + // 单独测试例中截图 + // '/pages/CSS/overflow/overflow', '/pages/CSS/text/color', - // '/pages/CSS/text/font-family', // 网络资源加载,单独测试例截图 - '/pages/CSS/text/font-size', + // 网络资源加载,单独测试例截图 + // '/pages/CSS/text/font-family', + // 单独测试例截图 + // '/pages/CSS/text/font-size', '/pages/CSS/text/font-style', '/pages/CSS/text/font-weight', '/pages/CSS/text/letter-spacing', '/pages/CSS/text/line-height', '/pages/CSS/text/text-align', - '/pages/CSS/text/text-decoration-line', '/pages/CSS/text/text-overflow', - '/pages/CSS/transform/rotate', - '/pages/CSS/transform/scale', - '/pages/CSS/transform/translate', - '/pages/CSS/transition/transition', + '/pages/CSS/text/text-decoration-line', + // 单独测试例截图 + // '/pages/CSS/transition/transition', '/pages/CSS/pointer-events/pointer-events', - - // tabBar //改动频繁,不再测试 - // '/pages/tabBar/API', - // '/pages/tabBar/component', - // '/pages/tabBar/CSS', - // '/pages/tabBar/template', + // 单独测试例截图 + // '/pages/CSS/transform/translate', + // 单独测试例截图 + // '/pages/CSS/transform/scale', + // 单独测试例截图 + // '/pages/CSS/transform/rotate', + // 单独测试例截图 + // '/pages/CSS/variable/variable', + '/pages/CSS/overflow/overflow-visible-event', // template - // '/pages/template/calendar/calendar', // 动态内容 + // 网络资源加载,单独测试例截图 + // '/pages/template/list-news/list-news', + // 依赖网络资源加载 + // '/pages/template/list-news/detail/detail', + '/pages/template/drop-card/drop-card', + '/pages/template/swiper-list/swiper-list', + '/pages/template/swiper-list2/swiper-list2', + '/pages/template/swiper-vertical-video/swiper-vertical-video', + '/pages/template/scroll-fold-nav/scroll-fold-nav', '/pages/template/custom-refresher/custom-refresher', - '/pages/template/custom-tab-bar/custom-tab-bar', - // '/pages/template/drop-card/drop-card', '/pages/template/half-screen/half-screen', - // '/pages/template/list-news/list-news', // 网络资源加载,单独测试例截图 - // '/pages/template/long-list/long-list', // 动态内容 - '/pages/template/navbar-lite/navbar-lite', + // 动态内容 + // '/pages/template/long-list/long-list', + '/pages/template/long-list2/long-list2', + '/pages/template/long-list-nested/long-list-nested', '/pages/template/pull-zoom-image/pull-zoom-image', - '/pages/template/scroll-fold-nav/scroll-fold-nav', - // '/pages/template/scroll-sticky/scroll-sticky', - '/pages/template/swiper-list/swiper-list', - '/pages/template/swiper-list2/swiper-list2', - // '/pages/template/swiper-vertical-video/swiper-vertical-video' - - // api - // '/pages/API/element-draw/element-draw', + '/pages/template/navbar-lite/navbar-lite', + '/pages/template/custom-tab-bar/custom-tab-bar', + // 动态内容 + // '/pages/template/calendar/calendar', + '/pages/template/schema/schema', + '/uni_modules/uni-pay-x/pages/success/success', + // 依赖 onload 参数获取 web-view src + // '/uni_modules/uni-pay-x/pages/ad-interactive-webview/ad-interactive-webview', + '/uni_modules/uni-pay-x/pages/pay-desk/pay-desk', + '/pages/template/custom-long-list/custom-long-list', + '/pages/template/test-background-color-content/test-background-color-content', ] - -const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() -if ((platformInfo.startsWith('android') || platformInfo.startsWith('ios')) && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { - // 规避 web 端不支持页面 + +if (isApp && !isAppWebview) { pages.push( '/pages/API/element-draw/element-draw', + '/pages/API/get-file-system-manager/get-file-system-manager', + '/pages/API/env/env', + '/pages/API/get-system-setting/get-system-setting', + '/pages/API/element-takesnapshot/element-takesnapshot', + '/pages/API/get-app-authorize-setting/get-app-authorize-setting', + '/pages/API/save-image-to-photos-album/save-image-to-photos-album', + '/pages/API/save-video-to-photos-album/save-video-to-photos-album', + '/pages/API/facial-recognition-verify/facial-recognition-verify', + '/pages/API/get-univerify-manager/get-univerify-manager', + '/pages/API/request-payment/request-payment', + '/pages/API/theme-change/theme-change', '/pages/template/scroll-sticky/scroll-sticky', ) } +if (isAndroid && !isAppWebview) { + pages.push( + '/pages/component/canvas/canvas', + '/pages/API/exit/exit', + '/pages/API/install-apk/install-apk', + '/pages/API/get-image-info/get-image-info', + '/pages/API/get-video-info/get-video-info', + '/pages/API/rewarded-video-ad/rewarded-video-ad', + '/pages/API/create-request-permission-listener/create-request-permission-listener', + '/pages/API/compress-image/compress-image', + '/pages/API/compress-video/compress-video', + '/pages/template/share/share', + ) +} + + +if (isWeb) { + pages.push( + '/pages/component/movable-view/movable-view', + '/pages/component/label/label', + '/pages/component/picker/picker', + '/pages/component/map/map', + '/pages/component/cover-view/cover-view', + '/pages/component/editor/editor', + '/pages/API/get-image-info/get-image-info', + '/pages/API/get-video-info/get-video-info', + '/pages/API/make-phone-call/make-phone-call', + '/pages/API/inner-audio/inner-audio', + '/pages/API/inner-audio/inner-audio-format', + '/pages/API/inner-audio/inner-audio-path', + '/pages/API/clipboard/clipboard', + '/pages/API/on-compass-change/on-compass-change', + '/pages/template/browser-canvas/browser-canvas', + ) +} + // 设置position: fixed的页面不能截取完整内容 const notFullPages = [ '/pages/CSS/layout/position', @@ -146,13 +340,40 @@ async function getWindowInfo() { return await windowInfoPage.callMethod('jest_getWindowInfo') } +function getWaitForTagName(pagePath) { + if (pagePath === '/pages/component/list-view/list-view-multiplex-input') { + return 'input' + } + if (pagePath === '/pages/component/list-view/list-view-multiplex-video') { + return 'video' + } + if ( + pagePath === '/pages/component/general-event/transition-event' || + pagePath === '/pages/component/list-view/list-view-refresh' || + pagePath === '/pages/API/env/env' + ) { + return 'text' + } + if ( + pagePath === '/pages/component/unicloud-db-contacts/edit' || + pagePath === '/pages/component/unicloud-db-contacts/detail' + ) { + return 'scroll-view' + } + if (pagePath === '/pages/API/get-file-system-manager/get-file-system-manager') { + return 'button' + } + return 'view' +} + describe("page screenshot test", () => { beforeAll(async () => { console.log("page screenshot test start"); }); beforeEach(async () => { - page = await program.reLaunch(pages[pageIndex]); - await page.waitFor(1000); + const currentPagePath = pages[pageIndex] + page = await program.reLaunch(currentPagePath); + await page.waitFor(getWaitForTagName(currentPagePath)); }); afterEach(() => { pageIndex++; @@ -161,26 +382,27 @@ describe("page screenshot test", () => { console.log("page screenshot test finish"); }); test.each(pages)("%s", async () => { - console.log("Taking screenshot: ", pageIndex, pages[pageIndex]); + const currentPagePath = pages[pageIndex] + console.log("Taking screenshot: ", pageIndex, currentPagePath); let fullPage = true; - if (notFullPages.includes(pages[pageIndex])) { + if (notFullPages.includes(currentPagePath)) { fullPage = false; } const screenshotParams = { fullPage } - if (!fullPage && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { + if (!fullPage && !isAppWebview) { if (!windowInfo) { windowInfo = await getWindowInfo() - page = await program.reLaunch(pages[pageIndex]); - await page.waitFor(1000); + page = await program.reLaunch(currentPagePath); + await page.waitFor(getWaitForTagName(currentPagePath)); } let offsetY = '0' - if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) { + if (isAndroid) { offsetY = `${windowInfo.statusBarHeight + 44}` } - if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { + if (isIos) { offsetY = `${windowInfo.safeAreaInsets.top + 44}` } screenshotParams.offsetY = offsetY @@ -189,7 +411,7 @@ describe("page screenshot test", () => { const image = await program.screenshot(screenshotParams); expect(image).toSaveImageSnapshot({ customSnapshotIdentifier() { - return `__pages_test__/${pages[pageIndex].replace(/\//g, "-").substring(1)}` + return `__pages_test__/${currentPagePath.replace(/\//g, "-").substring(1)}` } }) await page.waitFor(500); -- GitLab