Skip to content

Commit

Permalink
Fix sonar issues (#140) +semver: minor
Browse files Browse the repository at this point in the history
* #127 Browse: replace timeout properties setters with methods

* #139 Move docs to wiki

* #127 Fix properties that throw exceptions
  • Loading branch information
paveliam authored Aug 30, 2019
1 parent f7814ad commit b686152
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 646 deletions.
38 changes: 16 additions & 22 deletions Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public Browser(RemoteWebDriver webDriver, IConfiguration configuration)
this.configuration = configuration;
Driver = webDriver;
BrowserName = configuration.BrowserProfile.BrowserName;
ImplicitWaitTimeout = configuration.TimeoutConfiguration.Implicit;
PageLoadTimeout = configuration.TimeoutConfiguration.PageLoad;
ScriptTimeout = configuration.TimeoutConfiguration.Script;
SetImplicitWaitTimeout(configuration.TimeoutConfiguration.Implicit);
SetPageLoadTimeout(configuration.TimeoutConfiguration.PageLoad);
SetScriptTimeout(configuration.TimeoutConfiguration.Script);
}

private Logger Logger => Logger.Instance;
Expand All @@ -53,15 +53,13 @@ public Browser(RemoteWebDriver webDriver, IConfiguration configuration)
/// Sets Selenium WebDriver ImplicitWait timeout.
/// Default value: <see cref="ITimeoutConfiguration.Implicit"/>.
/// </summary>
public TimeSpan ImplicitWaitTimeout
/// <param name="timeout">Desired Implicit wait timeout.</param>
public void SetImplicitWaitTimeout(TimeSpan timeout)
{
set
if (!timeout.Equals(implicitWaitTimeout))
{
if (!value.Equals(implicitWaitTimeout))
{
Driver.Manage().Timeouts().ImplicitWait = value;
implicitWaitTimeout = value;
}
Driver.Manage().Timeouts().ImplicitWait = timeout;
implicitWaitTimeout = timeout;
}
}

Expand All @@ -70,28 +68,24 @@ public TimeSpan ImplicitWaitTimeout
/// Default value: <see cref="ITimeoutConfiguration.PageLoad"/>.
/// Ignored for Safari cause of https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/687.
/// </summary>
public TimeSpan PageLoadTimeout
/// <param name="timeout">Desired page load timeout.</param>
public void SetPageLoadTimeout(TimeSpan timeout)
{
set
if (!configuration.BrowserProfile.BrowserName.Equals(BrowserName.Safari))
{
if (!configuration.BrowserProfile.BrowserName.Equals(BrowserName.Safari))
{
Driver.Manage().Timeouts().PageLoad = value;
pageLoadTimeout = value;
}
Driver.Manage().Timeouts().PageLoad = timeout;
pageLoadTimeout = timeout;
}
}

/// <summary>
/// Sets Selenium WebDriver AsynchronousJavaScript timeout.
/// Default value: <see cref="ITimeoutConfiguration.Script"/>.
/// </summary>
public TimeSpan ScriptTimeout
/// <param name="timeout">Desired AsynchronousJavaScript timeout.</param>
public void SetScriptTimeout(TimeSpan timeout)
{
set
{
Driver.Manage().Timeouts().AsynchronousJavaScript = value;
}
Driver.Manage().Timeouts().AsynchronousJavaScript = timeout;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public BrowserProfile(JsonFile settingsFile)
this.settingsFile = settingsFile;
}

public BrowserName BrowserName => (BrowserName) Enum.Parse(typeof(BrowserName), settingsFile.GetValue<string>(".browserName"), ignoreCase: true);
public BrowserName BrowserName => (BrowserName)Enum.Parse(typeof(BrowserName), settingsFile.GetValue<string>(".browserName"), ignoreCase: true);

public bool IsElementHighlightEnabled => settingsFile.GetValue<bool>(".isElementHighlightEnabled");

