Created
September 17, 2015 04:55
-
-
Save droyad/906f6c4f1c1157548f03 to your computer and use it in GitHub Desktop.
Selenium Wait
This file contains hidden or 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
| public static void WaitForCgBusyCompletion(this BasePage page) | |
| { | |
| HostEx.WaitUntil(() => page.FindElements(By.ClassName("cg-busy"), TimeSpan.FromMilliseconds(100)).None(e => e.Displayed), TimeSpan.FromMinutes(1)); | |
| Thread.Sleep(TimeSpan.FromMilliseconds(100)); | |
| } | |
| public static void WaitUntil<T>(this T page, Func<T, bool> condition, TimeSpan? timeout = null) where T : Page | |
| { | |
| HostEx.WaitUntil(() => condition(page), timeout); | |
| } | |
| public static void WaitUntil(Func<bool> condition, TimeSpan? timeout = null) | |
| { | |
| // Always sleep for a little. | |
| // Also there is a 200ms delay before cg-busy appears | |
| Thread.Sleep(TimeSpan.FromMilliseconds(250)); | |
| var to = timeout ?? TimeSpan.FromSeconds(20); | |
| var sw = new Stopwatch(); | |
| while (!condition()) | |
| { | |
| if (sw.Elapsed > to) | |
| throw new TimeoutException(); | |
| Thread.Sleep(TimeSpan.FromMilliseconds(100)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment