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

test: 截图对比测试优化 webview src 为发行地址

上级 b1c5c7f2
...@@ -234,13 +234,13 @@ describe("shot-compare", () => { ...@@ -234,13 +234,13 @@ describe("shot-compare", () => {
page = await program.reLaunch(PAGE_PATH); page = await program.reLaunch(PAGE_PATH);
await page.waitFor(500); await page.waitFor(500);
// pre check webview-screenshot-comparison page baseSrc // set webview-screenshot-comparison page baseSrc
const data = await page.data(); baseSrc =
const _baseSrc = data["baseSrc"]; process.env.UNI_WEB_SERVICE_URL ||
if (!_baseSrc) { "http://test.dcloud.io/unix_h5_build/98_dev_hello-uni-app-x/#/";
throw new Error("webview-screenshot-comparison page baseSrc is null"); page.setData({
} baseSrc,
baseSrc = _baseSrc; });
}); });
beforeEach(async () => { beforeEach(async () => {
...@@ -267,8 +267,7 @@ describe("shot-compare", () => { ...@@ -267,8 +267,7 @@ describe("shot-compare", () => {
const isLoaded = page.data("isLoaded"); const isLoaded = page.data("isLoaded");
return isLoaded || Date.now() - startTime > 10000; return isLoaded || Date.now() - startTime > 10000;
}); });
// 这个等待无法保证 web 页面加载完成,可以等 web 服务调整为发行服务后进行优化 await page.waitFor(200);
await page.waitFor(4000);
} }
await page.setData({ await page.setData({
src: `${baseSrc}${pages[pageIndex]}`, src: `${baseSrc}${pages[pageIndex]}`,
...@@ -279,10 +278,9 @@ describe("shot-compare", () => { ...@@ -279,10 +278,9 @@ describe("shot-compare", () => {
const startTime = Date.now(); const startTime = Date.now();
await page.waitFor(async () => { await page.waitFor(async () => {
const isLoaded = page.data("isLoaded"); const isLoaded = page.data("isLoaded");
return isLoaded || Date.now() - startTime > 10000; return isLoaded || Date.now() - startTime > 3000;
}); });
// 这个等待无法保证 web 页面加载完成,可以等 web 服务调整为发行服务后进行优化 await page.waitFor(200);
await page.waitFor(4000);
if (pages[pageIndex].includes("load-font-face")) { if (pages[pageIndex].includes("load-font-face")) {
await page.waitFor(3000); await page.waitFor(3000);
} }
...@@ -308,7 +306,7 @@ describe("shot-compare", () => { ...@@ -308,7 +306,7 @@ describe("shot-compare", () => {
page = await program[navigateMethod](`/${pages[pageIndex]}`); page = await program[navigateMethod](`/${pages[pageIndex]}`);
await page.waitFor(500); await page.waitFor(500);
if (pages[pageIndex].includes("load-font-face")) { if (pages[pageIndex].includes("load-font-face")) {
await page.waitFor(2000); await page.waitFor(3000);
} }
const appAndroidSnapshot = await program.screenshot({ const appAndroidSnapshot = await program.screenshot({
fullPage: isNeedAdbScreenshot ? false : true, fullPage: isNeedAdbScreenshot ? false : true,
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
export default { export default {
data() { data() {
return { return {
// example baseSrc: 'http://ip:port/#/',
baseSrc: '', baseSrc: '',
src: '', src: '',
webviewContext: null as WebviewContext | null, webviewContext: null as WebviewContext | null,
...@@ -25,18 +24,18 @@ ...@@ -25,18 +24,18 @@
}, },
appendWebHeadPlaceholder() { appendWebHeadPlaceholder() {
this.webviewContext?.evalJS(` this.webviewContext?.evalJS(`
const hasWebHeadPlaceholder = document.querySelector('.web-head-placeholder-for-screenshot-comparison'); const hasWebHeadPlaceholder = document.querySelector('.web-head-placeholder-for-screenshot-comparison');
if (hasWebHeadPlaceholder) { if (hasWebHeadPlaceholder) {
return; return;
} }
const webHeadPlaceholder = document.createElement('div'); const webHeadPlaceholder = document.createElement('div');
webHeadPlaceholder.style.height = '52px'; webHeadPlaceholder.style.height = '52px';
webHeadPlaceholder.style.backgroundColor = '#007aff'; webHeadPlaceholder.style.backgroundColor = '#007aff';
webHeadPlaceholder.classList.add('web-head-placeholder-for-screenshot-comparison'); webHeadPlaceholder.classList.add('web-head-placeholder-for-screenshot-comparison');
const uniPage = document.querySelector('uni-page'); const uniPage = document.querySelector('uni-page');
const uniPageHead = document.querySelector('uni-page-head'); const uniPageHead = document.querySelector('uni-page-head');
uniPage.insertBefore(webHeadPlaceholder, uniPageHead); uniPage.insertBefore(webHeadPlaceholder, uniPageHead);
`); `);
}, },
loaded() { loaded() {
this.isLoaded = true this.isLoaded = true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册