Skip to content

Commit 1f42b94

Browse files
committed
[dotnet] Propagate async from navigation to tests
1 parent 3c87e6b commit 1f42b94

File tree

9 files changed

+62
-55
lines changed

9 files changed

+62
-55
lines changed

dotnet/test/common/CookieImplementationTest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using System.Collections.ObjectModel;
2525
using System.Text;
2626
using System.Text.RegularExpressions;
27+
using System.Threading.Tasks;
2728

2829
namespace OpenQA.Selenium
2930
{
@@ -478,14 +479,14 @@ public void ShouldRetainCookieExpiry()
478479
[Test]
479480
[Ignore("Unable to open secure url")]
480481
[IgnoreBrowser(Browser.IE, "Browser does not handle untrusted SSL certificates.")]
481-
public void CanHandleSecureCookie()
482+
public async Task CanHandleSecureCookie()
482483
{
483484
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIsSecure("animals");
484485

485486
Cookie addedCookie = new ReturnedCookie("fish", "cod", null, "/common/animals", null, true, false, null);
486487
driver.Manage().Cookies.AddCookie(addedCookie);
487488

488-
driver.Navigate().Refresh();
489+
await driver.Navigate().RefreshAsync();
489490

490491
Cookie retrieved = driver.Manage().Cookies.GetCookieNamed("fish");
491492
Assert.That(retrieved, Is.Not.Null);
@@ -494,15 +495,15 @@ public void CanHandleSecureCookie()
494495
[Test]
495496
[Ignore("Unable to open secure url")]
496497
[IgnoreBrowser(Browser.IE, "Browser does not handle untrusted SSL certificates.")]
497-
public void ShouldRetainCookieSecure()
498+
public async Task ShouldRetainCookieSecure()
498499
{
499500
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIsSecure("animals");
500501

501502
ReturnedCookie addedCookie = new ReturnedCookie("fish", "cod", string.Empty, "/common/animals", null, true, false, null);
502503

503504
driver.Manage().Cookies.AddCookie(addedCookie);
504505

505-
driver.Navigate().Refresh();
506+
await driver.Navigate().RefreshAsync();
506507

507508
Cookie retrieved = driver.Manage().Cookies.GetCookieNamed("fish");
508509
Assert.That(retrieved, Is.Not.Null);

dotnet/test/common/DevTools/DevToolsProfilerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public async Task SampleProfileEvents()
109109

110110
await domains.Profiler.Start();
111111
startSync.Wait(TimeSpan.FromSeconds(5));
112-
driver.Navigate().Refresh();
112+
await driver.Navigate().RefreshAsync();
113113

114114
ManualResetEventSlim finishSync = new ManualResetEventSlim(false);
115115
EventHandler<CurrentCdpVersion.Profiler.ConsoleProfileFinishedEventArgs> consoleProfileFinishedHandler = (sender, e) =>

dotnet/test/common/ExecutingJavascriptTest.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,35 +521,35 @@ public async Task ShouldBeAbleToAddInitializationScriptAndExecuteOnNewDocument()
521521

522522
await jsEngine.StartEventMonitoring();
523523

524-
driver.Navigate().Refresh();
524+
await driver.Navigate().RefreshAsync();
525525
driver.SwitchTo().Alert().Accept();
526526

527527
Assert.That(jsEngine.InitializationScripts, Does.Contain(initScript));
528528
await jsEngine.RemoveInitializationScript(ScriptName);
529529

530-
driver.Navigate().Refresh();
530+
await driver.Navigate().RefreshAsync();
531531
Assert.That(() => driver.SwitchTo().Alert().Accept(), Throws.TypeOf<NoAlertPresentException>());
532532

533533
Assert.That(jsEngine.InitializationScripts, Does.Not.Contain(initScript));
534534

535535
await jsEngine.AddInitializationScript(ScriptName, ScriptValue);
536536

537-
driver.Navigate().Refresh();
537+
await driver.Navigate().RefreshAsync();
538538
driver.SwitchTo().Alert().Accept();
539539
Assert.That(jsEngine.InitializationScripts, Does.Contain(initScript));
540540

541541
await jsEngine.ClearInitializationScripts();
542542

543-
driver.Navigate().Refresh();
543+
await driver.Navigate().RefreshAsync();
544544
Assert.That(() => driver.SwitchTo().Alert().Accept(), Throws.TypeOf<NoAlertPresentException>());
545545
Assert.That(jsEngine.InitializationScripts, Is.Empty);
546546

547547
await jsEngine.AddInitializationScript(ScriptName, ScriptValue);
548-
driver.Navigate().Refresh();
548+
await driver.Navigate().RefreshAsync();
549549
driver.SwitchTo().Alert().Accept();
550550

551551
await jsEngine.ClearAll();
552-
driver.Navigate().Refresh();
552+
await driver.Navigate().RefreshAsync();
553553
Assert.That(() => driver.SwitchTo().Alert().Accept(), Throws.TypeOf<NoAlertPresentException>());
554554
Assert.That(jsEngine.InitializationScripts, Is.Empty);
555555
}
@@ -571,17 +571,17 @@ public async Task ShouldBeAbleToAddAndRemoveScriptCallbackBinding()
571571
await jsEngine.AddInitializationScript(ScriptName, ScriptValue);
572572
await jsEngine.StartEventMonitoring();
573573

574-
driver.Navigate().Refresh();
574+
await driver.Navigate().RefreshAsync();
575575
driver.SwitchTo().Alert().Accept();
576576

577577
await jsEngine.AddScriptCallbackBinding(ScriptName);
578578

579-
driver.Navigate().Refresh();
579+
await driver.Navigate().RefreshAsync();
580580
Assert.That(() => driver.SwitchTo().Alert().Accept(), Throws.TypeOf<NoAlertPresentException>());
581581

582582
Assert.That(executedBindings, Does.Contain(ScriptName));
583583
int oldCount = executedBindings.Count;
584-
driver.Navigate().Refresh();
584+
await driver.Navigate().RefreshAsync();
585585

586586
Assert.That(executedBindings, Has.Count.GreaterThan(oldCount));
587587
Assert.That(jsEngine.ScriptCallbackBindings, Does.Contain(ScriptName));
@@ -595,7 +595,7 @@ public async Task ShouldBeAbleToAddAndRemoveScriptCallbackBinding()
595595
Assert.That(jsEngine.ScriptCallbackBindings, Is.Empty);
596596

597597
jsEngine.JavaScriptCallbackExecuted -= AddToList;
598-
driver.Navigate().Refresh();
598+
await driver.Navigate().RefreshAsync();
599599
Assert.That(executedBindings, Has.Count.EqualTo(oldCount));
600600

601601
void AddToList(object sender, JavaScriptCallbackExecutedEventArgs e) => executedBindings.Add(e.BindingName);

dotnet/test/common/NavigationTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ public async Task ShouldGoToUrlUsingStringAsync()
154154
}
155155

156156
[Test]
157-
public void ShouldGoToUrlUsingUriAsync()
157+
public async Task ShouldGoToUrlUsingUriAsync()
158158
{
159159
var navigation = driver.Navigate();
160160

161-
navigation.GoToUrlAsync(new Uri(macbethPage));
161+
await navigation.GoToUrlAsync(new Uri(macbethPage));
162162
Assert.That(macbethTitle, Is.EqualTo(driver.Title));
163-
navigation.GoToUrl(new Uri(simpleTestPage));
163+
await navigation.GoToUrlAsync(new Uri(simpleTestPage));
164164
Assert.That(driver.Title, Is.EqualTo(simpleTestTitle));
165165
}
166166

dotnet/test/common/NetworkInterceptionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public async Task TransformNetworkResponse()
101101
networkInterceptor.AddResponseHandler(handler);
102102
await networkInterceptor.StartMonitoring();
103103

104-
driver.Navigate().GoToUrl("https://www.selenium.dev");
104+
await driver.Navigate().GoToUrlAsync("https://www.selenium.dev");
105105
await networkInterceptor.StopMonitoring();
106106

107107
var body = driver.FindElement(By.TagName("body"));

dotnet/test/common/PageLoadingTest.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using NUnit.Framework;
2121
using OpenQA.Selenium.Environment;
2222
using System;
23+
using System.Threading.Tasks;
2324

2425
namespace 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;

dotnet/test/common/PrintTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
using NUnit.Framework;
2121
using System;
22+
using System.Threading.Tasks;
2223

2324
namespace OpenQA.Selenium
2425
{
@@ -29,13 +30,13 @@ public class PrintTest : DriverTestFixture
2930
private ISupportsPrint printer;
3031

3132
[SetUp]
32-
public void LocalSetUp()
33+
public async Task LocalSetUp()
3334
{
3435
Assert.That(driver, Is.InstanceOf<ISupportsPrint>(), $"Driver does not support {nameof(ISupportsPrint)}.");
3536

3637
printer = driver as ISupportsPrint;
3738

38-
driver.Navigate().GoToUrl(this.printPage);
39+
await driver.Navigate().GoToUrlAsync(this.printPage);
3940
}
4041

4142
[Test]

dotnet/test/common/SlowLoadingPageTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
using NUnit.Framework;
2121
using System;
22+
using System.Threading.Tasks;
2223

2324
namespace OpenQA.Selenium
2425
{
@@ -51,15 +52,15 @@ public void ShouldBlockUntilIFramesAreLoaded()
5152

5253
[Test]
5354
[NeedsFreshDriver(IsCreatedBeforeTest = true)]
54-
public void RefreshShouldBlockUntilPageLoads()
55+
public async Task RefreshShouldBlockUntilPageLoads()
5556
{
5657
DateTime start = DateTime.Now;
5758
driver.Url = sleepingPage + "?time=" + LoadTimeInSeconds.ToString();
5859
DateTime now = DateTime.Now;
5960
double elapsedTime = now.Subtract(start).TotalSeconds;
6061
Assert.That(elapsedTime, Is.GreaterThanOrEqualTo(LoadTimeInSeconds));
6162
start = DateTime.Now;
62-
driver.Navigate().Refresh();
63+
await driver.Navigate().RefreshAsync();
6364
now = DateTime.Now;
6465
elapsedTime = now.Subtract(start).TotalSeconds;
6566
Assert.That(elapsedTime, Is.GreaterThanOrEqualTo(LoadTimeInSeconds));

0 commit comments

Comments
 (0)