Skip to content

Commit b686152

Browse files
authored
Fix sonar issues (#140) +semver: minor
* #127 Browse: replace timeout properties setters with methods * #139 Move docs to wiki * #127 Fix properties that throw exceptions
1 parent f7814ad commit b686152

File tree

11 files changed

+32
-646
lines changed

11 files changed

+32
-646
lines changed

Aquality.Selenium/src/Aquality.Selenium/Browsers/Browser.cs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public Browser(RemoteWebDriver webDriver, IConfiguration configuration)
3030
this.configuration = configuration;
3131
Driver = webDriver;
3232
BrowserName = configuration.BrowserProfile.BrowserName;
33-
ImplicitWaitTimeout = configuration.TimeoutConfiguration.Implicit;
34-
PageLoadTimeout = configuration.TimeoutConfiguration.PageLoad;
35-
ScriptTimeout = configuration.TimeoutConfiguration.Script;
33+
SetImplicitWaitTimeout(configuration.TimeoutConfiguration.Implicit);
34+
SetPageLoadTimeout(configuration.TimeoutConfiguration.PageLoad);
35+
SetScriptTimeout(configuration.TimeoutConfiguration.Script);
3636
}
3737

3838
private Logger Logger => Logger.Instance;
@@ -53,15 +53,13 @@ public Browser(RemoteWebDriver webDriver, IConfiguration configuration)
5353
/// Sets Selenium WebDriver ImplicitWait timeout.
5454
/// Default value: <see cref="ITimeoutConfiguration.Implicit"/>.
5555
/// </summary>
56-
public TimeSpan ImplicitWaitTimeout
56+
/// <param name="timeout">Desired Implicit wait timeout.</param>
57+
public void SetImplicitWaitTimeout(TimeSpan timeout)
5758
{
58-
set
59+
if (!timeout.Equals(implicitWaitTimeout))
5960
{
60-
if (!value.Equals(implicitWaitTimeout))
61-
{
62-
Driver.Manage().Timeouts().ImplicitWait = value;
63-
implicitWaitTimeout = value;
64-
}
61+
Driver.Manage().Timeouts().ImplicitWait = timeout;
62+
implicitWaitTimeout = timeout;
6563
}
6664
}
6765

@@ -70,28 +68,24 @@ public TimeSpan ImplicitWaitTimeout
7068
/// Default value: <see cref="ITimeoutConfiguration.PageLoad"/>.
7169
/// Ignored for Safari cause of https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/687.
7270
/// </summary>
73-
public TimeSpan PageLoadTimeout
71+
/// <param name="timeout">Desired page load timeout.</param>
72+
public void SetPageLoadTimeout(TimeSpan timeout)
7473
{
75-
set
74+
if (!configuration.BrowserProfile.BrowserName.Equals(BrowserName.Safari))
7675
{
77-
if (!configuration.BrowserProfile.BrowserName.Equals(BrowserName.Safari))
78-
{
79-
Driver.Manage().Timeouts().PageLoad = value;
80-
pageLoadTimeout = value;
81-
}
76+
Driver.Manage().Timeouts().PageLoad = timeout;
77+
pageLoadTimeout = timeout;
8278
}
8379
}
8480

8581
/// <summary>
8682
/// Sets Selenium WebDriver AsynchronousJavaScript timeout.
8783
/// Default value: <see cref="ITimeoutConfiguration.Script"/>.
8884
/// </summary>
89-
public TimeSpan ScriptTimeout
85+
/// <param name="timeout">Desired AsynchronousJavaScript timeout.</param>
86+
public void SetScriptTimeout(TimeSpan timeout)
9087
{
91-
set
92-
{
93-
Driver.Manage().Timeouts().AsynchronousJavaScript = value;
94-
}
88+
Driver.Manage().Timeouts().AsynchronousJavaScript = timeout;
9589
}
9690

9791
/// <summary>

Aquality.Selenium/src/Aquality.Selenium/Configurations/BrowserProfile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public BrowserProfile(JsonFile settingsFile)
2121
this.settingsFile = settingsFile;
2222
}
2323

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

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

@@ -46,7 +46,7 @@ public IDriverSettings DriverSettings
4646
case BrowserName.Safari:
4747
return new SafariSettings(settingsFile);
4848
default:
49-
throw new ArgumentOutOfRangeException($"There is no assigned behaviour for retrieving driver driversettings for browser {BrowserName}");
49+
throw new InvalidOperationException($"There is no assigned behaviour for retrieving DriverSettings for browser {BrowserName}");
5050
}
5151
}
5252
}

Aquality.Selenium/src/Aquality.Selenium/Configurations/IBrowserProfile.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,27 @@ public interface IBrowserProfile
1212
/// <summary>
1313
/// Gets name of target browser.
1414
/// </summary>
15-
/// <value>Name of browser.</value>
1615
BrowserName BrowserName { get; }
1716

1817
/// <summary>
19-
/// Is remote browser or not.
18+
/// Is remote browser or not: true if remote browser and false if local.
2019
/// </summary>
21-
/// <value>True if remote browser and false if local.</value>
2220
bool IsRemote { get; }
2321

2422
/// <summary>
2523
/// Gets remote connection URI is case of remote browser.
2624
/// </summary>
27-
/// <value>URI for remote connection.</value>
2825
Uri RemoteConnectionUrl { get; }
2926

