提交 7c5ef6d0 编写于 作者: W wangjinxin613

test:优化截图对比测试用例

上级 5c285042
...@@ -67,7 +67,7 @@ const pages = [ ...@@ -67,7 +67,7 @@ const pages = [
'pages/composition-api/lifecycle/component-lifecycle/component-lifecycle', 'pages/composition-api/lifecycle/component-lifecycle/component-lifecycle',
'pages/built-in-component/teleport/teleport', 'pages/built-in-component/teleport/teleport',
'pages/component-instance/watch-function/watch-function' 'pages/component-instance/watch-function/watch-function'
// 仅app // 仅app
// 'pages/composition/mixins/mixins', // 'pages/composition/mixins/mixins',
// 'pages/composition/mixins/mixins-page2', // 'pages/composition/mixins/mixins-page2',
...@@ -144,12 +144,12 @@ describe("shot-compare", () => { ...@@ -144,12 +144,12 @@ describe("shot-compare", () => {
shouldCompareScreenShot = version > 9 shouldCompareScreenShot = version > 9
} }
if (!shouldCompareScreenShot) { if (!shouldCompareScreenShot) {
it("other platform not support", async () => { it("other platform not support", async () => {
expect(1).toBe(1); expect(1).toBe(1);
}); });
return return
} }
let page = null; let page = null;
let pageIndex = 0; let pageIndex = 0;
...@@ -157,15 +157,18 @@ describe("shot-compare", () => { ...@@ -157,15 +157,18 @@ describe("shot-compare", () => {
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH); page = await program.reLaunch(PAGE_PATH);
await page.waitFor(500); await page.waitFor(500);
await page.callMethod('getWindowInfo');
await page.callMethod('getDeviceInfo');
// set webview-screenshot-comparison page baseSrc
baseSrc =
process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` :
"http://test.dcloud.io/unix_h5_build/98_dev_hello-uvue/#/";
// set webview-screenshot-comparison page baseSrc page.setData({
baseSrc = baseSrc,
process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` : });
"http://test.dcloud.io/unix_h5_build/98_dev_hello-uvue/#/"; });
page.setData({
baseSrc,
});
});
beforeEach(async () => { beforeEach(async () => {
page = await program.reLaunch(PAGE_PATH); page = await program.reLaunch(PAGE_PATH);
...@@ -175,23 +178,23 @@ describe("shot-compare", () => { ...@@ -175,23 +178,23 @@ describe("shot-compare", () => {
pageIndex++; pageIndex++;
}); });
test.each(pages)("%s", async () => { test.each(pages)("%s", async () => {
const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]); const isNeedAdbScreenshot = needAdbScreenshot(pages[pageIndex]);
const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]); const isCustomNavigationBar = customNavigationPages.includes(pages[pageIndex]);
const { const {
statusBarHeight, statusBarHeight,
devicePixelRatio devicePixelRatio
} = await page.data(); } = await page.data();
const screenshotParams = { const screenshotParams = {
fullPage: true, fullPage: true,
adb: isNeedAdbScreenshot, adb: isNeedAdbScreenshot,
// adb 截图时跳过状态栏 // adb 截图时跳过状态栏
area: { area: {
x: 0, x: 0,
y: statusBarHeight * devicePixelRatio, y: statusBarHeight * devicePixelRatio,
}, },
} }
const screenshotPath = `__webview__${pages[pageIndex].replace(/\//g, "-")}`; const screenshotPath = `__webview__${pages[pageIndex].replace(/\//g, "-")}`;
// web in webview screenshot // web in webview screenshot
// 加载依赖页面 // 加载依赖页面
...@@ -212,36 +215,36 @@ describe("shot-compare", () => { ...@@ -212,36 +215,36 @@ describe("shot-compare", () => {
isCustomNavigationBar, isCustomNavigationBar,
}); });
const startTime = Date.now(); const startTime = Date.now();
await page.waitFor(async () => { await page.waitFor(async () => {
const isLoaded = await page.data("isLoaded"); const isLoaded = await page.data("isLoaded");
return isLoaded || Date.now() - startTime > 3000; return isLoaded || Date.now() - startTime > 3000;
}); });
await page.waitFor(800); await page.waitFor(800);
// web 端非 adb 截图时设置 offsetY 移除导航栏 // web 端非 adb 截图时设置 offsetY 移除导航栏
const webSnapshot = await program.screenshot({ const webSnapshot = await program.screenshot({
...screenshotParams, ...screenshotParams,
id: 'webview-screenshot-comparison', id: 'webview-screenshot-comparison',
offsetY: `${isCustomNavigationBar ? 0 : 44}` offsetY: `${isCustomNavigationBar ? 0 : 44}`
}); });
expect(webSnapshot).toMatchImageSnapshot({ expect(webSnapshot).toMatchImageSnapshot({
customSnapshotIdentifier() { customSnapshotIdentifier() {
return screenshotPath; return screenshotPath;
}, },
}); });
// app-android page screenshot comparison // app-android page screenshot comparison
const navigateMethod = pages[pageIndex].startsWith("pages/tab-bar") ? const navigateMethod = pages[pageIndex].startsWith("pages/tab-bar") ?
"switchTab" : "switchTab" :
"navigateTo"; "navigateTo";
page = await program[navigateMethod](`/${pages[pageIndex]}`); page = await program[navigateMethod](`/${pages[pageIndex]}`);
await page.waitFor(500); await page.waitFor(500);
const appAndroidSnapshot = await program.screenshot(screenshotParams); const appAndroidSnapshot = await program.screenshot(screenshotParams);
expect(appAndroidSnapshot).toMatchImageSnapshot({ expect(appAndroidSnapshot).toMatchImageSnapshot({
customSnapshotIdentifier() { customSnapshotIdentifier() {
return screenshotPath; return screenshotPath;
}, },
}); });
}); });
}); });
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
</template> </template>
<script> <script>
import { state, setStatusBarHeight, setDevicePixelRatio } from '@/store/index.uts'
export default { export default {
data() { data() {
return { return {
...@@ -13,17 +14,15 @@ ...@@ -13,17 +14,15 @@
src: '', src: '',
webviewContext: null as WebviewContext | null, webviewContext: null as WebviewContext | null,
isLoaded: false, isLoaded: false,
statusBarHeight: 0, statusBarHeight: state.statusBarHeight,
isCustomNavigationBar: false, isCustomNavigationBar: false,
devicePixelRatio: 1, devicePixelRatio: state.devicePixelRatio,
webviewStyles: { webviewStyles: {
progress: false progress: false
} }
} }
}, },
onReady() { onReady() {
this.getWindowInfo();
this.getDeviceInfo();
this.webviewContext = uni.createWebviewContext('webview-screenshot-comparison', this) this.webviewContext = uni.createWebviewContext('webview-screenshot-comparison', this)
}, },
methods: { methods: {
...@@ -35,13 +34,13 @@ ...@@ -35,13 +34,13 @@
}, },
getWindowInfo() { getWindowInfo() {
const res = uni.getWindowInfo(); const res = uni.getWindowInfo();
// 获取状态栏, 供截图对比使用 // 获取状态栏, 供截图对比使用
this.statusBarHeight = res.statusBarHeight; setStatusBarHeight(res.statusBarHeight);
}, },
getDeviceInfo: function () { getDeviceInfo: function () {
const res = uni.getDeviceInfo(); const res = uni.getDeviceInfo();
// 获取像素比, 供截图对比使用 // 获取像素比, 供截图对比使用
this.devicePixelRatio = res.devicePixelRatio !== null ? parseFloat(res.devicePixelRatio!) : 1 setDevicePixelRatio(res.devicePixelRatio !== null ? parseFloat(res.devicePixelRatio!) : 1);
} }
} }
} }
......
...@@ -148,7 +148,9 @@ describe("shot-compare", () => { ...@@ -148,7 +148,9 @@ describe("shot-compare", () => {
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH); page = await program.reLaunch(PAGE_PATH);
await page.waitFor(500); await page.waitFor(500);
await page.callMethod('getWindowInfo');
await page.callMethod('getDeviceInfo');
// set webview-screenshot page baseSrc // set webview-screenshot page baseSrc
baseSrc = baseSrc =
process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` : process.env.UNI_WEB_SERVICE_URL ? `${process.env.UNI_WEB_SERVICE_URL}/#/` :
...@@ -172,7 +174,7 @@ describe("shot-compare", () => { ...@@ -172,7 +174,7 @@ describe("shot-compare", () => {
const { const {
headerHeight, headerHeight,
devicePixelRatio devicePixelRatio
} = await page.data(); } = await page.data();
const screenshotParams = { const screenshotParams = {
fullPage: true, fullPage: true,
adb: isNeedAdbScreenshot, adb: isNeedAdbScreenshot,
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
</web-view> </web-view>
</template> </template>
<script> <script>
import { state, setStatusBarHeight, setDevicePixelRatio } from '@/store/index.uts'
export default { export default {
data() { data() {
return { return {
...@@ -16,13 +17,11 @@ ...@@ -16,13 +17,11 @@
webviewStyles: { webviewStyles: {
progress: false progress: false
}, },
headerHeight: 0, headerHeight: state.statusBarHeight,
devicePixelRatio: 1 devicePixelRatio: state.devicePixelRatio
} }
}, },
onReady() { onReady() {
this.getWindowInfo();
this.getDeviceInfo();
this.webviewContext = uni.createWebviewContext('webview-screenshot', this) this.webviewContext = uni.createWebviewContext('webview-screenshot', this)
}, },
methods: { methods: {
...@@ -35,12 +34,12 @@ ...@@ -35,12 +34,12 @@
getWindowInfo() { getWindowInfo() {
const res = uni.getWindowInfo(); const res = uni.getWindowInfo();
// 获取状态栏, 供截图对比使用 // 获取状态栏, 供截图对比使用
this.headerHeight = res.statusBarHeight; setStatusBarHeight(res.statusBarHeight);
}, },
getDeviceInfo: function () { getDeviceInfo: function () {
const res = uni.getDeviceInfo(); const res = uni.getDeviceInfo();
// 获取像素比, 供截图对比使用 // 获取像素比, 供截图对比使用
this.devicePixelRatio = res.devicePixelRatio !== null ? parseFloat(res.devicePixelRatio!) : 1 setDevicePixelRatio(res.devicePixelRatio !== null ? parseFloat(res.devicePixelRatio!) : 1);
} }
} }
} }
......
...@@ -2,13 +2,19 @@ export type State = { ...@@ -2,13 +2,19 @@ export type State = {
lifeCycleNum: number lifeCycleNum: number
componentMsg: number, componentMsg: number,
appLaunchPath: string appLaunchPath: string
appShowPath: string appShowPath: string,
// 状态栏高度
statusBarHeight : number,
// 设备像素比
devicePixelRatio : number
} }
export const state = reactive({ export const state = reactive({
lifeCycleNum: 0, lifeCycleNum: 0,
componentMsg: 0, componentMsg: 0,
appLaunchPath: '', appLaunchPath: '',
appShowPath: '', appShowPath: '',
statusBarHeight: 0,
devicePixelRatio: 1
} as State) } as State)
export const setLifeCycleNum = (num: number) => { export const setLifeCycleNum = (num: number) => {
...@@ -26,3 +32,12 @@ export const setAppLaunchPath = (path: string) => { ...@@ -26,3 +32,12 @@ export const setAppLaunchPath = (path: string) => {
export const setAppShowPath = (path: string) => { export const setAppShowPath = (path: string) => {
state.appShowPath = path state.appShowPath = path
} }
export const setStatusBarHeight = (height : number) => {
state.statusBarHeight = height
}
export const setDevicePixelRatio = (devicePixelRatio : number) => {
state.devicePixelRatio = devicePixelRatio
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册