提交 d44c443c 编写于 作者: DCloud-yinjiacheng's avatar DCloud-yinjiacheng 提交者: 雪洛

新增media自动化测试用例

上级 b4ea0193
// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('API-compressImage', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/API/compress-image/compress-image');
await page.waitFor(500);
});
it('test compressImage', async () => {
if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.startsWith('ios')) {
expect(1).toBe(1);
return;
}
await page.callMethod('testCompressImage');
await page.waitFor(1000);
expect(await page.data('imageInfoForTest')).toEqual({
width: 100,
height: 100,
size: 2
});
});
});
......@@ -52,7 +52,9 @@
compressedHeight: null as number | null,
width: "auto",
height: "auto",
rotate: 0
rotate: 0,
// 自动化测试
imageInfoForTest: null
}
},
methods: {
......@@ -103,7 +105,7 @@
complete: (_) => {
uni.hideLoading();
}
})
});
},
chooseImage() {
uni.chooseImage({
......@@ -142,6 +144,32 @@
},
onRotateConfirm(value : number) {
this.rotate = value;
},
testCompressImage() {
uni.compressImage({
src: '/static/test-image/logo.png',
quality: 50,
compressedWidth: 100,
compressedHeight: 100,
success: (res) => {
uni.getImageInfo({
src: res.tempFilePath,
success: (_res) => {
// #ifdef APP-ANDROID
const size = new FileInputStream(res.tempFilePath.substring("file://".length)).available() / 1024;
// #endif
this.imageInfoForTest = {
"width": _res.width,
"height": _res.height,
"size": size.toInt()
};
}
});
},
fail: (_) => {
this.imageInfoForTest = null;
}
});
}
}
}
......
// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('API-compressVideo', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/API/compress-video/compress-video');
await page.waitFor(500);
});
it('test compressVideo', async () => {
if (process.env.uniTestPlatformInfo.startsWith('web') || process.env.uniTestPlatformInfo.startsWith('ios')) {
expect(1).toBe(1);
return;
}
await page.callMethod('testCompressVideo');
await page.waitFor(3000);
expect(await page.data('videoInfoForTest')).toEqual({
width: 640,
height: 360,
size: 265
});
});
});
......@@ -46,7 +46,9 @@
fps: null as number | null,
resolution: null as number | null,
qualityItemTypes: [{ "value": 0, "name": "low(低)" }, { "value": 1, "name": "medium(中)" }, { "value": 2, "name": "high(高)" }] as ItemType[],
qualityItems: ["low", "medium", "high"]
qualityItems: ["low", "medium", "high"],
// 自动化测试
videoInfoForTest: null
}
},
methods: {
......@@ -111,6 +113,27 @@
},
onResolutionChange(event : UniSliderChangeEvent) {
this.resolution = event.detail.value;
},
testCompressVideo() {
uni.compressVideo({
src: '/static/test-video/10second-demo.mp4',
quality: 'medium',
success: (res) => {
uni.getVideoInfo({
src: res.tempFilePath,
success: (_res) => {
this.videoInfoForTest = {
"width": _res.width,
"height": _res.height,
"size": res.size.toInt()
};
}
});
},
fail: (_) => {
this.videoInfoForTest = null;
}
});
}
}
}
......
// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('API-getImageInfo', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/API/get-image-info/get-image-info');
await page.waitFor(500);
});
it('test getImageInfo', async () => {
if (process.env.uniTestPlatformInfo.startsWith('ios')) {
expect(1).toBe(1);
return;
}
await page.waitFor(500);
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await page.data('imageInfoForTest')).toEqual({
width: 192,
height: 192
});
return;
}
expect(await page.data('imageInfoForTest')).toEqual({
width: 192,
height: 192,
path: 'file:///storage/emulated/0/Android/data/io.dcloud.uniappx/apps/__UNI__HelloUniAppX/www/static/test-image/logo.png',
orientation: 'up',
type: 'png'
});
});
});
......@@ -39,6 +39,8 @@
absoluteImageInfo: "",
remoteImagePath: "https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/img/building.jpg",
remoteImageInfo: "",
// 自动化测试
imageInfoForTest: null,
}
},
methods: {
......@@ -71,6 +73,13 @@
success: (res) => {
console.log("getImageInfo success", JSON.stringify(res));
this.absoluteImageInfo = `图片宽度: ${res.width}\n图片高度: ${res.height}\n图片路径: ${res.path}\n图片方向: ${res.orientation}\n图片格式: ${res.type}`;
this.imageInfoForTest = {
"width": res.width,
"height": res.height,
"path": res.path,
"orientation": res.orientation,
"type": res.type
};
},
fail: (err) => {
uni.showModal({
......@@ -78,6 +87,7 @@
content: JSON.stringify(err),
showCancel: false
});
this.imageInfoForTest = null;
}
});
uni.getImageInfo({
......
// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('API-getVideoInfo', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/API/get-video-info/get-video-info');
await page.waitFor(500);
});
it('test getVideoInfo', async () => {
if (process.env.uniTestPlatformInfo.startsWith('ios')) {
expect(1).toBe(1);
return;
}
await page.callMethod('testGetVideoInfo');
await page.waitFor(1000);
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await page.data('videoInfoForTest')).toEqual({
duration: 10,
size: 211,
width: 1280,
height: 720
});
return;
}
expect(await page.data('videoInfoForTest')).toEqual({
orientation: 'up',
type: 'video/mp4',
duration: 10,
size: 211,
width: 1280,
height: 720,
fps: 30,
bitrate: 172
});
});
});
......@@ -25,6 +25,8 @@
title: "getVideoInfo",
absoluteVideoPath: "",
absoluteVideoInfo: "",
// 自动化测试
videoInfoForTest: null
}
},
methods: {
......@@ -49,6 +51,26 @@
});
}
});
},
testGetVideoInfo() {
uni.getVideoInfo({
src: '/static/test-video/10second-demo.mp4',
success: (res) => {
this.videoInfoForTest = {
"orientation": res.orientation,
"type": res.type,
"duration": res.duration.toInt(),
"size": res.size,
"width": res.width,
"height": res.height,
"fps": res.fps,
"bitrate": res.bitrate
};
},
fail: (_) => {
this.videoInfoForTest = null;
}
});
}
}
}
......
// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('API-saveImageToPhotosAlbum', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/API/save-image-to-photos-album/save-image-to-photos-album');
await page.waitFor(500);
});
it('test saveImageToPhotosAlbum', async () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(1).toBe(1);
return;
}
if (process.env.uniTestPlatformInfo.startsWith('android')) {
await program.adbCommand(
'pm grant io.dcloud.uniappx android.permission.WRITE_EXTERNAL_STORAGE');
await page.waitFor(500);
}
await page.callMethod('saveImage');
expect(await page.data('success')).toBe(true);
});
});
......@@ -16,7 +16,9 @@
export default {
data() {
return {
title: "saveImageToPhotosAlbum"
title: "saveImageToPhotosAlbum",
// 自动化测试
success: false
}
},
methods: {
......@@ -29,7 +31,8 @@
position: "center",
icon: "none",
title: "图片保存成功,请到手机相册查看"
})
});
this.success = true;
},
fail: (err) => {
uni.showModal({
......@@ -37,6 +40,7 @@
content: JSON.stringify(err),
showCancel: false
});
this.success = false;
}
})
}
......
// uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('API-saveVideoToPhotosAlbum', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/API/save-video-to-photos-album/save-video-to-photos-album');
await page.waitFor(500);
});
it('test saveVideoToPhotosAlbum', async () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(1).toBe(1);
return;
}
if (process.env.uniTestPlatformInfo.startsWith('android')) {
await program.adbCommand(
'pm grant io.dcloud.uniappx android.permission.WRITE_EXTERNAL_STORAGE');
await page.waitFor(500);
}
await page.callMethod('saveVideo');
expect(await page.data('success')).toBe(true);
});
});
......@@ -17,7 +17,9 @@
data() {
return {
title: 'saveVideoToPhotosAlbum',
src: ''
src: '/static/test-video/10second-demo.mp4',
// 自动化测试
success: false
}
},
methods: {
......@@ -31,6 +33,7 @@
icon: "none",
title: "视频保存成功,请到手机相册查看"
});
this.success = true;
},
fail: (err) => {
uni.showModal({
......@@ -38,22 +41,10 @@
content: JSON.stringify(err),
showCancel: false
});
this.success = false;
}
});
}
},
onReady() {
uni.showLoading({
title: '视频下载中'
});
uni.downloadFile({
url: 'https://qiniu-web-assets.dcloud.net.cn/uni-app-x/static/video/swiper-vertical-video/uts.mp4',
success: (res) => {
console.log("download video success", res.tempFilePath);
this.src = res.tempFilePath;
uni.hideLoading();
}
});
}
}
</script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册