Expand All @@ -46,7 +46,7 @@ public IDriverSettings DriverSettings
case BrowserName.Safari:
return new SafariSettings(settingsFile);
default:
throw new ArgumentOutOfRangeException($"There is no assigned behaviour for retrieving driver driversettings for browser {BrowserName}");
throw new InvalidOperationException($"There is no assigned behaviour for retrieving DriverSettings for browser {BrowserName}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,27 @@ public interface IBrowserProfile
/// <summary>
/// Gets name of target browser.
/// </summary>
/// <value>Name of browser.</value>
BrowserName BrowserName { get; }

/// <summary>
/// Is remote browser or not.
/// Is remote browser or not: true if remote browser and false if local.
/// </summary>
/// <value>True if remote browser and false if local.</value>
bool IsRemote { get; }

/// <summary>
/// Gets remote connection URI is case of remote browser.
/// </summary>
/// <value>URI for remote connection.</value>
Uri RemoteConnectionUrl { get; }

/// <summary>
/// Is element hightlight enabled or not.
/// Is element hightlight enabled or not: true if element highlight is enabled and false otherwise
/// </summary>
/// <value>True if element highlight is enabled and false otherwise.</value>
bool IsElementHighlightEnabled { get; }

/// <summary>
/// Gets driver settings for target browser.
/// </summary>
/// <value>Instance of driver settings.</value>
/// <exception cref="InvalidOperationException">Thrown when there is no assigned behaviour for retrieving DriverSettings for target browser.</exception>
IDriverSettings DriverSettings { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class DriverSettings : IDriverSettings
/// Instantiates class using JSON file with general settings.
/// </summary>
/// <param name="settingsFile">JSON settings file.</param>
public DriverSettings(JsonFile settingsFile)
protected DriverSettings(JsonFile settingsFile)
{
SettingsFile = settingsFile;
}
Expand Down Expand Up @@ -55,7 +55,7 @@ public virtual string DownloadDir
return pathInConfiguration.Contains(".") ? Path.GetFullPath(pathInConfiguration) : pathInConfiguration;
}

throw new InvalidDataException($"failed to find {DownloadDirCapabilityKey} option in settings profile for {BrowserName}");
throw new InvalidOperationException($"Failed to find {DownloadDirCapabilityKey} option in settings profile for {BrowserName}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,27 @@ public interface IDriverSettings
/// <summary>
/// Gets version of web driver for WebDriverManager.
/// </summary>
/// <value>Target version of web driver.</value>
string WebDriverVersion { get; }

/// <summary>
/// Gets system architecture for WebDriverManager.
/// Gets target system architecture for WebDriverManager.
/// </summary>
/// <value>Target system architecture.</value>
Architecture SystemArchitecture { get; }

/// <summary>
/// Gets desired options for web driver.
/// </summary>
/// <value>Options for web driver.</value>
DriverOptions DriverOptions { get; }

/// <summary>
/// Gets download directory for web driver.
/// </summary>
/// <value>Download directory.</value>
/// <exception cref="System.InvalidOperationException">Thrown when browser settings do not contain capability key.</exception>
string DownloadDir { get; }

/// <summary>
/// Gets web driver capability key for download directory.
/// </summary>
/// <value>Capability key.</value>
string DownloadDirCapabilityKey { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class ConditionalWait
/// <exception cref="WebDriverTimeoutException">Throws when timeout exceeded and condition not satisfied.</exception>
public static T WaitFor<T>(Func<IWebDriver, T> condition, TimeSpan? timeout = null, TimeSpan? pollingInterval = null, string message = null, IList<Type> exceptionsToIgnore = null)
{
BrowserManager.Browser.ImplicitWaitTimeout = TimeSpan.Zero;
BrowserManager.Browser.SetImplicitWaitTimeout(TimeSpan.Zero);
var waitTimeout = ResolveConditionTimeout(timeout);
var checkInterval = ResolvePollingInterval(pollingInterval);
var wait = new WebDriverWait(BrowserManager.Browser.Driver, waitTimeout)
Expand All @@ -41,7 +41,7 @@ public static T WaitFor<T>(Func<IWebDriver, T> condition, TimeSpan? timeout = nu
var ignoreExceptions = exceptionsToIgnore ?? new List<Type> { typeof(StaleElementReferenceException) };
wait.IgnoreExceptionTypes(ignoreExceptions.ToArray());
var result = wait.Until(condition);
BrowserManager.Browser.ImplicitWaitTimeout = Configuration.TimeoutConfiguration.Implicit;
BrowserManager.Browser.SetImplicitWaitTimeout(Configuration.TimeoutConfiguration.Implicit);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void Should_BePossibleTo_RefreshPage()
public void Should_BePossibleTo_SetPageLoadTimeout()
{
var browser = BrowserManager.Browser;
browser.PageLoadTimeout = TimeSpan.FromSeconds(1);
browser.SetPageLoadTimeout(TimeSpan.FromSeconds(1));
Assert.Throws<WebDriverTimeoutException>(() => browser.GoTo("https://github.com/aquality-automation"));
}

Expand Down Expand Up @@ -227,7 +227,7 @@ public void Should_BePossibleTo_SetImplicitWait()
var browser = BrowserManager.Browser;
browser.GoTo(new WelcomeForm().Url);
var waitTime = TimeSpan.FromSeconds(5);
browser.ImplicitWaitTimeout = waitTime;
browser.SetImplicitWaitTimeout(waitTime);

var stopwatch = Stopwatch.StartNew();
var elapsedTime = TimeSpan.Zero;
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ browser.Quit();
```

### Documentation
To get more details please look at documentation:
- [In English](./docs/General.en.md)
- [In Russian](./docs/General.ru.md)
To get more details please look at wiki:
- [In English](https://github.com/aquality-automation/aquality-selenium-dotnet/wiki/Overview-(English))
- [In Russian](https://github.com/aquality-automation/aquality-selenium-dotnet/wiki/Overview-(Russian))

### License
Library's source code is made available under the [Apache 2.0 license](https://github.com/aquality-automation/aquality-selenium-dotnet/blob/master/LICENSE).
Loading

0 comments on commit b686152

Please sign in to comment.