Skip to content

Commit

Permalink
add explicit tests for navigation async methods
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jun 3, 2024
1 parent 2153ba2 commit f50fd80
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion dotnet/test/common/NavigationTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NUnit.Framework;
using System;
using System.Threading.Tasks;

namespace OpenQA.Selenium
{
Expand Down Expand Up @@ -40,7 +41,7 @@ public void ShouldAcceptInvalidUrlsUsingUris()
INavigation navigation;
navigation = driver.Navigate();
Assert.That(() => navigation.GoToUrl((Uri)null), Throws.InstanceOf<ArgumentNullException>());
// new Uri("") and new Uri("isidsji30342??éåµñ©æ")
// new Uri("") and new Uri("isidsji30342??éåµñ©æ")
// throw an exception, so we needn't worry about them.
}

Expand Down Expand Up @@ -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<ArgumentNullException>());
}

[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);
}
}
}

0 comments on commit f50fd80

Please sign in to comment.