diff --git a/dotnet/test/common/NavigationTest.cs b/dotnet/test/common/NavigationTest.cs index ee40894aa047c..e1b514bf04cb9 100644 --- a/dotnet/test/common/NavigationTest.cs +++ b/dotnet/test/common/NavigationTest.cs @@ -1,5 +1,6 @@ using NUnit.Framework; using System; +using System.Threading.Tasks; namespace OpenQA.Selenium { @@ -40,7 +41,7 @@ public void ShouldAcceptInvalidUrlsUsingUris() INavigation navigation; navigation = driver.Navigate(); Assert.That(() => navigation.GoToUrl((Uri)null), Throws.InstanceOf()); - // new Uri("") and new Uri("isidsji30342??éåµñ©æ") + // new Uri("") and new Uri("isidsji30342??éåµñ©æ") // throw an exception, so we needn't worry about them. } @@ -90,5 +91,73 @@ public void ShouldRefreshPage() Assert.AreEqual("What's for dinner?", changedDiv.Text); } + [Test] + [NeedsFreshDriver(IsCreatedBeforeTest = true)] + public Task ShouldNotHaveProblemNavigatingWithNoPagesBrowsedAsync() + { + var navigation = driver.Navigate(); + Assert.DoesNotThrowAsync(async () => await navigation.BackAsync()); + Assert.DoesNotThrowAsync(async () => await navigation.ForwardAsync()); + return Task.CompletedTask; + } + + [Test] + public async Task ShouldGoBackAndForwardAsync() + { + INavigation navigation = driver.Navigate(); + + await navigation.GoToUrlAsync(macbethPage); + await navigation.GoToUrlAsync(simpleTestPage); + + await navigation.BackAsync(); + Assert.AreEqual(macbethTitle, driver.Title); + + await navigation.ForwardAsync(); + Assert.AreEqual(simpleTestTitle, driver.Title); + } + + [Test] + public void ShouldAcceptInvalidUrlsUsingUrisAsync() + { + INavigation navigation = driver.Navigate(); + Assert.That(async () => await navigation.GoToUrlAsync((Uri)null), Throws.InstanceOf()); + } + + [Test] + public async Task ShouldGoToUrlUsingStringAsync() + { + var navigation = driver.Navigate(); + + await navigation.GoToUrlAsync(macbethPage); + Assert.AreEqual(macbethTitle, driver.Title); + + await navigation.GoToUrlAsync(simpleTestPage); + Assert.AreEqual(simpleTestTitle, driver.Title); + } + + [Test] + public void ShouldGoToUrlUsingUriAsync() + { + var navigation = driver.Navigate(); + + navigation.GoToUrlAsync(new Uri(macbethPage)); + Assert.AreEqual(driver.Title, macbethTitle); + navigation.GoToUrl(new Uri(simpleTestPage)); + Assert.AreEqual(simpleTestTitle, driver.Title); + } + + [Test] + public async Task ShouldRefreshPageAsync() + { + await driver.Navigate().GoToUrlAsync(javascriptPage); + IWebElement changedDiv = driver.FindElement(By.Id("dynamo")); + driver.FindElement(By.Id("updatediv")).Click(); + + Assert.AreEqual("Fish and chips!", changedDiv.Text); + await driver.Navigate().RefreshAsync(); + + changedDiv = driver.FindElement(By.Id("dynamo")); + Assert.AreEqual("What's for dinner?", changedDiv.Text); + } } }