Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
3e5dc43e
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
3e5dc43e
编写于
1月 26, 2024
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: 低版本安卓不再进行截图对比
上级
bd6b3b80
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
252 addition
and
244 deletion
+252
-244
pages/API/download-file/download-file.test.js
pages/API/download-file/download-file.test.js
+5
-8
pages/API/request/request.test.js
pages/API/request/request.test.js
+28
-32
pages/API/upload-file/upload-file.test.js
pages/API/upload-file/upload-file.test.js
+26
-26
pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js
...reenshot-comparison/webview-screenshot-comparison.test.js
+109
-101
pages/webview-screenshot/webview-screenshot.test.js
pages/webview-screenshot/webview-screenshot.test.js
+84
-77
未找到文件。
pages/API/download-file/download-file.test.js
浏览文件 @
3e5dc43e
...
...
@@ -25,26 +25,23 @@ describe('ExtApi-DownloadFile', () => {
let
shouldTestCookie
=
false
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
version
=
process
.
env
.
uniTestPlatformInfo
version
=
version
.
split
(
"
"
)[
1
]
version
=
parseInt
(
version
.
split
(
"
"
)[
1
])
shouldTestCookie
=
version
>
9
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
}
else
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
// TODO 测试网址调整后放开此测试
shouldTestCookie
=
false
}
if
(
!
shouldTestCookie
)
{
return
}
it
(
'
Check Set Cookie
'
,
async
()
=>
{
if
(
!
shouldTestCookie
)
{
return
}
res
=
await
page
.
callMethod
(
'
jest_set_cookie
'
)
await
page
.
waitFor
(
2000
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
)
});
it
(
'
Check Delete Cookie
'
,
async
()
=>
{
if
(
!
shouldTestCookie
)
{
return
}
res
=
await
page
.
callMethod
(
'
jest_delete_cookie
'
)
await
page
.
waitFor
(
2000
);
res
=
await
page
.
data
(
'
jest_result
'
);
...
...
pages/API/request/request.test.js
浏览文件 @
3e5dc43e
...
...
@@ -39,8 +39,8 @@ describe('ExtApi-Request', () => {
beforeEach
(
async
()
=>
{
await
page
.
setData
({
jest_result
:
false
,
data
:
null
,
jest_result
:
false
,
data
:
null
,
header
:
null
})
});
...
...
@@ -69,41 +69,37 @@ describe('ExtApi-Request', () => {
});
it
(
'
Check PATCH
'
,
async
()
=>
{
await
request
(
page
,
'
PATCH
'
);
});
});
if
(
process
.
env
.
uniTestPlatformInfo
.
indexOf
(
'
web
'
)
===
-
1
)
{
it
(
'
Check OPTIONS
'
,
async
()
=>
{
await
request
(
page
,
'
OPTIONS
'
);
});
});
}
it
(
'
Check HEAD
'
,
async
()
=>
{
await
request
(
page
,
'
HEAD
'
);
});
if
(
process
.
env
.
uniTestPlatformInfo
.
indexOf
(
'
web
'
)
===
-
1
)
{
it
(
'
Check Set Cookie
'
,
async
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
version
=
process
.
env
.
uniTestPlatformInfo
version
=
version
.
split
(
"
"
)[
1
]
if
(
version
>
9
){
res
=
await
page
.
callMethod
(
'
jest_set_cookie
'
)
await
page
.
waitFor
(
2000
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
)
}
}
});
it
(
'
Check Delete Cookie
'
,
async
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
version
=
process
.
env
.
uniTestPlatformInfo
version
=
version
.
split
(
"
"
)[
1
]
if
(
version
>
9
){
res
=
await
page
.
callMethod
(
'
jest_delete_cookie
'
)
await
page
.
waitFor
(
2000
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
)
}
}
});
});
let
shouldTestCookie
=
false
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
version
=
process
.
env
.
uniTestPlatformInfo
version
=
parseInt
(
version
.
split
(
"
"
)[
1
])
shouldTestCookie
=
version
>
9
}
if
(
!
shouldTestCookie
)
{
return
}
it
(
'
Check Set Cookie
'
,
async
()
=>
{
res
=
await
page
.
callMethod
(
'
jest_set_cookie
'
)
await
page
.
waitFor
(
2000
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
)
});
it
(
'
Check Delete Cookie
'
,
async
()
=>
{
res
=
await
page
.
callMethod
(
'
jest_delete_cookie
'
)
await
page
.
waitFor
(
2000
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
)
});
});
pages/API/upload-file/upload-file.test.js
浏览文件 @
3e5dc43e
const
PAGE_PATH
=
'
/pages/API/upload-file/upload-file
'
describe
(
'
ExtApi-UploadFile
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
// TODO: web 端暂不支持测试
it
(
'
web
'
,
async
()
=>
{
expect
(
1
).
toBe
(
1
)
})
})
return
}
...
...
@@ -27,36 +27,36 @@ describe('ExtApi-UploadFile', () => {
it
(
'
Check
'
,
async
()
=>
{
expect
(
res
).
toBe
(
true
);
});
it
(
'
Check files upload
'
,
async
()
=>
{
res
=
await
page
.
callMethod
(
'
jest_files_upload
'
)
await
page
.
waitFor
(
2000
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
)
});
let
shouldTestCookie
=
false
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
version
=
process
.
env
.
uniTestPlatformInfo
version
=
parseInt
(
version
.
split
(
"
"
)[
1
])
shouldTestCookie
=
version
>
9
}
if
(
!
shouldTestCookie
)
{
return
}
it
(
'
Check Set Cookie
'
,
async
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
version
=
process
.
env
.
uniTestPlatformInfo
version
=
version
.
split
(
"
"
)[
1
]
if
(
version
>
9
){
res
=
await
page
.
callMethod
(
'
jest_set_cookie
'
)
await
page
.
waitFor
(
2000
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
)
}
}
res
=
await
page
.
callMethod
(
'
jest_set_cookie
'
)
await
page
.
waitFor
(
2000
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
)
});
it
(
'
Check Delete Cookie
'
,
async
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
version
=
process
.
env
.
uniTestPlatformInfo
version
=
version
.
split
(
"
"
)[
1
]
if
(
version
>
9
){
res
=
await
page
.
callMethod
(
'
jest_delete_cookie
'
)
await
page
.
waitFor
(
2000
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
)
}
}
});
it
(
'
Check files upload
'
,
async
()
=>
{
res
=
await
page
.
callMethod
(
'
jest_files_upload
'
)
res
=
await
page
.
callMethod
(
'
jest_delete_cookie
'
)
await
page
.
waitFor
(
2000
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
)
});
});
});
pages/webview-screenshot-comparison/webview-screenshot-comparison.test.js
浏览文件 @
3e5dc43e
...
...
@@ -193,8 +193,8 @@ const pages = [
// "pages/API/install-apk/install-apk",
// "pages/template/scroll-sticky/scroll-sticky",
// "pages/API/exit/exit",
// "pages/API/element-takesnapshot/element-takesnapshot",
// "pages/API/get-system-setting/get-system-setting",
// "pages/API/element-takesnapshot/element-takesnapshot",
// "pages/API/get-system-setting/get-system-setting",
// "pages/API/get-app-authorize-setting/get-app-authorize-setting",
// 仅 web
...
...
@@ -223,7 +223,7 @@ const needAdbScreenshotPages = [
"
pages/API/action-sheet/action-sheet
"
,
"
pages/API/modal/modal
"
,
"
pages/API/loading/loading
"
,
"
pages/API/toast/toast
"
,
"
pages/API/toast/toast
"
,
"
pages/API/pull-down-refresh/pull-down-refresh
"
,
];
...
...
@@ -235,115 +235,123 @@ const PAGE_PATH =
"
/pages/webview-screenshot-comparison/webview-screenshot-comparison
"
;
describe
(
"
shot-compare
"
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
"
android
"
))
{
let
page
=
null
;
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
);
let
shouldCompareScreenShot
=
false
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
version
=
process
.
env
.
uniTestPlatformInfo
version
=
parseInt
(
version
.
split
(
"
"
)[
1
])
shouldCompareScreenShot
=
version
>
9
}
// 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-uni-app-x/#/
"
;
page
.
setData
({
baseSrc
,
});
});
if
(
!
shouldCompareScreenShot
)
{
it
(
"
other platform not support
"
,
async
()
=>
{
expect
(
1
).
toBe
(
1
);
});
return
}
beforeEach
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
);
await
page
.
waitFor
(
500
);
});
afterEach
(()
=>
{
pageIndex
++
;
let
page
=
null
;
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
);
// 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-uni-app-x/#/
"
;
page
.
setData
({
baseSrc
,
});
});
test
.
each
(
pages
)(
"
%s
"
,
async
()
=>
{
const
isNeedAdbScreenshot
=
needAdbScreenshot
(
pages
[
pageIndex
]);
const
isCustomNavigationBar
=
customNavigationPages
.
includes
(
pages
[
pageIndex
]);
const
{
statusBarHeight
,
devicePixelRatio
}
=
await
page
.
data
();
const
screenshotParams
=
{
fullPage
:
true
,
adb
:
isNeedAdbScreenshot
,
// adb 截图时跳过状态栏
area
:
{
x
:
0
,
y
:
statusBarHeight
*
devicePixelRatio
,
},
}
const
screenshotPath
=
`__webview__
${
pages
[
pageIndex
].
replace
(
/
\/
/g
,
"
-
"
)}
`
;
beforeEach
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
);
await
page
.
waitFor
(
500
);
});
afterEach
(()
=>
{
pageIndex
++
;
});
// web in webview screenshot
// 加载依赖页面
if
(
childToParentPagesMap
.
get
(
pages
[
pageIndex
]))
{
await
page
.
setData
({
src
:
`
${
baseSrc
}${
childToParentPagesMap
.
get
(
pages
[
pageIndex
])}
`
,
isLoaded
:
false
});
await
page
.
waitFor
(
async
()
=>
{
const
isLoaded
=
await
page
.
data
(
"
isLoaded
"
);
return
isLoaded
||
Date
.
now
()
-
startTime
>
10000
;
});
await
page
.
waitFor
(
200
);
}
test
.
each
(
pages
)(
"
%s
"
,
async
()
=>
{
const
isNeedAdbScreenshot
=
needAdbScreenshot
(
pages
[
pageIndex
]);
const
isCustomNavigationBar
=
customNavigationPages
.
includes
(
pages
[
pageIndex
]);
const
{
statusBarHeight
,
devicePixelRatio
}
=
await
page
.
data
();
const
screenshotParams
=
{
fullPage
:
true
,
adb
:
isNeedAdbScreenshot
,
// adb 截图时跳过状态栏
area
:
{
x
:
0
,
y
:
statusBarHeight
*
devicePixelRatio
,
},
}
const
screenshotPath
=
`__webview__
${
pages
[
pageIndex
].
replace
(
/
\/
/g
,
"
-
"
)}
`
;
// web in webview screenshot
// 加载依赖页面
if
(
childToParentPagesMap
.
get
(
pages
[
pageIndex
]))
{
await
page
.
setData
({
src
:
`
${
baseSrc
}${
pages
[
pageIndex
]}
`
,
isLoaded
:
false
,
isCustomNavigationBar
,
src
:
`
${
baseSrc
}${
childToParentPagesMap
.
get
(
pages
[
pageIndex
])}
`
,
isLoaded
:
false
});
const
startTime
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
const
isLoaded
=
await
page
.
data
(
"
isLoaded
"
);
return
isLoaded
||
Date
.
now
()
-
startTime
>
3
000
;
return
isLoaded
||
Date
.
now
()
-
startTime
>
10
000
;
});
await
page
.
waitFor
(
800
);
if
(
pages
[
pageIndex
].
includes
(
"
load-font-face
"
))
{
await
page
.
waitFor
(
3000
);
}
await
page
.
waitFor
(
200
);
}
await
page
.
setData
({
src
:
`
${
baseSrc
}${
pages
[
pageIndex
]}
`
,
isLoaded
:
false
,
isCustomNavigationBar
,
});
// web 端非 adb 截图时设置 offsetY 移除导航栏
const
webSnapshot
=
await
program
.
screenshot
({
...
screenshotParams
,
id
:
'
webview-screenshot-comparison
'
,
offsetY
:
`
${
isCustomNavigationBar
?
0
:
44
}
`
});
expect
(
webSnapshot
).
toMatchImageSnapshot
({
customSnapshotIdentifier
()
{
return
screenshotPath
;
},
});
const
startTime
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
const
isLoaded
=
await
page
.
data
(
"
isLoaded
"
);
return
isLoaded
||
Date
.
now
()
-
startTime
>
3000
;
});
await
page
.
waitFor
(
800
);
if
(
pages
[
pageIndex
].
includes
(
"
load-font-face
"
))
{
await
page
.
waitFor
(
3000
);
}
// app-android page screenshot comparison
const
navigateMethod
=
pages
[
pageIndex
].
startsWith
(
"
pages/tabBar
"
)
?
"
switchTab
"
:
"
navigateTo
"
;
page
=
await
program
[
navigateMethod
](
`/
${
pages
[
pageIndex
]}
`
);
await
page
.
waitFor
(
500
);
if
(
pages
[
pageIndex
].
includes
(
"
load-font-face
"
))
{
await
page
.
waitFor
(
3000
);
}
const
appAndroidSnapshot
=
await
program
.
screenshot
(
screenshotParams
);
expect
(
appAndroidSnapshot
).
toMatchImageSnapshot
({
customSnapshotIdentifier
()
{
return
screenshotPath
;
},
});
// web 端非 adb 截图时设置 offsetY 移除导航栏
const
webSnapshot
=
await
program
.
screenshot
({
...
screenshotParams
,
id
:
'
webview-screenshot-comparison
'
,
offsetY
:
`
${
isCustomNavigationBar
?
0
:
44
}
`
});
}
else
{
it
(
"
other platform not support
"
,
async
()
=>
{
expect
(
1
).
toBe
(
1
);
expect
(
webSnapshot
).
toMatchImageSnapshot
({
customSnapshotIdentifier
()
{
return
screenshotPath
;
},
});
}
});
// app-android page screenshot comparison
const
navigateMethod
=
pages
[
pageIndex
].
startsWith
(
"
pages/tabBar
"
)
?
"
switchTab
"
:
"
navigateTo
"
;
page
=
await
program
[
navigateMethod
](
`/
${
pages
[
pageIndex
]}
`
);
await
page
.
waitFor
(
500
);
if
(
pages
[
pageIndex
].
includes
(
"
load-font-face
"
))
{
await
page
.
waitFor
(
3000
);
}
const
appAndroidSnapshot
=
await
program
.
screenshot
(
screenshotParams
);
expect
(
appAndroidSnapshot
).
toMatchImageSnapshot
({
customSnapshotIdentifier
()
{
return
screenshotPath
;
},
});
});
});
pages/webview-screenshot/webview-screenshot.test.js
浏览文件 @
3e5dc43e
...
...
@@ -223,7 +223,7 @@ const needAdbScreenshotPages = [
"
pages/API/action-sheet/action-sheet
"
,
"
pages/API/modal/modal
"
,
"
pages/API/loading/loading
"
,
"
pages/API/toast/toast
"
,
"
pages/API/toast/toast
"
,
"
pages/API/pull-down-refresh/pull-down-refresh
"
,
];
...
...
@@ -235,92 +235,99 @@ const PAGE_PATH =
"
/pages/webview-screenshot/webview-screenshot
"
;
describe
(
"
shot-compare
"
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
"
android
"
))
{
let
page
=
null
;
let
pageIndex
=
0
;
let
baseSrc
=
""
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
);
await
page
.
waitFor
(
500
);
let
shouldCompareScreenShot
=
false
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
version
=
process
.
env
.
uniTestPlatformInfo
version
=
parseInt
(
version
.
split
(
"
"
)[
1
])
shouldCompareScreenShot
=
version
>
9
}
// set webview-screenshot 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-uni-app-x/#/
"
;
page
.
setData
({
baseSrc
,
});
});
if
(
!
shouldCompareScreenShot
)
{
it
(
"
other platform not support
"
,
async
()
=>
{
expect
(
1
).
toBe
(
1
);
});
return
}
let
page
=
null
;
let
pageIndex
=
0
;
let
baseSrc
=
""
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
);
await
page
.
waitFor
(
500
);
beforeEach
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
);
await
page
.
waitFor
(
500
);
})
;
afterEach
(()
=>
{
pageIndex
++
;
// set webview-screenshot 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-uni-app-x/#/
"
;
page
.
setData
(
{
baseSrc
,
});
});
beforeEach
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
);
await
page
.
waitFor
(
500
);
});
afterEach
(()
=>
{
pageIndex
++
;
});
test
.
each
(
pages
)(
"
%s
"
,
async
()
=>
{
const
isNeedAdbScreenshot
=
needAdbScreenshot
(
pages
[
pageIndex
]);
const
isCustomNavigation
=
customNavigationPages
.
includes
(
pages
[
pageIndex
]);
const
{
headerHeight
,
devicePixelRatio
}
=
await
page
.
data
();
const
screenshotParams
=
{
fullPage
:
true
,
adb
:
isNeedAdbScreenshot
,
// adb 截图时跳过状态栏
area
:
{
x
:
0
,
y
:
(
headerHeight
-
44
)
*
devicePixelRatio
,
},
}
const
screenshotPath
=
`webview-shot__
${
pages
[
pageIndex
].
replace
(
/
\/
/g
,
"
-
"
)}
`
;
test
.
each
(
pages
)(
"
%s
"
,
async
()
=>
{
const
isNeedAdbScreenshot
=
needAdbScreenshot
(
pages
[
pageIndex
]);
const
isCustomNavigation
=
customNavigationPages
.
includes
(
pages
[
pageIndex
]);
const
{
headerHeight
,
devicePixelRatio
}
=
await
page
.
data
();
const
screenshotParams
=
{
fullPage
:
true
,
adb
:
isNeedAdbScreenshot
,
// adb 截图时跳过状态栏
area
:
{
x
:
0
,
y
:
(
headerHeight
-
44
)
*
devicePixelRatio
,
},
}
const
screenshotPath
=
`webview-shot__
${
pages
[
pageIndex
].
replace
(
/
\/
/g
,
"
-
"
)}
`
;
// web in webview screenshot
// 加载依赖页面
if
(
childToParentPagesMap
.
get
(
pages
[
pageIndex
]))
{
await
page
.
setData
({
src
:
`
${
baseSrc
}${
childToParentPagesMap
.
get
(
pages
[
pageIndex
])}
`
,
isLoaded
:
false
});
await
page
.
waitFor
(
async
()
=>
{
const
isLoaded
=
await
page
.
data
(
"
isLoaded
"
);
return
isLoaded
||
Date
.
now
()
-
startTime
>
10000
;
});
await
page
.
waitFor
(
200
);
}
// web in webview screenshot
// 加载依赖页面
if
(
childToParentPagesMap
.
get
(
pages
[
pageIndex
]))
{
await
page
.
setData
({
src
:
`
${
baseSrc
}${
pages
[
pageIndex
]}
`
,
isLoaded
:
false
,
needRemoveWebHead
:
!
isNeedAdbScreenshot
,
src
:
`
${
baseSrc
}${
childToParentPagesMap
.
get
(
pages
[
pageIndex
])}
`
,
isLoaded
:
false
});
const
startTime
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
const
isLoaded
=
await
page
.
data
(
"
isLoaded
"
);
return
isLoaded
||
Date
.
now
()
-
startTime
>
3
000
;
return
isLoaded
||
Date
.
now
()
-
startTime
>
10
000
;
});
await
page
.
waitFor
(
1000
);
if
(
pages
[
pageIndex
].
includes
(
"
load-font-face
"
))
{
await
page
.
waitFor
(
3000
);
}
await
page
.
waitFor
(
200
);
}
await
page
.
setData
({
src
:
`
${
baseSrc
}${
pages
[
pageIndex
]}
`
,
isLoaded
:
false
,
needRemoveWebHead
:
!
isNeedAdbScreenshot
,
});
// web 端非 adb 截图时设置 offsetY 移除导航栏
const
webSnapshot
=
await
program
.
screenshot
({
...
screenshotParams
,
offsetY
:
`
${
isCustomNavigation
?
0
:
headerHeight
}
`
});
expect
(
webSnapshot
).
toMatchImageSnapshot
({
customSnapshotIdentifier
()
{
return
screenshotPath
;
},
});
const
startTime
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
const
isLoaded
=
await
page
.
data
(
"
isLoaded
"
);
return
isLoaded
||
Date
.
now
()
-
startTime
>
3000
;
});
}
else
{
it
(
"
other platform not support
"
,
async
()
=>
{
expect
(
1
).
toBe
(
1
);
await
page
.
waitFor
(
1000
);
if
(
pages
[
pageIndex
].
includes
(
"
load-font-face
"
))
{
await
page
.
waitFor
(
3000
);
}
// web 端非 adb 截图时设置 offsetY 移除导航栏
const
webSnapshot
=
await
program
.
screenshot
({
...
screenshotParams
,
offsetY
:
`
${
isCustomNavigation
?
0
:
headerHeight
}
`
});
}
});
expect
(
webSnapshot
).
toMatchImageSnapshot
({
customSnapshotIdentifier
()
{
return
screenshotPath
;
},
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录