1
1
import { readdir } from 'fs-extra' ;
2
- import { test , useWebdriver } from '../helpers/webdriver' ;
2
+ import { test , TExecutionContext , useWebdriver } from '../helpers/webdriver' ;
3
3
import { sleep } from '../helpers/sleep' ;
4
4
import { startRecording , stopRecording } from '../helpers/modules/streaming' ;
5
- import { FormMonkey } from '../helpers/form-monkey' ;
6
5
import {
7
6
setOutputResolution ,
8
7
setTemporaryRecordingPath ,
9
8
showSettingsWindow ,
10
9
} from '../helpers/modules/settings/settings' ;
11
- import { clickButton , focusMain } from '../helpers/modules/core' ;
10
+ import {
11
+ clickButton ,
12
+ clickWhenDisplayed ,
13
+ focusMain ,
14
+ getNumElements ,
15
+ waitForDisplayed ,
16
+ } from '../helpers/modules/core' ;
12
17
import { logIn } from '../helpers/webdriver/user' ;
13
18
import { toggleDualOutputMode } from '../helpers/modules/dual-output' ;
19
+ import { setFormDropdown } from '../helpers/webdriver/forms' ;
20
+ import { showPage } from '../helpers/modules/navigation' ;
14
21
22
+ // not a react hook
23
+ // eslint-disable-next-line react-hooks/rules-of-hooks
15
24
useWebdriver ( ) ;
16
25
17
26
/**
18
- * Recording with one context active (horizontal)
27
+ * Iterate over all formats and record a 0.5s video in each.
28
+ * @param t - AVA test context
29
+ * @param advanced - whether to use advanced settings
30
+ * @returns number of formats
19
31
*/
20
-
21
- test ( 'Recording' , async t => {
22
- const tmpDir = await setTemporaryRecordingPath ( ) ;
23
-
24
- // low resolution reduces CPU usage
25
- await setOutputResolution ( '100x100' ) ;
26
-
27
- const formats = [ 'flv' , 'mp4' , 'mov' , 'mkv' , 'ts' , 'm3u8' ] ;
32
+ async function createRecordingFiles ( advanced : boolean = false ) : Promise < number > {
33
+ const formats = advanced
34
+ ? [ 'flv' , 'mp4' , 'mov' , 'mkv' , 'mpegts' , 'hls' ]
35
+ : [ 'flv' , 'mp4' , 'mov' , 'mkv' , 'mpegts' ] ;
28
36
29
37
// Record 0.5s video in every format
30
38
for ( const format of formats ) {
31
39
await showSettingsWindow ( 'Output' , async ( ) => {
32
- const form = new FormMonkey ( t ) ;
33
- await form . setInputValue ( await form . getInputSelectorByTitle ( 'Recording Format' ) , format ) ;
40
+ if ( advanced ) {
41
+ await clickButton ( 'Recording' ) ;
42
+ }
43
+
44
+ await setFormDropdown ( 'Recording Format' , format ) ;
45
+ await sleep ( 500 ) ;
34
46
await clickButton ( 'Done' ) ;
35
47
} ) ;
36
48
@@ -39,15 +51,85 @@ test('Recording', async t => {
39
51
await sleep ( 500 ) ;
40
52
await stopRecording ( ) ;
41
53
42
- // Wait to ensure that output setting are editable
54
+ // in advanced mode, it may take a little longer to save the recording
55
+ if ( advanced ) {
56
+ await sleep ( 1000 ) ;
57
+ }
58
+
59
+ // Confirm notification has been shown and navigate to the recording history
60
+ await focusMain ( ) ;
61
+ await clickWhenDisplayed ( 'span=A new Recording has been completed. Click for more info' ) ;
62
+ await waitForDisplayed ( 'h1=Recordings' , { timeout : 1000 } ) ;
43
63
await sleep ( 500 ) ;
64
+ await showPage ( 'Editor' ) ;
44
65
}
45
66
67
+ return Promise . resolve ( formats . length ) ;
68
+ }
69
+
70
+ /**
71
+ * Confirm correct number of files were created and that they are displayed in the recording history.
72
+ * @param t - AVA test context
73
+ * @param tmpDir - temporary directory where recordings are saved
74
+ * @param numFormats - number of formats used to record
75
+ */
76
+ async function validateRecordingFiles (
77
+ t : TExecutionContext ,
78
+ tmpDir : string ,
79
+ numFormats : number ,
80
+ advanced : boolean = false ,
81
+ ) {
46
82
// Check that every file was created
47
83
const files = await readdir ( tmpDir ) ;
48
84
49
85
// M3U8 creates multiple TS files in addition to the catalog itself.
50
- t . true ( files . length >= formats . length , `Files that were created:\n${ files . join ( '\n' ) } ` ) ;
86
+ // The additional TS files created by M3U8 in advanced mode are not displayed in the recording history
87
+ const numFiles = advanced ? files . length - 1 : files . length ;
88
+
89
+ t . true ( numFiles >= numFormats , `Files that were created:\n${ files . join ( '\n' ) } ` ) ;
90
+
91
+ // Check that the recordings are displayed in the recording history
92
+ await showPage ( 'Recordings' ) ;
93
+ waitForDisplayed ( 'h1=Recordings' ) ;
94
+
95
+ const numRecordings = await getNumElements ( '[data-test=filename]' ) ;
96
+ t . is ( numRecordings , numFiles , 'All recordings show in history matches number of files recorded' ) ;
97
+ }
98
+
99
+ /**
100
+ * Recording with one context active (horizontal, simple)
101
+ */
102
+ test ( 'Recording' , async t => {
103
+ // low resolution reduces CPU usage
104
+ await setOutputResolution ( '100x100' ) ;
105
+
106
+ // Simple Recording
107
+ const tmpDir = await setTemporaryRecordingPath ( ) ;
108
+ const numSimpleFormats = await createRecordingFiles ( ) ;
109
+ await validateRecordingFiles ( t , tmpDir , numSimpleFormats ) ;
110
+
111
+ // Advanced Recording
112
+ await setTemporaryRecordingPath ( true , tmpDir ) ;
113
+ const numAdvancedFormats = await createRecordingFiles ( true ) ;
114
+ await validateRecordingFiles ( t , tmpDir , numSimpleFormats + numAdvancedFormats , true ) ;
115
+
116
+ // Switches between Advanced and Simple Recording
117
+ // Note: The recording path for Simple Recording should have persisted from before
118
+ await sleep ( 2000 ) ;
119
+ await showSettingsWindow ( 'Output' , async ( ) => {
120
+ await setFormDropdown ( 'Output Mode' , 'Simple' ) ;
121
+ await clickButton ( 'Done' ) ;
122
+ } ) ;
123
+
124
+ await focusMain ( ) ;
125
+ await startRecording ( ) ;
126
+ // Record for 2s to prevent the recording from accidentally having the same key
127
+ await sleep ( 2000 ) ;
128
+ await stopRecording ( ) ;
129
+ await clickWhenDisplayed ( 'span=A new Recording has been completed. Click for more info' ) ;
130
+ await validateRecordingFiles ( t , tmpDir , numSimpleFormats + numAdvancedFormats + 1 , true ) ;
131
+
132
+ t . pass ( ) ;
51
133
} ) ;
52
134
53
135
/**
@@ -57,26 +139,11 @@ test('Recording', async t => {
57
139
test ( 'Recording with two contexts active' , async t => {
58
140
await logIn ( t ) ;
59
141
await toggleDualOutputMode ( ) ;
60
- const tmpDir = await setTemporaryRecordingPath ( ) ;
142
+
61
143
// low resolution reduces CPU usage
62
144
await setOutputResolution ( '100x100' ) ;
63
- const formats = [ 'flv' , 'mp4' , 'mov' , 'mkv' , 'ts' , 'm3u8' ] ;
64
- // Record 0.5s video in every format
65
- for ( const format of formats ) {
66
- await showSettingsWindow ( 'Output' , async ( ) => {
67
- const form = new FormMonkey ( t ) ;
68
- await form . setInputValue ( await form . getInputSelectorByTitle ( 'Recording Format' ) , format ) ;
69
- await clickButton ( 'Done' ) ;
70
- } ) ;
71
- await focusMain ( ) ;
72
- await startRecording ( ) ;
73
- await sleep ( 1000 ) ;
74
- await stopRecording ( ) ;
75
- // Wait to ensure that output setting are editable
76
- await sleep ( 1000 ) ;
77
- }
78
- // Check that every file was created
79
- const files = await readdir ( tmpDir ) ;
80
- // M3U8 creates multiple TS files in addition to the catalog itself.
81
- t . true ( files . length >= formats . length , `Files that were created:\n${ files . join ( '\n' ) } ` ) ;
145
+ const tmpDir = await setTemporaryRecordingPath ( true ) ;
146
+
147
+ const numFiles = await createRecordingFiles ( true ) ;
148
+ await validateRecordingFiles ( t , tmpDir , numFiles , true ) ;
82
149
} ) ;
0 commit comments