提交 256adf1c 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test: 优化截图对比测试

上级 349f214d
...@@ -192,12 +192,12 @@ const pages = [ ...@@ -192,12 +192,12 @@ const pages = [
// "pages/component/sticky-section/sticky-section", // "pages/component/sticky-section/sticky-section",
// pages/API/facial-recognition-verify/facial-recognition-verify // pages/API/facial-recognition-verify/facial-recognition-verify
// pages/API/get-file-system-manager/get-file-system-manager // pages/API/get-file-system-manager/get-file-system-manager
// "pages/API/install-apk/install-apk", // "pages/API/install-apk/install-apk",
// "pages/template/scroll-sticky/scroll-sticky", // "pages/template/scroll-sticky/scroll-sticky",
// "pages/API/exit/exit", // "pages/API/exit/exit",
// "pages/API/element-takesnapshot/element-takesnapshot", // "pages/API/element-takesnapshot/element-takesnapshot",
// 仅 web // 仅 web
// pages/template/browser-canvas/browser-canvas // pages/template/browser-canvas/browser-canvas
// pages/template/schema/schema // pages/template/schema/schema
// pages/template/share/share // pages/template/share/share
...@@ -210,8 +210,8 @@ const childToParentPagesMap = new Map([ ...@@ -210,8 +210,8 @@ const childToParentPagesMap = new Map([
]); ]);
const customNavigationPages = [ const customNavigationPages = [
"pages/template/navbar-lite/navbar-lite", "pages/template/navbar-lite/navbar-lite",
"pages/template/pull-zoom-image/pull-zoom-image", "pages/template/pull-zoom-image/pull-zoom-image",
"pages/template/scroll-fold-nav/scroll-fold-nav" "pages/template/scroll-fold-nav/scroll-fold-nav"
] ]
...@@ -267,7 +267,7 @@ describe("shot-compare", () => { ...@@ -267,7 +267,7 @@ describe("shot-compare", () => {
test.each(pages)("%s", async () => { test.each(pages)("%s", async () => {
const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]); const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]);
const isCustomNavigation = customNavigationPages.includes(pages[pageIndex]); const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]);
const { const {
headerHeight, headerHeight,
devicePixelRatio devicePixelRatio
...@@ -299,7 +299,7 @@ describe("shot-compare", () => { ...@@ -299,7 +299,7 @@ describe("shot-compare", () => {
await page.setData({ await page.setData({
src: `${baseSrc}${pages[pageIndex]}`, src: `${baseSrc}${pages[pageIndex]}`,
isLoaded: false, isLoaded: false,
needRemoveWebHead: !isNeedAdbScreenshot, isCustomNavigationBar,
}); });
const startTime = Date.now(); const startTime = Date.now();
...@@ -315,7 +315,8 @@ describe("shot-compare", () => { ...@@ -315,7 +315,8 @@ describe("shot-compare", () => {
// web 端非 adb 截图时设置 offsetY 移除导航栏 // web 端非 adb 截图时设置 offsetY 移除导航栏
const webSnapshot = await program.screenshot({ const webSnapshot = await program.screenshot({
...screenshotParams, ...screenshotParams,
offsetY: `${isCustomNavigation ? 0 : headerHeight}` id: 'webview-screenshot-comparison',
offsetY: `${isCustomNavigationBar ? 0 : 44}`
}); });
expect(webSnapshot).toMatchImageSnapshot({ expect(webSnapshot).toMatchImageSnapshot({
customSnapshotIdentifier() { customSnapshotIdentifier() {
...@@ -344,4 +345,4 @@ describe("shot-compare", () => { ...@@ -344,4 +345,4 @@ describe("shot-compare", () => {
expect(1).toBe(1); expect(1).toBe(1);
}); });
} }
}); });
<template> <template>
<view v-if="!isCustomNavigationBar" :style="placeholderStyle"></view>
<web-view id="webview-screenshot-comparison" class="webview-screenshot-comparison" :webview-styles="webviewStyles" <web-view id="webview-screenshot-comparison" class="webview-screenshot-comparison" :webview-styles="webviewStyles"
:src="src" @loaded="loaded" @error="error"> :src="src" @loaded="loaded" @error="error">
</web-view> </web-view>
...@@ -15,6 +16,12 @@ ...@@ -15,6 +16,12 @@
webviewContext: null as WebviewContext | null, webviewContext: null as WebviewContext | null,
isLoaded: false, isLoaded: false,
headerHeight: state.headerHeight, headerHeight: state.headerHeight,
isCustomNavigationBar: false,
placeholderStyle: {
display: 'block',
height: `${state.headerHeight - 44}px`,
backgroundColor: '#007aff'
},
devicePixelRatio: state.devicePixelRatio, devicePixelRatio: state.devicePixelRatio,
webviewStyles: { webviewStyles: {
progress: false progress: false
...@@ -25,41 +32,25 @@ ...@@ -25,41 +32,25 @@
this.webviewContext = uni.createWebviewContext('webview-screenshot-comparison', this) this.webviewContext = uni.createWebviewContext('webview-screenshot-comparison', this)
}, },
methods: { methods: {
appendWebHeadPlaceholder() { customNavigationBarPageAppendWebHeadPlaceholder() {
if (this.src.indexOf('pages/template/navbar-lite/navbar-lite') > -1) { if (this.src.indexOf('pages/template/navbar-lite/navbar-lite') > -1) {
this.webviewContext?.evalJS(` this.webviewContext?.evalJS(`
const uniNavbar = document.querySelector('.uni-navbar'); const uniNavbar = document.querySelector('.uni-navbar');
uniNavbar.style.paddingTop = '${state.headerHeight - 44}px'; uniNavbar.style.paddingTop = '${state.headerHeight - 44}px';
`) `)
} else if (this.src.indexOf('pages/template/scroll-fold-nav/scroll-fold-nav') > -1) { } else if (this.src.indexOf('pages/template/scroll-fold-nav/scroll-fold-nav') > -1) {
this.webviewContext?.evalJS(` this.webviewContext?.evalJS(`
const heightSeat = document.querySelector('.height-seat'); const heightSeat = document.querySelector('.height-seat');
heightSeat.style.height = '125px'; heightSeat.style.height = '125px';
heightSeat.style.backgroundColor = '#f0f8ff'; heightSeat.style.backgroundColor = '#f0f8ff';
const topBox = document.querySelector('.top-box'); const topBox = document.querySelector('.top-box');
topBox.style.top = '35px'; topBox.style.top = '35px';
`) `)
} else if (this.src.indexOf('pages/template/pull-zoom-image/pull-zoom-image') > -1) {
return
} else {
this.webviewContext?.evalJS(`
const hasWebHeadPlaceholder = document.querySelector('.web-head-placeholder-for-screenshot-comparison');
if (hasWebHeadPlaceholder) {
return;
}
const webHeadPlaceholder = document.createElement('div');
webHeadPlaceholder.style.height = '${state.headerHeight - 44}px';
webHeadPlaceholder.style.backgroundColor = '#007aff';
webHeadPlaceholder.classList.add('web-head-placeholder-for-screenshot-comparison');
const uniPage = document.querySelector('uni-page');
const uniPageHead = document.querySelector('uni-page-head');
uniPage.insertBefore(webHeadPlaceholder, uniPageHead);
`);
} }
}, },
loaded() { loaded() {
this.isLoaded = true this.isLoaded = true
this.appendWebHeadPlaceholder(); this.customNavigationBarPageAppendWebHeadPlaceholder();
}, },
error(event : WebViewErrorEvent) { error(event : WebViewErrorEvent) {
console.log('webview load error', JSON.stringify(event.detail)); console.log('webview load error', JSON.stringify(event.detail));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册