@@ -11,7 +11,7 @@ namespace PuppeteerSharp.Tests.WaitTaskTests
1111 [ Collection ( TestConstants . TestFixtureCollectionName ) ]
1212 public sealed class FrameWaitForFunctionTests : PuppeteerPageBaseTest , IDisposable
1313 {
14- private ConnectionTransportInterceptor _connectionTransportInterceptor ;
14+ private PollerInterceptor _pollerInterceptor ;
1515
1616 public FrameWaitForFunctionTests ( ITestOutputHelper output ) : base ( output )
1717 {
@@ -25,14 +25,14 @@ public FrameWaitForFunctionTests(ITestOutputHelper output) : base(output)
2525 // due to differences between node.js's task scheduler and .net's.
2626 DefaultOptions . TransportFactory = async ( url , options , cancellationToken ) =>
2727 {
28- _connectionTransportInterceptor = new ConnectionTransportInterceptor ( await WebSocketTransport . DefaultTransportFactory ( url , options , cancellationToken ) ) ;
29- return _connectionTransportInterceptor ;
28+ _pollerInterceptor = new PollerInterceptor ( await WebSocketTransport . DefaultTransportFactory ( url , options , cancellationToken ) ) ;
29+ return _pollerInterceptor ;
3030 } ;
3131 }
3232
3333 public void Dispose ( )
3434 {
35- _connectionTransportInterceptor . Dispose ( ) ;
35+ _pollerInterceptor . Dispose ( ) ;
3636 }
3737
3838 [ PuppeteerTest ( "waittask.spec.ts" , "Frame.waitForFunction" , "should work when resolved right before execution context disposal" ) ]
@@ -54,7 +54,7 @@ public async Task ShouldPollOnInterval()
5454 {
5555 var startTime = DateTime . UtcNow ;
5656 var polling = 100 ;
57- var startedPolling = WaitForStartPollingAsync ( ) ;
57+ var startedPolling = _pollerInterceptor . WaitForStartPollingAsync ( ) ;
5858 var watchdog = Page . WaitForFunctionAsync ( "() => window.__FOO === 'hit'" , new WaitForFunctionOptions { PollingInterval = polling } ) ;
5959 await startedPolling ;
6060 await Page . EvaluateFunctionAsync ( "() => setTimeout(window.__FOO = 'hit', 50)" ) ;
@@ -69,7 +69,7 @@ public async Task ShouldPollOnIntervalAsync()
6969 {
7070 var startTime = DateTime . UtcNow ;
7171 var polling = 1000 ;
72- var startedPolling = WaitForStartPollingAsync ( ) ;
72+ var startedPolling = _pollerInterceptor . WaitForStartPollingAsync ( ) ;
7373 var watchdog = Page . WaitForFunctionAsync ( "async () => window.__FOO === 'hit'" , new WaitForFunctionOptions { PollingInterval = polling } ) ;
7474 await startedPolling ;
7575 await Page . EvaluateFunctionAsync ( "async () => setTimeout(window.__FOO = 'hit', 50)" ) ;
@@ -82,7 +82,7 @@ public async Task ShouldPollOnIntervalAsync()
8282 public async Task ShouldPollOnMutation ( )
8383 {
8484 var success = false ;
85- var startedPolling = WaitForStartPollingAsync ( ) ;
85+ var startedPolling = _pollerInterceptor . WaitForStartPollingAsync ( ) ;
8686 var watchdog = Page . WaitForFunctionAsync ( "() => window.__FOO === 'hit'" ,
8787 new WaitForFunctionOptions { Polling = WaitForFunctionPollingOption . Mutation } )
8888 . ContinueWith ( _ => success = true ) ;
@@ -98,7 +98,7 @@ public async Task ShouldPollOnMutation()
9898 public async Task ShouldPollOnMutationAsync ( )
9999 {
100100 var success = false ;
101- var startedPolling = WaitForStartPollingAsync ( ) ;
101+ var startedPolling = _pollerInterceptor . WaitForStartPollingAsync ( ) ;
102102 var watchdog = Page . WaitForFunctionAsync ( "async () => window.__FOO === 'hit'" ,
103103 new WaitForFunctionOptions { Polling = WaitForFunctionPollingOption . Mutation } )
104104 . ContinueWith ( _ => success = true ) ;
@@ -239,22 +239,5 @@ public async Task ShouldSurviveNavigations()
239239 await Page . EvaluateFunctionAsync ( "() => window.__done = true" ) ;
240240 await watchdog ;
241241 }
242-
243- private Task < bool > WaitForStartPollingAsync ( )
244- {
245- TaskCompletionSource < bool > startedPolling = new TaskCompletionSource < bool > ( ) ;
246-
247- // Wait for function will release the execution faster than in node.
248- // We intercept the poller.start() call to prevent tests from continuing before the polling has started.
249- _connectionTransportInterceptor . MessageSent += ( _ , message ) =>
250- {
251- if ( message . Contains ( "poller => poller.start()" ) )
252- {
253- startedPolling . SetResult ( true ) ;
254- }
255- } ;
256-
257- return startedPolling . Task ;
258- }
259242 }
260243}
0 commit comments