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

test: webview 截图 对齐 pages 截图

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