diff --git a/pages/component/video/video.test.js b/pages/component/video/video.test.js new file mode 100644 index 0000000000000000000000000000000000000000..fbc65dfdcb6cd8a8accbee73e43a3c346fa87040 --- /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 adbd046dfebb89c1a6d143f72f1857ec3c7d6f59..0d0cccc3af9eca3175257b19dad1f6f414051c6c 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(); } } }