提交 0e868417 编写于 作者: 雪洛's avatar 雪洛

test: 测试与示例适配微信小程序

上级 230d88b1
...@@ -53,13 +53,16 @@ describe('nodes-info', () => { ...@@ -53,13 +53,16 @@ describe('nodes-info', () => {
expect(nodeInfo2.top > 220).toBe(true) expect(nodeInfo2.top > 220).toBe(true)
expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH) expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH)
expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT) expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT)
}) })
it('get-node-info-child', async () => { if(!isMP) {
const child = await page.$('.node-child') // 小程序端启用了虚拟host,无法获取到子组件
const childData = await child.data() it('get-node-info-child', async () => {
console.log('get-node-info-child.childData.top', childData.top); const child = await page.$('.node-child')
expect(childData.top > 100).toBe(true) 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 () => { it('multi-child', async () => {
const pageData = await page.data() const pageData = await page.data()
......
const PAGE_PATH = "/pages/API/get-element-by-id/get-element-by-id"; const PAGE_PATH = "/pages/API/get-element-by-id/get-element-by-id";
let page; 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 () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH); page = await program.reLaunch(PAGE_PATH);
await page.waitFor('view'); await page.waitFor('view');
...@@ -11,7 +16,7 @@ describe("getElementById", () => { ...@@ -11,7 +16,7 @@ describe("getElementById", () => {
expect(res).toBe(null); expect(res).toBe(null);
}); });
it("changeStyle", async () => { it("changeStyle", async () => {
if (!process.env.uniTestPlatformInfo.startsWith('mp')) { if (!isMP) {
await page.callMethod("changePageHeadBackgroundColor"); await page.callMethod("changePageHeadBackgroundColor");
} }
await page.callMethod("changeTextColor"); await page.callMethod("changeTextColor");
...@@ -20,6 +25,10 @@ describe("getElementById", () => { ...@@ -20,6 +25,10 @@ describe("getElementById", () => {
const image = await program.screenshot({fullPage: true}); const image = await program.screenshot({fullPage: true});
expect(image).toSaveImageSnapshot(); expect(image).toSaveImageSnapshot();
}); });
if(isMP) {
return
}
/** /**
* 检测元素offsetLeft属性值域 * 检测元素offsetLeft属性值域
*/ */
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<button class="btnstyle" type="primary" @tap="rmdirTest" id="btn-remove-dir">删除文件夹{{rmDirFile}}</button> <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" <button class="btnstyle" type="primary" @tap="statFileInfoSyncTest"
id="btn-stat-file-sync">同步递归获取目录files的Stats对象{{statFile}}</button> id="btn-stat-file-sync">同步递归获取目录files的Stats对象{{statFile}}</button>
<button class="btnstyle" type="primary" @tap="appendFileTest" <button class="btnstyle" type="primary" @tap="appendFileTest"
...@@ -163,12 +163,21 @@ ...@@ -163,12 +163,21 @@
arrayBufferRes: 0, 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, basePath: uni.env.USER_DATA_PATH,
copyToBasePath: uni.env.USER_DATA_PATH, copyToBasePath: uni.env.USER_DATA_PATH,
globalTempPath: uni.env.CACHE_PATH, globalTempPath: uni.env.CACHE_PATH,
globalRootPath: uni.env.SANDBOX_PATH, globalRootPath: uni.env.SANDBOX_PATH,
globalUserDataPath: uni.env.USER_DATA_PATH globalUserDataPath: uni.env.USER_DATA_PATH,
// #endif
} }
}, },
onLoad() { onLoad() {
......
...@@ -2,7 +2,7 @@ jest.setTimeout(50000); ...@@ -2,7 +2,7 @@ jest.setTimeout(50000);
const PAGE_PATH = '/pages/API/storage/storage' const PAGE_PATH = '/pages/API/storage/storage'
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isIos = platformInfo.startsWith('ios') const isIOS = platformInfo.startsWith('ios')
describe('ExtApi-StorageInfoTest', () => { describe('ExtApi-StorageInfoTest', () => {
if( if(
...@@ -144,7 +144,7 @@ describe('ExtApi-StorageInfoTest', () => { ...@@ -144,7 +144,7 @@ describe('ExtApi-StorageInfoTest', () => {
let btnComplexStaticTest = await page.$('.btn-complexStaticTest') let btnComplexStaticTest = await page.$('.btn-complexStaticTest')
await btnComplexStaticTest.tap() await btnComplexStaticTest.tap()
await page.waitFor(600) await page.waitFor(600)
if(process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios') == false) { if(!isIOS) {
expect(await getData('staticComplexRet')).toEqual(true) expect(await getData('staticComplexRet')).toEqual(true)
} }
await page.setData({ await page.setData({
...@@ -302,6 +302,7 @@ describe('ExtApi-StorageInfoTest', () => { ...@@ -302,6 +302,7 @@ describe('ExtApi-StorageInfoTest', () => {
it('saveUTSJSONObject', async () => { it('saveUTSJSONObject', async () => {
await page.callMethod('jest_saveUTSJSONObject') await page.callMethod('jest_saveUTSJSONObject')
await page.waitFor(600)
const { const {
jest_saveUTSJSONObjectSyncResult, jest_saveUTSJSONObjectSyncResult,
jest_saveUTSJSONObjectAsyncResult jest_saveUTSJSONObjectAsyncResult
......
...@@ -24,6 +24,7 @@ describe('unicloud-import-object', () => { ...@@ -24,6 +24,7 @@ describe('unicloud-import-object', () => {
genericDemoReturnTodoTitle, genericDemoReturnTodoTitle,
genericDemoReturnTodoContent, genericDemoReturnTodoContent,
failErrCode, failErrCode,
failErrSubject,
failErrDetailTips, failErrDetailTips,
failNumberErrCode, failNumberErrCode,
successErrCode, successErrCode,
......
const PAGE_PATH = '/pages/API/upload-file/upload-file' const PAGE_PATH = '/pages/API/upload-file/upload-file'
describe('ExtApi-UploadFile', () => { 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 端暂不支持测试 // TODO: web 端暂不支持测试
it('web', async () => { it('web', async () => {
expect(1).toBe(1) expect(1).toBe(1)
...@@ -42,16 +47,20 @@ describe('ExtApi-UploadFile', () => { ...@@ -42,16 +47,20 @@ describe('ExtApi-UploadFile', () => {
it('Check uni.env', async () => { it('Check uni.env', async () => {
await page.callMethod('jest_uploadFile_with_uni_env'); await page.callMethod('jest_uploadFile_with_uni_env');
await page.waitFor(2000); await page.waitFor(3000);
res = await page.data('jest_result'); res = await page.data('jest_result');
expect(res).toBe(true); expect(res).toBe(true);
}); });
if(isMP) {
return
}
// 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备 // 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备
let version = process.env.uniTestPlatformInfo let version = process.env.uniTestPlatformInfo
let split = version.split(" ") let split = version.split(" ")
version = parseInt(split[split.length - 1]) 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 () => { it('Check Upload File In UTS Module', async () => {
res = await page.callMethod('jest_uts_module_invoked') res = await page.callMethod('jest_uts_module_invoked')
await page.waitFor(2000); await page.waitFor(2000);
......
...@@ -94,7 +94,9 @@ ...@@ -94,7 +94,9 @@
// #ifdef WEB // #ifdef WEB
context.toBlob((blob : Blob) => { context.toBlob((blob : Blob) => {
this.testToBlobResult = (blob.size > 0 && blob.type == 'image/jpeg') 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') this.testToDataURLResult = this.canvasContext!.toDataURL().startsWith('data:image/png;base64')
// #endif // #endif
this.testCanvasContext = true this.testCanvasContext = true
......
...@@ -70,18 +70,21 @@ describe('Checkbox.uvue', () => { ...@@ -70,18 +70,21 @@ describe('Checkbox.uvue', () => {
expect(disabled2).toBe(false + '') expect(disabled2).toBe(false + '')
}) })
} }
it('checked', async () => { if(!isMP) {
const cb = await page.$('.cb') // 自动化测试获取的property checked在app、web和微信小程序之间有差异。微信小程序获取的和显示效果一致,app、web获取的是绑定值
// TODO it('checked', async () => {
const newValue1 = await cb.property('checked') const cb = await page.$('.cb')
expect(newValue1.toString()).toBe(true + '') // TODO
await page.setData({ const newValue1 = await cb.property('checked')
checked: false, 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) { if(!isMP) {
it('color', async () => { it('color', async () => {
const cb = await page.$('.cb') const cb = await page.$('.cb')
......
const PAGE_PATH = '/pages/component/global-events/touch-events-bubbles' 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 ( if (
process.env.uniTestPlatformInfo.startsWith('android') || isAndroid ||
process.env.uniTestPlatformInfo.startsWith('web') || isWeb ||
process.env.uniTestPlatformInfo.startsWith('mp') isMP
) { ) {
it('other platform', () => { it('other platform', () => {
expect(1).toBe(1) expect(1).toBe(1)
......
...@@ -75,7 +75,7 @@ describe('PickerView.uvue', () => { ...@@ -75,7 +75,7 @@ describe('PickerView.uvue', () => {
indicatorStyle: "", //清空indicatorStyle indicatorStyle: "", //清空indicatorStyle
indicatorClass: "indicator-test", //设置indicatorClass为indicator-test 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 toScreenshot('picker-view-web-indicator-class')
await page.setData({ await page.setData({
indicatorClass: "", //清空indicatorClass indicatorClass: "", //清空indicatorClass
...@@ -86,14 +86,14 @@ describe('PickerView.uvue', () => { ...@@ -86,14 +86,14 @@ describe('PickerView.uvue', () => {
await page.setData({ await page.setData({
maskStyle 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') await toScreenshot('picker-view-web-mask-style')
}) })
it('mask-class', async () => { it('mask-class', async () => {
await page.setData({ await page.setData({
maskClass: "mask-test" 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') await toScreenshot('picker-view-web-mask-class')
}) })
return return
......
...@@ -28,7 +28,7 @@ describe('component-native-scroll-view-props', () => { ...@@ -28,7 +28,7 @@ describe('component-native-scroll-view-props', () => {
//检测竖向scrolltop属性赋值 //检测竖向scrolltop属性赋值
it('check_scroll_top', async () => { it('check_scroll_top', async () => {
await page.setData({ await page.setData({
scrollTop: 600 scrollTop: 600
}) })
await page.waitFor(600) await page.waitFor(600)
//检测滚动top 是否触发scroll 事件 //检测滚动top 是否触发scroll 事件
...@@ -44,7 +44,7 @@ describe('component-native-scroll-view-props', () => { ...@@ -44,7 +44,7 @@ describe('component-native-scroll-view-props', () => {
//检测竖向scroll_into_view属性赋值 //检测竖向scroll_into_view属性赋值
it('check_scroll_into_view_top', async () => { it('check_scroll_into_view_top', async () => {
await page.setData({ await page.setData({
scrollIntoView: "item3" scrollIntoView: "item3"
}) })
await page.waitFor(600) await page.waitFor(600)
const element = await page.$('#scrollViewY') const element = await page.$('#scrollViewY')
...@@ -71,7 +71,10 @@ describe('component-native-scroll-view-props', () => { ...@@ -71,7 +71,10 @@ describe('component-native-scroll-view-props', () => {
//检测横向scrollLeft属性赋值 //检测横向scrollLeft属性赋值
it('check_scroll_left', async () => { it('check_scroll_left', async () => {
await page.setData({ await page.setData({
scrollLeft: 600 scrollX: true
})
await page.setData({
scrollLeft: 600
}) })
await page.waitFor(600) await page.waitFor(600)
const element = await page.$('#scrollViewX') const element = await page.$('#scrollViewX')
...@@ -82,6 +85,9 @@ describe('component-native-scroll-view-props', () => { ...@@ -82,6 +85,9 @@ describe('component-native-scroll-view-props', () => {
//检测横向scroll_into_view属性赋值 //检测横向scroll_into_view属性赋值
it('check_scroll_into_view_left', async () => { it('check_scroll_into_view_left', async () => {
await page.setData({
scrollX: true
})
await page.setData({ await page.setData({
scrollIntoView: "horizontal_item3" scrollIntoView: "horizontal_item3"
}) })
......
const PAGE_PATH = '/pages/component/swiper/swiper' const PAGE_PATH = '/pages/component/swiper/swiper'
describe('swiper-touch-test', () => { describe('swiper-touch-test', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android') const isAndroid = platformInfo.startsWith('android')
const isWeb = platformInfo.startsWith('web') const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp') const isMP = platformInfo.startsWith('mp')
// 屏蔽 web * android 平台, 需要针对调整坐标 // 屏蔽 web * android 平台, 需要针对调整坐标
// 屏蔽 小程序,不支持 program.swipe // 屏蔽 小程序,不支持 program.swipe
if (isWeb || isAndroid || isMP) { if (isWeb || isAndroid || isMP) {
......
jest.setTimeout(60000); jest.setTimeout(60000);
describe('component-native-video', () => { describe('component-native-video', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android') const isAndroid = platformInfo.startsWith('android')
const isIOS = platformInfo.startsWith('ios') const isIOS = platformInfo.startsWith('ios')
const isMP = platformInfo.startsWith('mp') const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web') const isWeb = platformInfo.startsWith('web')
if(isWeb){ if (isWeb) {
// TODO: web 端暂不支持测试 // TODO: web 端暂不支持测试
it('web', async () => { it('web', async () => {
expect(1).toBe(1) expect(1).toBe(1)
}) })
return return
} }
let page; let page;
let start = 0; let start = 0;
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch('/pages/component/video/video'); page = await program.reLaunch('/pages/component/video/video');
if(process.env.uniTestPlatformInfo.startsWith('web')){ if (process.env.uniTestPlatformInfo.startsWith('web')) {
await page.setData({ await page.setData({
muted: true muted: true
}); });
} }
await page.waitFor(1000); await page.waitFor(1000);
}); });
it('test API', async () => { it('test API', async () => {
expect(await page.data('isError')).toBe(false); expect(await page.data('isError')).toBe(false);
// play // play
await page.callMethod('play'); await page.callMethod('play');
await page.waitFor(100); await page.waitFor(100);
expect(await page.data('isPlaying')).toBe(true); expect(await page.data('isPlaying')).toBe(true);
// pause // pause
await page.callMethod('pause'); await page.callMethod('pause');
await page.waitFor(100); await page.waitFor(100);
expect(await page.data('isPause')).toBe(true); expect(await page.data('isPause')).toBe(true);
}); });
if(!isMP) { if (!isMP) {
it('test local source', async () => { it('test local source', async () => {
await page.setData({ await page.setData({
autoTest: true, autoTest: true,
isError: false isError: false
}); });
const oldSrc = await page.data('src'); const oldSrc = await page.data('src');
await page.callMethod('downloadSource'); await page.callMethod('downloadSource');
await page.waitFor(5000); await page.waitFor(5000);
expect(await page.data('isError')).toBe(false); expect(await page.data('isError')).toBe(false);
await page.setData({ await page.setData({
src: '/static/test-video/2minute-demo.m3u8' src: '/static/test-video/2minute-demo.m3u8'
}); });
await page.waitFor(100); await page.waitFor(100);
expect(await page.data('isError')).toBe(false); expect(await page.data('isError')).toBe(false);
await page.setData({ await page.setData({
src: oldSrc src: oldSrc
}); });
}); });
it('test assets path', async () => { it('test assets path', async () => {
if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) return; if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) return;
const oldSrc = await page.data('src'); const oldSrc = await page.data('src');
await page.setData({ await page.setData({
isError: false, isError: false,
src: 'file:///android_asset/uni-autoTest/demo10s.mp4' src: 'file:///android_asset/uni-autoTest/demo10s.mp4'
}); });
await page.waitFor(500); await page.waitFor(500);
expect(await page.data('isError')).toBe(false); expect(await page.data('isError')).toBe(false);
await page.setData({ await page.setData({
src: oldSrc src: oldSrc
}); });
}); });
} }
it('test event play pause controlstoggle', async () => { it('test event play pause controlstoggle', async () => {
await page.setData({ await page.setData({
autoTest: true, autoTest: true,
}); });
await page.callMethod('play'); await page.callMethod('play');
start = Date.now(); start = Date.now();
await page.waitFor(async () => { await page.waitFor(async () => {
return (await page.data('eventPlay')) || (Date.now() - start > 500); return (await page.data('eventPlay')) || (Date.now() - start > 500);
}); });
if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
// expect(await page.data('eventPlay')).toEqual({ // expect(await page.data('eventPlay')).toEqual({
// type: 'play' // type: 'play'
// }); // });
}else { } else {
expect(await page.data('eventPlay')).toEqual({ expect(await page.data('eventPlay')).toEqual({
tagName: isMP ? undefined : 'VIDEO', tagName: isMP ? undefined : 'VIDEO',
type: 'play' type: 'play'
}); });
} }
await page.callMethod('pause'); await page.callMethod('pause');
start = Date.now(); start = Date.now();
await page.waitFor(async () => { await page.waitFor(async () => {
return (await page.data('eventPause')) || (Date.now() - start > 1000); return (await page.data('eventPause')) || (Date.now() - start > 1000);
}); });
if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
// expect(await page.data('eventPause')).toEqual({ // expect(await page.data('eventPause')).toEqual({
// type: 'pause' // type: 'pause'
// }); // });
} else { } else {
expect(await page.data('eventPause')).toEqual({ expect(await page.data('eventPause')).toEqual({
tagName: isMP ? undefined : 'VIDEO', tagName: isMP ? undefined : 'VIDEO',
type: 'pause' type: 'pause'
}); });
} }
if(!isMP && !isWeb) { if (!isMP && !isWeb) {
/** /**
* app端video组件controlstoggle事件会在controls显示和隐藏触发(播放、暂停等操作都会触发)。 * app端video组件controlstoggle事件会在controls显示和隐藏触发(播放、暂停等操作都会触发)。
* 微信小程序和web播放暂停或者一些其他的操作也会影响controls的显隐,但是不会触发controlstoggle, 只有controls属性变化的时候才会触发 * 微信小程序和web播放暂停或者一些其他的操作也会影响controls的显隐,但是不会触发controlstoggle, 只有controls属性变化的时候才会触发
*/ */
await page.callMethod('play'); await page.callMethod('play');
start = Date.now(); start = Date.now();
await page.waitFor(async () => { await page.waitFor(async () => {
return (await page.data('eventControlstoggle')) || (Date.now() - start > 1000); return (await page.data('eventControlstoggle')) || (Date.now() - start > 1000);
}); });
if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) {
// expect(await page.data('eventControlstoggle')).toEqual({ // expect(await page.data('eventControlstoggle')).toEqual({
// tagName: 'VIDEO', // tagName: 'VIDEO',
// type: 'controlstoggle', // type: 'controlstoggle',
// show: true // show: true
// }); // });
} else { } else {
expect(await page.data('eventControlstoggle')).toEqual({ expect(await page.data('eventControlstoggle')).toEqual({
tagName: isMP ? undefined : 'VIDEO', tagName: isMP ? undefined : 'VIDEO',
type: 'controlstoggle', type: 'controlstoggle',
show: true show: true
}); });
} }
} }
}); });
it('test event waiting progress', async () => {
if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { if (isAndroid) {
return it('test event waiting progress', async () => {
} await page.callMethod('seek', 10);
await page.callMethod('seek', 10); start = Date.now();
start = Date.now(); await page.waitFor(async () => {
await page.waitFor(async () => { return (await page.data('eventWaiting')) && (await page.data('eventProgress')) || (Date.now() -
return (await page.data('eventWaiting')) && (await page.data('eventProgress')) || (Date.now() - start > 1000); start > 1000);
}); });
expect(await page.data('eventWaiting')).toEqual({ expect(await page.data('eventWaiting')).toEqual({
tagName: isMP ? undefined : 'VIDEO', tagName: isMP ? undefined : 'VIDEO',
type: 'waiting' type: 'waiting'
}); });
expect(await page.data('eventProgress')).toEqual({ expect(await page.data('eventProgress')).toEqual({
tagName: isMP ? undefined : 'VIDEO', tagName: isMP ? undefined : 'VIDEO',
type: 'progress', type: 'progress',
isBufferedValid: true isBufferedValid: true
}); });
}); });
if (isAndroid) { it('test event fullscreenchange fullscreenclick', async () => {
it('test event fullscreenchange fullscreenclick', async () => { await page.callMethod('requestFullScreen');
await page.callMethod('requestFullScreen'); start = Date.now();
start = Date.now(); await page.waitFor(async () => {
await page.waitFor(async () => { return (await page.data('eventFullscreenchange')) || (Date.now() - start > 1000);
return (await page.data('eventFullscreenchange')) || (Date.now() - start > 1000); });
}); expect(await page.data('eventFullscreenchange')).toEqual({
expect(await page.data('eventFullscreenchange')).toEqual({ tagName: isMP ? undefined : 'VIDEO',
tagName: isMP ? undefined : 'VIDEO', type: 'fullscreenchange',
type: 'fullscreenchange', fullScreen: true,
fullScreen: true, direction: 'horizontal'
direction: 'horizontal' });
}); const infos = process.env.uniTestPlatformInfo.split(' ');
const infos = process.env.uniTestPlatformInfo.split(' '); const version = parseInt(infos[infos.length - 1]);
const version = parseInt(infos[infos.length - 1]); if (process.env.uniTestPlatformInfo.startsWith('android') && version >
if (process.env.uniTestPlatformInfo.startsWith('android') && version > 5) { // android5.1模拟器全屏时会弹出系统提示框,无法响应adb tap命令 5) { // android5.1模拟器全屏时会弹出系统提示框,无法响应adb tap命令
await page.waitFor(5000); await page.waitFor(5000);
await program.adbCommand('input tap 10 10'); await program.adbCommand('input tap 10 10');
start = Date.now(); start = Date.now();
await page.waitFor(async () => { await page.waitFor(async () => {
return (await page.data('eventFullscreenclick')) || (Date.now() - start > 1000); return (await page.data('eventFullscreenclick')) || (Date.now() - start > 1000);
}); });
const res = await program.adbCommand('wm size'); const res = await program.adbCommand('wm size');
const width = res.data.split(' ').at(-1).split('x')[0]; const width = res.data.split(' ').at(-1).split('x')[0];
const height = res.data.split(' ').at(-1).split('x')[1]; const height = res.data.split(' ').at(-1).split('x')[1];
const res2 = await program.adbCommand('wm density'); const res2 = await program.adbCommand('wm density');
const scale = res2.data.split(' ').at(-1) / 160; const scale = res2.data.split(' ').at(-1) / 160;
expect(await page.data('eventFullscreenclick')).toEqual({ expect(await page.data('eventFullscreenclick')).toEqual({
tagName: isMP ? undefined : 'VIDEO', tagName: isMP ? undefined : 'VIDEO',
type: 'fullscreenclick', type: 'fullscreenclick',
screenX: parseInt(10 / scale), screenX: parseInt(10 / scale),
screenY: parseInt(10 / scale), screenY: parseInt(10 / scale),
screenWidth: parseInt(height / scale), screenWidth: parseInt(height / scale),
screenHeight: parseInt(width / scale) screenHeight: parseInt(width / scale)
}); });
} }
await page.callMethod('exitFullScreen'); await page.callMethod('exitFullScreen');
}); });
}
it('test event ended timeupdate', async () => {
it('test event ended timeupdate', async () => { await page.callMethod('seek', 120);
if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('ios')) { start = Date.now();
return await page.waitFor(async () => {
} return (await page.data('eventEnded')) || (Date.now() - start > 30000);
await page.callMethod('seek', 120); });
start = Date.now(); expect(await page.data('eventEnded')).toEqual({
await page.waitFor(async () => { tagName: isMP ? undefined : 'VIDEO',
return (await page.data('eventEnded')) || (Date.now() - start > 30000); type: 'ended'
}); });
expect(await page.data('eventEnded')).toEqual({ const infos = process.env.uniTestPlatformInfo.split(' ');
tagName: isMP ? undefined : 'VIDEO', const version = parseInt(infos[infos.length - 1]);
type: 'ended' if (process.env.uniTestPlatformInfo.startsWith('android') && version > 5) {
}); start = Date.now();
const infos = process.env.uniTestPlatformInfo.split(' '); await page.waitFor(async () => {
const version = parseInt(infos[infos.length - 1]); return (await page.data('eventTimeupdate')) || (Date.now() - start > 500);
if (process.env.uniTestPlatformInfo.startsWith('android') && version > 5) { });
start = Date.now(); expect(await page.data('eventTimeupdate')).toEqual({
await page.waitFor(async () => { tagName: isMP ? undefined : 'VIDEO',
return (await page.data('eventTimeupdate')) || (Date.now() - start > 500); type: 'timeupdate',
}); currentTime: 121,
expect(await page.data('eventTimeupdate')).toEqual({ duration: 121
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'
it('test event error', async () => { });
if (isIOS || isMP) { start = Date.now();
return await page.waitFor(async () => {
} return (await page.data('eventError')) || (Date.now() - start > 1000);
const oldSrc = await page.data('src'); });
await page.setData({ expect(await page.data('eventError')).toEqual({
src: 'invalid url' tagName: 'VIDEO',
}); type: 'error',
start = Date.now(); errCode: 300001
await page.waitFor(async () => { });
return (await page.data('eventError')) || (Date.now() - start > 1000); await page.setData({
}); autoTest: false,
expect(await page.data('eventError')).toEqual({ src: oldSrc
tagName: 'VIDEO', });
type: 'error', });
errCode: 300001
}); it('test sub component', async () => {
await page.setData({ await page.setData({
autoTest: false, subCompEnable: true,
src: oldSrc subCompShow: true
}); });
}); await page.waitFor(100);
expect(await page.callMethod('hasSubComponent')).toBe(true);
it('test sub component', async () => { });
if (isIOS || isMP) { }
return
} it('test format', async () => {
await page.setData({ page = await program.navigateTo('/pages/component/video/video-format');
subCompEnable: true, await page.waitFor(1000);
subCompShow: true expect((await page.data('isError')).value).toBe(false);
}); });
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.
先完成此消息的编辑!
想要评论请 注册