Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
0e868417
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6045
Star
91
Fork
165
代码
文件
提交
分支
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看板
提交
0e868417
编写于
11月 27, 2024
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: 测试与示例适配微信小程序
上级
230d88b1
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
1853 addition
and
1806 deletion
+1853
-1806
pages/API/create-selector-query/create-selector-query.test.js
...s/API/create-selector-query/create-selector-query.test.js
+10
-7
pages/API/get-element-by-id/get-element-by-id.test.js
pages/API/get-element-by-id/get-element-by-id.test.js
+11
-2
pages/API/get-file-system-manager/get-file-system-manager.test.js
...I/get-file-system-manager/get-file-system-manager.test.js
+1512
-1503
pages/API/get-file-system-manager/get-file-system-manager.uvue
.../API/get-file-system-manager/get-file-system-manager.uvue
+12
-3
pages/API/storage/storage.test.js
pages/API/storage/storage.test.js
+3
-2
pages/API/unicloud/unicloud/cloud-object.test.js
pages/API/unicloud/unicloud/cloud-object.test.js
+1
-0
pages/API/upload-file/upload-file.test.js
pages/API/upload-file/upload-file.test.js
+13
-4
pages/component/canvas/canvas.uvue
pages/component/canvas/canvas.uvue
+3
-1
pages/component/checkbox/checkbox.test.js
pages/component/checkbox/checkbox.test.js
+14
-11
pages/component/global-events/touch-events-bubbles.test.js
pages/component/global-events/touch-events-bubbles.test.js
+9
-5
pages/component/picker-view/picker-view.test.js
pages/component/picker-view/picker-view.test.js
+3
-3
pages/component/scroll-view/scroll-view-props.test.js
pages/component/scroll-view/scroll-view-props.test.js
+9
-3
pages/component/swiper/swiper2.test.js
pages/component/swiper/swiper2.test.js
+4
-4
pages/component/video/video.test.js
pages/component/video/video.test.js
+249
-258
未找到文件。
pages/API/create-selector-query/create-selector-query.test.js
浏览文件 @
0e868417
...
...
@@ -53,13 +53,16 @@ describe('nodes-info', () => {
expect
(
nodeInfo2
.
top
>
220
).
toBe
(
true
)
expect
(
Math
.
round
(
nodeInfo2
.
width
)).
toBe
(
RECT_WIDTH
)
expect
(
Math
.
round
(
nodeInfo2
.
height
)).
toBe
(
RECT_HEIGHT
)
})
it
(
'
get-node-info-child
'
,
async
()
=>
{
const
child
=
await
page
.
$
(
'
.node-child
'
)
const
childData
=
await
child
.
data
()
console
.
log
(
'
get-node-info-child.childData.top
'
,
childData
.
top
);
expect
(
childData
.
top
>
100
).
toBe
(
true
)
})
})
if
(
!
isMP
)
{
// 小程序端启用了虚拟host,无法获取到子组件
it
(
'
get-node-info-child
'
,
async
()
=>
{
const
child
=
await
page
.
$
(
'
.node-child
'
)
const
childData
=
await
child
.
data
()
console
.
log
(
'
get-node-info-child.childData.top
'
,
childData
.
top
);
expect
(
childData
.
top
>
100
).
toBe
(
true
)
})
}
it
(
'
multi-child
'
,
async
()
=>
{
const
pageData
=
await
page
.
data
()
...
...
pages/API/get-element-by-id/get-element-by-id.test.js
浏览文件 @
0e868417
const
PAGE_PATH
=
"
/pages/API/get-element-by-id/get-element-by-id
"
;
let
page
;
describe
(
"
getElementById
"
,
()
=>
{
describe
(
"
getElementById
"
,
()
=>
{
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isIOS
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isMP
=
platformInfo
.
startsWith
(
'
mp
'
)
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
);
await
page
.
waitFor
(
'
view
'
);
...
...
@@ -11,7 +16,7 @@ describe("getElementById", () => {
expect
(
res
).
toBe
(
null
);
});
it
(
"
changeStyle
"
,
async
()
=>
{
if
(
!
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
mp
'
)
)
{
if
(
!
isMP
)
{
await
page
.
callMethod
(
"
changePageHeadBackgroundColor
"
);
}
await
page
.
callMethod
(
"
changeTextColor
"
);
...
...
@@ -20,6 +25,10 @@ describe("getElementById", () => {
const
image
=
await
program
.
screenshot
({
fullPage
:
true
});
expect
(
image
).
toSaveImageSnapshot
();
});
if
(
isMP
)
{
return
}
/**
* 检测元素offsetLeft属性值域
*/
...
...
pages/API/get-file-system-manager/get-file-system-manager.test.js
浏览文件 @
0e868417
此差异已折叠。
点击以展开。
pages/API/get-file-system-manager/get-file-system-manager.uvue
浏览文件 @
0e868417
...
...
@@ -28,7 +28,7 @@
<button class="btnstyle" type="primary" @tap="rmdirTest" id="btn-remove-dir">删除文件夹{{rmDirFile}}</button>
<!-- #ifdef APP-ANDROID -->
<!-- #ifdef APP-ANDROID
|| MP
-->
<button class="btnstyle" type="primary" @tap="statFileInfoSyncTest"
id="btn-stat-file-sync">同步递归获取目录files的Stats对象{{statFile}}</button>
<button class="btnstyle" type="primary" @tap="appendFileTest"
...
...
@@ -163,12 +163,21 @@
arrayBufferRes: 0,
/**
* 待测试的全局环境变量
*/
*/
// #ifdef MP
basePath: uni.env.USER_DATA_PATH + '/',
copyToBasePath: uni.env.USER_DATA_PATH + '/',
globalTempPath: uni.env.CACHE_PATH,
globalRootPath: uni.env.SANDBOX_PATH,
globalUserDataPath: uni.env.USER_DATA_PATH + '/',
// #endif
// #ifndef MP
basePath: uni.env.USER_DATA_PATH,
copyToBasePath: uni.env.USER_DATA_PATH,
globalTempPath: uni.env.CACHE_PATH,
globalRootPath: uni.env.SANDBOX_PATH,
globalUserDataPath: uni.env.USER_DATA_PATH
globalUserDataPath: uni.env.USER_DATA_PATH,
// #endif
}
},
onLoad() {
...
...
pages/API/storage/storage.test.js
浏览文件 @
0e868417
...
...
@@ -2,7 +2,7 @@ jest.setTimeout(50000);
const
PAGE_PATH
=
'
/pages/API/storage/storage
'
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isI
os
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isI
OS
=
platformInfo
.
startsWith
(
'
ios
'
)
describe
(
'
ExtApi-StorageInfoTest
'
,
()
=>
{
if
(
...
...
@@ -144,7 +144,7 @@ describe('ExtApi-StorageInfoTest', () => {
let
btnComplexStaticTest
=
await
page
.
$
(
'
.btn-complexStaticTest
'
)
await
btnComplexStaticTest
.
tap
()
await
page
.
waitFor
(
600
)
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
ios
'
)
==
false
)
{
if
(
!
isIOS
)
{
expect
(
await
getData
(
'
staticComplexRet
'
)).
toEqual
(
true
)
}
await
page
.
setData
({
...
...
@@ -302,6 +302,7 @@ describe('ExtApi-StorageInfoTest', () => {
it
(
'
saveUTSJSONObject
'
,
async
()
=>
{
await
page
.
callMethod
(
'
jest_saveUTSJSONObject
'
)
await
page
.
waitFor
(
600
)
const
{
jest_saveUTSJSONObjectSyncResult
,
jest_saveUTSJSONObjectAsyncResult
...
...
pages/API/unicloud/unicloud/cloud-object.test.js
浏览文件 @
0e868417
...
...
@@ -24,6 +24,7 @@ describe('unicloud-import-object', () => {
genericDemoReturnTodoTitle
,
genericDemoReturnTodoContent
,
failErrCode
,
failErrSubject
,
failErrDetailTips
,
failNumberErrCode
,
successErrCode
,
...
...
pages/API/upload-file/upload-file.test.js
浏览文件 @
0e868417
const
PAGE_PATH
=
'
/pages/API/upload-file/upload-file
'
describe
(
'
ExtApi-UploadFile
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isIOS
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isMP
=
platformInfo
.
startsWith
(
'
mp
'
)
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
if
(
isWeb
)
{
// TODO: web 端暂不支持测试
it
(
'
web
'
,
async
()
=>
{
expect
(
1
).
toBe
(
1
)
...
...
@@ -42,16 +47,20 @@ describe('ExtApi-UploadFile', () => {
it
(
'
Check uni.env
'
,
async
()
=>
{
await
page
.
callMethod
(
'
jest_uploadFile_with_uni_env
'
);
await
page
.
waitFor
(
2
000
);
await
page
.
waitFor
(
3
000
);
res
=
await
page
.
data
(
'
jest_result
'
);
expect
(
res
).
toBe
(
true
);
});
});
if
(
isMP
)
{
return
}
// 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备
let
version
=
process
.
env
.
uniTestPlatformInfo
let
split
=
version
.
split
(
"
"
)
version
=
parseInt
(
split
[
split
.
length
-
1
])
if
(
!
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
().
startsWith
(
'
ios
'
)
||
version
>
15
)
{
if
(
!
isIOS
||
version
>
15
)
{
it
(
'
Check Upload File In UTS Module
'
,
async
()
=>
{
res
=
await
page
.
callMethod
(
'
jest_uts_module_invoked
'
)
await
page
.
waitFor
(
2000
);
...
...
pages/component/canvas/canvas.uvue
浏览文件 @
0e868417
...
...
@@ -94,7 +94,9 @@
// #ifdef WEB
context.toBlob((blob : Blob) => {
this.testToBlobResult = (blob.size > 0 && blob.type == 'image/jpeg')
}, 'image/jpeg', 0.95);
}, 'image/jpeg', 0.95);
// #endif
// #ifdef WEB || MP
this.testToDataURLResult = this.canvasContext!.toDataURL().startsWith('data:image/png;base64')
// #endif
this.testCanvasContext = true
...
...
pages/component/checkbox/checkbox.test.js
浏览文件 @
0e868417
...
...
@@ -70,18 +70,21 @@ describe('Checkbox.uvue', () => {
expect
(
disabled2
).
toBe
(
false
+
''
)
})
}
it
(
'
checked
'
,
async
()
=>
{
const
cb
=
await
page
.
$
(
'
.cb
'
)
// TODO
const
newValue1
=
await
cb
.
property
(
'
checked
'
)
expect
(
newValue1
.
toString
()).
toBe
(
true
+
''
)
await
page
.
setData
({
checked
:
false
,
if
(
!
isMP
)
{
// 自动化测试获取的property checked在app、web和微信小程序之间有差异。微信小程序获取的和显示效果一致,app、web获取的是绑定值
it
(
'
checked
'
,
async
()
=>
{
const
cb
=
await
page
.
$
(
'
.cb
'
)
// TODO
const
newValue1
=
await
cb
.
property
(
'
checked
'
)
expect
(
newValue1
.
toString
()).
toBe
(
true
+
''
)
await
page
.
setData
({
checked
:
false
,
})
// TODO
const
newValue2
=
await
cb
.
property
(
'
checked
'
)
expect
(
newValue2
.
toString
()).
toBe
(
false
+
''
)
})
// TODO
const
newValue2
=
await
cb
.
property
(
'
checked
'
)
expect
(
newValue2
.
toString
()).
toBe
(
false
+
''
)
})
}
if
(
!
isMP
)
{
it
(
'
color
'
,
async
()
=>
{
const
cb
=
await
page
.
$
(
'
.cb
'
)
...
...
pages/component/global-events/touch-events-bubbles.test.js
浏览文件 @
0e868417
const
PAGE_PATH
=
'
/pages/component/global-events/touch-events-bubbles
'
describe
(
'
touch-events-test
'
,
()
=>
{
describe
(
'
touch-events-test
'
,
()
=>
{
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isIOS
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isMP
=
platformInfo
.
startsWith
(
'
mp
'
)
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
// 先屏蔽 android 及 web 平台
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)
||
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)
||
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
mp
'
)
isAndroid
||
isWeb
||
isMP
)
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
...
...
pages/component/picker-view/picker-view.test.js
浏览文件 @
0e868417
...
...
@@ -75,7 +75,7 @@ describe('PickerView.uvue', () => {
indicatorStyle
:
""
,
//清空indicatorStyle
indicatorClass
:
"
indicator-test
"
,
//设置indicatorClass为indicator-test
})
expect
(
await
pickerViewEl
.
attribute
(
'
indicatorClass
'
)).
toBe
(
"
indicator-test
"
)
expect
(
await
pickerViewEl
.
attribute
(
isMP
?
'
indicator-class
'
:
'
indicatorClass
'
)).
toBe
(
"
indicator-test
"
)
await
toScreenshot
(
'
picker-view-web-indicator-class
'
)
await
page
.
setData
({
indicatorClass
:
""
,
//清空indicatorClass
...
...
@@ -86,14 +86,14 @@ describe('PickerView.uvue', () => {
await
page
.
setData
({
maskStyle
})
expect
(
await
pickerViewEl
.
attribute
(
'
maskStyle
'
)).
toBe
(
maskStyle
)
expect
(
await
pickerViewEl
.
attribute
(
isMP
?
'
mask-style
'
:
'
maskStyle
'
)).
toBe
(
maskStyle
)
await
toScreenshot
(
'
picker-view-web-mask-style
'
)
})
it
(
'
mask-class
'
,
async
()
=>
{
await
page
.
setData
({
maskClass
:
"
mask-test
"
})
expect
(
await
pickerViewEl
.
attribute
(
'
maskClass
'
)).
toBe
(
"
mask-test
"
)
expect
(
await
pickerViewEl
.
attribute
(
isMP
?
'
mask-class
'
:
maskClass
)).
toBe
(
"
mask-test
"
)
await
toScreenshot
(
'
picker-view-web-mask-class
'
)
})
return
...
...
pages/component/scroll-view/scroll-view-props.test.js
浏览文件 @
0e868417
...
...
@@ -28,7 +28,7 @@ describe('component-native-scroll-view-props', () => {
//检测竖向scrolltop属性赋值
it
(
'
check_scroll_top
'
,
async
()
=>
{
await
page
.
setData
({
scrollTop
:
600
scrollTop
:
600
})
await
page
.
waitFor
(
600
)
//检测滚动top 是否触发scroll 事件
...
...
@@ -44,7 +44,7 @@ describe('component-native-scroll-view-props', () => {
//检测竖向scroll_into_view属性赋值
it
(
'
check_scroll_into_view_top
'
,
async
()
=>
{
await
page
.
setData
({
scrollIntoView
:
"
item3
"
scrollIntoView
:
"
item3
"
})
await
page
.
waitFor
(
600
)
const
element
=
await
page
.
$
(
'
#scrollViewY
'
)
...
...
@@ -71,7 +71,10 @@ describe('component-native-scroll-view-props', () => {
//检测横向scrollLeft属性赋值
it
(
'
check_scroll_left
'
,
async
()
=>
{
await
page
.
setData
({
scrollLeft
:
600
scrollX
:
true
})
await
page
.
setData
({
scrollLeft
:
600
})
await
page
.
waitFor
(
600
)
const
element
=
await
page
.
$
(
'
#scrollViewX
'
)
...
...
@@ -82,6 +85,9 @@ describe('component-native-scroll-view-props', () => {
//检测横向scroll_into_view属性赋值
it
(
'
check_scroll_into_view_left
'
,
async
()
=>
{
await
page
.
setData
({
scrollX
:
true
})
await
page
.
setData
({
scrollIntoView
:
"
horizontal_item3
"
})
...
...
pages/component/swiper/swiper2.test.js
浏览文件 @
0e868417
const
PAGE_PATH
=
'
/pages/component/swiper/swiper
'
describe
(
'
swiper-touch-test
'
,
()
=>
{
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
const
isMP
=
platformInfo
.
startsWith
(
'
mp
'
)
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
const
isMP
=
platformInfo
.
startsWith
(
'
mp
'
)
// 屏蔽 web * android 平台, 需要针对调整坐标
// 屏蔽 小程序,不支持 program.swipe
if
(
isWeb
||
isAndroid
||
isMP
)
{
...
...
pages/component/video/video.test.js
浏览文件 @
0e868417
jest
.
setTimeout
(
60000
);
jest
.
setTimeout
(
60000
);
describe
(
'
component-native-video
'
,
()
=>
{
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isIOS
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isIOS
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isMP
=
platformInfo
.
startsWith
(
'
mp
'
)
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
if
(
isWeb
){
// TODO: web 端暂不支持测试
it
(
'
web
'
,
async
()
=>
{
expect
(
1
).
toBe
(
1
)
})
return
}
let
page
;
let
start
=
0
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/component/video/video
'
);
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
)){
await
page
.
setData
({
muted
:
true
});
}
await
page
.
waitFor
(
1000
);
});
it
(
'
test API
'
,
async
()
=>
{
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
// play
await
page
.
callMethod
(
'
play
'
);
await
page
.
waitFor
(
100
);
expect
(
await
page
.
data
(
'
isPlaying
'
)).
toBe
(
true
);
// pause
await
page
.
callMethod
(
'
pause
'
);
await
page
.
waitFor
(
100
);
expect
(
await
page
.
data
(
'
isPause
'
)).
toBe
(
true
);
});
if
(
!
isMP
)
{
it
(
'
test local source
'
,
async
()
=>
{
await
page
.
setData
({
autoTest
:
true
,
isError
:
false
});
const
oldSrc
=
await
page
.
data
(
'
src
'
);
await
page
.
callMethod
(
'
downloadSource
'
);
await
page
.
waitFor
(
5000
);
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
await
page
.
setData
({
src
:
'
/static/test-video/2minute-demo.m3u8
'
});
await
page
.
waitFor
(
100
);
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
await
page
.
setData
({
src
:
oldSrc
});
});
it
(
'
test assets path
'
,
async
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
ios
'
))
return
;
const
oldSrc
=
await
page
.
data
(
'
src
'
);
await
page
.
setData
({
isError
:
false
,
src
:
'
file:///android_asset/uni-autoTest/demo10s.mp4
'
});
await
page
.
waitFor
(
500
);
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
await
page
.
setData
({
src
:
oldSrc
});
});
}
it
(
'
test event play pause controlstoggle
'
,
async
()
=>
{
await
page
.
setData
({
autoTest
:
true
,
});
await
page
.
callMethod
(
'
play
'
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventPlay
'
))
||
(
Date
.
now
()
-
start
>
500
);
});
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
ios
'
))
{
// expect(await page.data('eventPlay')).toEqual({
// type: 'play'
// });
}
else
{
expect
(
await
page
.
data
(
'
eventPlay
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
play
'
});
}
await
page
.
callMethod
(
'
pause
'
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventPause
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
ios
'
))
{
// expect(await page.data('eventPause')).toEqual({
// type: 'pause'
// });
}
else
{
expect
(
await
page
.
data
(
'
eventPause
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
pause
'
});
}
if
(
!
isMP
&&
!
isWeb
)
{
/**
* app端video组件controlstoggle事件会在controls显示和隐藏触发(播放、暂停等操作都会触发)。
* 微信小程序和web播放暂停或者一些其他的操作也会影响controls的显隐,但是不会触发controlstoggle, 只有controls属性变化的时候才会触发
*/
await
page
.
callMethod
(
'
play
'
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventControlstoggle
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
ios
'
))
{
// expect(await page.data('eventControlstoggle')).toEqual({
// tagName: 'VIDEO',
// type: 'controlstoggle',
// show: true
// });
}
else
{
expect
(
await
page
.
data
(
'
eventControlstoggle
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
controlstoggle
'
,
show
:
true
});
}
}
});
it
(
'
test event waiting progress
'
,
async
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
ios
'
))
{
return
}
await
page
.
callMethod
(
'
seek
'
,
10
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventWaiting
'
))
&&
(
await
page
.
data
(
'
eventProgress
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
expect
(
await
page
.
data
(
'
eventWaiting
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
waiting
'
});
expect
(
await
page
.
data
(
'
eventProgress
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
progress
'
,
isBufferedValid
:
true
});
});
if
(
isAndroid
)
{
it
(
'
test event fullscreenchange fullscreenclick
'
,
async
()
=>
{
await
page
.
callMethod
(
'
requestFullScreen
'
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventFullscreenchange
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
expect
(
await
page
.
data
(
'
eventFullscreenchange
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
fullscreenchange
'
,
fullScreen
:
true
,
direction
:
'
horizontal
'
});
const
infos
=
process
.
env
.
uniTestPlatformInfo
.
split
(
'
'
);
const
version
=
parseInt
(
infos
[
infos
.
length
-
1
]);
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)
&&
version
>
5
)
{
// android5.1模拟器全屏时会弹出系统提示框,无法响应adb tap命令
await
page
.
waitFor
(
5000
);
await
program
.
adbCommand
(
'
input tap 10 10
'
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventFullscreenclick
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
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
;
expect
(
await
page
.
data
(
'
eventFullscreenclick
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
fullscreenclick
'
,
screenX
:
parseInt
(
10
/
scale
),
screenY
:
parseInt
(
10
/
scale
),
screenWidth
:
parseInt
(
height
/
scale
),
screenHeight
:
parseInt
(
width
/
scale
)
});
}
await
page
.
callMethod
(
'
exitFullScreen
'
);
});
}
it
(
'
test event ended timeupdate
'
,
async
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
ios
'
))
{
return
}
await
page
.
callMethod
(
'
seek
'
,
120
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventEnded
'
))
||
(
Date
.
now
()
-
start
>
30000
);
});
expect
(
await
page
.
data
(
'
eventEnded
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
ended
'
});
const
infos
=
process
.
env
.
uniTestPlatformInfo
.
split
(
'
'
);
const
version
=
parseInt
(
infos
[
infos
.
length
-
1
]);
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)
&&
version
>
5
)
{
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventTimeupdate
'
))
||
(
Date
.
now
()
-
start
>
500
);
});
expect
(
await
page
.
data
(
'
eventTimeupdate
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
timeupdate
'
,
currentTime
:
121
,
duration
:
121
});
}
});
it
(
'
test event error
'
,
async
()
=>
{
if
(
isIOS
||
isMP
)
{
return
}
const
oldSrc
=
await
page
.
data
(
'
src
'
);
await
page
.
setData
({
src
:
'
invalid url
'
});
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventError
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
expect
(
await
page
.
data
(
'
eventError
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
error
'
,
errCode
:
300001
});
await
page
.
setData
({
autoTest
:
false
,
src
:
oldSrc
});
});
it
(
'
test sub component
'
,
async
()
=>
{
if
(
isIOS
||
isMP
)
{
return
}
await
page
.
setData
({
subCompEnable
:
true
,
subCompShow
:
true
});
await
page
.
waitFor
(
100
);
expect
(
await
page
.
callMethod
(
'
hasSubComponent
'
)).
toBe
(
true
);
});
it
(
'
test format
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
'
/pages/component/video/video-format
'
);
await
page
.
waitFor
(
1000
);
expect
((
await
page
.
data
(
'
isError
'
)).
value
).
toBe
(
false
);
});
const
isWeb
=
platformInfo
.
startsWith
(
'
web
'
)
if
(
isWeb
)
{
// TODO: web 端暂不支持测试
it
(
'
web
'
,
async
()
=>
{
expect
(
1
).
toBe
(
1
)
})
return
}
let
page
;
let
start
=
0
;
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
'
/pages/component/video/video
'
);
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
await
page
.
setData
({
muted
:
true
});
}
await
page
.
waitFor
(
1000
);
});
it
(
'
test API
'
,
async
()
=>
{
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
// play
await
page
.
callMethod
(
'
play
'
);
await
page
.
waitFor
(
100
);
expect
(
await
page
.
data
(
'
isPlaying
'
)).
toBe
(
true
);
// pause
await
page
.
callMethod
(
'
pause
'
);
await
page
.
waitFor
(
100
);
expect
(
await
page
.
data
(
'
isPause
'
)).
toBe
(
true
);
});
if
(
!
isMP
)
{
it
(
'
test local source
'
,
async
()
=>
{
await
page
.
setData
({
autoTest
:
true
,
isError
:
false
});
const
oldSrc
=
await
page
.
data
(
'
src
'
);
await
page
.
callMethod
(
'
downloadSource
'
);
await
page
.
waitFor
(
5000
);
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
await
page
.
setData
({
src
:
'
/static/test-video/2minute-demo.m3u8
'
});
await
page
.
waitFor
(
100
);
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
await
page
.
setData
({
src
:
oldSrc
});
});
it
(
'
test assets path
'
,
async
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
ios
'
))
return
;
const
oldSrc
=
await
page
.
data
(
'
src
'
);
await
page
.
setData
({
isError
:
false
,
src
:
'
file:///android_asset/uni-autoTest/demo10s.mp4
'
});
await
page
.
waitFor
(
500
);
expect
(
await
page
.
data
(
'
isError
'
)).
toBe
(
false
);
await
page
.
setData
({
src
:
oldSrc
});
});
}
it
(
'
test event play pause controlstoggle
'
,
async
()
=>
{
await
page
.
setData
({
autoTest
:
true
,
});
await
page
.
callMethod
(
'
play
'
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventPlay
'
))
||
(
Date
.
now
()
-
start
>
500
);
});
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
ios
'
))
{
// expect(await page.data('eventPlay')).toEqual({
// type: 'play'
// });
}
else
{
expect
(
await
page
.
data
(
'
eventPlay
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
play
'
});
}
await
page
.
callMethod
(
'
pause
'
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventPause
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
ios
'
))
{
// expect(await page.data('eventPause')).toEqual({
// type: 'pause'
// });
}
else
{
expect
(
await
page
.
data
(
'
eventPause
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
pause
'
});
}
if
(
!
isMP
&&
!
isWeb
)
{
/**
* app端video组件controlstoggle事件会在controls显示和隐藏触发(播放、暂停等操作都会触发)。
* 微信小程序和web播放暂停或者一些其他的操作也会影响controls的显隐,但是不会触发controlstoggle, 只有controls属性变化的时候才会触发
*/
await
page
.
callMethod
(
'
play
'
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventControlstoggle
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
if
(
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
().
startsWith
(
'
ios
'
))
{
// expect(await page.data('eventControlstoggle')).toEqual({
// tagName: 'VIDEO',
// type: 'controlstoggle',
// show: true
// });
}
else
{
expect
(
await
page
.
data
(
'
eventControlstoggle
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
controlstoggle
'
,
show
:
true
});
}
}
});
if
(
isAndroid
)
{
it
(
'
test event waiting progress
'
,
async
()
=>
{
await
page
.
callMethod
(
'
seek
'
,
10
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventWaiting
'
))
&&
(
await
page
.
data
(
'
eventProgress
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
expect
(
await
page
.
data
(
'
eventWaiting
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
waiting
'
});
expect
(
await
page
.
data
(
'
eventProgress
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
progress
'
,
isBufferedValid
:
true
});
});
it
(
'
test event fullscreenchange fullscreenclick
'
,
async
()
=>
{
await
page
.
callMethod
(
'
requestFullScreen
'
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventFullscreenchange
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
expect
(
await
page
.
data
(
'
eventFullscreenchange
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
fullscreenchange
'
,
fullScreen
:
true
,
direction
:
'
horizontal
'
});
const
infos
=
process
.
env
.
uniTestPlatformInfo
.
split
(
'
'
);
const
version
=
parseInt
(
infos
[
infos
.
length
-
1
]);
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)
&&
version
>
5
)
{
// android5.1模拟器全屏时会弹出系统提示框,无法响应adb tap命令
await
page
.
waitFor
(
5000
);
await
program
.
adbCommand
(
'
input tap 10 10
'
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventFullscreenclick
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
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
;
expect
(
await
page
.
data
(
'
eventFullscreenclick
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
fullscreenclick
'
,
screenX
:
parseInt
(
10
/
scale
),
screenY
:
parseInt
(
10
/
scale
),
screenWidth
:
parseInt
(
height
/
scale
),
screenHeight
:
parseInt
(
width
/
scale
)
});
}
await
page
.
callMethod
(
'
exitFullScreen
'
);
});
it
(
'
test event ended timeupdate
'
,
async
()
=>
{
await
page
.
callMethod
(
'
seek
'
,
120
);
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventEnded
'
))
||
(
Date
.
now
()
-
start
>
30000
);
});
expect
(
await
page
.
data
(
'
eventEnded
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
ended
'
});
const
infos
=
process
.
env
.
uniTestPlatformInfo
.
split
(
'
'
);
const
version
=
parseInt
(
infos
[
infos
.
length
-
1
]);
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
)
&&
version
>
5
)
{
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventTimeupdate
'
))
||
(
Date
.
now
()
-
start
>
500
);
});
expect
(
await
page
.
data
(
'
eventTimeupdate
'
)).
toEqual
({
tagName
:
isMP
?
undefined
:
'
VIDEO
'
,
type
:
'
timeupdate
'
,
currentTime
:
121
,
duration
:
121
});
}
});
it
(
'
test event error
'
,
async
()
=>
{
const
oldSrc
=
await
page
.
data
(
'
src
'
);
await
page
.
setData
({
src
:
'
invalid url
'
});
start
=
Date
.
now
();
await
page
.
waitFor
(
async
()
=>
{
return
(
await
page
.
data
(
'
eventError
'
))
||
(
Date
.
now
()
-
start
>
1000
);
});
expect
(
await
page
.
data
(
'
eventError
'
)).
toEqual
({
tagName
:
'
VIDEO
'
,
type
:
'
error
'
,
errCode
:
300001
});
await
page
.
setData
({
autoTest
:
false
,
src
:
oldSrc
});
});
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 format
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
'
/pages/component/video/video-format
'
);
await
page
.
waitFor
(
1000
);
expect
((
await
page
.
data
(
'
isError
'
)).
value
).
toBe
(
false
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录