2020using NUnit . Framework ;
2121using OpenQA . Selenium . Environment ;
2222using System ;
23+ using System . Threading . Tasks ;
2324
2425namespace OpenQA . Selenium
2526{
@@ -63,7 +64,7 @@ public void NoneStrategyShouldNotWaitForPageToLoad()
6364
6465
6566 [ Test ]
66- public void NoneStrategyShouldNotWaitForPageToRefresh ( )
67+ public async Task NoneStrategyShouldNotWaitForPageToRefresh ( )
6768 {
6869 InitLocalDriver ( PageLoadStrategy . None ) ;
6970
@@ -73,7 +74,7 @@ public void NoneStrategyShouldNotWaitForPageToRefresh()
7374 WaitFor ( ( ) => localDriver . FindElement ( By . TagName ( "body" ) ) , TimeSpan . FromSeconds ( 10 ) , "did not find body" ) ;
7475
7576 DateTime start = DateTime . Now ;
76- localDriver . Navigate ( ) . Refresh ( ) ;
77+ await localDriver . Navigate ( ) . RefreshAsync ( ) ;
7778 DateTime end = DateTime . Now ;
7879
7980 TimeSpan duration = end - start ;
@@ -103,7 +104,7 @@ public void EagerStrategyShouldNotWaitForResources()
103104 }
104105
105106 [ Test ]
106- public void EagerStrategyShouldNotWaitForResourcesOnRefresh ( )
107+ public async Task EagerStrategyShouldNotWaitForResourcesOnRefresh ( )
107108 {
108109 InitLocalDriver ( PageLoadStrategy . Eager ) ;
109110
@@ -115,7 +116,7 @@ public void EagerStrategyShouldNotWaitForResourcesOnRefresh()
115116 WaitFor ( ( ) => localDriver . FindElement ( By . Id ( "peas" ) ) , TimeSpan . FromSeconds ( 10 ) , "did not find element" ) ;
116117
117118 DateTime start = DateTime . Now ;
118- localDriver . Navigate ( ) . Refresh ( ) ;
119+ await localDriver . Navigate ( ) . RefreshAsync ( ) ;
119120 // We discard the element, but want a check to make sure the GET actually
120121 // completed.
121122 WaitFor ( ( ) => localDriver . FindElement ( By . Id ( "peas" ) ) , TimeSpan . FromSeconds ( 10 ) , "did not find element" ) ;
@@ -211,64 +212,64 @@ public void ShouldBeAbleToLoadAPageWithFramesetsAndWaitUntilAllFramesAreLoaded()
211212
212213 [ Test ]
213214 [ NeedsFreshDriver ( IsCreatedBeforeTest = true ) ]
214- public void ShouldDoNothingIfThereIsNothingToGoBackTo ( )
215+ public async Task ShouldDoNothingIfThereIsNothingToGoBackTo ( )
215216 {
216217 string originalTitle = driver . Title ;
217218 driver . Url = formsPage ;
218219
219- driver . Navigate ( ) . Back ( ) ;
220+ await driver . Navigate ( ) . BackAsync ( ) ;
220221 // We may have returned to the browser's home page
221222 string currentTitle = driver . Title ;
222223 Assert . That ( currentTitle , Is . EqualTo ( originalTitle ) . Or . EqualTo ( "We Leave From Here" ) ) ;
223224 if ( driver . Title == originalTitle )
224225 {
225- driver . Navigate ( ) . Back ( ) ;
226+ await driver . Navigate ( ) . BackAsync ( ) ;
226227 Assert . That ( driver . Title , Is . EqualTo ( originalTitle ) ) ;
227228 }
228229 }
229230
230231 [ Test ]
231- public void ShouldBeAbleToNavigateBackInTheBrowserHistory ( )
232+ public async Task ShouldBeAbleToNavigateBackInTheBrowserHistory ( )
232233 {
233234 driver . Url = formsPage ;
234235
235236 driver . FindElement ( By . Id ( "imageButton" ) ) . Submit ( ) ;
236237 WaitFor ( TitleToBeEqualTo ( "We Arrive Here" ) , "Browser title was not 'We Arrive Here'" ) ;
237238 Assert . That ( driver . Title , Is . EqualTo ( "We Arrive Here" ) ) ;
238239
239- driver . Navigate ( ) . Back ( ) ;
240+ await driver . Navigate ( ) . BackAsync ( ) ;
240241 WaitFor ( TitleToBeEqualTo ( "We Leave From Here" ) , "Browser title was not 'We Leave From Here'" ) ;
241242 Assert . That ( driver . Title , Is . EqualTo ( "We Leave From Here" ) ) ;
242243 }
243244
244245 [ Test ]
245- public void ShouldBeAbleToNavigateBackInTheBrowserHistoryInPresenceOfIframes ( )
246+ public async Task ShouldBeAbleToNavigateBackInTheBrowserHistoryInPresenceOfIframes ( )
246247 {
247248 driver . Url = xhtmlTestPage ;
248249
249250 driver . FindElement ( By . Name ( "sameWindow" ) ) . Click ( ) ;
250251 WaitFor ( TitleToBeEqualTo ( "This page has iframes" ) , "Browser title was not 'This page has iframes'" ) ;
251252 Assert . That ( driver . Title , Is . EqualTo ( "This page has iframes" ) ) ;
252253
253- driver . Navigate ( ) . Back ( ) ;
254+ await driver . Navigate ( ) . BackAsync ( ) ;
254255 WaitFor ( TitleToBeEqualTo ( "XHTML Test Page" ) , "Browser title was not 'XHTML Test Page'" ) ;
255256 Assert . That ( driver . Title , Is . EqualTo ( "XHTML Test Page" ) ) ;
256257 }
257258
258259 [ Test ]
259- public void ShouldBeAbleToNavigateForwardsInTheBrowserHistory ( )
260+ public async Task ShouldBeAbleToNavigateForwardsInTheBrowserHistory ( )
260261 {
261262 driver . Url = formsPage ;
262263
263264 driver . FindElement ( By . Id ( "imageButton" ) ) . Submit ( ) ;
264265 WaitFor ( TitleToBeEqualTo ( "We Arrive Here" ) , "Browser title was not 'We Arrive Here'" ) ;
265266 Assert . That ( driver . Title , Is . EqualTo ( "We Arrive Here" ) ) ;
266267
267- driver . Navigate ( ) . Back ( ) ;
268+ await driver . Navigate ( ) . BackAsync ( ) ;
268269 WaitFor ( TitleToBeEqualTo ( "We Leave From Here" ) , "Browser title was not 'We Leave From Here'" ) ;
269270 Assert . That ( driver . Title , Is . EqualTo ( "We Leave From Here" ) ) ;
270271
271- driver . Navigate ( ) . Forward ( ) ;
272+ await driver . Navigate ( ) . ForwardAsync ( ) ;
272273 WaitFor ( TitleToBeEqualTo ( "We Arrive Here" ) , "Browser title was not 'We Arrive Here'" ) ;
273274 Assert . That ( driver . Title , Is . EqualTo ( "We Arrive Here" ) ) ;
274275 }
@@ -287,11 +288,11 @@ public void ShouldBeAbleToAccessPagesWithAnInsecureSslCertificate()
287288 }
288289
289290 [ Test ]
290- public void ShouldBeAbleToRefreshAPage ( )
291+ public async Task ShouldBeAbleToRefreshAPage ( )
291292 {
292293 driver . Url = xhtmlTestPage ;
293294
294- driver . Navigate ( ) . Refresh ( ) ;
295+ await driver . Navigate ( ) . RefreshAsync ( ) ;
295296
296297 Assert . That ( driver . Title , Is . EqualTo ( "XHTML Test Page" ) ) ;
297298 }
@@ -326,8 +327,8 @@ public void CanHandleSequentialPageLoadTimeouts()
326327 long pageLoadTimeBuffer = 10 ;
327328 string slowLoadingPageUrl = EnvironmentManager . Instance . UrlBuilder . WhereIs ( "sleep?time=" + ( pageLoadTimeout + pageLoadTimeBuffer ) ) ;
328329 driver . Manage ( ) . Timeouts ( ) . PageLoad = TimeSpan . FromSeconds ( 2 ) ;
329- AssertPageLoadTimeoutIsEnforced ( ( ) => driver . Url = slowLoadingPageUrl , pageLoadTimeout , pageLoadTimeBuffer ) ;
330- AssertPageLoadTimeoutIsEnforced ( ( ) => driver . Url = slowLoadingPageUrl , pageLoadTimeout , pageLoadTimeBuffer ) ;
330+ AssertPageLoadTimeoutIsEnforced ( async ( ) => await driver . Navigate ( ) . GoToUrlAsync ( slowLoadingPageUrl ) , pageLoadTimeout , pageLoadTimeBuffer ) ;
331+ AssertPageLoadTimeoutIsEnforced ( async ( ) => await driver . Navigate ( ) . GoToUrlAsync ( slowLoadingPageUrl ) , pageLoadTimeout , pageLoadTimeBuffer ) ;
331332 }
332333
333334 [ Test ]
@@ -359,7 +360,7 @@ public void ShouldTimeoutIfAPageTakesTooLongToLoadAfterClick()
359360
360361 try
361362 {
362- AssertPageLoadTimeoutIsEnforced ( ( ) => link . Click ( ) , 2 , 3 ) ;
363+ AssertPageLoadTimeoutIsEnforced ( async ( ) => link . Click ( ) , 2 , 3 ) ;
363364 }
364365 finally
365366 {
@@ -385,7 +386,7 @@ public void ShouldTimeoutIfAPageTakesTooLongToRefresh()
385386
386387 try
387388 {
388- AssertPageLoadTimeoutIsEnforced ( ( ) => driver . Navigate ( ) . Refresh ( ) , 2 , 4 ) ;
389+ AssertPageLoadTimeoutIsEnforced ( async ( ) => await driver . Navigate ( ) . RefreshAsync ( ) , 2 , 4 ) ;
389390 }
390391 finally
391392 {
@@ -449,12 +450,14 @@ private void TestPageLoadTimeoutIsEnforced(long webDriverPageLoadTimeoutInSecond
449450 long pageLoadTimeBufferInSeconds = 10 ;
450451 string slowLoadingPageUrl = EnvironmentManager . Instance . UrlBuilder . WhereIs ( "sleep?time=" + ( webDriverPageLoadTimeoutInSeconds + pageLoadTimeBufferInSeconds ) ) ;
451452 driver . Manage ( ) . Timeouts ( ) . PageLoad = TimeSpan . FromSeconds ( webDriverPageLoadTimeoutInSeconds ) ;
452- AssertPageLoadTimeoutIsEnforced ( ( ) => driver . Url = slowLoadingPageUrl , webDriverPageLoadTimeoutInSeconds , pageLoadTimeBufferInSeconds ) ;
453+ AssertPageLoadTimeoutIsEnforced ( async ( ) => await driver . Navigate ( ) . GoToUrlAsync ( slowLoadingPageUrl ) , webDriverPageLoadTimeoutInSeconds , pageLoadTimeBufferInSeconds ) ;
453454 }
454455
455- private void AssertPageLoadTimeoutIsEnforced ( TestDelegate delegateToTest , long webDriverPageLoadTimeoutInSeconds , long pageLoadTimeBufferInSeconds )
456+ private void AssertPageLoadTimeoutIsEnforced ( AsyncTestDelegate delegateToTest , long webDriverPageLoadTimeoutInSeconds , long pageLoadTimeBufferInSeconds )
456457 {
457458 DateTime start = DateTime . Now ;
459+
460+ // TODO in NUnit 4, change this to await Assert.ThatAsync
458461 Assert . That ( delegateToTest , Throws . InstanceOf < WebDriverTimeoutException > ( ) , "I should have timed out after " + webDriverPageLoadTimeoutInSeconds + " seconds" ) ;
459462 DateTime end = DateTime . Now ;
460463 TimeSpan duration = end - start ;
0 commit comments