From 31c631785803d39b57e6c5b9714585928366f0de Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 5 Mar 2019 11:49:42 +0100 Subject: [PATCH 01/10] Added setting of internetExplorer preferences, fixes #95 --- .../DriverContext.cs | 278 +------------- .../DriverContextHelper.cs | 357 ++++++++++++++++++ .../Objectivity.Test.Automation.Common.csproj | 1 + .../App.config | 2 + .../ProjectTestBase.cs | 10 +- 5 files changed, 369 insertions(+), 279 deletions(-) create mode 100644 Objectivity.Test.Automation.Common/DriverContextHelper.cs diff --git a/Objectivity.Test.Automation.Common/DriverContext.cs b/Objectivity.Test.Automation.Common/DriverContext.cs index 3f56dd0e9..fadc58345 100644 --- a/Objectivity.Test.Automation.Common/DriverContext.cs +++ b/Objectivity.Test.Automation.Common/DriverContext.cs @@ -49,7 +49,7 @@ namespace Objectivity.Test.Automation.Common /// Contains handle to driver and methods for web browser /// [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Driver is disposed on test end")] - public class DriverContext + public partial class DriverContext { private static readonly NLog.Logger Logger = LogManager.GetLogger("DRIVER"); private readonly Collection verifyMessages = new Collection(); @@ -422,23 +422,7 @@ private InternetExplorerOptions InternetExplorerOptions return options; } - // 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; - } - } + this.GetInternetExplorerPreferences(internetExplorerPreferences, options); return options; } @@ -603,263 +587,5 @@ public void Stop() this.driver.Quit(); } } - - /// - /// Saves the screenshot. - /// - /// The error detail. - /// The folder. - /// The title. - /// Path to the screenshot - public string SaveScreenshot(ErrorDetail errorDetail, string folder, string title) - { - var fileName = string.Format(CultureInfo.CurrentCulture, "{0}_{1}_{2}.png", title, errorDetail.DateTime.ToString("yyyy-MM-dd HH-mm-ss-fff", CultureInfo.CurrentCulture), "browser"); - var correctFileName = Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(CultureInfo.CurrentCulture), string.Empty)); - correctFileName = Regex.Replace(correctFileName, "[^0-9a-zA-Z._]+", "_"); - correctFileName = NameHelper.ShortenFileName(folder, correctFileName, "_", 255); - - var filePath = Path.Combine(folder, correctFileName); - - try - { - errorDetail.Screenshot.SaveAsFile(filePath, ScreenshotImageFormat.Png); - FilesHelper.WaitForFileOfGivenName(BaseConfiguration.ShortTimeout, correctFileName, folder); - Logger.Error(CultureInfo.CurrentCulture, "Test failed: screenshot saved to {0}.", filePath); - Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath)); - return filePath; - } - catch (NullReferenceException) - { - Logger.Error("Test failed but was unable to get webdriver screenshot."); - } - - return null; - } - - /// - /// Saves the page source. - /// - /// Name of the file. - /// The saved source file - public string SavePageSource(string fileName) - { - if (BaseConfiguration.GetPageSourceEnabled) - { - var fileNameShort = Regex.Replace(fileName, "[^0-9a-zA-Z._]+", "_"); - fileNameShort = NameHelper.ShortenFileName(this.PageSourceFolder, fileNameShort, "_", 255); - var fileNameWithExtension = string.Format(CultureInfo.CurrentCulture, "{0}{1}", fileNameShort, ".html"); - var path = Path.Combine(this.PageSourceFolder, fileNameWithExtension); - if (File.Exists(path)) - { - File.Delete(path); - } - - var pageSource = this.driver.PageSource; - pageSource = pageSource.Replace("", string.Format(CultureInfo.CurrentCulture, "", BaseConfiguration.Host)); - File.WriteAllText(path, pageSource); - FilesHelper.WaitForFileOfGivenName(BaseConfiguration.LongTimeout, fileNameWithExtension, this.PageSourceFolder); - Logger.Error(CultureInfo.CurrentCulture, "Test failed: page Source saved to {0}.", path); - Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", path)); - return path; - } - - return null; - } - - /// - /// Takes and saves screen shot - /// - /// Array of filepaths - public string[] TakeAndSaveScreenshot() - { - List filePaths = new List(); - if (BaseConfiguration.FullDesktopScreenShotEnabled) - { - filePaths.Add(TakeScreenShot.Save(TakeScreenShot.DoIt(), ImageFormat.Png, this.ScreenShotFolder, this.TestTitle)); - } - - if (BaseConfiguration.SeleniumScreenShotEnabled) - { - filePaths.Add(this.SaveScreenshot(new ErrorDetail(this.TakeScreenshot(), DateTime.Now, null), this.ScreenShotFolder, this.TestTitle)); - } - - return filePaths.ToArray(); - } - - /// - /// Logs JavaScript errors - /// - /// True if JavaScript errors found - public bool LogJavaScriptErrors() - { - IEnumerable jsErrors = null; - bool javScriptErrors = false; - - // Check JavaScript browser logs for errors. - if (BaseConfiguration.JavaScriptErrorLogging) - { - Logger.Debug(CultureInfo.CurrentCulture, "Checking JavaScript error(s) in browser"); - try - { - jsErrors = - this.driver.Manage() - .Logs.GetLog(LogType.Browser) - .Where(x => BaseConfiguration.JavaScriptErrorTypes.Any(e => x.Message.Contains(e))); - } - catch (NullReferenceException) - { - Logger.Error(CultureInfo.CurrentCulture, "NullReferenceException while trying to read JavaScript errors from browser."); - return false; - } - - if (jsErrors.Any()) - { - // Show JavaScript errors if there are any - Logger.Error(CultureInfo.CurrentCulture, "JavaScript error(s): {0}", Environment.NewLine + jsErrors.Aggregate(string.Empty, (s, entry) => s + entry.Message + Environment.NewLine)); - javScriptErrors = true; - } - } - - return javScriptErrors; - } - - /// - /// Sets the driver options. - /// - /// The type of DriverOptions for the specific Browser - /// The options. - /// - /// The Driver Options - /// - private T SetDriverOptions(T options) - where T : DriverOptions - { - this.DriverOptionsSet?.Invoke(this, new DriverOptionsSetEventArgs(options)); - return options; - } - - private Proxy CurrentProxy() - { - Proxy proxy = new Proxy - { - HttpProxy = BaseConfiguration.Proxy, - FtpProxy = BaseConfiguration.Proxy, - SslProxy = BaseConfiguration.Proxy, - SocksProxy = BaseConfiguration.Proxy - }; - return proxy; - } - - private void CheckIfProxySetForSafari() - { - // set browser proxy for Safari - if (!string.IsNullOrEmpty(BaseConfiguration.Proxy)) - { - throw new NotSupportedException("Use command line to setup proxy"); - } - } - - private FirefoxOptions AddFirefoxArguments(FirefoxOptions option) - { - var firefoxArguments = ConfigurationManager.GetSection("FirefoxArguments") as NameValueCollection; - - // if there are any arguments - if (firefoxArguments != null) - { - // loop through all of them - for (var i = 0; i < firefoxArguments.Count; i++) - { - Logger.Trace(CultureInfo.CurrentCulture, "Setting FireFox Arguments {0}", firefoxArguments.GetKey(i)); - option.AddArgument(firefoxArguments.GetKey(i)); - } - } - - return option; - } - - private T SetRemoteDriverOptions(NameValueCollection driverCapabilitiesConf, NameValueCollection settings, T options) - where T : DriverOptions - { - // if there are any capability - if (driverCapabilitiesConf != null) - { - // loop through all of them - for (var i = 0; i < driverCapabilitiesConf.Count; i++) - { - string value = driverCapabilitiesConf.GetValues(i)[0]; - Logger.Trace(CultureInfo.CurrentCulture, "Adding driver capability {0}", driverCapabilitiesConf.GetKey(i)); - options.AddAdditionalCapability(driverCapabilitiesConf.GetKey(i), value); - } - } - - // if there are any capability - if (settings != null) - { - foreach (string key in settings.AllKeys) - { - Logger.Trace(CultureInfo.CurrentCulture, "Adding driver capability {0} from {1}", key, this.CrossBrowserEnvironment); - - options.AddAdditionalCapability(key, settings[key]); - } - } - - return options; - } - - private BrowserType GetBrowserTypeForRemoteDriver(NameValueCollection settings) - { - if (BaseConfiguration.TestBrowserCapabilities != BrowserType.CloudProvider) - { - return BaseConfiguration.TestBrowserCapabilities; - } - - BrowserType browserType = BrowserType.None; - bool supportedBrowser = false; - if (settings != null) - { - string browser = settings.GetValues("browser")?[0]; - supportedBrowser = Enum.TryParse(browser, true, out browserType); - Logger.Info(CultureInfo.CurrentCulture, "supportedBrowser {0} : {1}", supportedBrowser, browserType); - } - - if (!supportedBrowser) - { - if (this.CrossBrowserEnvironment.ToLower(CultureInfo.CurrentCulture).Contains(BrowserType.Android.ToString().ToLower(CultureInfo.CurrentCulture))) - { - browserType = BrowserType.Chrome; - } - else if (this.CrossBrowserEnvironment.ToLower(CultureInfo.CurrentCulture).Contains(BrowserType.Iphone.ToString().ToLower(CultureInfo.CurrentCulture))) - { - browserType = BrowserType.Safari; - } - } - - return browserType; - } - - private void SetRemoteDriverBrowserOptions(NameValueCollection driverCapabilitiesConf, NameValueCollection settings, dynamic browserOptions) - { - // if there are any capability - if (driverCapabilitiesConf != null) - { - // loop through all of them - for (var i = 0; i < driverCapabilitiesConf.Count; i++) - { - string value = driverCapabilitiesConf.GetValues(i)[0]; - Logger.Trace(CultureInfo.CurrentCulture, "Adding driver capability {0}", driverCapabilitiesConf.GetKey(i)); - browserOptions.AddAdditionalCapability(driverCapabilitiesConf.GetKey(i), value, true); - } - } - - // if there are any capability - if (settings != null) - { - foreach (string key in settings.AllKeys) - { - Logger.Trace(CultureInfo.CurrentCulture, "Adding driver capability {0} from {1}", key, this.CrossBrowserEnvironment); - browserOptions.AddAdditionalCapability(key, settings[key], true); - } - } - } } } diff --git a/Objectivity.Test.Automation.Common/DriverContextHelper.cs b/Objectivity.Test.Automation.Common/DriverContextHelper.cs new file mode 100644 index 000000000..4ff1d5952 --- /dev/null +++ b/Objectivity.Test.Automation.Common/DriverContextHelper.cs @@ -0,0 +1,357 @@ +// +// Copyright (c) Objectivity Bespoke Software Specialists. All rights reserved. +// +// +// The MIT License (MIT) +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +namespace Objectivity.Test.Automation.Common +{ + using System; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Collections.Specialized; + using System.Configuration; + using System.Diagnostics.CodeAnalysis; + using System.Drawing.Imaging; + using System.Globalization; + using System.IO; + using System.Linq; + using System.Text.RegularExpressions; + using NLog; + using Objectivity.Test.Automation.Common.Helpers; + using Objectivity.Test.Automation.Common.Logger; + using Objectivity.Test.Automation.Common.Types; + using OpenQA.Selenium; + using OpenQA.Selenium.Chrome; + using OpenQA.Selenium.Edge; + using OpenQA.Selenium.Firefox; + using OpenQA.Selenium.IE; + using OpenQA.Selenium.Remote; + using OpenQA.Selenium.Safari; + + /// + /// Contains handle to driver and methods for web browser + /// + [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Driver is disposed on test end")] + public partial class DriverContext + { + /// + /// Saves the screenshot. + /// + /// The error detail. + /// The folder. + /// The title. + /// Path to the screenshot + public string SaveScreenshot(ErrorDetail errorDetail, string folder, string title) + { + var fileName = string.Format(CultureInfo.CurrentCulture, "{0}_{1}_{2}.png", title, errorDetail.DateTime.ToString("yyyy-MM-dd HH-mm-ss-fff", CultureInfo.CurrentCulture), "browser"); + var correctFileName = Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(CultureInfo.CurrentCulture), string.Empty)); + correctFileName = Regex.Replace(correctFileName, "[^0-9a-zA-Z._]+", "_"); + correctFileName = NameHelper.ShortenFileName(folder, correctFileName, "_", 255); + + var filePath = Path.Combine(folder, correctFileName); + + try + { + errorDetail.Screenshot.SaveAsFile(filePath, ScreenshotImageFormat.Png); + FilesHelper.WaitForFileOfGivenName(BaseConfiguration.ShortTimeout, correctFileName, folder); + Logger.Error(CultureInfo.CurrentCulture, "Test failed: screenshot saved to {0}.", filePath); + Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath)); + return filePath; + } + catch (NullReferenceException) + { + Logger.Error("Test failed but was unable to get webdriver screenshot."); + } + + return null; + } + + /// + /// Saves the page source. + /// + /// Name of the file. + /// The saved source file + public string SavePageSource(string fileName) + { + if (BaseConfiguration.GetPageSourceEnabled) + { + var fileNameShort = Regex.Replace(fileName, "[^0-9a-zA-Z._]+", "_"); + fileNameShort = NameHelper.ShortenFileName(this.PageSourceFolder, fileNameShort, "_", 255); + var fileNameWithExtension = string.Format(CultureInfo.CurrentCulture, "{0}{1}", fileNameShort, ".html"); + var path = Path.Combine(this.PageSourceFolder, fileNameWithExtension); + if (File.Exists(path)) + { + File.Delete(path); + } + + var pageSource = this.driver.PageSource; + pageSource = pageSource.Replace("", string.Format(CultureInfo.CurrentCulture, "", BaseConfiguration.Host)); + File.WriteAllText(path, pageSource); + FilesHelper.WaitForFileOfGivenName(BaseConfiguration.LongTimeout, fileNameWithExtension, this.PageSourceFolder); + Logger.Error(CultureInfo.CurrentCulture, "Test failed: page Source saved to {0}.", path); + Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", path)); + return path; + } + + return null; + } + + /// + /// Takes and saves screen shot + /// + /// Array of filepaths + public string[] TakeAndSaveScreenshot() + { + List filePaths = new List(); + if (BaseConfiguration.FullDesktopScreenShotEnabled) + { + filePaths.Add(TakeScreenShot.Save(TakeScreenShot.DoIt(), ImageFormat.Png, this.ScreenShotFolder, this.TestTitle)); + } + + if (BaseConfiguration.SeleniumScreenShotEnabled) + { + filePaths.Add(this.SaveScreenshot(new ErrorDetail(this.TakeScreenshot(), DateTime.Now, null), this.ScreenShotFolder, this.TestTitle)); + } + + return filePaths.ToArray(); + } + + /// + /// Logs JavaScript errors + /// + /// True if JavaScript errors found + public bool LogJavaScriptErrors() + { + IEnumerable jsErrors = null; + bool javScriptErrors = false; + + // Check JavaScript browser logs for errors. + if (BaseConfiguration.JavaScriptErrorLogging) + { + Logger.Debug(CultureInfo.CurrentCulture, "Checking JavaScript error(s) in browser"); + try + { + jsErrors = + this.driver.Manage() + .Logs.GetLog(LogType.Browser) + .Where(x => BaseConfiguration.JavaScriptErrorTypes.Any(e => x.Message.Contains(e))); + } + catch (NullReferenceException) + { + Logger.Error(CultureInfo.CurrentCulture, "NullReferenceException while trying to read JavaScript errors from browser."); + return false; + } + + if (jsErrors.Any()) + { + // Show JavaScript errors if there are any + Logger.Error(CultureInfo.CurrentCulture, "JavaScript error(s): {0}", Environment.NewLine + jsErrors.Aggregate(string.Empty, (s, entry) => s + entry.Message + Environment.NewLine)); + javScriptErrors = true; + } + } + + return javScriptErrors; + } + + /// + /// Sets the driver options. + /// + /// The type of DriverOptions for the specific Browser + /// The options. + /// + /// The Driver Options + /// + private T SetDriverOptions(T options) + where T : DriverOptions + { + this.DriverOptionsSet?.Invoke(this, new DriverOptionsSetEventArgs(options)); + return options; + } + + private Proxy CurrentProxy() + { + Proxy proxy = new Proxy + { + HttpProxy = BaseConfiguration.Proxy, + FtpProxy = BaseConfiguration.Proxy, + SslProxy = BaseConfiguration.Proxy, + SocksProxy = BaseConfiguration.Proxy + }; + return proxy; + } + + private void CheckIfProxySetForSafari() + { + // set browser proxy for Safari + if (!string.IsNullOrEmpty(BaseConfiguration.Proxy)) + { + throw new NotSupportedException("Use command line to setup proxy"); + } + } + + private FirefoxOptions AddFirefoxArguments(FirefoxOptions option) + { + var firefoxArguments = ConfigurationManager.GetSection("FirefoxArguments") as NameValueCollection; + + // if there are any arguments + if (firefoxArguments != null) + { + // loop through all of them + for (var i = 0; i < firefoxArguments.Count; i++) + { + Logger.Trace(CultureInfo.CurrentCulture, "Setting FireFox Arguments {0}", firefoxArguments.GetKey(i)); + option.AddArgument(firefoxArguments.GetKey(i)); + } + } + + return option; + } + + private T SetRemoteDriverOptions(NameValueCollection driverCapabilitiesConf, NameValueCollection settings, T options) + where T : DriverOptions + { + // if there are any capability + if (driverCapabilitiesConf != null) + { + // loop through all of them + for (var i = 0; i < driverCapabilitiesConf.Count; i++) + { + string value = driverCapabilitiesConf.GetValues(i)[0]; + Logger.Trace(CultureInfo.CurrentCulture, "Adding driver capability {0}", driverCapabilitiesConf.GetKey(i)); + options.AddAdditionalCapability(driverCapabilitiesConf.GetKey(i), value); + } + } + + // if there are any capability + if (settings != null) + { + foreach (string key in settings.AllKeys) + { + Logger.Trace(CultureInfo.CurrentCulture, "Adding driver capability {0} from {1}", key, this.CrossBrowserEnvironment); + + options.AddAdditionalCapability(key, settings[key]); + } + } + + return options; + } + + private BrowserType GetBrowserTypeForRemoteDriver(NameValueCollection settings) + { + if (BaseConfiguration.TestBrowserCapabilities != BrowserType.CloudProvider) + { + return BaseConfiguration.TestBrowserCapabilities; + } + + BrowserType browserType = BrowserType.None; + bool supportedBrowser = false; + if (settings != null) + { + string browser = settings.GetValues("browser")?[0]; + supportedBrowser = Enum.TryParse(browser, true, out browserType); + Logger.Info(CultureInfo.CurrentCulture, "supportedBrowser {0} : {1}", supportedBrowser, browserType); + } + + if (!supportedBrowser) + { + if (this.CrossBrowserEnvironment.ToLower(CultureInfo.CurrentCulture).Contains(BrowserType.Android.ToString().ToLower(CultureInfo.CurrentCulture))) + { + browserType = BrowserType.Chrome; + } + else if (this.CrossBrowserEnvironment.ToLower(CultureInfo.CurrentCulture).Contains(BrowserType.Iphone.ToString().ToLower(CultureInfo.CurrentCulture))) + { + browserType = BrowserType.Safari; + } + } + + return browserType; + } + + private void SetRemoteDriverBrowserOptions(NameValueCollection driverCapabilitiesConf, NameValueCollection settings, dynamic browserOptions) + { + // if there are any capability + if (driverCapabilitiesConf != null) + { + // loop through all of them + for (var i = 0; i < driverCapabilitiesConf.Count; i++) + { + string value = driverCapabilitiesConf.GetValues(i)[0]; + Logger.Trace(CultureInfo.CurrentCulture, "Adding driver capability {0}", driverCapabilitiesConf.GetKey(i)); + browserOptions.AddAdditionalCapability(driverCapabilitiesConf.GetKey(i), value, true); + } + } + + // if there are any capability + if (settings != null) + { + foreach (string key in settings.AllKeys) + { + Logger.Trace(CultureInfo.CurrentCulture, "Adding driver capability {0} from {1}", key, this.CrossBrowserEnvironment); + browserOptions.AddAdditionalCapability(key, settings[key], true); + } + } + } + + private void GetInternetExplorerPreferences(NameValueCollection internetExplorerPreferences, InternetExplorerOptions options) + { + // 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; + + case "EnablePersistentHover": + options.EnablePersistentHover = Convert.ToBoolean(internetExplorerPreferences[i], CultureInfo.CurrentCulture); + break; + + case "IntroduceInstabilityByIgnoringProtectedModeSettings": + options.IntroduceInstabilityByIgnoringProtectedModeSettings = Convert.ToBoolean(internetExplorerPreferences[i], CultureInfo.CurrentCulture); + break; + + case "BrowserCommandLineArguments": + options.BrowserCommandLineArguments = Convert.ToString(internetExplorerPreferences[i], CultureInfo.CurrentCulture); + break; + + case "EnableNativeEvents": + options.EnableNativeEvents = Convert.ToBoolean(internetExplorerPreferences[i], CultureInfo.CurrentCulture); + break; + + case "RequireWindowFocus": + options.RequireWindowFocus = Convert.ToBoolean(internetExplorerPreferences[i], CultureInfo.CurrentCulture); + break; + + case "InitialBrowserUrl": + options.InitialBrowserUrl = Convert.ToString(internetExplorerPreferences[i], CultureInfo.CurrentCulture); + break; + } + } + } + } +} diff --git a/Objectivity.Test.Automation.Common/Objectivity.Test.Automation.Common.csproj b/Objectivity.Test.Automation.Common/Objectivity.Test.Automation.Common.csproj index 30fecdbc6..a15481371 100644 --- a/Objectivity.Test.Automation.Common/Objectivity.Test.Automation.Common.csproj +++ b/Objectivity.Test.Automation.Common/Objectivity.Test.Automation.Common.csproj @@ -61,6 +61,7 @@ + diff --git a/Objectivity.Test.Automation.Tests.Angular/App.config b/Objectivity.Test.Automation.Tests.Angular/App.config index 063b44700..47bb72e80 100644 --- a/Objectivity.Test.Automation.Tests.Angular/App.config +++ b/Objectivity.Test.Automation.Tests.Angular/App.config @@ -81,5 +81,7 @@ + + diff --git a/Objectivity.Test.Automation.Tests.Angular/ProjectTestBase.cs b/Objectivity.Test.Automation.Tests.Angular/ProjectTestBase.cs index d07c1c659..80510c68a 100644 --- a/Objectivity.Test.Automation.Tests.Angular/ProjectTestBase.cs +++ b/Objectivity.Test.Automation.Tests.Angular/ProjectTestBase.cs @@ -111,11 +111,15 @@ public void AfterTest() this.LogTest.LogTestEnding(this.driverContext); this.LogTest.LogTestEnding(this.driverContext); var logs = this.driverContext.Driver.Manage().Logs; - var perfLogs = logs.GetLog("performance"); - foreach (var perfLog in perfLogs) + if (BaseConfiguration.TestBrowser == BrowserType.Chrome) { - Logger.Info(perfLog.ToString); + var perfLogs = logs.GetLog("performance"); + foreach (var perfLog in perfLogs) + { + Logger.Info(perfLog.ToString); + } } + if (this.IsVerifyFailedAndClearMessages(this.driverContext) && TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Failed) { Assert.Fail(); From 3621d57981bdaa5b9d36edf20e3bbb9d96c49285 Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 5 Mar 2019 12:01:05 +0100 Subject: [PATCH 02/10] Set and execute Angular test for Internet Explorer --- appveyor.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index aacab3a9a..acbd93387 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -224,6 +224,22 @@ test_script: 7z a testresults_$env:appveyor_build_version.zip .\Objectivity.Test.Automation.UnitTests\bin\Release\*.log + echo '********************************************Angular test for Internet Explorer********************************************' + + .\scripts\set_AppConfig_for_tests.ps1 ".\Objectivity.Test.Automation.Tests.Angular\bin\Release" "Objectivity.Test.Automation.Tests.Angular.dll.config" "//appSettings" "browser" "InternetExplorer" + + & $OpenCover -target:nunit3-console.exe -mergeoutput -targetargs:".\Objectivity.Test.Automation.Tests.Angular\bin\Release\Objectivity.Test.Automation.Tests.Angular.dll --result=myresults.xml`;format=AppVeyor" -filter:"+[Objectivity.Test.Automation.Common]*" -register:user -output:opencoverCoverage.xml + + if($lastexitcode -ne 0) + { + echo $lastexitcode + } + + 7z a testresults_$env:appveyor_build_version.zip .\Objectivity.Test.Automation.Tests.Angular\bin\Release\**\*.png + + 7z a testresults_$env:appveyor_build_version.zip .\Objectivity.Test.Automation.Tests.Angular\bin\Release\**\*.html + + 7z a testresults_$env:appveyor_build_version.zip .\Objectivity.Test.Automation.Tests.Angular\bin\Release\*.log echo '********************************************MSTest tests********************************************' From 59cdc81fc726e74e5bd0563554655535ae011219 Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 5 Mar 2019 12:17:53 +0100 Subject: [PATCH 03/10] Updated "OpenCover" version="4.7.922" --- Objectivity.Test.Automation.UnitTests/packages.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objectivity.Test.Automation.UnitTests/packages.config b/Objectivity.Test.Automation.UnitTests/packages.config index e5843d321..ab6fe22ff 100644 --- a/Objectivity.Test.Automation.UnitTests/packages.config +++ b/Objectivity.Test.Automation.UnitTests/packages.config @@ -7,7 +7,7 @@ - + From 23f40834a96deb6add97d1dc3debed18e63ebd6b Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 5 Mar 2019 14:09:18 +0100 Subject: [PATCH 04/10] Updated "coveralls.net" version="1.0.0" --- Objectivity.Test.Automation.UnitTests/packages.config | 1 - appveyor.yml | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Objectivity.Test.Automation.UnitTests/packages.config b/Objectivity.Test.Automation.UnitTests/packages.config index ab6fe22ff..06ebf0b4b 100644 --- a/Objectivity.Test.Automation.UnitTests/packages.config +++ b/Objectivity.Test.Automation.UnitTests/packages.config @@ -1,6 +1,5 @@  - diff --git a/appveyor.yml b/appveyor.yml index acbd93387..faae5fc86 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -70,6 +70,8 @@ before_build: .\.nuget\nuget restore + dotnet tool install coveralls.net --version 1.0.0 --tool-path packages + build: project: TestFramework.sln verbosity: minimal @@ -375,7 +377,7 @@ test_script: echo '********************************************Sending coverage test results********************************************' - $coveralls = (Resolve-Path ".\packages\coveralls.net.*\tools\csmacnz.coveralls.exe").ToString() + $coveralls = (Resolve-Path ".\packages\csmacnz.coveralls.exe").ToString() & $coveralls --opencover -i opencoverCoverage.xml --repoToken $env:COVERALLS_REPO_TOKEN --useRelativePaths --commitId $env:APPVEYOR_REPO_COMMIT --commitBranch $env:APPVEYOR_REPO_BRANCH --commitAuthor $env:APPVEYOR_REPO_COMMIT_AUTHOR --commitEmail $env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL --commitMessage $env:APPVEYOR_REPO_COMMIT_MESSAGE --jobId $env:APPVEYOR_BUILD_NUMBER --serviceName appveyor From 04f5fd5f0110cfad0d99808abd7af19f759ff0b9 Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Tue, 5 Mar 2019 14:26:33 +0100 Subject: [PATCH 05/10] Updated "coveralls.net" version="1.0.0" --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index faae5fc86..b7de09cfe 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -70,7 +70,7 @@ before_build: .\.nuget\nuget restore - dotnet tool install coveralls.net --version 1.0.0 --tool-path packages + dotnet tool install coveralls.net --tool-path packages build: project: TestFramework.sln From 80cc01d87239c42cbb866fd2f881476460788d9e Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Thu, 7 Mar 2019 15:33:23 +0100 Subject: [PATCH 06/10] Added setting of internetExplorer preferences, fixes #95 --- .../DriverContextHelper.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Objectivity.Test.Automation.Common/DriverContextHelper.cs b/Objectivity.Test.Automation.Common/DriverContextHelper.cs index 4ff1d5952..28fdc221f 100644 --- a/Objectivity.Test.Automation.Common/DriverContextHelper.cs +++ b/Objectivity.Test.Automation.Common/DriverContextHelper.cs @@ -350,6 +350,26 @@ private void GetInternetExplorerPreferences(NameValueCollection internetExplorer case "InitialBrowserUrl": options.InitialBrowserUrl = Convert.ToString(internetExplorerPreferences[i], CultureInfo.CurrentCulture); break; + + case "BrowserAttachTimeout": + options.BrowserAttachTimeout = TimeSpan.FromSeconds(Convert.ToDouble(internetExplorerPreferences[i], CultureInfo.CurrentCulture)); + break; + + case "ForceCreateProcessApi": + options.ForceCreateProcessApi = Convert.ToBoolean(internetExplorerPreferences[i], CultureInfo.CurrentCulture); + break; + + case "ForceShellWindowsApi": + options.ForceShellWindowsApi = Convert.ToBoolean(internetExplorerPreferences[i], CultureInfo.CurrentCulture); + break; + + case "UsePerProcessProxy": + options.UsePerProcessProxy = Convert.ToBoolean(internetExplorerPreferences[i], CultureInfo.CurrentCulture); + break; + + case "FileUploadDialogTimeout": + options.FileUploadDialogTimeout = TimeSpan.FromSeconds(Convert.ToDouble(internetExplorerPreferences[i], CultureInfo.CurrentCulture)); + break; } } } From c1f161e3ffc7945d41a3d72710022433a8ed604c Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Thu, 7 Mar 2019 15:54:59 +0100 Subject: [PATCH 07/10] fixed small build issue --- Objectivity.Test.Automation.Common/DriverContextHelper.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Objectivity.Test.Automation.Common/DriverContextHelper.cs b/Objectivity.Test.Automation.Common/DriverContextHelper.cs index 28fdc221f..ff280c3bf 100644 --- a/Objectivity.Test.Automation.Common/DriverContextHelper.cs +++ b/Objectivity.Test.Automation.Common/DriverContextHelper.cs @@ -309,6 +309,7 @@ private void SetRemoteDriverBrowserOptions(NameValueCollection driverCapabilitie } } + [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Loop through all internetExplorerPreferences")] private void GetInternetExplorerPreferences(NameValueCollection internetExplorerPreferences, InternetExplorerOptions options) { // loop through all of them From c74f1bc27b039f118372504947b601db0ac10581 Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Fri, 8 Mar 2019 09:05:46 +0100 Subject: [PATCH 08/10] removed unused CrossBrowserProfile property --- Objectivity.Test.Automation.Common/DriverContext.cs | 5 ----- .../App.config | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Objectivity.Test.Automation.Common/DriverContext.cs b/Objectivity.Test.Automation.Common/DriverContext.cs index fadc58345..837ae9b93 100644 --- a/Objectivity.Test.Automation.Common/DriverContext.cs +++ b/Objectivity.Test.Automation.Common/DriverContext.cs @@ -82,11 +82,6 @@ public partial class DriverContext /// public string TestTitle { get; set; } - /// - /// Gets or sets the CrossBrowserProfile from App.config - /// - public string CrossBrowserProfile { get; set; } - /// /// Gets or sets the Environment Browsers from App.config /// diff --git a/Objectivity.Test.Automation.Tests.CloudProviderCrossBrowser/App.config b/Objectivity.Test.Automation.Tests.CloudProviderCrossBrowser/App.config index f830078a0..6fd674140 100644 --- a/Objectivity.Test.Automation.Tests.CloudProviderCrossBrowser/App.config +++ b/Objectivity.Test.Automation.Tests.CloudProviderCrossBrowser/App.config @@ -94,6 +94,7 @@ + saucelabs Settings/--> From 7bc8acbe15827fdf5a17c907d08378d073560be9 Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Thu, 28 Mar 2019 10:07:32 +0100 Subject: [PATCH 09/10] Fixed problem with out of memory exception in method TakeScreenShotOfElement --- .../Helpers/TakeScreenShot.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs b/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs index 595ad451c..c9784b61c 100644 --- a/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs +++ b/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs @@ -166,8 +166,19 @@ public static string TakeScreenShotOfElement(int iframeLocationX, int iframeLoca Logger.Debug(CultureInfo.CurrentCulture, "Cutting out screenshot of element locationX:{0} locationY:{1} elementWidth:{2} elementHeight:{3}", locationX, locationY, elementWidth, elementHeight); - var image = new Rectangle(locationX, locationY, elementWidth, elementHeight); var importFile = new Bitmap(filePath); + ////Check if new size of image is not bigger than imported. + if (importFile.Size.Height - locationY < elementHeight) + { + elementHeight = importFile.Size.Height - locationY; + } + + if (importFile.Size.Width - locationX < elementWidth) + { + elementHeight = importFile.Size.Height - locationX; + } + + var image = new Rectangle(locationX, locationY, elementWidth, elementHeight); string newFilePath; Bitmap cloneFile; try From 894f8ad5cc918e04a582b018bebeee92089ea2e2 Mon Sep 17 00:00:00 2001 From: Jakub Raczek Date: Thu, 28 Mar 2019 10:24:15 +0100 Subject: [PATCH 10/10] Fixed small build issue --- .../Helpers/TakeScreenShot.cs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs b/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs index c9784b61c..1511d32cb 100644 --- a/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs +++ b/Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs @@ -166,29 +166,30 @@ public static string TakeScreenShotOfElement(int iframeLocationX, int iframeLoca Logger.Debug(CultureInfo.CurrentCulture, "Cutting out screenshot of element locationX:{0} locationY:{1} elementWidth:{2} elementHeight:{3}", locationX, locationY, elementWidth, elementHeight); - var importFile = new Bitmap(filePath); - ////Check if new size of image is not bigger than imported. - if (importFile.Size.Height - locationY < elementHeight) - { - elementHeight = importFile.Size.Height - locationY; - } - - if (importFile.Size.Width - locationX < elementWidth) - { - elementHeight = importFile.Size.Height - locationX; - } - - var image = new Rectangle(locationX, locationY, elementWidth, elementHeight); string newFilePath; + Bitmap importFile = null; Bitmap cloneFile; try { + importFile = new Bitmap(filePath); + ////Check if new size of image is not bigger than imported. + if (importFile.Size.Height - locationY < elementHeight) + { + elementHeight = importFile.Size.Height - locationY; + } + + if (importFile.Size.Width - locationX < elementWidth) + { + elementWidth = importFile.Size.Width - locationX; + } + + var image = new Rectangle(locationX, locationY, elementWidth, elementHeight); newFilePath = Path.Combine(folder, screenshotName + ".png"); cloneFile = (Bitmap)importFile.Clone(image, importFile.PixelFormat); } finally { - importFile.Dispose(); + importFile?.Dispose(); } Logger.Debug(CultureInfo.CurrentCulture, "Saving screenshot of element {0}", newFilePath);