Skip to content

Commit

Permalink
Merge pull request #99 from ObjectivityLtd/3.1.11
Browse files Browse the repository at this point in the history
3.1.11
  • Loading branch information
raczeja authored Apr 4, 2019
2 parents 7d6b39d + 9ac0deb commit 9ab59aa
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 116 deletions.
16 changes: 10 additions & 6 deletions Objectivity.Test.Automation.Common/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@
<add key="url" value="/ObjectivityLTD/Test.Automation"/>
<!--<add key="browser" value="Chrome" />-->
<!--<add key="browser" value="InternetExplorer" />-->
<!--<add key="browser" value="FirefoxPortable" />-->
<!--<add key="browser" value="Firefox" />-->
<!--<add key="browser" value="Safari" />-->
<!--<add key="browser" value="Edge" />-->
<!--<add key="browser" value="RemoteWebDriver" />-->
<add key="browser" value="Firefox"/>
<!--Set path to the directory containing Drivers, leave it empty for default locations \bin-->
<add key="PathToChromeDriverDirectory" value=""/>
<add key="PathToFirefoxDriverDirectory" value=""/>
<add key="PathToInternetExplorerDriverDirectory" value=""/>
<add key="PathToEdgeDriverDirectory" value=""/>
<!--Set path and file name of the browsers executable, leave it empty for default locations-->
<add key="ChromeBrowserExecutableLocation" value=""/>
<add key="FireFoxBrowserExecutableLocation" value=""/>
<add key="FirefoxUseLegacyImplementation" value="false"/>
<!--Set FireFoxPath if using FirefoxPortable as browser-->
<add key="FireFoxPath" value="\..\..\..\FirefoxPortable\FirefoxPortable.exe"/>
<!--Set path path to firefox profile, leave it empty for default-->
<add key="PathToFirefoxProfile" value=""/>
<!--Set RemoteWebDriverHub if using RemoteWebDriver as browser-->
<add key="RemoteWebDriverHub" value="http://localhost:4444/wd/hub"/>
<!--Set DriverCapabilities if using RemoteWebDriver as browser-->
Expand Down Expand Up @@ -56,9 +63,6 @@
<add key="JavaScriptErrorTypes" value="SyntaxError,EvalError,ReferenceError,RangeError,TypeError,URIError,Refused to display,Internal Server Error,Cannot read property" />
<!--Enable or disable synchronization with AngularJS, can be also set in source code this.Driver.SynchronizeWithAngular(true);-->
<add key="SynchronizationWithAngularEnabled" value="false"/>
<!--Use default firefox profile?-->
<add key="UseDefaultFirefoxProfile" value="false"/>
<add key="PathToFirefoxProfile" value="C:\Users\ci_objectivity\AppData\Roaming\Mozilla\Firefox\Profiles"/>
</appSettings>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
128 changes: 99 additions & 29 deletions Objectivity.Test.Automation.Common/BaseConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,19 @@ public static BrowserType TestBrowserCapabilities
/// <summary>
/// Gets the path to firefox profile.
/// </summary>
public static string PathToFirefoxProfile => ConfigurationManager.AppSettings["PathToFirefoxProfile"];
public static string PathToFirefoxProfile
{
get
{
Logger.Trace(CultureInfo.CurrentCulture, "Gets the path to firefox profile from App.config '{0}'", ConfigurationManager.AppSettings["PathToFirefoxProfile"]);
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["PathToFirefoxProfile"]))
{
return string.Empty;
}

return ConfigurationManager.AppSettings["PathToFirefoxProfile"];
}
}

/// <summary>
/// Gets the application protocol (http or https).
Expand Down Expand Up @@ -179,24 +191,36 @@ public static double ImplicitlyWaitMilliseconds
}

/// <summary>
/// Gets the firefox path
/// Gets the path and file name of the Firefox browser executable
/// </summary>
public static string FirefoxPath
public static string FirefoxBrowserExecutableLocation
{
get
{
return ConfigurationManager.AppSettings["FireFoxPath"];
Logger.Trace(CultureInfo.CurrentCulture, "Gets the path and file name of the Firefox browser executable from App.config '{0}'", ConfigurationManager.AppSettings["FirefoxBrowserExecutableLocation"]);
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["FirefoxBrowserExecutableLocation"]))
{
return string.Empty;
}

return ConfigurationManager.AppSettings["FirefoxBrowserExecutableLocation"];
}
}

/// <summary>
/// Gets the chrome path
/// Gets the path and file name of the Chrome browser executable
/// </summary>
public static string ChromePath
public static string ChromeBrowserExecutableLocation
{
get
{
return ConfigurationManager.AppSettings["ChromePath"];
Logger.Trace(CultureInfo.CurrentCulture, "Gets the path and file name of the Chrome browser executable from App.config '{0}'", ConfigurationManager.AppSettings["FirefoxBrowserExecutableLocation"]);
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["ChromeBrowserExecutableLocation"]))
{
return string.Empty;
}

return ConfigurationManager.AppSettings["ChromeBrowserExecutableLocation"];
}
}

Expand Down Expand Up @@ -233,6 +257,74 @@ public static bool FullDesktopScreenShotEnabled
}
}

/// <summary>
/// Gets specified path to the directory containing InternetExplorer Driver.
/// </summary>
public static string PathToInternetExplorerDriverDirectory
{
get
{
Logger.Trace(CultureInfo.CurrentCulture, "Path to the directory containing Internet Explorer Driver from App.config '{0}'", ConfigurationManager.AppSettings["PathToInternetExplorerDriverDirectory"]);
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["PathToInternetExplorerDriverDirectory"]))
{
return string.Empty;
}

return ConfigurationManager.AppSettings["PathToInternetExplorerDriverDirectory"];
}
}

/// <summary>
/// Gets specified path to the directory containing Edge Driver.
/// </summary>
public static string PathToEdgeDriverDirectory
{
get
{
Logger.Trace(CultureInfo.CurrentCulture, "Path to the directory containing Edge Driver from App.config '{0}'", ConfigurationManager.AppSettings["PathToEdgeDriverDirectory"]);
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["PathToEdgeDriverDirectory"]))
{
return string.Empty;
}

return ConfigurationManager.AppSettings["PathToEdgeDriverDirectory"];
}
}

/// <summary>
/// Gets specified path to the directory containing ChromeDriver.
/// </summary>
public static string PathToChromeDriverDirectory
{
get
{
Logger.Trace(CultureInfo.CurrentCulture, "Path to the directory containing Chrome Driver from App.config '{0}'", ConfigurationManager.AppSettings["PathToChromeDriverDirectory"]);
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["PathToChromeDriverDirectory"]))
{
return string.Empty;
}

return ConfigurationManager.AppSettings["PathToChromeDriverDirectory"];
}
}

/// <summary>
/// Gets specified path to the directory containing Firefox Driver.
/// </summary>
public static string PathToFirefoxDriverDirectory
{
get
{
Logger.Trace(CultureInfo.CurrentCulture, "Path to the directory containing Firefox Driver from App.config '{0}'", ConfigurationManager.AppSettings["PathToFirefoxDriverDirectory"]);
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["PathToFirefoxDriverDirectory"]))
{
return string.Empty;
}

return ConfigurationManager.AppSettings["PathToFirefoxDriverDirectory"];
}
}

/// <summary>
/// Gets a value indicating whether logs JavaScript errors from a browser. False by default.
/// </summary>
Expand Down Expand Up @@ -305,28 +397,6 @@ public static bool FirefoxUseLegacyImplementation
}
}

/// <summary>
/// Gets a value indicating whether use firefox profile. False by default.
/// </summary>
public static bool UseDefaultFirefoxProfile
{
get
{
Logger.Trace(CultureInfo.CurrentCulture, "Use Default Firefox Profile value from App.config '{0}'", ConfigurationManager.AppSettings["UseDefaultFirefoxProfile"]);
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["UseDefaultFirefoxProfile"]))
{
return false;
}

if (ConfigurationManager.AppSettings["UseDefaultFirefoxProfile"].ToLower(CultureInfo.CurrentCulture).Equals("true"))
{
return true;
}

return false;
}
}

/// <summary>
/// Gets a value indicating whether enable full desktop screen shot. True by default.
/// </summary>
Expand Down
5 changes: 0 additions & 5 deletions Objectivity.Test.Automation.Common/BrowserType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ public enum BrowserType
/// </summary>
Firefox,

/// <summary>
/// Firefox portable
/// </summary>
FirefoxPortable,

/// <summary>
/// InternetExplorer browser
/// </summary>
Expand Down
32 changes: 16 additions & 16 deletions Objectivity.Test.Automation.Common/DriverContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private FirefoxOptions FirefoxOptions
{
FirefoxOptions options = new FirefoxOptions();

if (BaseConfiguration.UseDefaultFirefoxProfile)
if (!string.IsNullOrEmpty(BaseConfiguration.PathToFirefoxProfile))
{
try
{
Expand All @@ -188,7 +188,7 @@ private FirefoxOptions FirefoxOptions
}
catch (DirectoryNotFoundException e)
{
Logger.Info(CultureInfo.CurrentCulture, "problem with loading firefox profile {0}", e.Message);
Logger.Error(CultureInfo.CurrentCulture, "problem with loading firefox profile {0}", e.Message);
}
}

Expand Down Expand Up @@ -328,12 +328,6 @@ private ChromeOptions ChromeOptions
}
}

if (BaseConfiguration.ChromePath != null)
{
Logger.Trace(CultureInfo.CurrentCulture, "Setting Chrome Path {0}", BaseConfiguration.ChromePath);
options.BinaryLocation = BaseConfiguration.ChromePath;
}

