Skip to content

Commit

Permalink
fixed static code analyses SonarQube errors
Browse files Browse the repository at this point in the history
  • Loading branch information
raczeja committed Apr 27, 2018
1 parent 46a3f8f commit 9572d24
Showing 1 changed file with 120 additions and 110 deletions.
230 changes: 120 additions & 110 deletions Objectivity.Test.Automation.Common/DriverContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,47 +227,6 @@ private FirefoxProfile FirefoxProfile
profile.SetPreference("plugin.scan.Acrobat", "99.0");
profile.SetPreference("plugin.scan.plid.all", false);

// custom preferences
// if there are any settings
if (firefoxPreferences != null)
{
// loop through all of them
for (var i = 0; i < firefoxPreferences.Count; i++)
{
Logger.Trace(CultureInfo.CurrentCulture, "Set custom preference '{0},{1}'", firefoxPreferences.GetKey(i), firefoxPreferences[i]);

// and verify all of them
switch (firefoxPreferences[i])
{
// if current settings value is "true"
case "true":
profile.SetPreference(firefoxPreferences.GetKey(i), true);
break;

// if "false"
case "false":
profile.SetPreference(firefoxPreferences.GetKey(i), false);
break;

// otherwise
default:
int temp;

// an attempt to parse current settings value to an integer. Method TryParse returns True if the attempt is successful (the string is integer) or return False (if the string is just a string and cannot be cast to a number)
if (int.TryParse(firefoxPreferences.Get(i), out temp))
{
profile.SetPreference(firefoxPreferences.GetKey(i), temp);
}
else
{
profile.SetPreference(firefoxPreferences.GetKey(i), firefoxPreferences[i]);
}

break;
}
}
}

// if there are any extensions
if (firefoxExtensions != null)
{
Expand All @@ -279,6 +238,49 @@ private FirefoxProfile FirefoxProfile
}
}

// custom preferences
// if there are any settings
if (firefoxPreferences == null)
{
return profile;
}

// loop through all of them
for (var i = 0; i < firefoxPreferences.Count; i++)
{
Logger.Trace(CultureInfo.CurrentCulture, "Set custom preference '{0},{1}'", firefoxPreferences.GetKey(i), firefoxPreferences[i]);

// and verify all of them
switch (firefoxPreferences[i])
{
// if current settings value is "true"
case "true":
profile.SetPreference(firefoxPreferences.GetKey(i), true);
break;

// if "false"
case "false":
profile.SetPreference(firefoxPreferences.GetKey(i), false);
break;

// otherwise
default:
int temp;

// an attempt to parse current settings value to an integer. Method TryParse returns True if the attempt is successful (the string is integer) or return False (if the string is just a string and cannot be cast to a number)
if (int.TryParse(firefoxPreferences.Get(i), out temp))
{
profile.SetPreference(firefoxPreferences.GetKey(i), temp);
}
else
{
profile.SetPreference(firefoxPreferences.GetKey(i), firefoxPreferences[i]);
}

break;
}
}

return profile;
}
}
Expand Down Expand Up @@ -313,47 +315,6 @@ private ChromeOptions ChromeProfile
options.Proxy = this.CurrentProxy();
}

// custom preferences
// if there are any settings
if (chromePreferences != null)
{
// loop through all of them
for (var i = 0; i < chromePreferences.Count; i++)
{
Logger.Trace(CultureInfo.CurrentCulture, "Set custom preference '{0},{1}'", chromePreferences.GetKey(i), chromePreferences[i]);

// and verify all of them
switch (chromePreferences[i])
{
// if current settings value is "true"
case "true":
options.AddUserProfilePreference(chromePreferences.GetKey(i), true);
break;

// if "false"
case "false":
options.AddUserProfilePreference(chromePreferences.GetKey(i), false);
break;

// otherwise
default:
int temp;

// an attempt to parse current settings value to an integer. Method TryParse returns True if the attempt is successful (the string is integer) or return False (if the string is just a string and cannot be cast to a number)
if (int.TryParse(chromePreferences.Get(i), out temp))
{
options.AddUserProfilePreference(chromePreferences.GetKey(i), temp);
}
else
{
options.AddUserProfilePreference(chromePreferences.GetKey(i), chromePreferences[i]);
}

break;
}
}
}

// if there are any extensions
if (chromeExtensions != null)
{
Expand All @@ -380,6 +341,49 @@ private ChromeOptions ChromeProfile
}
}

// custom preferences
// if there are any settings
if (chromePreferences == null)
{
return options;
}