3027
/// <summary>
31-
/// Is element hightlight enabled or not.
28+
/// Is element hightlight enabled or not: true if element highlight is enabled and false otherwise
3229
/// </summary>
33-
/// <value>True if element highlight is enabled and false otherwise.</value>
3430
bool IsElementHighlightEnabled { get; }
3531

3632
/// <summary>
3733
/// Gets driver settings for target browser.
3834
/// </summary>
39-
/// <value>Instance of driver settings.</value>
35+
/// <exception cref="InvalidOperationException">Thrown when there is no assigned behaviour for retrieving DriverSettings for target browser.</exception>
4036
IDriverSettings DriverSettings { get; }
4137
}
4238
}

Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/DriverSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public abstract class DriverSettings : IDriverSettings
1818
/// Instantiates class using JSON file with general settings.
1919
/// </summary>
2020
/// <param name="settingsFile">JSON settings file.</param>
21-
public DriverSettings(JsonFile settingsFile)
21+
protected DriverSettings(JsonFile settingsFile)
2222
{
2323
SettingsFile = settingsFile;
2424
}
@@ -55,7 +55,7 @@ public virtual string DownloadDir
5555
return pathInConfiguration.Contains(".") ? Path.GetFullPath(pathInConfiguration) : pathInConfiguration;
5656
}
5757

58-
throw new InvalidDataException($"failed to find {DownloadDirCapabilityKey} option in settings profile for {BrowserName}");
58+
throw new InvalidOperationException($"Failed to find {DownloadDirCapabilityKey} option in settings profile for {BrowserName}");
5959
}
6060
}
6161

Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/IDriverSettings.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,27 @@ public interface IDriverSettings
1111
/// <summary>
1212
/// Gets version of web driver for WebDriverManager.
1313
/// </summary>
14-
/// <value>Target version of web driver.</value>
1514
string WebDriverVersion { get; }
1615

1716
/// <summary>
18-
/// Gets system architecture for WebDriverManager.
17+
/// Gets target system architecture for WebDriverManager.
1918
/// </summary>
20-
/// <value>Target system architecture.</value>
2119
Architecture SystemArchitecture { get; }
2220

2321
/// <summary>
2422
/// Gets desired options for web driver.
2523
/// </summary>
26-
/// <value>Options for web driver.</value>
2724
DriverOptions DriverOptions { get; }
2825

2926
/// <summary>
3027
/// Gets download directory for web driver.
3128
/// </summary>
32-
/// <value>Download directory.</value>
29+
/// <exception cref="System.InvalidOperationException">Thrown when browser settings do not contain capability key.</exception>
3330
string DownloadDir { get; }
3431

3532
/// <summary>
3633
/// Gets web driver capability key for download directory.
3734
/// </summary>
38-
/// <value>Capability key.</value>
3935
string DownloadDirCapabilityKey { get; }
4036
}
4137
}

Aquality.Selenium/src/Aquality.Selenium/Waitings/ConditionalWait.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class ConditionalWait
3030
/// <exception cref="WebDriverTimeoutException">Throws when timeout exceeded and condition not satisfied.</exception>
3131
public static T WaitFor<T>(Func<IWebDriver, T> condition, TimeSpan? timeout = null, TimeSpan? pollingInterval = null, string message = null, IList<Type> exceptionsToIgnore = null)
3232
{
33-
BrowserManager.Browser.ImplicitWaitTimeout = TimeSpan.Zero;
33+
BrowserManager.Browser.SetImplicitWaitTimeout(TimeSpan.Zero);
3434
var waitTimeout = ResolveConditionTimeout(timeout);
3535
var checkInterval = ResolvePollingInterval(pollingInterval);
3636
var wait = new WebDriverWait(BrowserManager.Browser.Driver, waitTimeout)
@@ -41,7 +41,7 @@ public static T WaitFor<T>(Func<IWebDriver, T> condition, TimeSpan? timeout = nu
4141
var ignoreExceptions = exceptionsToIgnore ?? new List<Type> { typeof(StaleElementReferenceException) };
4242
wait.IgnoreExceptionTypes(ignoreExceptions.ToArray());
4343
var result = wait.Until(condition);
44-
BrowserManager.Browser.ImplicitWaitTimeout = Configuration.TimeoutConfiguration.Implicit;
44+
BrowserManager.Browser.SetImplicitWaitTimeout(Configuration.TimeoutConfiguration.Implicit);
4545
return result;
4646
}
4747

Aquality.Selenium/tests/Aquality.Selenium.Tests/Integration/BrowserTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void Should_BePossibleTo_RefreshPage()
8383
public void Should_BePossibleTo_SetPageLoadTimeout()
8484
{
8585
var browser = BrowserManager.Browser;
86-
browser.PageLoadTimeout = TimeSpan.FromSeconds(1);
86+
browser.SetPageLoadTimeout(TimeSpan.FromSeconds(1));
8787
Assert.Throws<WebDriverTimeoutException>(() => browser.GoTo("https://github.com/aquality-automation"));
8888
}
8989

@@ -227,7 +227,7 @@ public void Should_BePossibleTo_SetImplicitWait()
227227
var browser = BrowserManager.Browser;
228228
browser.GoTo(new WelcomeForm().Url);
229229
var waitTime = TimeSpan.FromSeconds(5);
230-
browser.ImplicitWaitTimeout = waitTime;
230+
browser.SetImplicitWaitTimeout(waitTime);
231231

232232
var stopwatch = Stopwatch.StartNew();
233233
var elapsedTime = TimeSpan.Zero;

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ browser.Quit();
4646
```
4747

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

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

0 commit comments

Comments
 (0)