diff --git a/pages/API/compress-image/compress-image.test.js b/pages/API/compress-image/compress-image.test.js new file mode 100644 index 0000000000000000000000000000000000000000..5792961140f6e055cdf601103b3350810f5777ee --- /dev/null +++ b/pages/API/compress-image/compress-image.test.js @@ -0,0 +1,22 @@ +// 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 + }); + }); +}); diff --git a/pages/API/compress-image/compress-image.uvue b/pages/API/compress-image/compress-image.uvue index bd76cc8e28f7612a53f6d09cc5c90507c814f53c..709d4065b4022cf88d0b0d5b26d1446921945593 100644 --- a/pages/API/compress-image/compress-image.uvue +++ b/pages/API/compress-image/compress-image.uvue @@ -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; + } + }); } } } diff --git a/pages/API/compress-video/compress-video.test.js b/pages/API/compress-video/compress-video.test.js new file mode 100644 index 0000000000000000000000000000000000000000..f6999b93c478a290562e053aa0851f8b0ef86aca --- /dev/null +++ b/pages/API/compress-video/compress-video.test.js @@ -0,0 +1,22 @@ +// 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 + }); + }); +}); diff --git a/pages/API/compress-video/compress-video.uvue b/pages/API/compress-video/compress-video.uvue index d6306ac37b48ac1219de62bb71d14e33a25bced5..abbb1641e6bc4c5fc6ff1ef4234d5bb3ed5f036c 100644 --- a/pages/API/compress-video/compress-video.uvue +++ b/pages/API/compress-video/compress-video.uvue @@ -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; + } + }); } } } diff --git a/pages/API/get-image-info/get-image-info.test.js b/pages/API/get-image-info/get-image-info.test.js new file mode 100644 index 0000000000000000000000000000000000000000..4172ebbf7a62e52abb5e1b85dd8edc77354026f0 --- /dev/null +++ b/pages/API/get-image-info/get-image-info.test.js @@ -0,0 +1,30 @@ +// 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' + }); + }); +}); diff --git a/pages/API/get-image-info/get-image-info.uvue b/pages/API/get-image-info/get-image-info.uvue index 1312188f937c688d358041ae92261fe17ba3ef97..62306a761fe96d006ba8cf288ecd5ccde9ca8a26 100644 --- a/pages/API/get-image-info/get-image-info.uvue +++ b/pages/API/get-image-info/get-image-info.uvue @@ -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({ diff --git a/pages/API/get-video-info/get-video-info.test.js b/pages/API/get-video-info/get-video-info.test.js new file mode 100644 index 0000000000000000000000000000000000000000..b0272fe500e82566a9ad45a037059adb041a7b70 --- /dev/null +++ b/pages/API/get-video-info/get-video-info.test.js @@ -0,0 +1,36 @@ +// 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 + }); + }); +}); diff --git a/pages/API/get-video-info/get-video-info.uvue b/pages/API/get-video-info/get-video-info.uvue index 8ba0c7f8b2da7b918e6687ba5b36c32bc2329855..2c8a49589df204d3bd1dc6dd537c2f0cba9b7940 100644 --- a/pages/API/get-video-info/get-video-info.uvue +++ b/pages/API/get-video-info/get-video-info.uvue @@ -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; + } + }); } } } diff --git a/pages/API/save-image-to-photos-album/save-image-to-photos-album.test.js b/pages/API/save-image-to-photos-album/save-image-to-photos-album.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a08d657f9aefd9c68eae4b8156731495bb1aba56 --- /dev/null +++ b/pages/API/save-image-to-photos-album/save-image-to-photos-album.test.js @@ -0,0 +1,22 @@ +// 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); + }); +}); diff --git a/pages/API/save-image-to-photos-album/save-image-to-photos-album.uvue b/pages/API/save-image-to-photos-album/save-image-to-photos-album.uvue index b6e87e2eac68d75375738d56bb6fd5482414b24b..1a3bea9328ccb64f8aed3965077254ae62b8fa2d 100644 --- a/pages/API/save-image-to-photos-album/save-image-to-photos-album.uvue +++ b/pages/API/save-image-to-photos-album/save-image-to-photos-album.uvue @@ -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; } }) } diff --git a/pages/API/save-video-to-photos-album/save-video-to-photos-album.test.js b/pages/API/save-video-to-photos-album/save-video-to-photos-album.test.js new file mode 100644 index 0000000000000000000000000000000000000000..8b718dfe6aab3d7e742e80e0be844b17905b828d --- /dev/null +++ b/pages/API/save-video-to-photos-album/save-video-to-photos-album.test.js @@ -0,0 +1,22 @@ +// 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); + }); +}); diff --git a/pages/API/save-video-to-photos-album/save-video-to-photos-album.uvue b/pages/API/save-video-to-photos-album/save-video-to-photos-album.uvue index e98bdc518bbe7447e439301cc9206dc82bb1bc68..b9d89d0bb6131f8829ad1b17ebbb20c9edf8b6a1 100644 --- a/pages/API/save-video-to-photos-album/save-video-to-photos-album.uvue +++ b/pages/API/save-video-to-photos-album/save-video-to-photos-album.uvue @@ -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(); - } - }); } } diff --git a/static/test-video/10second-demo.mp4 b/static/test-video/10second-demo.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b35d666391d54b545125e89e313583aaee597e38 Binary files /dev/null and b/static/test-video/10second-demo.mp4 differ