Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
f1d0c7b2
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6067
Star
93
Fork
166
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f1d0c7b2
编写于
6月 05, 2024
作者:
DCloud-yinjiacheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新image、video、web-view自动化测试用例
上级
e7d677d8
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
459 addition
and
43 deletion
+459
-43
hybrid/html/local.html
hybrid/html/local.html
+2
-0
pages/component/image/image.test.js
pages/component/image/image.test.js
+32
-0
pages/component/image/image.uvue
pages/component/image/image.uvue
+20
-3
pages/component/video/video.test.js
pages/component/video/video.test.js
+137
-11
pages/component/video/video.uvue
pages/component/video/video.uvue
+82
-2
pages/component/web-view-local/web-view-local.test.js
pages/component/web-view-local/web-view-local.test.js
+65
-12
pages/component/web-view-local/web-view-local.uvue
pages/component/web-view-local/web-view-local.uvue
+40
-7
pages/component/web-view/web-view.test.js
pages/component/web-view/web-view.test.js
+45
-1
pages/component/web-view/web-view.uvue
pages/component/web-view/web-view.uvue
+36
-7
未找到文件。
hybrid/html/local.html
浏览文件 @
f1d0c7b2
...
...
@@ -48,6 +48,8 @@
<input
type=
"file"
accept=
"image/*"
multiple
/>
<p
style=
"font-size: 14px;"
>
普通input
</p>
<input
placeholder=
"底部输入框"
/>
<br/>
<a
href=
"https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk"
download
>
hello uni-app x apk下载(自动化测试使用)
</a>
</div>
<!-- uni 的 SDK -->
<script
type=
"text/javascript"
src=
"uni.webview.1.5.5.js"
></script>
...
...
pages/component/image/image.test.js
浏览文件 @
f1d0c7b2
...
...
@@ -70,6 +70,38 @@ describe('component-native-image', () => {
})
}
it
(
'
test event load
'
,
async
()
=>
{
await
page
.
setData
({
autoTest
:
true
,
imageSrc
:
'
https://request.dcloud.net.cn/api/http/contentType/image/png
'
});
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventLoad
'
);
});
expect
(
await
page
.
data
(
'
eventLoad
'
)).
toEqual
({
tagName
:
'
IMAGE
'
,
type
:
'
load
'
,
width
:
10
,
height
:
10
});
});
it
(
'
test event error
'
,
async
()
=>
{
await
page
.
setData
({
imageSrc
:
'
https://request.dcloud.net.cn/api/http/contentType/404.png
'
});
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventError
'
);
});
expect
(
await
page
.
data
(
'
eventError
'
)).
toEqual
({
tagName
:
'
IMAGE
'
,
type
:
'
error
'
});
await
page
.
setData
({
autoTest
:
false
});
});
it
(
'
path-screenshot
'
,
async
()
=>
{
const
page
=
await
program
.
navigateTo
(
'
/pages/component/image/image-path
'
);
await
page
.
waitFor
(
3000
);
...
...
pages/component/image/image.uvue
浏览文件 @
f1d0c7b2
...
...
@@ -34,16 +34,33 @@
// 自动化测试
autoTest: false,
setCookieImage: "",
verifyCookieImage: ""
verifyCookieImage: "",
eventLoad: null,
eventError: null
}
},
methods: {
error(event : ImageErrorEvent) {
this.loadError = true
console.log(event.type, event.detail);
console.log(event.type, event.detail);
if (this.autoTest) {
this.eventError = {
"tagName": event.target?.tagName,
"type": event.type,
// "errMsg": event.detail.errMsg
};
}
},
load(event : ImageLoadEvent) {
console.log(event.type, event.detail);
console.log(event.type, event.detail);
if (this.autoTest) {
this.eventLoad = {
"tagName": event.target?.tagName,
"type": event.type,
"width": event.detail.width,
"height": event.detail.height
};
}
},
imageFormat() {
uni.navigateTo({
...
...
pages/component/video/video.test.js
浏览文件 @
f1d0c7b2
...
...
@@ -30,17 +30,143 @@ describe('component-native-video', () => {
});
it
(
'
test local source
'
,
async
()
=>
{
await
page
.
callMethod
(
'
downloadSource
'
);
await
page
.
waitFor
(
5000
);
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
await
page
.
setData
({
localSrc
:
'
/static/test-video/2minute-demo.m3u8
'
});
await
page
.
waitFor
(
100
);
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
await
page
.
setData
({
autoTest
:
false
});
await
page
.
setData
({
autoTest
:
true
,
isError
:
false
});
await
page
.
callMethod
(
'
downloadSource
'
);
await
page
.
waitFor
(
5000
);
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
await
page
.
setData
({
localSrc
:
'
/static/test-video/2minute-demo.m3u8
'
});
await
page
.
waitFor
(
100
);
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
await
page
.
setData
({
autoTest
:
false
});
});
it
(
'
test event play pause
'
,
async
()
=>
{
await
page
.
setData
({
autoTest
:
true
});
await
page
.
callMethod
(
'
play
'
);
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventPlay
'
);
});
expect
(
await
page
.
data
(
'
eventPlay
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
play
'
});
await
page
.
callMethod
(
'
pause
'
);
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventPause
'
);
});
expect
(
await
page
.
data
(
'
eventPause
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
pause
'
});
await
page
.
callMethod
(
'
play
'
);
});
it
(
'
test event waiting progress timeupdate
'
,
async
()
=>
{
await
page
.
setData
({
pos
:
10
});
await
page
.
callMethod
(
'
seek
'
);
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventWaiting
'
);
});
expect
(
await
page
.
data
(
'
eventWaiting
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
waiting
'
});
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventProgress
'
);
});
expect
(
await
page
.
data
(
'
eventProgress
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
progress
'
,
buffered
:
100
});
await
page
.
waitFor
(
250
);
expect
(
await
page
.
data
(
'
eventTimeupdate
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
timeupdate
'
,
currentTime
:
10
,
duration
:
121
});
});
it
(
'
test event fullscreenchange fullscreenclick controlstoggle
'
,
async
()
=>
{
await
page
.
callMethod
(
'
requestFullScreen
'
);
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventFullscreenchange
'
);
});
expect
(
await
page
.
data
(
'
eventFullscreenchange
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
fullscreenchange
'
,
fullScreen
:
true
,
direction
:
'
horizontal
'
});
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
const
res
=
await
program
.
adbCommand
(
'
wm size
'
);
const
width
=
res
.
data
.
split
(
'
'
).
at
(
-
1
).
split
(
'
x
'
)[
0
]
const
height
=
res
.
data
.
split
(
'
'
).
at
(
-
1
).
split
(
'
x
'
)[
1
]
const
res2
=
await
program
.
adbCommand
(
'
wm density
'
);
const
scale
=
res2
.
data
.
split
(
'
'
).
at
(
-
1
)
/
160
;
await
page
.
waitFor
(
100
);
await
program
.
adbCommand
(
`input tap
${
parseInt
(
height
/
2
)}
${
parseInt
(
width
/
2
)}
`
);
await
page
.
waitFor
(
100
);
expect
(
await
page
.
data
(
'
eventControlstoggle
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
controlstoggle
'
,
show
:
false
});
expect
(
await
page
.
data
(
'
eventFullscreenclick
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
fullscreenclick
'
,
screenX
:
parseInt
(
height
/
2
/
scale
),
screenY
:
parseInt
(
width
/
2
/
scale
),
screenWidth
:
parseInt
(
height
/
scale
),
screenHeight
:
parseInt
(
width
/
scale
)
});
}
await
page
.
callMethod
(
'
exitFullScreen
'
);
});
it
(
'
test event ended
'
,
async
()
=>
{
await
page
.
setData
({
pos
:
120
});
await
page
.
callMethod
(
'
seek
'
);
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventEnded
'
);
});
expect
(
await
page
.
data
(
'
eventEnded
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
ended
'
});
});
it
(
'
test event error
'
,
async
()
=>
{
const
oldSrc
=
await
page
.
data
(
'
src
'
);
await
page
.
setData
({
src
:
'
invalid url
'
});
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventError
'
);
});
expect
(
await
page
.
data
(
'
eventError
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
error
'
,
errCode
:
300001
});
await
page
.
setData
({
autoTest
:
false
,
src
:
oldSrc
});
});
it
(
'
test format
'
,
async
()
=>
{
...
...
pages/component/video/video.uvue
浏览文件 @
f1d0c7b2
...
...
@@ -174,7 +174,17 @@
isPlaying: false,
isPause: false,
isError: false,
localSrc: ''
localSrc: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4',
eventPlay: null,
eventPause: null,
eventEnded: null,
eventTimeupdate: null,
eventFullscreenchange: null,
eventWaiting: null,
eventError: null,
eventProgress: null,
eventFullscreenclick: null,
eventControlstoggle: null
}
},
onLoad() {
...
...
@@ -362,36 +372,107 @@
console.log(res.type);
this.isPlaying = true;
this.isPause = false;
if (this.autoTest) {
this.eventPlay = {
"tagName": res.target?.tagName,
"type": res.type
};
}
},
onPause: function (res : UniEvent) {
console.log(res.type);
this.isPlaying = false;
this.isPause = true;
if (this.autoTest) {
this.eventPause = {
"tagName": res.target?.tagName,
"type": res.type
};
}
},
onEnded: function (res : UniEvent) {
console.log(res.type);
if (this.autoTest) {
this.eventEnded = {
"tagName": res.target?.tagName,
"type": res.type
};
}
},
onTimeUpdate: function (res : UniVideoTimeUpdateEvent) {
console.log(res.type + " -> " + JSON.stringify(res.detail));
if (this.autoTest) {
this.eventTimeupdate = {
"tagName": res.target?.tagName,
"type": res.type,
"currentTime": Math.round(res.detail.currentTime),
"duration": res.detail.duration.toInt()
};
}
},
onFullScreenChange: function (res : UniVideoFullScreenChangeEvent) {
console.log(res.type + " -> " + JSON.stringify(res.detail));
if (this.autoTest) {
this.eventFullscreenchange = {
"tagName": res.target?.tagName,
"type": res.type,
"fullScreen": res.detail.fullScreen,
"direction": res.detail.direction
};
}
},
onWaiting: function (res : UniEvent) {
console.log(res.type);
if (this.autoTest) {
this.eventWaiting = {
"tagName": res.target?.tagName,
"type": res.type
};
}
},
onError: function (res : UniVideoErrorEvent) {
console.log(res.type + " -> " + JSON.stringify(res.detail));
this.isError = true;
if (this.autoTest) {
this.eventError = {
"tagName": res.target?.tagName,
"type": res.type,
"errCode": res.detail.errCode
};
}
},
onProgress: function (res : UniVideoProgressEvent) {
console.log(res.type + " -> " + JSON.stringify(res.detail));
if (this.autoTest) {
this.eventProgress = {
"tagName": res.target?.tagName,
"type": res.type,
"buffered": res.detail.buffered
};
}
},
onFullScreenClick: function (res : UniVideoFullScreenClickEvent) {
console.log(res.type + " -> " + JSON.stringify(res.detail));
if (this.autoTest) {
this.eventFullscreenclick = {
"tagName": res.target?.tagName,
"type": res.type,
"screenX": res.detail.screenX.toInt(),
"screenY": res.detail.screenY.toInt(),
"screenWidth": res.detail.screenWidth.toInt(),
"screenHeight": res.detail.screenHeight.toInt()
};
}
},
onControlsToggle: function (res : UniVideoControlsToggleEvent) {
console.log(res.type + " -> " + JSON.stringify(res.detail));
if (this.autoTest) {
this.eventControlstoggle = {
"tagName": res.target?.tagName,
"type": res.type,
"show": res.detail.show
};
}
},
// 自动化测试
downloadSource() {
...
...
@@ -399,7 +480,6 @@
url: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4',
success: (res) => {
this.localSrc = res.tempFilePath;
this.autoTest = true;
},
fail: (_) => {
this.isError = true;
...
...
pages/component/web-view-local/web-view-local.test.js
浏览文件 @
f1d0c7b2
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe
(
'
component-native-web-view
'
,
()
=>
{
let
page
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/component/web-view-local/web-view-local
'
);
await
page
.
waitFor
(
1000
);
});
if
(
!
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)
&&
!
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
)
{
let
page
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/component/web-view-local/web-view-local
'
);
await
page
.
waitFor
(
1000
);
});
it
(
'
check_load_url
'
,
async
()
=>
{
expect
(
await
page
.
data
(
'
loadError
'
)).
toBe
(
false
)
});
it
(
'
check_load_url
'
,
async
()
=>
{
expect
(
await
page
.
data
(
'
loadError
'
)).
toBe
(
false
)
});
it
(
'
screenshot
'
,
async
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)
&&
!
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
)
{
it
(
'
screenshot
'
,
async
()
=>
{
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
loadFinish
'
)
===
true
;
});
...
...
@@ -20,6 +20,59 @@ describe('component-native-web-view', () => {
fullPage
:
true
});
expect
(
image
).
toSaveImageSnapshot
();
}
});
});
it
(
'
test event download
'
,
async
()
=>
{
await
page
.
setData
({
autoTest
:
true
});
await
page
.
callMethod
(
'
testEventDownload
'
);
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventDownload
'
);
});
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
ios
'
))
{
expect
(
await
page
.
data
(
'
eventDownload
'
)).
toEqual
({
tagName
:
'
WEB-VIEW
'
,
type
:
'
download
'
,
url
:
'
https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk
'
,
userAgent
:
`uni-app-x/
${
process
.
env
.
HX_Version
.
split
(
'
-
'
)[
0
].
split
(
'
.
'
).
slice
(
0
,
2
).
join
(
'
.
'
)}
`
,
contentDisposition
:
''
,
mimetype
:
'
application/vnd.android.package-archive
'
,
contentLength
:
27317517
});
return
;
}
expect
(
await
page
.
data
(
'
eventDownload
'
)).
toEqual
({
tagName
:
'
WEB-VIEW
'
,
type
:
'
download
'
,
url
:
'
https://web-ext-storage.dcloud.net.cn/uni-app-x/pkg/hello-uniappx.apk
'
,
userAgent
:
`uni-app-x/
${
process
.
env
.
HX_Version
.
split
(
'
-
'
)[
0
].
split
(
'
.
'
).
slice
(
0
,
2
).
join
(
'
.
'
)}
`
,
contentDisposition
:
`attachment; filename="hello-uniappx.apk"; filename*=utf-8''hello-uniappx.apk`
,
mimetype
:
'
application/vnd.android.package-archive
'
,
contentLength
:
27317517
});
});
it
(
'
test event message
'
,
async
()
=>
{
await
page
.
callMethod
(
'
testEventMessage
'
);
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventMessage
'
);
});
expect
(
await
page
.
data
(
'
eventMessage
'
)).
toEqual
({
tagName
:
'
WEB-VIEW
'
,
type
:
'
message
'
,
data
:
[{
action
:
'
message
'
}]
});
await
page
.
setData
({
autoTest
:
false
});
});
}
else
{
// TODO: web 端暂不支持
it
(
'
web
'
,
async
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
});
\ No newline at end of file
pages/component/web-view-local/web-view-local.uvue
浏览文件 @
f1d0c7b2
<template>
<web-view ref="web-view" class="web-view" src="/hybrid/html/local.html" @message="message" @error="error"
@loading="loading" @load="load">
<web-view
id="web-view"
ref="web-view" class="web-view" src="/hybrid/html/local.html" @message="message" @error="error"
@loading="loading" @load="load"
@download="download"
>
</web-view>
</template>
...
...
@@ -9,12 +9,16 @@
data() {
return {
loadError: false,
loadFinish: false
loadFinish: false,
// 自动化测试
autoTest: false,
eventMessage: null,
eventDownload: null
}
},
methods: {
message(event : UniWebViewMessageEvent) {
console.log(JSON.stringify(event));
console.log(JSON.stringify(event
.detail
));
let contentStr = JSON.stringify(event.detail);
<!-- #ifdef APP-IOS -->
contentStr = JSON.stringify(event.detail.data[0]);
...
...
@@ -23,17 +27,46 @@
content: contentStr,
showCancel: false
});
if (this.autoTest) {
this.eventMessage = {
"tagName": event.target?.tagName,
"type": event.type,
"data": event.detail.data
};
}
},
error(event : UniWebViewErrorEvent) {
this.loadError = true
console.log(JSON.stringify(event));
console.log(JSON.stringify(event
.detail
));
},
loading(event : UniWebViewLoadingEvent) {
console.log(JSON.stringify(event));
console.log(JSON.stringify(event
.detail
));
},
load(event : UniWebViewLoadEvent) {
this.loadFinish = true;
console.log(JSON.stringify(event));
console.log(JSON.stringify(event.detail));
},
download(event : UniWebViewDownloadEvent) {
console.log(JSON.stringify(event.detail));
if (this.autoTest) {
const arr = event.detail.userAgent.split(' ');
this.eventDownload = {
"tagName": event.target?.tagName,
"type": event.type,
"url": event.detail.url,
"userAgent": arr[arr.length - 1],
"contentDisposition": event.detail.contentDisposition,
"mimetype": event.detail.mimetype,
"contentLength": event.detail.contentLength.toInt()
};
}
},
// 自动化测试
testEventDownload() {
uni.createWebviewContext('web-view')?.evalJS("document.getElementsByTagName('a')[0].click()");
},
testEventMessage() {
uni.createWebviewContext('web-view')?.evalJS("document.getElementById('postMessage').click()");
}
}
}
...
...
pages/component/web-view/web-view.test.js
浏览文件 @
f1d0c7b2
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe
(
'
component-native-web-view
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)
&&
!
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
)
{
if
(
!
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)
&&
!
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
)
{
let
page
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/component/web-view/web-view
'
);
...
...
@@ -11,6 +11,50 @@ describe('component-native-web-view', () => {
it
(
'
check_load_url
'
,
async
()
=>
{
expect
(
await
page
.
data
(
'
loadError
'
)).
toBe
(
false
)
});
it
(
'
test event loading load
'
,
async
()
=>
{
await
page
.
setData
({
autoTest
:
true
});
await
page
.
callMethod
(
'
reload
'
);
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventLoading
'
);
});
expect
(
await
page
.
data
(
'
eventLoading
'
)).
toEqual
({
tagName
:
'
WEB-VIEW
'
,
type
:
'
loading
'
,
src
:
'
https://www.dcloud.io/
'
});
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventLoad
'
);
});
expect
(
await
page
.
data
(
'
eventLoad
'
)).
toEqual
({
tagName
:
'
WEB-VIEW
'
,
type
:
'
load
'
,
src
:
'
https://www.dcloud.io/
'
});
});
it
(
'
test event error
'
,
async
()
=>
{
await
page
.
setData
({
src
:
'
https://www.dclou.io/uni-app-x
'
});
await
page
.
waitFor
(
async
()
=>
{
return
await
page
.
data
(
'
eventError
'
);
});
expect
(
await
page
.
data
(
'
eventError
'
)).
toEqual
({
tagName
:
'
WEB-VIEW
'
,
type
:
'
error
'
,
errCode
:
100002
,
errMsg
:
'
page error
'
,
url
:
'
https://www.dclou.io
'
,
fullUrl
:
'
https://www.dclou.io/uni-app-x
'
,
src
:
'
https://www.dclou.io/uni-app-x
'
});
await
page
.
setData
({
autoTest
:
false
});
});
}
else
{
// TODO: web 端暂不支持
it
(
'
web
'
,
async
()
=>
{
...
...
pages/component/web-view/web-view.uvue
浏览文件 @
f1d0c7b2
...
...
@@ -50,7 +50,12 @@
webviewContext: null as WebviewContext | null,
loadError: false,
horizontalScrollBarAccess: true,
verticalScrollBarAccess: true
verticalScrollBarAccess: true,
// 自动化测试
autoTest: false,
eventLoading: null,
eventLoad: null,
eventError: null
}
},
onReady() {
...
...
@@ -76,27 +81,51 @@
this.webviewContext?.evalJS("alert('hello uni-app x')");
},
message(event : UniWebViewMessageEvent) {
console.log(JSON.stringify(event));
console.log(JSON.stringify(event
.detail
));
},
error(event : UniWebViewErrorEvent) {
this.loadError = true
console.log(JSON.stringify(event));
console.log(JSON.stringify(event.detail));
if (this.autoTest) {
this.eventError = {
"tagName": event.target?.tagName,
"type": event.type,
"errCode": event.detail.errCode,
"errMsg": event.detail.errMsg,
"url": event.detail.url,
"fullUrl": event.detail.fullUrl,
"src": event.detail.src
};
}
},
loading(event : UniWebViewLoadingEvent) {
console.log(JSON.stringify(event));
console.log(JSON.stringify(event.detail));
if (this.autoTest) {
this.eventLoading = {
"tagName": event.target?.tagName,
"type": event.type,
"src": event.detail.src
};
}
},
load(event : UniWebViewLoadEvent) {
console.log(JSON.stringify(event));
console.log(JSON.stringify(event.detail));
if (this.autoTest) {
this.eventLoad = {
"tagName": event.target?.tagName,
"type": event.type,
"src": event.detail.src
};
}
},
download(event : UniWebViewDownloadEvent) {
console.log(JSON.stringify(event));
console.log(JSON.stringify(event
.detail
));
uni.showModal({
content: "下载链接: " + event.detail.url + "\n文件大小: " + event.detail.contentLength / 1024 + "KB",
showCancel: false
});
},
confirm(event : UniInputConfirmEvent) {
console.log(JSON.stringify(event));
let url = event.detail.value;
if (!url.startsWith('https://') && !url.startsWith('http://')) {
url = 'https://' + url;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录