From 7c30d1ad93d88090614c50f7569da1c8e4db8640 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Sun, 7 Apr 2024 16:06:23 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E8=B0=83=E6=95=B4=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BE=8B=EF=BC=8C=E5=85=BC=E5=AE=B9=E8=B7=A8?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E6=88=AA=E5=9B=BE=E5=AF=B9=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/image/image.test.js | 129 ++++++++++-------- .../sticky-header/sticky-header.test.js | 22 ++- pages/template/list-news/list-news.test.js | 24 +++- 3 files changed, 115 insertions(+), 60 deletions(-) diff --git a/pages/component/image/image.test.js b/pages/component/image/image.test.js index b9535cc8..2f7e1d04 100644 --- a/pages/component/image/image.test.js +++ b/pages/component/image/image.test.js @@ -1,70 +1,87 @@ // uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ describe('component-native-image', () => { + let page; + + 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') + } + const screenshotParams = { fullPage: true } + let windowInfo + + beforeAll(async () => { + if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) { + screenshotParams.fullPage = false + windowInfo = await getWindowInfo() + let offsetY = '0' + if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) { + offsetY = `${windowInfo.statusBarHeight + 44}` + } + if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { + offsetY = `${windowInfo.safeAreaInsets.top + 44}` + } + screenshotParams.offsetY = offsetY + } + + page = await program.reLaunch('/pages/component/image/image'); + await page.waitFor(600); + }); - let page; - beforeAll(async () => { - page = await program.reLaunch('/pages/component/image/image'); - await page.waitFor(600); - }); + it('check_image_load', async () => { + expect(await page.data('loadError')).toBe(false) + }); - it('check_image_load', async () => { - expect(await page.data('loadError')).toBe(false) - }); + it('check_image_load_url', async () => { + await page.setData({ + loadError: false, + imageSrc: 'https://request.dcloud.net.cn/api/http/contentType/image/png' + }) + await page.waitFor(300); + expect(await page.data('loadError')).toBe(false) + }) - it('check_image_load_url', async () => { - await page.setData({ - loadError: false, - imageSrc: 'https://request.dcloud.net.cn/api/http/contentType/image/png' - }) - await page.waitFor(300); - expect(await page.data('loadError')).toBe(false) + it('check_image_load_error', async () => { + await page.setData({ + loadError: false, + imageSrc: 'testerror.jpg' }) + await page.waitFor(300); + expect(await page.data('loadError')).toBe(true) + }) - it('check_image_load_error', async () => { + if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { + it('check-cookie', async () => { + await page.setData({ + autoTest: true, + setCookieImage: 'https://cdn.dcloud.net.cn/img/shadow-grey.png' + }); + await page.waitFor(1000); await page.setData({ loadError: false, - imageSrc: 'testerror.jpg' - }) - await page.waitFor(300); - expect(await page.data('loadError')).toBe(true) + verifyCookieImage: 'https://request.dcloud.net.cn/img/shadow-grey.png' + }); + await page.waitFor(1000); + expect(await page.data('loadError')).toBe(false); + await page.setData({ + autoTest: false + }); }) + } - if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) { - it('check-cookie', async () => { - await page.setData({ - autoTest: true, - setCookieImage: 'https://cdn.dcloud.net.cn/img/shadow-grey.png' - }); - await page.waitFor(1000); - await page.setData({ - loadError: false, - verifyCookieImage: 'https://request.dcloud.net.cn/img/shadow-grey.png' - }); - await page.waitFor(1000); - expect(await page.data('loadError')).toBe(false); - await page.setData({ - autoTest: false - }); - }) - } + it('path-screenshot', async () => { + const page = await program.navigateTo('/pages/component/image/image-path'); + await page.waitFor(3000); + const image = await program.screenshot(screenshotParams) + expect(image).toSaveImageSnapshot() + }); - it('path-screenshot', async () => { - const page = await program.navigateTo('/pages/component/image/image-path'); - await page.waitFor(3000); - const image = await program.screenshot({ - fullPage: true - }) - expect(image).toSaveImageSnapshot() - }); - - it('mode-screenshot', async () => { - if (process.env.android_cpu_type === 'x86_64') return - const page = await program.navigateTo('/pages/component/image/image-mode'); - await page.waitFor(1000); - const image = await program.screenshot({ - fullPage: true - }) - expect(image).toSaveImageSnapshot() - }); + it('mode-screenshot', async () => { + if (process.env.android_cpu_type === 'x86_64') return + const page = await program.navigateTo('/pages/component/image/image-mode'); + await page.waitFor(1000); + const image = await program.screenshot(screenshotParams) + expect(image).toSaveImageSnapshot() + }); }); diff --git a/pages/component/sticky-header/sticky-header.test.js b/pages/component/sticky-header/sticky-header.test.js index 2f56803a..f7b87a43 100644 --- a/pages/component/sticky-header/sticky-header.test.js +++ b/pages/component/sticky-header/sticky-header.test.js @@ -1,6 +1,26 @@ describe('component-native-sticky-header', () => { let page + 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') + } + const screenshotParams = { fullPage: true } + let windowInfo + beforeAll(async () => { + if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) { + screenshotParams.fullPage = false + windowInfo = await getWindowInfo() + let offsetY = '0' + if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) { + offsetY = `${windowInfo.statusBarHeight + 44}` + } + if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { + offsetY = `${windowInfo.safeAreaInsets.top + 44}` + } + screenshotParams.offsetY = offsetY + } page = await program.reLaunch('/pages/component/sticky-header/sticky-header') await page.waitFor('sticky-header') }) @@ -8,7 +28,7 @@ describe('component-native-sticky-header', () => { //检测吸顶效果 it('check_sticky_header', async () => { await page.callMethod('confirm_scroll_top_input', 600) - const image = await program.screenshot({fullPage: true}); + const image = await program.screenshot(screenshotParams); expect(image).toSaveImageSnapshot(); }) }) diff --git a/pages/template/list-news/list-news.test.js b/pages/template/list-news/list-news.test.js index 045cd9ea..efaa7f7a 100644 --- a/pages/template/list-news/list-news.test.js +++ b/pages/template/list-news/list-news.test.js @@ -2,15 +2,33 @@ describe('template-list-news', () => { let page; + + 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') + } + const screenshotParams = { fullPage: true } + let windowInfo beforeAll(async () => { + if (!process.env.UNI_AUTOMATOR_APP_WEBVIEW) { + screenshotParams.fullPage = false + windowInfo = await getWindowInfo() + let offsetY = '0' + if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('android')) { + offsetY = `${windowInfo.statusBarHeight + 44}` + } + if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { + offsetY = `${windowInfo.safeAreaInsets.top + 44}` + } + screenshotParams.offsetY = offsetY + } page = await program.reLaunch('/pages/template/list-news/list-news'); await page.waitFor(3000); }); it('screenshot', async () => { - const image = await program.screenshot({ - fullPage: true - }) + const image = await program.screenshot(screenshotParams) expect(image).toSaveImageSnapshot() }); }); -- GitLab