// if there are any arguments
if (chromeArguments != null)
{
Expand Down Expand Up @@ -484,18 +478,24 @@ public void Start()
switch (BaseConfiguration.TestBrowser)
{
case BrowserType.Firefox:
this.driver = new FirefoxDriver(this.SetDriverOptions(this.FirefoxOptions));
break;
case BrowserType.FirefoxPortable:
this.FirefoxOptions.BrowserExecutableLocation = BaseConfiguration.FirefoxPath;
this.driver = new FirefoxDriver(this.SetDriverOptions(this.FirefoxOptions));
if (!string.IsNullOrEmpty(BaseConfiguration.FirefoxBrowserExecutableLocation))
{
this.FirefoxOptions.BrowserExecutableLocation = BaseConfiguration.FirefoxBrowserExecutableLocation;
}

this.driver = string.IsNullOrEmpty(BaseConfiguration.PathToFirefoxDriverDirectory) ? new FirefoxDriver(this.SetDriverOptions(this.FirefoxOptions)) : new FirefoxDriver(BaseConfiguration.PathToFirefoxDriverDirectory, this.SetDriverOptions(this.FirefoxOptions));
break;
case BrowserType.InternetExplorer:
case BrowserType.IE:
this.driver = new InternetExplorerDriver(this.SetDriverOptions(this.InternetExplorerOptions));
this.driver = string.IsNullOrEmpty(BaseConfiguration.PathToInternetExplorerDriverDirectory) ? new InternetExplorerDriver(this.SetDriverOptions(this.InternetExplorerOptions)) : new InternetExplorerDriver(BaseConfiguration.PathToInternetExplorerDriverDirectory, this.SetDriverOptions(this.InternetExplorerOptions));
break;
case BrowserType.Chrome:
this.driver = new ChromeDriver(this.SetDriverOptions(this.ChromeOptions));
if (!string.IsNullOrEmpty(BaseConfiguration.ChromeBrowserExecutableLocation))
{
this.ChromeOptions.BinaryLocation = BaseConfiguration.ChromeBrowserExecutableLocation;
}

this.driver = string.IsNullOrEmpty(BaseConfiguration.PathToChromeDriverDirectory) ? new ChromeDriver(this.SetDriverOptions(this.ChromeOptions)) : new ChromeDriver(BaseConfiguration.PathToChromeDriverDirectory, this.SetDriverOptions(this.ChromeOptions));
break;
case BrowserType.Safari:
this.driver = new SafariDriver(this.SetDriverOptions(this.SafariOptions));
Expand Down Expand Up @@ -543,7 +543,7 @@ public void Start()

break;
case BrowserType.Edge:
this.driver = new EdgeDriver(this.SetDriverOptions(this.EdgeOptions));
this.driver = string.IsNullOrEmpty(BaseConfiguration.PathToEdgeDriverDirectory) ? new EdgeDriver(this.SetDriverOptions(this.EdgeOptions)) : new EdgeDriver(BaseConfiguration.PathToEdgeDriverDirectory, this.SetDriverOptions(this.EdgeOptions));
break;
default:
throw new NotSupportedException(
Expand Down
37 changes: 32 additions & 5 deletions Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,41 @@ public static string TakeScreenShotOfElement(int iframeLocationX, int iframeLoca
var elementWidth = element.Size.Width;
var elementHeight = element.Size.Height;

Logger.Debug(CultureInfo.CurrentCulture, "Cutting out screenshot of element locationX:{0} locationY:{1} elementWidth:{2} elementHeight:{3}", locationX, locationY, elementWidth, elementHeight);
return CutOutScreenShot(folder, screenshotName, locationX, locationY, elementWidth, elementHeight, filePath);
}

/// <summary>
/// Cut out the screen shot by giving locationX, locationY, elementWidth, elementHeight.
/// </summary>
/// <param name="folder">Folder to save new screenshot</param>
/// <param name="newScreenShotName">Name of new screenshot</param>
/// <param name="locationX">The x-coordinate of the upper-left corner of the new rectangle.</param>
/// <param name="locationY">The y-coordinate of the upper-left corner of the new rectangle.</param>
/// <param name="elementWidth">The width of the new rectangle.</param>
/// <param name="elementHeight">The height of the new rectangle</param>
/// <param name="fullPathToScreenShotToCutOut">Full path to the screenshot to be cut out</param>
/// <returns>Full path of cutted out screenshot</returns>
/// <example>How to use it: <code>
/// var fullPath = CutOutScreenShot(folder, screenshotName, locationX, locationY, elementWidth, elementHeight, fullPathToScreenShotToCutOut);
/// </code></example>
public static string CutOutScreenShot(string folder, string newScreenShotName, int locationX, int locationY, int elementWidth, int elementHeight, string fullPathToScreenShotToCutOut)
{
Logger.Debug(CultureInfo.CurrentCulture, "Trying to cut out screenshot locationX:{0} locationY:{1} elementWidth:{2} elementHeight:{3}", locationX, locationY, elementWidth, elementHeight);

string newFilePath;
Bitmap importFile = null;
Bitmap cloneFile;
try
{
importFile = new Bitmap(filePath);
importFile = new Bitmap(fullPathToScreenShotToCutOut);
Logger.Debug(CultureInfo.CurrentCulture, "Size of imported screenshot Width:{0} Height:{1}", importFile.Size.Width, importFile.Size.Height);
////Check if new size of image is not bigger than imported.
if (locationY > importFile.Size.Height || locationX > importFile.Size.Width)
{
Logger.Error(CultureInfo.CurrentCulture, "Cutting out screenshot locationX:{0} locationY:{1} elementWidth:{2} elementHeight:{3} is not possible", locationX, locationY, elementWidth, elementHeight);
return null;
}

if (importFile.Size.Height - locationY < elementHeight)
{
elementHeight = importFile.Size.Height - locationY;
Expand All @@ -183,18 +209,19 @@ public static string TakeScreenShotOfElement(int iframeLocationX, int iframeLoca
elementWidth = importFile.Size.Width - locationX;
}

Logger.Debug(CultureInfo.CurrentCulture, "Cutting out screenshot locationX:{0} locationY:{1} elementWidth:{2} elementHeight:{3}", locationX, locationY, elementWidth, elementHeight);
var image = new Rectangle(locationX, locationY, elementWidth, elementHeight);
newFilePath = Path.Combine(folder, screenshotName + ".png");
newFilePath = Path.Combine(folder, newScreenShotName + ".png");
cloneFile = (Bitmap)importFile.Clone(image, importFile.PixelFormat);
}
finally
{
importFile?.Dispose();
}

Logger.Debug(CultureInfo.CurrentCulture, "Saving screenshot of element {0}", newFilePath);
Logger.Debug(CultureInfo.CurrentCulture, "Saving new screenshot {0}", newFilePath);
cloneFile.Save(newFilePath);
File.Delete(filePath);
File.Delete(fullPathToScreenShotToCutOut);
return newFilePath;
}
}
Expand Down
Loading

0 comments on commit 9ab59aa

Please sign in to comment.