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

test: webview 截图 对齐 pages 截图

上级 3e0e5947
...@@ -255,6 +255,13 @@ describe("shot-compare", () => { ...@@ -255,6 +255,13 @@ describe("shot-compare", () => {
let pageIndex = 0; let pageIndex = 0;
let baseSrc = ""; let baseSrc = "";
beforeAll(async () => { beforeAll(async () => {
// 获取导航栏+状态栏高度
page = await program.reLaunch('/pages/API/get-window-info/get-window-info')
await page.callMethod('getWindowInfo')
// 获取设备像素比
page = await program.reLaunch('/pages/API/get-device-info/get-device-info')
await page.callMethod('getDeviceInfo')
page = await program.reLaunch(PAGE_PATH); page = await program.reLaunch(PAGE_PATH);
await page.waitFor(500); await page.waitFor(500);
...@@ -279,7 +286,7 @@ describe("shot-compare", () => { ...@@ -279,7 +286,7 @@ describe("shot-compare", () => {
const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]); const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]);
const isCustomNavigation = customNavigationPages.includes(pages[pageIndex]); const isCustomNavigation = customNavigationPages.includes(pages[pageIndex]);
const { const {
headerHeight, statusBarHeight,
devicePixelRatio devicePixelRatio
} = await page.data(); } = await page.data();
const screenshotParams = { const screenshotParams = {
...@@ -288,7 +295,7 @@ describe("shot-compare", () => { ...@@ -288,7 +295,7 @@ describe("shot-compare", () => {
// deviceShot 截图时跳过状态栏 // deviceShot 截图时跳过状态栏
area: { area: {
x: 0, x: 0,
y: (headerHeight - 44) * devicePixelRatio, y: (statusBarHeight - 44) * devicePixelRatio,
}, },
} }
const screenshotPath = `__webview-shot__/${pages[pageIndex].replace(/\//g, "-")}`; const screenshotPath = `__webview-shot__/${pages[pageIndex].replace(/\//g, "-")}`;
...@@ -326,7 +333,7 @@ describe("shot-compare", () => { ...@@ -326,7 +333,7 @@ describe("shot-compare", () => {
// web 端非 deviceShot 截图时设置 offsetY 移除导航栏 // web 端非 deviceShot 截图时设置 offsetY 移除导航栏
const webSnapshot = await program.screenshot({ const webSnapshot = await program.screenshot({
...screenshotParams, ...screenshotParams,
offsetY: `${isCustomNavigation ? 0 : headerHeight}` offsetY: `${isCustomNavigation ? 0 : statusBarHeight + 44}`
}); });
expect(webSnapshot).toSaveImageSnapshot({ expect(webSnapshot).toSaveImageSnapshot({
customSnapshotIdentifier() { customSnapshotIdentifier() {
......
<template> <template>
<web-view id="webview-screenshot" class="webview-screenshot" :webview-styles='webviewStyles' :src="src" <view style="flex:1;">
@loaded="loaded" @error="error"> <view :style='{height: `${statusBarHeight}px`}'></view>
</web-view> <web-view id="webview-screenshot" class="webview-screenshot" :webview-styles='webviewStyles' :src="src"
@loaded="loaded" @error="error">
</web-view>
</view>
</template> </template>
<script> <script>
import { state } from '@/store/index.uts'
export default { export default {
data() { data() {
return { return {
baseSrc: '', baseSrc: '',
src: '', src: '',
statusBarHeight: state.statusBarHeight,
devicePixelRatio: state.devicePixelRatio,
webviewContext: null as WebviewContext | null, webviewContext: null as WebviewContext | null,
isLoaded: false, isLoaded: false,
webviewStyles: { webviewStyles: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册