From f30c14eadc892367a18b89f6df34ff1cd76e7ba9 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Mon, 8 Jan 2024 17:05:49 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BC=98=E5=8C=96=E6=88=AA=E5=9B=BE?= =?UTF-8?q?=E5=AF=B9=E6=AF=94=E6=B5=8B=E8=AF=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webview-screenshot-comparison.test.js | 54 +++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js b/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js index 9d5298f1..4aa1016c 100644 --- a/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js +++ b/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js @@ -80,6 +80,9 @@ const pages = [ "pages/API/unicloud-database/unicloud-database", "pages/API/get-window-info/get-window-info", "pages/API/element-takesnapshot/element-takesnapshot", + "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/navigator/new-page/onLoad", "pages/tabBar/CSS", "pages/CSS/background/background-color", "pages/CSS/background/background-image", @@ -152,14 +155,11 @@ const pages = [ // web 暂不支持 // "pages/component/list-view/list-view", + // "pages/component/list-view/list-view-multiplex", + // "pages/API/element-draw/element-draw", // "pages/template/swiper-list/swiper-list", // "pages/template/swiper-list2/swiper-list2", - // "pages/API/element-draw/element-draw", - // "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/navigator/new-page/onLoad", // "pages/template/long-list2/long-list2", - // "pages/component/list-view/list-view-multiplex", // 动态内容 // "pages/component/web-view/web-view" @@ -201,6 +201,13 @@ const pages = [ // pages/template/schema/schema // pages/template/share/share ]; +const childToParentPagesMap = new Map([ + [ + "pages/API/load-font-face/load-font-face-child", + "pages/API/load-font-face/load-font-face", + ], +]); + const needAdbScreenshotPages = [ "pages/tabBar/component", "pages/tabBar/API", @@ -249,6 +256,20 @@ describe("shot-compare", () => { const screenshotPath = pages[pageIndex].replace(/\//g, "-"); // web in webview screenshot + // 加载依赖页面 + if (childToParentPagesMap.get(pages[pageIndex])) { + await page.setData({ + src: `${baseSrc}${childToParentPagesMap.get(pages[pageIndex])}`, + isLoaded: false, + needRemoveWebHead: !isNeedAdbScreenshot, + }); + await page.waitFor(async () => { + const isLoaded = page.data("isLoaded"); + return isLoaded || Date.now() - startTime > 10000; + }); + // 这个等待无法保证 web 页面加载完成,可以等 web 服务调整为发行服务后进行优化 + await page.waitFor(4000); + } await page.setData({ src: `${baseSrc}${pages[pageIndex]}`, isLoaded: false, @@ -262,9 +283,17 @@ describe("shot-compare", () => { }); // 这个等待无法保证 web 页面加载完成,可以等 web 服务调整为发行服务后进行优化 await page.waitFor(4000); + if (pages[pageIndex].includes("load-font-face")) { + await page.waitFor(3000); + } const webSnapshot = await program.screenshot({ fullPage: isNeedAdbScreenshot ? false : true, + adb: isNeedAdbScreenshot ? true : false, + area: { + x: 0, + y: 100, + }, }); expect(webSnapshot).toMatchImageSnapshot({ customSnapshotIdentifier() { @@ -273,14 +302,21 @@ describe("shot-compare", () => { }); // app-android page screenshot comparison - const navigateMethod = pages[pageIndex].startsWith("pages/tabBar") - ? "switchTab" - : "navigateTo"; + const navigateMethod = pages[pageIndex].startsWith("pages/tabBar") ? + "switchTab" : + "navigateTo"; page = await program[navigateMethod](`/${pages[pageIndex]}`); await page.waitFor(500); + if (pages[pageIndex].includes("load-font-face")) { + await page.waitFor(2000); + } const appAndroidSnapshot = await program.screenshot({ fullPage: isNeedAdbScreenshot ? false : true, adb: isNeedAdbScreenshot ? true : false, + area: { + x: 0, + y: 100, + }, }); expect(appAndroidSnapshot).toMatchImageSnapshot({ customSnapshotIdentifier() { @@ -293,4 +329,4 @@ describe("shot-compare", () => { expect(1).toBe(1); }); } -}); +}); -- GitLab