// loop through all of them
for (var i = 0; i < chromePreferences.Count; i++)
{
Logger.Trace(CultureInfo.CurrentCulture, "Set custom preference '{0},{1}'", chromePreferences.GetKey(i), chromePreferences[i]);

// and verify all of them
switch (chromePreferences[i])
{
// if current settings value is "true"
case "true":
options.AddUserProfilePreference(chromePreferences.GetKey(i), true);
break;

// if "false"
case "false":
options.AddUserProfilePreference(chromePreferences.GetKey(i), false);
break;

// otherwise
default:
int temp;

// an attempt to parse current settings value to an integer. Method TryParse returns True if the attempt is successful (the string is integer) or return False (if the string is just a string and cannot be cast to a number)
if (int.TryParse(chromePreferences.Get(i), out temp))
{
options.AddUserProfilePreference(chromePreferences.GetKey(i), temp);
}
else
{
options.AddUserProfilePreference(chromePreferences.GetKey(i), chromePreferences[i]);
}

break;
}
}

return options;
}
}
Expand All @@ -396,33 +400,35 @@ private InternetExplorerOptions InternetExplorerProfile
IgnoreZoomLevel = true,
};

// set browser proxy for IE
if (!string.IsNullOrEmpty(BaseConfiguration.Proxy))
{
options.Proxy = this.CurrentProxy();
}

// custom preferences
// if there are any settings
if (internetExplorerPreferences != null)
if (internetExplorerPreferences == null)
{
// loop through all of them
for (var i = 0; i < internetExplorerPreferences.Count; i++)
{
Logger.Trace(CultureInfo.CurrentCulture, "Set custom preference '{0},{1}'", internetExplorerPreferences.GetKey(i), internetExplorerPreferences[i]);

// and verify all of them
switch (internetExplorerPreferences.GetKey(i))
{
case "EnsureCleanSession":
options.EnsureCleanSession = Convert.ToBoolean(internetExplorerPreferences[i], CultureInfo.CurrentCulture);
break;

case "IgnoreZoomLevel":
options.IgnoreZoomLevel = Convert.ToBoolean(internetExplorerPreferences[i], CultureInfo.CurrentCulture);
break;
}
}
return options;
}

// set browser proxy for IE
if (!string.IsNullOrEmpty(BaseConfiguration.Proxy))
// loop through all of them
for (var i = 0; i < internetExplorerPreferences.Count; i++)
{
options.Proxy = this.CurrentProxy();
Logger.Trace(CultureInfo.CurrentCulture, "Set custom preference '{0},{1}'", internetExplorerPreferences.GetKey(i), internetExplorerPreferences[i]);

// and verify all of them
switch (internetExplorerPreferences.GetKey(i))
{
case "EnsureCleanSession":
options.EnsureCleanSession = Convert.ToBoolean(internetExplorerPreferences[i], CultureInfo.CurrentCulture);
break;

case "IgnoreZoomLevel":
options.IgnoreZoomLevel = Convert.ToBoolean(internetExplorerPreferences[i], CultureInfo.CurrentCulture);
break;
}
}

return options;
Expand Down Expand Up @@ -452,12 +458,6 @@ private SafariOptions SafariProfile
var options = new SafariOptions();
options.AddAdditionalCapability("cleanSession", true);

// set browser proxy for Safari
if (!string.IsNullOrEmpty(BaseConfiguration.Proxy))
{
throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Use command line to setup proxy"));
}

return options;
}
}
Expand Down Expand Up @@ -526,9 +526,9 @@ public void Start()
break;
case BrowserType.Safari:
this.driver = new SafariDriver(this.SetDriverOptions(this.SafariProfile));
this.CheckIfProxySetForSafari();
break;
case BrowserType.RemoteWebDriver:
case BrowserType.CloudProvider:
this.driver = new RemoteWebDriver(BaseConfiguration.RemoteWebDriverHub, this.SetCapabilities());
break;
case BrowserType.Edge:
Expand Down Expand Up @@ -733,6 +733,7 @@ private DesiredCapabilities SetCapabilities()
break;
case BrowserType.Safari:
capabilities = (DesiredCapabilities)this.SetDriverOptions(this.SafariProfile).ToCapabilities();
this.CheckIfProxySetForSafari();
break;
case BrowserType.Edge:
capabilities = (DesiredCapabilities)this.SetDriverOptions(this.EdgeProfile).ToCapabilities();
Expand Down Expand Up @@ -819,5 +820,14 @@ private Proxy CurrentProxy()
};
return proxy;
}

private void CheckIfProxySetForSafari()
{
// set browser proxy for Safari
if (!string.IsNullOrEmpty(BaseConfiguration.Proxy))
{
throw new NotSupportedException("Use command line to setup proxy");
}
}
}
}

0 comments on commit 9572d24

Please sign in to comment.