@@ -151,6 +151,51 @@ public static void WaitUntilUrlIs(this IWebDriver driver, string targetUrl, int
151151
152152 #endregion
153153
154+ #region URL CONTAINS
155+
156+ /// <summary>
157+ /// Polls the driver URL until it contains the fragment of url or until the timeout expires
158+ /// <exception cref="TimeoutException"></exception>
159+ /// </summary>
160+ /// <param name="driver"></param>
161+ /// <param name="targetUrlPart">The URL fragment to look for</param>
162+ /// <param name="timeout">Throws if the URL has not changed before the specified timeout period is elapsed</param>
163+ /// <param name="pollInterval">The time to wait between two polls</param>
164+ public static void WaitUntilUrlContains ( this IWebDriver driver , string targetUrlPart , TimeSpan timeout , int pollInterval = 500 )
165+ {
166+ var timer = new Stopwatch ( ) ;
167+ timer . Start ( ) ;
168+
169+ while ( true )
170+ {
171+ if ( driver . Url . Contains ( targetUrlPart ) )
172+ return ;
173+
174+ var isTimeout = TimeSpan . Compare ( timer . Elapsed , timeout ) > 0 ;
175+ if ( isTimeout )
176+ throw new TimeoutException ( $ "The URL { driver . Url } has not changed to { targetUrlPart } within the allowed { timeout } milliseconds") ;
177+
178+ Thread . Sleep ( pollInterval ) ;
179+ }
180+ }
181+
182+ /// <summary>
183+ /// Polls the driver URL until it contains the fragment of url or until the timeout expires
184+ /// <exception cref="TimeoutException"></exception>
185+ /// </summary>
186+ /// <param name="driver"></param>
187+ /// <param name="targetUrlPart">The URL fragment to look for</param>
188+ /// <param name="timeout">Throws if the URL has not changed before the specified timeout period is elapsed</param>
189+ /// <param name="pollInterval">The time to wait between two polls</param>
190+ public static void WaitUntilUrlContains ( this IWebDriver driver , string targetUrlPart , int timeout = 10000 , int pollInterval = 500 )
191+ {
192+
193+ var timeoutSpan = new TimeSpan ( 0 , 0 , 0 , 0 , timeout ) ;
194+ WaitUntilUrlContains ( driver , targetUrlPart , timeoutSpan , pollInterval ) ;
195+ }
196+
197+ #endregion
198+
154199 #endregion
155200 }
156201}
0 commit comments