From fc2ab3813bfc78222805816be0cdec5342683167 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Tue, 2 Apr 2024 16:24:35 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E8=B0=83=E6=95=B4=20pages.test.js=20?= =?UTF-8?q?=E6=88=AA=E5=9B=BE=E7=A7=BB=E9=99=A4=E5=AF=BC=E8=88=AA=E6=A0=8F?= =?UTF-8?q?=EF=BC=8C=E9=80=82=E9=85=8D=E8=B7=A8=E5=B9=B3=E5=8F=B0=E5=AF=B9?= =?UTF-8?q?=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/pages.test.js | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/pages/pages.test.js b/pages/pages.test.js index 563f1850..69599f4b 100755 --- a/pages/pages.test.js +++ b/pages/pages.test.js @@ -120,7 +120,7 @@ const pages = [ // '/pages/API/element-draw/element-draw', ] -if (process.env.uniTestPlatformInfo.startsWith('android')&& !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { +if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { // 规避 web 端不支持页面 pages.push( "/pages/component/list-view/list-view", @@ -145,6 +145,14 @@ const notFullPages = [ ] let page; +let windowInfo + +async function getWindowInfo() { + const windowInfoPage = await program.reLaunch('/pages/API/get-window-info/get-window-info') + await windowInfoPage.waitFor(600); + return await windowInfoPage.callMethod('jest_getWindowInfo') +} + describe("page screenshot test", () => { beforeAll(async () => { console.log("page screenshot test start"); @@ -165,9 +173,27 @@ describe("page screenshot test", () => { if (notFullPages.includes(pages[pageIndex])) { fullPage = false; } - const image = await program.screenshot({ - fullPage: fullPage - }); + + const screenshotParams = { + fullPage + } + if (!fullPage && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { + let offsetY = '0' + if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) { + offsetY = '44' + } + if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { + if (!windowInfo) { + windowInfo = await getWindowInfo() + page = await program.reLaunch(pages[pageIndex]); + await page.waitFor(1000); + } + offsetY = `${windowInfo.safeAreaInsets.top + 44}` + } + screenshotParams.offsetY = offsetY + } + + const image = await program.screenshot(screenshotParams); expect(image).toSaveImageSnapshot({ customSnapshotIdentifier() { return `__pages_test__/${pages[pageIndex].replace(/\//g, "-").substring(1)}` -- GitLab