Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
be709506
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6373
Star
108
Fork
184
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
24
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
24
Issue
24
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
be709506
编写于
3月 27, 2025
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: 优化部分示例及测试
上级
cd992c61
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
117 addition
and
264 deletion
+117
-264
pages/API/get-window-info/get-window-info.test.js
pages/API/get-window-info/get-window-info.test.js
+9
-9
pages/API/get-window-info/get-window-info.uvue
pages/API/get-window-info/get-window-info.uvue
+1
-5
pages/API/show-toast/show-toast.test.js
pages/API/show-toast/show-toast.test.js
+17
-26
pages/component/image/image.test.js
pages/component/image/image.test.js
+7
-24
pages/component/rich-text/rich-text-tags.test.js
pages/component/rich-text/rich-text-tags.test.js
+9
-70
pages/component/rich-text/rich-text.test.js
pages/component/rich-text/rich-text.test.js
+3
-3
pages/component/rich-text/rich-text.uvue
pages/component/rich-text/rich-text.uvue
+17
-20
pages/component/sticky-header/sticky-header.test.js
pages/component/sticky-header/sticky-header.test.js
+3
-19
pages/component/text/text-props.test.js
pages/component/text/text-props.test.js
+2
-2
pages/component/text/text-props.uvue
pages/component/text/text-props.uvue
+0
-3
pages/component/video/video.test.js
pages/component/video/video.test.js
+13
-13
pages/component/web-view/web-view.test.js
pages/component/web-view/web-view.test.js
+3
-3
pages/component/web-view/web-view.uvue
pages/component/web-view/web-view.uvue
+25
-28
pages/pages.test.js
pages/pages.test.js
+2
-19
pages/template/list-news/list-news.test.js
pages/template/list-news/list-news.test.js
+6
-20
未找到文件。
pages/API/get-window-info/get-window-info.test.js
浏览文件 @
be709506
...
...
@@ -13,7 +13,7 @@ describe('ExtApi-GetWindowInfo', () => {
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
600
);
res
=
await
p
age
.
callMethod
(
'
jest_getWindowInfo
'
)
res
=
await
p
rogram
.
callUniMethod
(
'
getWindowInfo
'
);
});
it
(
'
Check GetWindowInfo
'
,
async
()
=>
{
...
...
@@ -23,13 +23,13 @@ describe('ExtApi-GetWindowInfo', () => {
if
(
numberProperties
.
indexOf
(
key
)
!=
-
1
)
{
expect
(
value
).
toBeGreaterThanOrEqual
(
0
);
}
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
if
(
res
.
safeAreaInsets
.
bottom
>
0
)
{
expect
(
res
.
safeAreaInsets
.
top
+
44
+
res
.
windowHeight
).
toBe
(
res
.
screenHeight
);
}
else
{
expect
(
res
.
safeAreaInsets
.
top
+
44
+
res
.
windowHeight
).
toBe
(
res
.
safeArea
.
bottom
);
}
}
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
if
(
res
.
safeAreaInsets
.
bottom
>
0
)
{
expect
(
res
.
safeAreaInsets
.
top
+
44
+
res
.
windowHeight
).
toBe
(
res
.
screenHeight
);
}
else
{
expect
(
res
.
safeAreaInsets
.
top
+
44
+
res
.
windowHeight
).
toBe
(
res
.
safeArea
.
bottom
);
}
}
});
});
});
pages/API/get-window-info/get-window-info.uvue
浏览文件 @
be709506
...
...
@@ -93,10 +93,6 @@
}
});
},
//自动化测试例专用
jest_getWindowInfo() : GetWindowInfoResult {
return uni.getWindowInfo();
},
}
}
</script>
...
...
@@ -105,4 +101,4 @@
.uni-pd {
padding-left: 15px;
}
</style>
</style>
pages/API/show-toast/show-toast.test.js
浏览文件 @
be709506
...
...
@@ -6,38 +6,29 @@ const isApp = isAndroid || isIOS || isHarmony
describe
(
'
API-toast
'
,
()
=>
{
let
page
;
const
screeShotParams
=
{
deviceShot
:
true
,
fullPage
:
true
}
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/API/show-toast/show-toast
'
)
await
page
.
waitFor
(
"
view
"
);
if
(
isApp
)
{
const
windowInfo
=
await
program
.
callUniMethod
(
'
getWindowInfo
'
);
// android 端 app-webview 时顶部安全区高度为0,所以统一设置为60
const
topSafeArea
=
isAndroid
?
60
:
windowInfo
.
safeAreaInsets
.
top
;
screeShotParams
.
area
=
{
x
:
0
,
y
:
topSafeArea
+
44
}
}
});
async
function
toScreenshot
(
imgName
)
{
if
(
isApp
)
{
await
page
.
waitFor
(
500
);
const
res
=
await
page
.
callMethod
(
'
jest_getWindowInfo
'
)
const
windowHeight
=
res
.
windowHeight
*
res
.
pixelRatio
;
const
windowWidth
=
res
.
windowWidth
*
res
.
pixelRatio
;
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
area
:
{
x
:
0
,
y
:
200
,
height
:
windowHeight
-
200
,
width
:
windowWidth
},
});
expect
(
image
).
toSaveImageSnapshot
({
customSnapshotIdentifier
()
{
return
imgName
}})
}
else
{
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
fullPage
:
true
});
expect
(
image
).
toSaveImageSnapshot
({
customSnapshotIdentifier
()
{
return
imgName
}})
}
const
image
=
await
program
.
screenshot
(
screeShotParams
);
expect
(
image
).
toSaveImageSnapshot
({
customSnapshotIdentifier
()
{
return
imgName
}})
await
page
.
waitFor
(
500
);
}
...
...
pages/component/image/image.test.js
浏览文件 @
be709506
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isMP
=
platformInfo
.
startsWith
(
'
mp
'
)
const
isAppWebview
=
!!
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
describe
(
'
component-native-image
'
,
()
=>
{
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isMP
=
platformInfo
.
startsWith
(
'
mp
'
)
const
screenshotParams
=
{
fullPage
:
true
}
let
page
;
let
start
=
0
;
async
function
getWindowInfo
()
{
const
windowInfoPage
=
await
program
.
reLaunch
(
'
/pages/API/get-window-info/get-window-info
'
)
await
windowInfoPage
.
waitFor
(
600
);
return
await
windowInfoPage
.
callMethod
(
'
jest_getWindowInfo
'
)
}
const
screenshotParams
=
{
fullPage
:
true
}
let
windowInfo
beforeAll
(
async
()
=>
{
if
(
!
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
)
{
screenshotParams
.
fullPage
=
false
windowInfo
=
await
getWindowInfo
()
let
offsetY
=
'
0
'
if
(
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
android
'
))
{
offsetY
=
`
${
windowInfo
.
statusBarHeight
+
44
}
`
}
if
(
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
ios
'
))
{
offsetY
=
`
${
windowInfo
.
safeAreaInsets
.
top
+
44
}
`
}
screenshotParams
.
offsetY
=
offsetY
}
page
=
await
program
.
reLaunch
(
'
/pages/component/image/image
'
);
await
page
.
waitFor
(
600
);
});
...
...
@@ -132,14 +115,14 @@ describe('component-native-image', () => {
if
(
process
.
env
.
android_cpu_type
===
'
x86_64
'
)
return
const
page
=
await
program
.
navigateTo
(
'
/pages/component/image/image-mode
'
);
await
page
.
waitFor
(
1000
);
const
image
=
await
program
.
screenshot
(
{
fullPage
:
true
}
)
const
image
=
await
program
.
screenshot
(
screenshotParams
)
expect
(
image
).
toSaveImageSnapshot
()
});
it
(
'
long-path-screenshot
'
,
async
()
=>
{
const
page
=
await
program
.
navigateTo
(
'
/pages/component/image/image-long
'
);
await
page
.
waitFor
(
3000
);
const
image
=
await
program
.
screenshot
(
{
fullPage
:
true
}
)
const
image
=
await
program
.
screenshot
(
screenshotParams
)
expect
(
image
).
toSaveImageSnapshot
()
})
});
pages/component/rich-text/rich-text-tags.test.js
浏览文件 @
be709506
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isIos
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isApp
=
isAndroid
||
isIos
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
const
isMP
=
platformInfo
.
startsWith
(
'
mp
'
)
const
isHarmony
=
platformInfo
.
startsWith
(
'
harmony
'
)
const
isApp
=
isAndroid
||
isIos
||
isHarmony
const
isAppWebview
=
!!
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
let
pageIndex
=
0
const
pages
=
[
'
/pages/component/rich-text/rich-text-tags
'
]
describe
(
"
rich-text-tags
"
,
()
=>
{
it
(
"
screenshot
"
,
async
()
=>
{
const
page
=
await
program
.
reLaunch
(
'
/pages/component/rich-text/rich-text-tags
'
);
await
page
.
waitFor
(
'
view
'
);
let
page
;
let
windowInfo
async
function
getWindowInfo
()
{
const
windowInfoPage
=
await
program
.
reLaunch
(
'
/pages/API/get-window-info/get-window-info
'
)
await
windowInfoPage
.
waitFor
(
600
);
return
await
windowInfoPage
.
callMethod
(
'
jest_getWindowInfo
'
)
}
describe
(
"
page screenshot test
"
,
()
=>
{
if
(
platformInfo
.
indexOf
(
'
safari
'
)
!==
-
1
)
{
it
(
'
暂时规避 safari 截图测试
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
return
}
beforeAll
(
async
()
=>
{
console
.
log
(
"
page screenshot test start
"
);
});
beforeEach
(
async
()
=>
{
const
currentPagePath
=
pages
[
pageIndex
]
page
=
await
program
.
reLaunch
(
currentPagePath
);
});
afterEach
(()
=>
{
pageIndex
++
;
});
afterAll
(()
=>
{
console
.
log
(
"
page screenshot test finish
"
);
});
test
.
each
(
pages
)(
"
%s
"
,
async
()
=>
{
const
currentPagePath
=
pages
[
pageIndex
]
console
.
log
(
"
Taking screenshot:
"
,
pageIndex
,
currentPagePath
);
let
fullPage
=
true
;
const
screenshotParams
=
{
fullPage
}
if
(
!
fullPage
&&
!
isAppWebview
)
{
if
(
!
windowInfo
)
{
windowInfo
=
await
getWindowInfo
()
page
=
await
program
.
reLaunch
(
currentPagePath
);
}
let
offsetY
=
'
0
'
if
(
isAndroid
)
{
offsetY
=
`
${
windowInfo
.
statusBarHeight
+
44
}
`
}
if
(
isIos
)
{
offsetY
=
`
${
windowInfo
.
safeAreaInsets
.
top
+
44
}
`
}
screenshotParams
.
offsetY
=
offsetY
}
await
page
.
waitFor
(
2000
);
const
image
=
await
program
.
screenshot
(
screenshotParams
);
expect
(
image
).
toSaveImageSnapshot
({
customSnapshotIdentifier
()
{
return
`__pages_test__/
${
currentPagePath
.
replace
(
/
\/
/g
,
"
-
"
).
substring
(
1
)}
`
}
})
await
page
.
waitFor
(
800
);
});
const
image
=
await
program
.
screenshot
({
fullPage
:
true
});
expect
(
image
).
toSaveImageSnapshot
();
})
});
pages/component/rich-text/rich-text.test.js
浏览文件 @
be709506
...
...
@@ -49,11 +49,11 @@ describe('rich-text-test', () => {
isItemClickTrigger
:
false
});
await
page
.
waitFor
(
1000
);
const
info
=
await
page
.
callMethod
(
'
getWindowInfoForTest
'
);
const
windowInfo
=
await
program
.
callUniMethod
(
'
getWindowInfo
'
);
const
rect
=
await
page
.
callMethod
(
'
getBoundingClientRectForTest
'
);
await
program
.
tap
({
x
:
(
rect
.
right
-
rect
.
left
)
/
2
,
y
:
i
nfo
.
statusBarHeight
+
44
+
(
rect
.
bottom
-
rect
.
top
)
/
2
y
:
windowI
nfo
.
statusBarHeight
+
44
+
(
rect
.
bottom
-
rect
.
top
)
/
2
});
await
page
.
waitFor
(
1000
);
expect
(
await
page
.
data
(
'
isItemClickTrigger
'
)).
toBe
(
true
);
...
...
@@ -65,7 +65,7 @@ describe('rich-text-test', () => {
await
program
.
navigateBack
();
await
program
.
tap
({
x
:
(
rect
.
right
-
rect
.
left
)
/
2
,
y
:
i
nfo
.
statusBarHeight
+
44
+
(
rect
.
bottom
-
rect
.
top
)
/
2
y
:
windowI
nfo
.
statusBarHeight
+
44
+
(
rect
.
bottom
-
rect
.
top
)
/
2
});
await
page
.
waitFor
(
1000
);
expect
(
await
page
.
data
(
'
isItemClickTrigger
'
)).
toBe
(
true
);
...
...
pages/component/rich-text/rich-text.uvue
浏览文件 @
be709506
...
...
@@ -2,12 +2,12 @@
<view>
<page-head title="rich-text"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<!-- #ifndef APP-HARMONY -->
<view class="uni-btn-v">
<navigator url="/pages/component/rich-text/rich-text-tags">
<button type="primary">rich-text渲染单个HTML标签示例</button>
</navigator>
</view>
<!-- #ifndef APP-HARMONY -->
<view class="uni-btn-v">
<navigator url="/pages/component/rich-text/rich-text-tags">
<button type="primary">rich-text渲染单个HTML标签示例</button>
</navigator>
</view>
<!-- #endif -->
<view class="uni-btn-v">
<navigator url="/pages/component/rich-text/rich-text-complex">
...
...
@@ -27,10 +27,10 @@
</view>
<view class="uni-title">
<text class="uni-subtitle-text">selectable</text>
</view>
<view class="text-box2">
<rich-text style="height: 80px;" :selectable="true"
:nodes="text"></rich-text>
</view>
<view class="text-box2">
<rich-text style="height: 80px;" :selectable="true"
:nodes="text"></rich-text>
</view>
</view>
</view>
...
...
@@ -72,7 +72,7 @@
if (this.richTextElement != null) {
this.richTextElement!.getBoundingClientRectAsync()!.then((elRect: DOMRect) => {
this.richTextHeight = elRect.height
console.log('richTextHeight:', this.richTextHeight)
console.log('richTextHeight:', this.richTextHeight)
})
}
},
...
...
@@ -83,9 +83,6 @@
getBoundingClientRectForTest() : DOMRect {
return uni.getElementById('test-rich-text')?.getBoundingClientRect()!;
},
getWindowInfoForTest() : GetWindowInfoResult {
return uni.getWindowInfo();
},
richTextParentClick() {
this.richTextStr = true;
}
...
...
@@ -97,11 +94,11 @@
.text-box {
padding: 20px 0;
background-color: white;
}
.text-box2 {
top: 20px;
background-color: white;
}
}
.text-box2 {
top: 20px;
background-color: white;
}
</style>
pages/component/sticky-header/sticky-header.test.js
浏览文件 @
be709506
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isMP
=
platformInfo
.
startsWith
(
'
mp
'
)
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isIos
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isHarmony
=
platformInfo
.
startsWith
(
'
harmony
'
)
describe
(
'
component-native-sticky-header
'
,
()
=>
{
...
...
@@ -13,26 +11,12 @@ describe('component-native-sticky-header', () => {
}
let
page
async
function
getWindowInfo
()
{
const
windowInfoPage
=
await
program
.
reLaunch
(
'
/pages/API/get-window-info/get-window-info
'
)
await
windowInfoPage
.
waitFor
(
600
);
return
await
windowInfoPage
.
callMethod
(
'
jest_getWindowInfo
'
)
}
const
screenshotParams
=
{
fullPage
:
true
}
let
windowInfo
const
screenshotParams
=
{
}
beforeAll
(
async
()
=>
{
if
(
!
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
)
{
screenshotParams
.
fullPage
=
false
windowInfo
=
await
getWindowInfo
()
let
offsetY
=
'
0
'
if
(
isAndroid
)
{
offsetY
=
`
${
windowInfo
.
statusBarHeight
+
44
}
`
}
if
(
isIos
)
{
offsetY
=
`
${
windowInfo
.
safeAreaInsets
.
top
+
44
}
`
}
screenshotParams
.
offsetY
=
offsetY
const
windowInfo
=
await
program
.
callUniMethod
(
'
getWindowInfo
'
);
screenshotParams
.
offsetY
=
`
${
windowInfo
.
safeAreaInsets
.
top
+
44
}
`
}
page
=
await
program
.
reLaunch
(
'
/pages/component/sticky-header/sticky-header
'
)
await
page
.
waitFor
(
'
sticky-header
'
)
...
...
pages/component/text/text-props.test.js
浏览文件 @
be709506
...
...
@@ -63,10 +63,10 @@ describe('text-props', () => {
}
const
rect
=
await
page
.
callMethod
(
"
getBoundingClientRectForTest
"
)
const
info
=
await
page
.
callMethod
(
"
getWindowInfoForTest
"
)
const
windowInfo
=
await
program
.
callUniMethod
(
'
getWindowInfo
'
);
let
x
=
Math
.
ceil
(
rect
.
left
+
rect
.
width
/
2
)
let
y
=
Math
.
ceil
(
i
nfo
.
statusBarHeight
+
44
+
rect
.
top
+
rect
.
height
/
2
)
let
y
=
Math
.
ceil
(
windowI
nfo
.
statusBarHeight
+
44
+
rect
.
top
+
rect
.
height
/
2
)
await
program
.
tap
({
x
:
x
,
...
...
pages/component/text/text-props.uvue
浏览文件 @
be709506
...
...
@@ -207,9 +207,6 @@
getBoundingClientRectForTest() : DOMRect | null {
return uni.getElementById('nested-text2')?.getBoundingClientRect();
},
getWindowInfoForTest() : GetWindowInfoResult {
return uni.getWindowInfo();
},
nestedText1TapForTest() {
this.isNestedText1TapTriggered = true;
},
...
...
pages/component/video/video.test.js
浏览文件 @
be709506
...
...
@@ -276,18 +276,18 @@ describe('component-native-video', () => {
autoTest
:
false
,
src
:
oldSrc
});
});
});
if
(
isAndroid
)
{
it
(
'
test sub component
'
,
async
()
=>
{
await
page
.
setData
({
subCompEnable
:
true
,
subCompShow
:
true
});
await
page
.
waitFor
(
100
);
expect
(
await
page
.
callMethod
(
'
hasSubComponent
'
)).
toBe
(
true
);
});
}
if
(
isAndroid
)
{
it
(
'
test sub component
'
,
async
()
=>
{
await
page
.
setData
({
subCompEnable
:
true
,
subCompShow
:
true
});
await
page
.
waitFor
(
100
);
expect
(
await
page
.
callMethod
(
'
hasSubComponent
'
)).
toBe
(
true
);
});
}
it
(
'
test enable-danmu
'
,
async
()
=>
{
await
page
.
callMethod
(
'
play
'
);
...
...
@@ -295,12 +295,12 @@ describe('component-native-video', () => {
await
page
.
setData
({
enableDanmu
:
false
});
const
info
=
await
page
.
call
Method
(
'
getWindowInfo
'
);
const
windowInfo
=
await
program
.
callUni
Method
(
'
getWindowInfo
'
);
const
image
=
await
program
.
screenshot
({
deviceShot
:
true
,
area
:
{
x
:
0
,
y
:
i
nfo
.
statusBarHeight
+
44
y
:
windowI
nfo
.
statusBarHeight
+
44
}
});
expect
(
image
).
toSaveImageSnapshot
();
...
...
pages/component/web-view/web-view.test.js
浏览文件 @
be709506
...
...
@@ -57,10 +57,10 @@ describe('component-native-web-view', () => {
});
if
(
!
isHarmony
)
{
it
(
'
test touch event
'
,
async
()
=>
{
const
info
=
await
page
.
call
Method
(
'
getWindowInfo
'
);
const
windowInfo
=
await
program
.
callUni
Method
(
'
getWindowInfo
'
);
await
program
.
tap
({
x
:
1
,
y
:
i
nfo
.
statusBarHeight
+
44
+
1
y
:
windowI
nfo
.
statusBarHeight
+
44
+
1
});
await
page
.
waitFor
(
500
);
if
(
!
isIOS
)
{
...
...
@@ -74,7 +74,7 @@ describe('component-native-web-view', () => {
await
page
.
waitFor
(
100
);
await
program
.
tap
({
x
:
10
,
y
:
i
nfo
.
statusBarHeight
+
44
+
10
y
:
windowI
nfo
.
statusBarHeight
+
44
+
10
});
await
page
.
waitFor
(
500
);
if
(
!
isIOS
)
{
...
...
pages/component/web-view/web-view.uvue
浏览文件 @
be709506
...
...
@@ -58,10 +58,10 @@
</view>
<!-- #endif -->
</view>
<!-- #endif -->
<!-- #ifdef APP-ANDROID || APP-IOS -->
<view class="safe-area-inset-bottom"></view>
<!-- #endif -->
<!-- #endif -->
<!-- #ifdef APP-ANDROID || APP-IOS -->
<view class="safe-area-inset-bottom"></view>
<!-- #endif -->
</view>
</template>
...
...
@@ -92,25 +92,25 @@
eventLoad: null as UTSJSONObject | null,
eventError: null as UTSJSONObject | null,
pointerEvents: 'auto',
isTouchEnable: false,
updateTitle: true,
isTouchEnable: false,
updateTitle: true,
showController: true
}
},
onLoad(options: OnLoadOptions) {
if (typeof options['url'] === 'string' && options['url']!.length > 0) {
const src = decodeURIComponent(options['url'] as string)
if (src != null) {
this.src = src
this.showController = false
}
}
if (typeof options['title'] === 'string' && options['title']!.length > 0) {
this.updateTitle = false;
uni.setNavigationBarTitle({
title: options['title']!
});
}
},
onLoad(options: OnLoadOptions) {
if (typeof options['url'] === 'string' && options['url']!.length > 0) {
const src = decodeURIComponent(options['url'] as string)
if (src != null) {
this.src = src
this.showController = false
}
}
if (typeof options['title'] === 'string' && options['title']!.length > 0) {
this.updateTitle = false;
uni.setNavigationBarTitle({
title: options['title']!
});
}
},
onReady() {
// #ifdef APP
...
...
@@ -230,9 +230,6 @@
this.isTouchEnable = event.clientX > 0 && event.clientY > 0;
}
},
getWindowInfo() : GetWindowInfoResult {
return uni.getWindowInfo();
},
//自动化测试专用
checkNativeWebView() : boolean {
// #ifdef APP
...
...
@@ -253,9 +250,9 @@
.align-items-center {
align-items: center;
}
.safe-area-inset-bottom {
height: var(--uni-safe-area-inset-bottom);
}
.safe-area-inset-bottom {
height: var(--uni-safe-area-inset-bottom);
}
</style>
pages/pages.test.js
浏览文件 @
be709506
...
...
@@ -361,12 +361,6 @@ if (isWeb) {
let
page
;
let
windowInfo
async
function
getWindowInfo
()
{
const
windowInfoPage
=
await
program
.
reLaunch
(
'
/pages/API/get-window-info/get-window-info
'
)
await
windowInfoPage
.
waitFor
(
600
);
return
await
windowInfoPage
.
callMethod
(
'
jest_getWindowInfo
'
)
}
function
getWaitForTagName
(
pagePath
)
{
if
(
pagePath
===
'
/pages/component/list-view/list-view-multiplex-input
'
)
{
return
'
input
'
...
...
@@ -406,6 +400,7 @@ describe("page screenshot test", () => {
beforeAll
(
async
()
=>
{
console
.
log
(
"
page screenshot test start
"
);
windowInfo
=
await
program
.
callUniMethod
(
'
getWindowInfo
'
);
});
beforeEach
(
async
()
=>
{
const
currentPagePath
=
pages
[
pageIndex
]
...
...
@@ -427,19 +422,7 @@ describe("page screenshot test", () => {
fullPage
}
if
(
!
fullPage
&&
!
isAppWebview
)
{
if
(
!
windowInfo
)
{
windowInfo
=
await
getWindowInfo
()
page
=
await
program
.
reLaunch
(
currentPagePath
);
await
page
.
waitFor
(
getWaitForTagName
(
currentPagePath
));
}
let
offsetY
=
'
0
'
if
(
isAndroid
)
{
offsetY
=
`
${
windowInfo
.
statusBarHeight
+
44
}
`
}
if
(
isIos
||
isHarmony
)
{
offsetY
=
`
${
windowInfo
.
safeAreaInsets
.
top
+
44
}
`
}
screenshotParams
.
offsetY
=
offsetY
screenshotParams
.
offsetY
=
isApp
?
`
${
windowInfo
.
safeAreaInsets
.
top
+
44
}
`
:
'
0
'
}
const
image
=
await
program
.
screenshot
(
screenshotParams
);
...
...
pages/template/list-news/list-news.test.js
浏览文件 @
be709506
// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isAppWebview
=
!!
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
describe
(
'
template-list-news
'
,
()
=>
{
let
page
;
async
function
getWindowInfo
()
{
const
windowInfoPage
=
await
program
.
reLaunch
(
'
/pages/API/get-window-info/get-window-info
'
)
await
windowInfoPage
.
waitFor
(
600
);
return
await
windowInfoPage
.
callMethod
(
'
jest_getWindowInfo
'
)
}
const
screenshotParams
=
{
fullPage
:
true
}
let
windowInfo
const
screenshotParams
=
{
}
beforeAll
(
async
()
=>
{
if
(
!
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
)
{
screenshotParams
.
fullPage
=
false
windowInfo
=
await
getWindowInfo
()
let
offsetY
=
'
0
'
if
(
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
android
'
))
{
offsetY
=
`
${
windowInfo
.
statusBarHeight
+
44
}
`
}
if
(
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
ios
'
))
{
offsetY
=
`
${
windowInfo
.
safeAreaInsets
.
top
+
44
}
`
}
screenshotParams
.
offsetY
=
offsetY
if
(
!
isAppWebview
)
{
const
windowInfo
=
await
program
.
callUniMethod
(
'
getWindowInfo
'
);
screenshotParams
.
offsetY
=
`
${
windowInfo
.
safeAreaInsets
.
top
+
44
}
`
}
page
=
await
program
.
reLaunch
(
'
/pages/template/list-news/list-news
'
);
await
page
.
waitFor
(
3000
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录