Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions dotnet/test/common/CookieImplementationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Collections.ObjectModel;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace OpenQA.Selenium
{
Expand Down Expand Up @@ -478,14 +479,14 @@ public void ShouldRetainCookieExpiry()
[Test]
[Ignore("Unable to open secure url")]
[IgnoreBrowser(Browser.IE, "Browser does not handle untrusted SSL certificates.")]
public void CanHandleSecureCookie()
public async Task CanHandleSecureCookie()
{
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIsSecure("animals");

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

driver.Navigate().Refresh();
await driver.Navigate().RefreshAsync();

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

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

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

driver.Navigate().Refresh();
await driver.Navigate().RefreshAsync();

Cookie retrieved = driver.Manage().Cookies.GetCookieNamed("fish");
Assert.That(retrieved, Is.Not.Null);
Expand Down
2 changes: 1 addition & 1 deletion dotnet/test/common/DevTools/DevToolsProfilerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public async Task SampleProfileEvents()

await domains.Profiler.Start();
startSync.Wait(TimeSpan.FromSeconds(5));
driver.Navigate().Refresh();
await driver.Navigate().RefreshAsync();

ManualResetEventSlim finishSync = new ManualResetEventSlim(false);
EventHandler<CurrentCdpVersion.Profiler.ConsoleProfileFinishedEventArgs> consoleProfileFinishedHandler = (sender, e) =>
Expand Down
20 changes: 10 additions & 10 deletions dotnet/test/common/ExecutingJavascriptTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,35 +521,35 @@ public async Task ShouldBeAbleToAddInitializationScriptAndExecuteOnNewDocument()

await jsEngine.StartEventMonitoring();

driver.Navigate().Refresh();
await driver.Navigate().RefreshAsync();
driver.SwitchTo().Alert().Accept();

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

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

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

await jsEngine.AddInitializationScript(ScriptName, ScriptValue);

driver.Navigate().Refresh();
await driver.Navigate().RefreshAsync();
driver.SwitchTo().Alert().Accept();
Assert.That(jsEngine.InitializationScripts, Does.Contain(initScript));

await jsEngine.ClearInitializationScripts();

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

await jsEngine.AddInitializationScript(ScriptName, ScriptValue);
driver.Navigate().Refresh();
await driver.Navigate().RefreshAsync();
driver.SwitchTo().Alert().Accept();

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

driver.Navigate().Refresh();
await driver.Navigate().RefreshAsync();
driver.SwitchTo().Alert().Accept();

await jsEngine.AddScriptCallbackBinding(ScriptName);

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

Assert.That(executedBindings, Does.Contain(ScriptName));
int oldCount = executedBindings.Count;
driver.Navigate().Refresh();
await driver.Navigate().RefreshAsync();

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

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

void AddToList(object sender, JavaScriptCallbackExecutedEventArgs e) => executedBindings.Add(e.BindingName);
Expand Down
6 changes: 3 additions & 3 deletions dotnet/test/common/NavigationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ public async Task ShouldGoToUrlUsingStringAsync()
}

[Test]
public void ShouldGoToUrlUsingUriAsync()
public async Task ShouldGoToUrlUsingUriAsync()
{
var navigation = driver.Navigate();

navigation.GoToUrlAsync(new Uri(macbethPage));
await navigation.GoToUrlAsync(new Uri(macbethPage));
Assert.That(macbethTitle, Is.EqualTo(driver.Title));
navigation.GoToUrl(new Uri(simpleTestPage));
await navigation.GoToUrlAsync(new Uri(simpleTestPage));
Assert.That(driver.Title, Is.EqualTo(simpleTestTitle));
}

Expand Down
2 changes: 1 addition & 1 deletion dotnet/test/common/NetworkInterceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public async Task TransformNetworkResponse()
networkInterceptor.AddResponseHandler(handler);
await networkInterceptor.StartMonitoring();

driver.Navigate().GoToUrl("https://www.selenium.dev");
await driver.Navigate().GoToUrlAsync("https://www.selenium.dev");
await networkInterceptor.StopMonitoring();

var body = driver.FindElement(By.TagName("body"));
Expand Down
47 changes: 25 additions & 22 deletions dotnet/test/common/PageLoadingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using NUnit.Framework;
using OpenQA.Selenium.Environment;
using System;
using System.Threading.Tasks;

namespace OpenQA.Selenium
{
Expand Down Expand Up @@ -63,7 +64,7 @@ public void NoneStrategyShouldNotWaitForPageToLoad()


[Test]
public void NoneStrategyShouldNotWaitForPageToRefresh()
public async Task NoneStrategyShouldNotWaitForPageToRefresh()
{
InitLocalDriver(PageLoadStrategy.None);

Expand All @@ -73,7 +74,7 @@ public void NoneStrategyShouldNotWaitForPageToRefresh()
WaitFor(() => localDriver.FindElement(By.TagName("body")), TimeSpan.FromSeconds(10), "did not find body");

DateTime start = DateTime.Now;
localDriver.Navigate().Refresh();
await localDriver.Navigate().RefreshAsync();
DateTime end = DateTime.Now;

TimeSpan duration = end - start;
Expand Down Expand Up @@ -103,7 +104,7 @@ public void EagerStrategyShouldNotWaitForResources()
}

[Test]
public void EagerStrategyShouldNotWaitForResourcesOnRefresh()
public async Task EagerStrategyShouldNotWaitForResourcesOnRefresh()
{
InitLocalDriver(PageLoadStrategy.Eager);

Expand All @@ -115,7 +116,7 @@ public void EagerStrategyShouldNotWaitForResourcesOnRefresh()
WaitFor(() => localDriver.FindElement(By.Id("peas")), TimeSpan.FromSeconds(10), "did not find element");

DateTime start = DateTime.Now;
localDriver.Navigate().Refresh();
await localDriver.Navigate().RefreshAsync();
// We discard the element, but want a check to make sure the GET actually
// completed.
WaitFor(() => localDriver.FindElement(By.Id("peas")), TimeSpan.FromSeconds(10), "did not find element");
Expand Down Expand Up @@ -211,64 +212,64 @@ public void ShouldBeAbleToLoadAPageWithFramesetsAndWaitUntilAllFramesAreLoaded()

[Test]
[NeedsFreshDriver(IsCreatedBeforeTest = true)]
public void ShouldDoNothingIfThereIsNothingToGoBackTo()
public async Task ShouldDoNothingIfThereIsNothingToGoBackTo()
{
string originalTitle = driver.Title;
driver.Url = formsPage;

driver.Navigate().Back();
await driver.Navigate().BackAsync();
// We may have returned to the browser's home page
string currentTitle = driver.Title;
Assert.That(currentTitle, Is.EqualTo(originalTitle).Or.EqualTo("We Leave From Here"));
if (driver.Title == originalTitle)
{
driver.Navigate().Back();
await driver.Navigate().BackAsync();
Assert.That(driver.Title, Is.EqualTo(originalTitle));
}
}

[Test]
public void ShouldBeAbleToNavigateBackInTheBrowserHistory()
public async Task ShouldBeAbleToNavigateBackInTheBrowserHistory()
{
driver.Url = formsPage;

driver.FindElement(By.Id("imageButton")).Submit();
WaitFor(TitleToBeEqualTo("We Arrive Here"), "Browser title was not 'We Arrive Here'");
Assert.That(driver.Title, Is.EqualTo("We Arrive Here"));

driver.Navigate().Back();
await driver.Navigate().BackAsync();
WaitFor(TitleToBeEqualTo("We Leave From Here"), "Browser title was not 'We Leave From Here'");
Assert.That(driver.Title, Is.EqualTo("We Leave From Here"));
}

[Test]
public void ShouldBeAbleToNavigateBackInTheBrowserHistoryInPresenceOfIframes()
public async Task ShouldBeAbleToNavigateBackInTheBrowserHistoryInPresenceOfIframes()
{
driver.Url = xhtmlTestPage;

driver.FindElement(By.Name("sameWindow")).Click();
WaitFor(TitleToBeEqualTo("This page has iframes"), "Browser title was not 'This page has iframes'");
Assert.That(driver.Title, Is.EqualTo("This page has iframes"));

driver.Navigate().Back();
await driver.Navigate().BackAsync();
WaitFor(TitleToBeEqualTo("XHTML Test Page"), "Browser title was not 'XHTML Test Page'");
Assert.That(driver.Title, Is.EqualTo("XHTML Test Page"));
}

[Test]
public void ShouldBeAbleToNavigateForwardsInTheBrowserHistory()
public async Task ShouldBeAbleToNavigateForwardsInTheBrowserHistory()
{
driver.Url = formsPage;

driver.FindElement(By.Id("imageButton")).Submit();
WaitFor(TitleToBeEqualTo("We Arrive Here"), "Browser title was not 'We Arrive Here'");
Assert.That(driver.Title, Is.EqualTo("We Arrive Here"));

driver.Navigate().Back();
await driver.Navigate().BackAsync();
WaitFor(TitleToBeEqualTo("We Leave From Here"), "Browser title was not 'We Leave From Here'");
Assert.That(driver.Title, Is.EqualTo("We Leave From Here"));

driver.Navigate().Forward();
await driver.Navigate().ForwardAsync();
WaitFor(TitleToBeEqualTo("We Arrive Here"), "Browser title was not 'We Arrive Here'");
Assert.That(driver.Title, Is.EqualTo("We Arrive Here"));
}
Expand All @@ -287,11 +288,11 @@ public void ShouldBeAbleToAccessPagesWithAnInsecureSslCertificate()
}

[Test]
public void ShouldBeAbleToRefreshAPage()
public async Task ShouldBeAbleToRefreshAPage()
{
driver.Url = xhtmlTestPage;

driver.Navigate().Refresh();
await driver.Navigate().RefreshAsync();

Assert.That(driver.Title, Is.EqualTo("XHTML Test Page"));
}
Expand Down Expand Up @@ -326,8 +327,8 @@ public void CanHandleSequentialPageLoadTimeouts()
long pageLoadTimeBuffer = 10;
string slowLoadingPageUrl = EnvironmentManager.Instance.UrlBuilder.WhereIs("sleep?time=" + (pageLoadTimeout + pageLoadTimeBuffer));
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(2);
AssertPageLoadTimeoutIsEnforced(() => driver.Url = slowLoadingPageUrl, pageLoadTimeout, pageLoadTimeBuffer);
AssertPageLoadTimeoutIsEnforced(() => driver.Url = slowLoadingPageUrl, pageLoadTimeout, pageLoadTimeBuffer);
AssertPageLoadTimeoutIsEnforced(async () => await driver.Navigate().GoToUrlAsync(slowLoadingPageUrl), pageLoadTimeout, pageLoadTimeBuffer);
AssertPageLoadTimeoutIsEnforced(async () => await driver.Navigate().GoToUrlAsync(slowLoadingPageUrl), pageLoadTimeout, pageLoadTimeBuffer);
}

[Test]
Expand Down Expand Up @@ -359,7 +360,7 @@ public void ShouldTimeoutIfAPageTakesTooLongToLoadAfterClick()

try
{
AssertPageLoadTimeoutIsEnforced(() => link.Click(), 2, 3);
AssertPageLoadTimeoutIsEnforced(async () => link.Click(), 2, 3);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will give a warning, but there is no ClickAsync yet. I can add more code to clean it up, but is it worth it?

}
finally
{
Expand All @@ -385,7 +386,7 @@ public void ShouldTimeoutIfAPageTakesTooLongToRefresh()

try
{
AssertPageLoadTimeoutIsEnforced(() => driver.Navigate().Refresh(), 2, 4);
AssertPageLoadTimeoutIsEnforced(async () => await driver.Navigate().RefreshAsync(), 2, 4);
}
finally
{
Expand Down Expand Up @@ -449,12 +450,14 @@ private void TestPageLoadTimeoutIsEnforced(long webDriverPageLoadTimeoutInSecond
long pageLoadTimeBufferInSeconds = 10;
string slowLoadingPageUrl = EnvironmentManager.Instance.UrlBuilder.WhereIs("sleep?time=" + (webDriverPageLoadTimeoutInSeconds + pageLoadTimeBufferInSeconds));
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(webDriverPageLoadTimeoutInSeconds);
AssertPageLoadTimeoutIsEnforced(() => driver.Url = slowLoadingPageUrl, webDriverPageLoadTimeoutInSeconds, pageLoadTimeBufferInSeconds);
AssertPageLoadTimeoutIsEnforced(async () => await driver.Navigate().GoToUrlAsync(slowLoadingPageUrl), webDriverPageLoadTimeoutInSeconds, pageLoadTimeBufferInSeconds);
}

private void AssertPageLoadTimeoutIsEnforced(TestDelegate delegateToTest, long webDriverPageLoadTimeoutInSeconds, long pageLoadTimeBufferInSeconds)
private void AssertPageLoadTimeoutIsEnforced(AsyncTestDelegate delegateToTest, long webDriverPageLoadTimeoutInSeconds, long pageLoadTimeBufferInSeconds)
{
DateTime start = DateTime.Now;

// TODO in NUnit 4, change this to await Assert.ThatAsync
Assert.That(delegateToTest, Throws.InstanceOf<WebDriverTimeoutException>(), "I should have timed out after " + webDriverPageLoadTimeoutInSeconds + " seconds");
DateTime end = DateTime.Now;
TimeSpan duration = end - start;
Expand Down
5 changes: 3 additions & 2 deletions dotnet/test/common/PrintTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using NUnit.Framework;
using System;
using System.Threading.Tasks;

namespace OpenQA.Selenium
{
Expand All @@ -29,13 +30,13 @@ public class PrintTest : DriverTestFixture
private ISupportsPrint printer;

[SetUp]
public void LocalSetUp()
public async Task LocalSetUp()
{
Assert.That(driver, Is.InstanceOf<ISupportsPrint>(), $"Driver does not support {nameof(ISupportsPrint)}.");

printer = driver as ISupportsPrint;

driver.Navigate().GoToUrl(this.printPage);
await driver.Navigate().GoToUrlAsync(this.printPage);
}

[Test]
Expand Down
5 changes: 3 additions & 2 deletions dotnet/test/common/SlowLoadingPageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using NUnit.Framework;
using System;
using System.Threading.Tasks;

namespace OpenQA.Selenium
{
Expand Down Expand Up @@ -51,15 +52,15 @@ public void ShouldBlockUntilIFramesAreLoaded()

[Test]
[NeedsFreshDriver(IsCreatedBeforeTest = true)]
public void RefreshShouldBlockUntilPageLoads()
public async Task RefreshShouldBlockUntilPageLoads()
{
DateTime start = DateTime.Now;
driver.Url = sleepingPage + "?time=" + LoadTimeInSeconds.ToString();
DateTime now = DateTime.Now;
double elapsedTime = now.Subtract(start).TotalSeconds;
Assert.That(elapsedTime, Is.GreaterThanOrEqualTo(LoadTimeInSeconds));
start = DateTime.Now;
driver.Navigate().Refresh();
await driver.Navigate().RefreshAsync();
now = DateTime.Now;
elapsedTime = now.Subtract(start).TotalSeconds;
Assert.That(elapsedTime, Is.GreaterThanOrEqualTo(LoadTimeInSeconds));
Expand Down
Loading