@@ -127,48 +127,6 @@ public async Task ShouldExposeVideoPathBlankPage()
127127 Assert . True ( new FileInfo ( path ) . Exists ) ;
128128 }
129129
130- [ PlaywrightTest ( "screencast.spec.ts" , "should expose video path blank popup" ) ]
131- [ Ignore ( "We don't need to test video details" ) ]
132- public void ShouldExposeVideoPathBlankPopup ( )
133- {
134- }
135-
136- [ PlaywrightTest ( "screencast.spec.ts" , "should capture navigation" ) ]
137- [ Ignore ( "We don't need to test video details" ) ]
138- public void ShouldCaptureNavigation ( )
139- {
140- }
141-
142- [ PlaywrightTest ( "screencast.spec.ts" , "should capture css transformation" ) ]
143- [ Ignore ( "We don't need to test video details" ) ]
144- public void ShouldCaptureCssTransformation ( )
145- {
146- }
147-
148- [ PlaywrightTest ( "screencast.spec.ts" , "should work for popups" ) ]
149- [ Ignore ( "We don't need to test video details" ) ]
150- public void ShouldWorkForPopups ( )
151- {
152- }
153-
154- [ PlaywrightTest ( "screencast.spec.ts" , "should scale frames down to the requested size" ) ]
155- [ Ignore ( "We don't need to test video details" ) ]
156- public void ShouldScaleFramesDownToTheRequestedSize ( )
157- {
158- }
159-
160- [ PlaywrightTest ( "screencast.spec.ts" , "should use viewport as default size" ) ]
161- [ Ignore ( "We don't need to test video details" ) ]
162- public void ShouldUseViewportAsDefaultSize ( )
163- {
164- }
165-
166- [ PlaywrightTest ( "screencast.spec.ts" , "should be 1280x720 by default" ) ]
167- [ Ignore ( "We don't need to test video details" ) ]
168- public void ShouldBe1280x720ByDefault ( )
169- {
170- }
171-
172130 [ PlaywrightTest ( "screencast.spec.ts" , "should capture static page in persistent context" ) ]
173131 [ Skip ( SkipAttribute . Targets . Webkit , SkipAttribute . Targets . Firefox ) ]
174132 public async Task ShouldCaptureStaticPageInPersistentContext ( )
@@ -259,4 +217,68 @@ public async Task SaveAsShouldThrowWhenNoVideoFrames()
259217 StringAssert . Contains ( "Page did not produce any video frames" , exception . Message ) ;
260218 await context . CloseAsync ( ) ;
261219 }
220+
221+ [ PlaywrightTest ( "screencast.spec.ts" , "start throws if screencast is already started" ) ]
222+ public async Task StartThrowsIfScreencastIsAlreadyStarted ( )
223+ {
224+ var context = await Browser . NewContextAsync ( new ( ) { ViewportSize = new ( ) { Width = 500 , Height = 400 } } ) ;
225+ var page = await context . NewPageAsync ( ) ;
226+
227+ await page . Screencast . StartAsync ( new ( ) { OnFrame = _ => Task . CompletedTask } ) ;
228+ var exception = await PlaywrightAssert . ThrowsAsync < PlaywrightException > ( ( ) =>
229+ page . Screencast . StartAsync ( new ( ) { OnFrame = _ => Task . CompletedTask } ) ) ;
230+ StringAssert . Contains ( "Screencast is already started" , exception . Message ) ;
231+
232+ await page . Screencast . StopAsync ( ) ;
233+ await context . CloseAsync ( ) ;
234+ }
235+
236+ [ PlaywrightTest ( "screencast.spec.ts" , "start should record video to file" ) ]
237+ public async Task StartShouldRecordVideoToFile ( )
238+ {
239+ using var tempDirectory = new TempDirectory ( ) ;
240+ var context = await Browser . NewContextAsync ( new ( )
241+ {
242+ ViewportSize = new ( ) { Width = 500 , Height = 400 }
243+ } ) ;
244+ var page = await context . NewPageAsync ( ) ;
245+
246+ var videoPath = Path . Combine ( tempDirectory . Path , "video.webm" ) ;
247+ await page . Screencast . StartAsync ( new ( ) { Path = videoPath } ) ;
248+ await page . EvaluateAsync ( "() => document.body.style.backgroundColor = 'red'" ) ;
249+ await Task . Delay ( 1000 ) ;
250+ await page . Screencast . StopAsync ( ) ;
251+
252+ Assert . True ( File . Exists ( videoPath ) ) ;
253+ Assert . Greater ( new FileInfo ( videoPath ) . Length , 0 ) ;
254+ await context . CloseAsync ( ) ;
255+ }
256+
257+ [ PlaywrightTest ( "screencast.spec.ts" , "start delivers frames via onFrame callback" ) ]
258+ public async Task StartDeliversFramesViaOnFrameCallback ( )
259+ {
260+ var context = await Browser . NewContextAsync ( new ( ) { ViewportSize = new ( ) { Width = 500 , Height = 400 } } ) ;
261+ var page = await context . NewPageAsync ( ) ;
262+
263+ var frames = new List < byte [ ] > ( ) ;
264+ await page . Screencast . StartAsync ( new ( )
265+ {
266+ OnFrame = async frame =>
267+ {
268+ frames . Add ( frame . Data ) ;
269+ }
270+ } ) ;
271+ await page . EvaluateAsync ( "() => document.body.style.backgroundColor = 'red'" ) ;
272+ await Task . Delay ( 1000 ) ;
273+ await page . Screencast . StopAsync ( ) ;
274+
275+ Assert . Greater ( frames . Count , 0 ) ;
276+ // Each frame must be a valid JPEG (starts with FF D8).
277+ foreach ( var frame in frames )
278+ {
279+ Assert . AreEqual ( 0xFF , frame [ 0 ] ) ;
280+ Assert . AreEqual ( 0xD8 , frame [ 1 ] ) ;
281+ }
282+ await context . CloseAsync ( ) ;
283+ }
262284}
0 commit comments