Skip to content

Commit

Permalink
[dotnet] implement appropriate waiting for bidi navigation based on p…
Browse files Browse the repository at this point in the history
…age load strategy
  • Loading branch information
titusfortner committed Jun 7, 2024
1 parent c7a4cdf commit 69c568e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions dotnet/src/webdriver/Navigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ internal class Navigator : INavigation
{
private WebDriver driver;
private string browsingContextId;
private static readonly Dictionary<string, ReadinessState> PageLoadStrategyMapper = new()
{
{"normal", ReadinessState.Complete},
{"eager", ReadinessState.Interactive},
{"none", ReadinessState.None}
};
private ReadinessState readinessState;

/// <summary>
/// Initializes a new instance of the <see cref="Navigator"/> class
Expand All @@ -38,8 +45,9 @@ internal class Navigator : INavigation
public Navigator(WebDriver driver)
{
this.driver = driver;
// TODO: store the value of the current window's context id on the driver object
this.browsingContextId = driver.CurrentWindowHandle;
string strategyCap = driver.Capabilities.GetCapability("pageLoadStrategy") as string;
this.readinessState = strategyCap == null ? ReadinessState.Complete : PageLoadStrategyMapper[strategyCap];
}

/// <summary>
Expand Down Expand Up @@ -128,7 +136,11 @@ public async Task GoToUrlAsync(string url)

if (this.driver.BiDiDriver != null)
{
await driver.BiDiDriver.BrowsingContext.NavigateAsync(new NavigateCommandParameters(this.browsingContextId, url)).ConfigureAwait(false);
NavigateCommandParameters navigateCommandParameters = new NavigateCommandParameters(this.browsingContextId, url)
{
Wait = this.readinessState
};
await driver.BiDiDriver.BrowsingContext.NavigateAsync(navigateCommandParameters).ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -187,7 +199,10 @@ public async Task RefreshAsync()
if (this.driver.BiDiDriver != null)
{
var reloadCommandParameters =
new ReloadCommandParameters(this.browsingContextId);
new ReloadCommandParameters(this.browsingContextId)
{
Wait = this.readinessState
};
await this.driver.BiDiDriver.BrowsingContext.ReloadAsync(reloadCommandParameters).ConfigureAwait(false);
}
else
Expand Down

0 comments on commit 69c568e

Please sign in to comment.