Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
256adf1c
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
256adf1c
编写于
1月 20, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: 优化截图对比测试
上级
349f214d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
37 deletion
+29
-37
pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js
...reenshot-comparison/webview-screenshot-comparison.test.js
+11
-10
pages/webview-screenshot-comparison/webview-screenshot-comparison.uvue
...-screenshot-comparison/webview-screenshot-comparison.uvue
+18
-27
未找到文件。
pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js
浏览文件 @
256adf1c
...
...
@@ -192,12 +192,12 @@ const pages = [
// "pages/component/sticky-section/sticky-section",
// pages/API/facial-recognition-verify/facial-recognition-verify
// pages/API/get-file-system-manager/get-file-system-manager
// "pages/API/install-apk/install-apk",
// "pages/template/scroll-sticky/scroll-sticky",
// "pages/API/exit/exit",
// "pages/API/install-apk/install-apk",
// "pages/template/scroll-sticky/scroll-sticky",
// "pages/API/exit/exit",
// "pages/API/element-takesnapshot/element-takesnapshot",
// 仅 web
// 仅 web
// pages/template/browser-canvas/browser-canvas
// pages/template/schema/schema
// pages/template/share/share
...
...
@@ -210,8 +210,8 @@ const childToParentPagesMap = new Map([
]);
const
customNavigationPages
=
[
"
pages/template/navbar-lite/navbar-lite
"
,
"
pages/template/pull-zoom-image/pull-zoom-image
"
,
"
pages/template/navbar-lite/navbar-lite
"
,
"
pages/template/pull-zoom-image/pull-zoom-image
"
,
"
pages/template/scroll-fold-nav/scroll-fold-nav
"
]
...
...
@@ -267,7 +267,7 @@ describe("shot-compare", () => {
test
.
each
(
pages
)(
"
%s
"
,
async
()
=>
{
const
isNeedAdbScreenshot
=
needAdbScreenshot
(
pages
[
pageIndex
]);
const
isCustomNavigation
=
customNavigationPages
.
includes
(
pages
[
pageIndex
]);
const
isCustomNavigation
Bar
=
customNavigationPages
.
includes
(
pages
[
pageIndex
]);
const
{
headerHeight
,
devicePixelRatio
...
...
@@ -299,7 +299,7 @@ describe("shot-compare", () => {
await
page
.
setData
({
src
:
`
${
baseSrc
}${
pages
[
pageIndex
]}
`
,
isLoaded
:
false
,
needRemoveWebHead
:
!
isNeedAdbScreenshot
,
isCustomNavigationBar
,
});
const
startTime
=
Date
.
now
();
...
...
@@ -315,7 +315,8 @@ describe("shot-compare", () => {
// web 端非 adb 截图时设置 offsetY 移除导航栏
const
webSnapshot
=
await
program
.
screenshot
({
...
screenshotParams
,
offsetY
:
`
${
isCustomNavigation
?
0
:
headerHeight
}
`
id
:
'
webview-screenshot-comparison
'
,
offsetY
:
`
${
isCustomNavigationBar
?
0
:
44
}
`
});
expect
(
webSnapshot
).
toMatchImageSnapshot
({
customSnapshotIdentifier
()
{
...
...
@@ -344,4 +345,4 @@ describe("shot-compare", () => {
expect
(
1
).
toBe
(
1
);
});
}
});
});
pages/webview-screenshot-comparison/webview-screenshot-comparison.uvue
浏览文件 @
256adf1c
<template>
<view v-if="!isCustomNavigationBar" :style="placeholderStyle"></view>
<web-view id="webview-screenshot-comparison" class="webview-screenshot-comparison" :webview-styles="webviewStyles"
:src="src" @loaded="loaded" @error="error">
</web-view>
...
...
@@ -15,6 +16,12 @@
webviewContext: null as WebviewContext | null,
isLoaded: false,
headerHeight: state.headerHeight,
isCustomNavigationBar: false,
placeholderStyle: {
display: 'block',
height: `${state.headerHeight - 44}px`,
backgroundColor: '#007aff'
},
devicePixelRatio: state.devicePixelRatio,
webviewStyles: {
progress: false
...
...
@@ -25,41 +32,25 @@
this.webviewContext = uni.createWebviewContext('webview-screenshot-comparison', this)
},
methods: {
a
ppendWebHeadPlaceholder() {
customNavigationBarPageA
ppendWebHeadPlaceholder() {
if (this.src.indexOf('pages/template/navbar-lite/navbar-lite') > -1) {
this.webviewContext?.evalJS(`
const uniNavbar = document.querySelector('.uni-navbar');
uniNavbar.style.paddingTop = '${state.headerHeight - 44}px';
`)
const uniNavbar = document.querySelector('.uni-navbar');
uniNavbar.style.paddingTop = '${state.headerHeight - 44}px';
`)
} else if (this.src.indexOf('pages/template/scroll-fold-nav/scroll-fold-nav') > -1) {
this.webviewContext?.evalJS(`
const heightSeat = document.querySelector('.height-seat');
heightSeat.style.height = '125px';
heightSeat.style.backgroundColor = '#f0f8ff';
const topBox = document.querySelector('.top-box');
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);
`);
const heightSeat = document.querySelector('.height-seat');
heightSeat.style.height = '125px';
heightSeat.style.backgroundColor = '#f0f8ff';
const topBox = document.querySelector('.top-box');
topBox.style.top = '35px';
`)
}
},
loaded() {
this.isLoaded = true
this.
a
ppendWebHeadPlaceholder();
this.
customNavigationBarPageA
ppendWebHeadPlaceholder();
},
error(event : WebViewErrorEvent) {
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录