From f1faa3a9cbcf9598f6131a4111aa481699e0ae5b Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Tue, 9 Jan 2024 19:45:04 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=88=AA=E5=9B=BE=E5=AF=B9=E6=AF=94?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BC=98=E5=8C=96=20webview=20src=20?= =?UTF-8?q?=E4=B8=BA=E5=8F=91=E8=A1=8C=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webview-screenshot-comparison.test.js | 24 ++++++++---------- .../webview-screenshot-comparison.uvue | 25 +++++++++---------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js b/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js index 4aa1016c..f2156dc7 100644 --- a/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js +++ b/pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js @@ -234,13 +234,13 @@ describe("shot-compare", () => { page = await program.reLaunch(PAGE_PATH); await page.waitFor(500); - // pre check webview-screenshot-comparison page baseSrc - const data = await page.data(); - const _baseSrc = data["baseSrc"]; - if (!_baseSrc) { - throw new Error("webview-screenshot-comparison page baseSrc is null"); - } - baseSrc = _baseSrc; + // set webview-screenshot-comparison page baseSrc + baseSrc = + process.env.UNI_WEB_SERVICE_URL || + "http://test.dcloud.io/unix_h5_build/98_dev_hello-uni-app-x/#/"; + page.setData({ + baseSrc, + }); }); beforeEach(async () => { @@ -267,8 +267,7 @@ describe("shot-compare", () => { const isLoaded = page.data("isLoaded"); return isLoaded || Date.now() - startTime > 10000; }); - // 这个等待无法保证 web 页面加载完成,可以等 web 服务调整为发行服务后进行优化 - await page.waitFor(4000); + await page.waitFor(200); } await page.setData({ src: `${baseSrc}${pages[pageIndex]}`, @@ -279,10 +278,9 @@ describe("shot-compare", () => { const startTime = Date.now(); await page.waitFor(async () => { const isLoaded = page.data("isLoaded"); - return isLoaded || Date.now() - startTime > 10000; + return isLoaded || Date.now() - startTime > 3000; }); - // 这个等待无法保证 web 页面加载完成,可以等 web 服务调整为发行服务后进行优化 - await page.waitFor(4000); + await page.waitFor(200); if (pages[pageIndex].includes("load-font-face")) { await page.waitFor(3000); } @@ -308,7 +306,7 @@ describe("shot-compare", () => { page = await program[navigateMethod](`/${pages[pageIndex]}`); await page.waitFor(500); if (pages[pageIndex].includes("load-font-face")) { - await page.waitFor(2000); + await page.waitFor(3000); } const appAndroidSnapshot = await program.screenshot({ fullPage: isNeedAdbScreenshot ? false : true, diff --git a/pages/webview-screenshot-comparison/webview-screenshot-comparison.uvue b/pages/webview-screenshot-comparison/webview-screenshot-comparison.uvue index ad53cc66..5c7681cc 100644 --- a/pages/webview-screenshot-comparison/webview-screenshot-comparison.uvue +++ b/pages/webview-screenshot-comparison/webview-screenshot-comparison.uvue @@ -8,7 +8,6 @@ export default { data() { return { - // example baseSrc: 'http://ip:port/#/', baseSrc: '', src: '', webviewContext: null as WebviewContext | null, @@ -25,18 +24,18 @@ }, appendWebHeadPlaceholder() { this.webviewContext?.evalJS(` - const hasWebHeadPlaceholder = document.querySelector('.web-head-placeholder-for-screenshot-comparison'); - if (hasWebHeadPlaceholder) { - return; - } - const webHeadPlaceholder = document.createElement('div'); - webHeadPlaceholder.style.height = '52px'; - 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 hasWebHeadPlaceholder = document.querySelector('.web-head-placeholder-for-screenshot-comparison'); + if (hasWebHeadPlaceholder) { + return; + } + const webHeadPlaceholder = document.createElement('div'); + webHeadPlaceholder.style.height = '52px'; + 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); + `); }, loaded() { this.isLoaded = true -- GitLab