From 7c5ef6d070c53259d8afd323c3740959e60c5bc6 Mon Sep 17 00:00:00 2001 From: wangjinxin613 <1749574663@qq.com> Date: Wed, 31 Jan 2024 16:14:33 +0800 Subject: [PATCH] =?UTF-8?q?test=EF=BC=9A=E4=BC=98=E5=8C=96=E6=88=AA?= =?UTF-8?q?=E5=9B=BE=E5=AF=B9=E6=AF=94=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webview-screenshot-comparison.test.js | 133 +++++++++--------- .../webview-screenshot-comparison.uvue | 13 +- .../webview-screenshot.test.js | 6 +- .../webview-screenshot.uvue | 13 +- store/index.uts | 17 ++- 5 files changed, 100 insertions(+), 82 deletions(-) diff --git a/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js b/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js index cf6859a..eda19c0 100644 --- a/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js +++ b/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js @@ -67,7 +67,7 @@ const pages = [ 'pages/composition-api/lifecycle/component-lifecycle/component-lifecycle', 'pages/built-in-component/teleport/teleport', 'pages/component-instance/watch-function/watch-function' - + // 仅app // 'pages/composition/mixins/mixins', // 'pages/composition/mixins/mixins-page2', @@ -144,12 +144,12 @@ describe("shot-compare", () => { shouldCompareScreenShot = version > 9 } - if (!shouldCompareScreenShot) { - it("other platform not support", async () => { - expect(1).toBe(1); - }); - return - } + if (!shouldCompareScreenShot) { + it("other platform not support", async () => { + expect(1).toBe(1); + }); + return + } let page = null; let pageIndex = 0; @@ -157,15 +157,18 @@ describe("shot-compare", () => { beforeAll(async () => { page = await program.reLaunch(PAGE_PATH); await page.waitFor(500); + await page.callMethod('getWindowInfo'); + await page.callMethod('getDeviceInfo'); + + // set webview-screenshot-comparison page baseSrc + baseSrc = + process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` : + "http://test.dcloud.io/unix_h5_build/98_dev_hello-uvue/#/"; - // set webview-screenshot-comparison page baseSrc - baseSrc = - process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` : - "http://test.dcloud.io/unix_h5_build/98_dev_hello-uvue/#/"; - page.setData({ - baseSrc, - }); - }); + page.setData({ + baseSrc, + }); + }); beforeEach(async () => { page = await program.reLaunch(PAGE_PATH); @@ -175,23 +178,23 @@ describe("shot-compare", () => { pageIndex++; }); - test.each(pages)("%s", async () => { - const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]); - const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]); - const { - statusBarHeight, - devicePixelRatio - } = await page.data(); - const screenshotParams = { - fullPage: true, - adb: isNeedAdbScreenshot, - // adb 截图时跳过状态栏 - area: { - x: 0, - y: statusBarHeight * devicePixelRatio, - }, - } - const screenshotPath = `__webview__${pages[pageIndex].replace(/\//g, "-")}`; + test.each(pages)("%s", async () => { + const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]); + const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]); + const { + statusBarHeight, + devicePixelRatio + } = await page.data(); + const screenshotParams = { + fullPage: true, + adb: isNeedAdbScreenshot, + // adb 截图时跳过状态栏 + area: { + x: 0, + y: statusBarHeight * devicePixelRatio, + }, + } + const screenshotPath = `__webview__${pages[pageIndex].replace(/\//g, "-")}`; // web in webview screenshot // 加载依赖页面 @@ -212,36 +215,36 @@ describe("shot-compare", () => { isCustomNavigationBar, }); - const startTime = Date.now(); - await page.waitFor(async () => { - const isLoaded = await page.data("isLoaded"); - return isLoaded || Date.now() - startTime > 3000; - }); - await page.waitFor(800); - - // web 端非 adb 截图时设置 offsetY 移除导航栏 - const webSnapshot = await program.screenshot({ - ...screenshotParams, - id: 'webview-screenshot-comparison', - offsetY: `${isCustomNavigationBar ? 0 : 44}` - }); - expect(webSnapshot).toMatchImageSnapshot({ - customSnapshotIdentifier() { - return screenshotPath; - }, - }); - - // app-android page screenshot comparison - const navigateMethod = pages[pageIndex].startsWith("pages/tab-bar") ? - "switchTab" : - "navigateTo"; - page = await program[navigateMethod](`/${pages[pageIndex]}`); - await page.waitFor(500); - const appAndroidSnapshot = await program.screenshot(screenshotParams); - expect(appAndroidSnapshot).toMatchImageSnapshot({ - customSnapshotIdentifier() { - return screenshotPath; - }, - }); - }); -}); + const startTime = Date.now(); + await page.waitFor(async () => { + const isLoaded = await page.data("isLoaded"); + return isLoaded || Date.now() - startTime > 3000; + }); + await page.waitFor(800); + + // web 端非 adb 截图时设置 offsetY 移除导航栏 + const webSnapshot = await program.screenshot({ + ...screenshotParams, + id: 'webview-screenshot-comparison', + offsetY: `${isCustomNavigationBar ? 0 : 44}` + }); + expect(webSnapshot).toMatchImageSnapshot({ + customSnapshotIdentifier() { + return screenshotPath; + }, + }); + + // app-android page screenshot comparison + const navigateMethod = pages[pageIndex].startsWith("pages/tab-bar") ? + "switchTab" : + "navigateTo"; + page = await program[navigateMethod](`/${pages[pageIndex]}`); + await page.waitFor(500); + const appAndroidSnapshot = await program.screenshot(screenshotParams); + expect(appAndroidSnapshot).toMatchImageSnapshot({ + customSnapshotIdentifier() { + return screenshotPath; + }, + }); + }); +}); \ No newline at end of file diff --git a/pages/webview-screenshot-comparison/webview-screenshot-comparison.uvue b/pages/webview-screenshot-comparison/webview-screenshot-comparison.uvue index 77e5ae9..4e55e91 100644 --- a/pages/webview-screenshot-comparison/webview-screenshot-comparison.uvue +++ b/pages/webview-screenshot-comparison/webview-screenshot-comparison.uvue @@ -6,6 +6,7 @@