forked from hardkoded/puppeteer-sharp
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test - Mouse/Keyboard Add WaitForRenderIdle
Need to wait for the browser to finish rendering before executing our mouse/keyboard tests. They will fail otherwise. Resolves #8
- Loading branch information
Showing
3 changed files
with
112 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Timers; | ||
using CefSharp.OffScreen; | ||
|
||
namespace PuppeteerSharp.Tests | ||
{ | ||
public static class WebBrowserExtensions | ||
{ | ||
public static Task WaitForRenderIdle(this ChromiumWebBrowser chromiumWebBrowser, int idleTime = 500) | ||
{ | ||
var renderIdleTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously); | ||
|
||
var idleTimer = new Timer | ||
{ | ||
Interval = idleTime | ||
}; | ||
|
||
EventHandler<OnPaintEventArgs> handler = null; | ||
|
||
idleTimer.Elapsed += (sender, args) => | ||
{ | ||
chromiumWebBrowser.Paint -= handler; | ||
idleTimer.Stop(); | ||
idleTimer.Dispose(); | ||
renderIdleTcs.TrySetResult(true); | ||
}; | ||
|
||
handler = (s, args) => | ||
{ | ||
idleTimer.Stop(); | ||
idleTimer.Start(); | ||
}; | ||
|
||
idleTimer.Start(); | ||
|
||
chromiumWebBrowser.Paint += handler; | ||
|
||
return renderIdleTcs.Task; | ||
} | ||
} | ||
} |