From 305c4a9b4c5b46b79ccb3b8810ebe00c6350d3e4 Mon Sep 17 00:00:00 2001 From: yinjiacheng Date: Mon, 25 Sep 2023 18:41:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Evideo=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/component/video/video.test.js | 47 +++++++++++++++++++++++++++++ pages/component/video/video.uvue | 30 +++++++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 pages/component/video/video.test.js diff --git a/pages/component/video/video.test.js b/pages/component/video/video.test.js new file mode 100644 index 00000000..fbc65dfd --- /dev/null +++ b/pages/component/video/video.test.js @@ -0,0 +1,47 @@ +// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/ + +describe('component-native-video', () => { + + let page; + beforeAll(async () => { + page = await program.reLaunch('/pages/component/video/video'); + await page.waitFor(1000); + }); + + it('check API play', async () => { + await page.callMethod('playTest'); + await page.waitFor(500); + expect(await page.data('isPlaying')).toBe(true); + expect(await page.data('isPause')).toBe(false); + }); + + it('check API requestFullScreen', async () => { + await page.callMethod('requestFullScreenTest'); + await page.waitFor(1000); + expect(await page.data('isFullScreen')).toBe(true); + }); + + it('check API exitFullScreen', async () => { + await page.callMethod('exitFullScreenTest'); + await page.waitFor(1000); + expect(await page.data('isFullScreen')).toBe(false); + }); + + it('check API pause', async () => { + await page.callMethod('pauseTest'); + await page.waitFor(500); + expect(await page.data('isPause')).toBe(true); + expect(await page.data('isPlaying')).toBe(false); + await page.callMethod('playTest'); + await page.waitFor(500); + expect(await page.data('isPlaying')).toBe(true); + expect(await page.data('isPause')).toBe(false); + }); + + it('check API stop', async () => { + await page.callMethod('stopTest'); + await page.waitFor(500); + expect(await page.data('isPause')).toBe(true); + expect(await page.data('isPlaying')).toBe(false); + }); +}); \ No newline at end of file diff --git a/pages/component/video/video.uvue b/pages/component/video/video.uvue index adbd046d..0d0cccc3 100644 --- a/pages/component/video/video.uvue +++ b/pages/component/video/video.uvue @@ -208,7 +208,11 @@ danmu: { text: '要显示的文本', color: '#FF0000' - } as Danmu + } as Danmu, + // 自动化测试 + isPlaying: false, + isPause: false, + isFullScreen: false } }, methods: { @@ -357,9 +361,13 @@ // 事件 onPlay: function (res : any) { console.log(JSON.stringify(res)); + this.isPlaying = true; + this.isPause = false; }, onPause: function (res : any) { console.log(JSON.stringify(res)); + this.isPlaying = false; + this.isPause = true; }, onEnded: function (res : any) { console.log(JSON.stringify(res)); @@ -369,6 +377,7 @@ }, onFullScreenChange: function (res : any) { console.log(JSON.stringify(res)); + this.isFullScreen = !this.isFullScreen; }, onWaiting: function (res : any) { console.log(JSON.stringify(res)); @@ -384,6 +393,25 @@ }, onControlsToggle: function (res : any) { console.log(JSON.stringify(res)); + }, + // 自动化测试 + playTest: function () { + this.videoContext?.play(); + }, + pauseTest: function () { + this.videoContext?.pause(); + }, + requestFullScreenTest: function () { + const options : RequestFullScreenOptions = { + direction: -90 + }; + this.videoContext?.requestFullScreen(options); + }, + exitFullScreenTest: function () { + this.videoContext?.exitFullScreen(); + }, + stopTest: function () { + this.videoContext?.stop(); } } } -- GitLab