Skip to content

Commit

Permalink
Add PageLoadStrategy to IDriverSettings (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
paveliam authored May 8, 2020
1 parent 6acd182 commit f0f09c7
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public override DriverOptions DriverOptions
SetChromePrefs(options);
SetCapabilities(options, (name, value) => options.AddAdditionalCapability(name, value, isGlobalCapability: true));
SetChromeArguments(options);
SetPageLoadStratergy(options);
return options;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,15 @@ protected DriverSettings(ISettingsFile settingsFile)
SettingsFile = settingsFile;
}

private string DriverSettingsPath => $".driverSettings.{BrowserName.ToString().ToLowerInvariant()}";

protected IDictionary<string, object> BrowserCapabilities => SettingsFile.GetValueOrNew<Dictionary<string, object>>($"{DriverSettingsPath}.capabilities");

protected IDictionary<string, object> BrowserOptions => SettingsFile.GetValueOrNew<Dictionary<string, object>>($"{DriverSettingsPath}.options");

protected IReadOnlyList<string> BrowserStartArguments => SettingsFile.GetValueListOrEmpty<string>($"{DriverSettingsPath}.startArguments");

protected ISettingsFile SettingsFile { get; }

protected abstract BrowserName BrowserName { get; }

protected virtual IDictionary<string, Action<DriverOptions, object>> KnownCapabilitySetters => new Dictionary<string, Action<DriverOptions, object>>();
public string WebDriverVersion => SettingsFile.GetValueOrDefault($"{DriverSettingsPath}.webDriverVersion", "Latest");

public abstract string DownloadDirCapabilityKey { get; }
public Architecture SystemArchitecture => SettingsFile.GetValueOrDefault($"{DriverSettingsPath}.systemArchitecture", Architecture.Auto).ToEnum<Architecture>();

public abstract DriverOptions DriverOptions { get; }

public string WebDriverVersion => SettingsFile.GetValueOrDefault($"{DriverSettingsPath}.webDriverVersion", defaultValue: "Latest");

public Architecture SystemArchitecture => SettingsFile.GetValueOrDefault($"{DriverSettingsPath}.systemArchitecture", "Auto").ToEnum<Architecture>();
public PageLoadStrategy PageLoadStrategy => SettingsFile.GetValueOrDefault($"{DriverSettingsPath}.pageLoadStrategy", PageLoadStrategy.Normal).ToEnum<PageLoadStrategy>();

public virtual string DownloadDir
{
Expand All @@ -60,6 +48,25 @@ public virtual string DownloadDir
}
}

public abstract string DownloadDirCapabilityKey { get; }

protected IDictionary<string, object> BrowserCapabilities => SettingsFile.GetValueOrNew<Dictionary<string, object>>($"{DriverSettingsPath}.capabilities");

protected IDictionary<string, object> BrowserOptions => SettingsFile.GetValueOrNew<Dictionary<string, object>>($"{DriverSettingsPath}.options");

protected IReadOnlyList<string> BrowserStartArguments => SettingsFile.GetValueListOrEmpty<string>($"{DriverSettingsPath}.startArguments");

private string DriverSettingsPath => $".driverSettings.{BrowserName.ToString().ToLowerInvariant()}";

protected abstract BrowserName BrowserName { get; }

protected virtual IDictionary<string, Action<DriverOptions, object>> KnownCapabilitySetters => new Dictionary<string, Action<DriverOptions, object>>();

protected void SetPageLoadStratergy(DriverOptions options)
{
options.PageLoadStrategy = PageLoadStrategy;
}

protected void SetCapabilities(DriverOptions options, Action<string, object> addCapabilityMethod = null)
{
foreach (var capability in BrowserCapabilities)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public override DriverOptions DriverOptions
var options = new EdgeOptions();
SetCapabilities(options);
SetOptionsByPropertyNames(options);
SetPageLoadStratergy(options);
return options;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public override DriverOptions DriverOptions
SetCapabilities(options, (name, value) => options.AddAdditionalCapability(name, value, isGlobalCapability: true));
SetFirefoxPrefs(options);
SetFirefoxArguments(options);
SetPageLoadStratergy(options);
return options;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public interface IDriverSettings
/// </summary>
DriverOptions DriverOptions { get; }

/// <summary>
/// WebDriver page load strategy.
/// </summary>
PageLoadStrategy PageLoadStrategy { get; }

/// <summary>
/// Gets download directory for web driver.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public override DriverOptions DriverOptions
var options = new InternetExplorerOptions();
SetCapabilities(options);
SetOptionsByPropertyNames(options);
SetPageLoadStratergy(options);
options.BrowserCommandLineArguments = string.Join(" ", BrowserStartArguments);
return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public override DriverOptions DriverOptions
var options = new SafariOptions();
SetCapabilities(options);
SetOptionsByPropertyNames(options);
SetPageLoadStratergy(options);
return options;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"download.prompt_for_download": "false",
"download.default_directory": "//home//selenium//downloads"
},
"startArguments": []
"startArguments": [],
"pageLoadStrategy": "Normal"
},
"firefox": {
"webDriverVersion": "Latest",
Expand Down

0 comments on commit f0f09c7

Please sign in to comment.