Skip to content

Commit

Permalink
Merge pull request #66 from ObjectivityLtd/3.1.2
Browse files Browse the repository at this point in the history
3.1.2
  • Loading branch information
raczeja authored Mar 19, 2018
2 parents 268f8d7 + 641eb18 commit a9160c6
Show file tree
Hide file tree
Showing 53 changed files with 488 additions and 288 deletions.
2 changes: 1 addition & 1 deletion .nuspec/Objectivity.Test.Automation.Features.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<tags>selenium webdriver testautomation tests specflow Objectivity.Test.Automation.Common template</tags>
<dependencies>
<dependency id="SpecFlow" version="2.2.0"/>
<dependency id="NUnit" version="3.9.0" />
<dependency id="NUnit" version="3.10.1" />
<dependency id="NUnit.ConsoleRunner" version="3.7.0" />
</dependencies>
</metadata>
Expand Down
10 changes: 5 additions & 5 deletions .nuspec/Objectivity.Test.Automation.Nunit.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
<copyright>Copyright 2015</copyright>
<tags>selenium webdriver testautomation tests nunit Objectivity.Test.Automation.Common</tags>
<dependencies>
<dependency id="NUnit" version="3.9.0" />
<dependency id="NUnit.ConsoleRunner" version="3.7.0" />
<dependency id="NUnit.Runners" version="3.7.0" />
<dependency id="NUnit" version="3.10.1" />
<dependency id="NUnit.ConsoleRunner" version="3.8.0" />
<dependency id="NUnit.Runners" version="3.8.0" />
<dependency id="NUnit.Extension.NUnitProjectLoader" version="3.6.0" />
<dependency id="NUnit.Extension.NUnitV2Driver" version="3.7.0" />
<dependency id="NUnit.Extension.NUnitV2ResultWriter" version="3.6.0" />
<dependency id="NUnit.Extension.VSProjectLoader" version="3.6.0" />
<dependency id="NUnit.Extension.TeamCityEventListener" version="1.0.2" />
<dependency id="NUnit.Extension.VSProjectLoader" version="3.7.0" />
<dependency id="NUnit.Extension.TeamCityEventListener" version="1.0.3" />
</dependencies>
</metadata>
<files>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
<Argument Key="maxVersionParts" Value="" xmlns="" />
</TransformComponentArguments>
<DocumentationSources>
<DocumentationSource sourceFile="..\packages\Selenium.WebDriver.3.8.0\lib\net45\WebDriver.dll" />
<DocumentationSource sourceFile="..\packages\Selenium.WebDriver.3.8.0\lib\net45\WebDriver.xml" />
<DocumentationSource sourceFile="..\packages\Selenium.Support.3.8.0\lib\net45\WebDriver.Support.dll" />
<DocumentationSource sourceFile="..\packages\Selenium.Support.3.8.0\lib\net45\WebDriver.Support.xml" /></DocumentationSources>
<DocumentationSource sourceFile="..\packages\Selenium.WebDriver.3.11.0\lib\net45\WebDriver.dll" />
<DocumentationSource sourceFile="..\packages\Selenium.WebDriver.3.11.0\lib\net45\WebDriver.xml" />
<DocumentationSource sourceFile="..\packages\Selenium.Support.3.11.0\lib\net45\WebDriver.Support.dll" />
<DocumentationSource sourceFile="..\packages\Selenium.Support.3.11.0\lib\net45\WebDriver.Support.xml" /></DocumentationSources>
<SaveComponentCacheCapacity>100</SaveComponentCacheCapacity>
<BuildAssemblerVerbosity>OnlyWarningsAndErrors</BuildAssemblerVerbosity>
<HelpFileFormat>Website</HelpFileFormat>
Expand Down
6 changes: 4 additions & 2 deletions Objectivity.Test.Automation.Common/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<section name="ChromeExtensions" type="System.Configuration.NameValueSectionHandler"/>
<section name="DriverCapabilities" type="System.Configuration.NameValueSectionHandler"/>
<section name="ChromeArguments" type="System.Configuration.NameValueSectionHandler"/>
<section name="InternetExplorerPreferences" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
<appSettings>
<!--mandatory keys-->
Expand All @@ -18,12 +19,10 @@
<!--<add key="browser" value="InternetExplorer" />-->
<!--<add key="browser" value="FirefoxPortable" />-->
<!--<add key="browser" value="Safari" />-->
<!--<add key="browser" value="PhantomJs" />-->
<!--<add key="browser" value="RemoteWebDriver" />-->
<add key="browser" value="Firefox"/>
<add key="FirefoxUseLegacyImplementation" value="false"/>
<add key="FireFoxPath" value="\..\..\..\FirefoxPortable\FirefoxPortable.exe"/>
<add key="PhantomJsPath" value="\..\..\..\packages\PhantomJS.2.1.1\tools\phantomjs\"/>
<add key="RemoteWebDriverHub" value="http://localhost:4444/wd/hub"/>
<add key="DriverCapabilities" value="Firefox"/>
<!--<add key="proxy" value="127.0.0.1:9999" />-->
Expand Down Expand Up @@ -89,4 +88,7 @@
<ChromeArguments>
<!--<add key="ChromeArgument" value=""/>-->
</ChromeArguments>
<InternetExplorerPreferences>
<!--<add key="InternetExplorerArgument" value=""/>-->
</InternetExplorerPreferences>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
11 changes: 0 additions & 11 deletions Objectivity.Test.Automation.Common/BaseConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,6 @@ public static string ChromePath
}
}

/// <summary>
/// Gets the PhantomJs path
/// </summary>
public static string PhantomJsPath
{
get
{
return ConfigurationManager.AppSettings["PhantomJsPath"];
}
}

/// <summary>
/// Gets the Remote Web Driver hub url
/// </summary>
Expand Down
7 changes: 1 addition & 6 deletions Objectivity.Test.Automation.Common/BrowserType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ public enum BrowserType
/// <summary>
/// Chrome browser
/// </summary>
Chrome,

/// <summary>
/// PhantomJs browser
/// </summary>
PhantomJs,
Chrome,

/// <summary>
/// Safari browser
Expand Down
47 changes: 42 additions & 5 deletions Objectivity.Test.Automation.Common/DriverContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ namespace Objectivity.Test.Automation.Common
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.PhantomJS;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Safari;

Expand Down Expand Up @@ -71,6 +70,11 @@ public class DriverContext
/// </summary>
public event EventHandler<CapabilitiesSetEventArgs> CapabilitiesSet;

/// <summary>
/// Gets instance of Performance PerformanceMeasures class
/// </summary>
public PerformanceHelper PerformanceMeasures { get; } = new PerformanceHelper();

/// <summary>
/// Gets or sets the test title.
/// </summary>
Expand Down Expand Up @@ -370,12 +374,37 @@ private InternetExplorerOptions InternetExplorerProfile
{
get
{
// retrieving settings from config file
var internetExplorerPreferences = ConfigurationManager.GetSection("InternetExplorerPreferences") as NameValueCollection;
var options = new InternetExplorerOptions
{
EnsureCleanSession = true,
IgnoreZoomLevel = true,
};

// custom preferences
// if there are any settings
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;
}
}
}

// set browser proxy for IE
if (!string.IsNullOrEmpty(BaseConfiguration.Proxy))
{
Expand Down Expand Up @@ -483,9 +512,6 @@ public void Start()
case BrowserType.Safari:
this.driver = new SafariDriver(this.SafariProfile);
break;
case BrowserType.PhantomJs:
this.driver = new PhantomJSDriver(this.CurrentDirectory + BaseConfiguration.PhantomJsPath);
break;
case BrowserType.RemoteWebDriver:
case BrowserType.BrowserStack:
this.driver = new RemoteWebDriver(BaseConfiguration.RemoteWebDriverHub, this.SetCapabilities());
Expand Down Expand Up @@ -630,7 +656,18 @@ public bool LogJavaScriptErrors()
if (BaseConfiguration.JavaScriptErrorLogging)
{
Logger.Debug(CultureInfo.CurrentCulture, "Checking JavaScript error(s) in browser");
jsErrors = this.driver.Manage().Logs.GetLog(LogType.Browser).Where(x => BaseConfiguration.JavaScriptErrorTypes.Any(e => x.Message.Contains(e)));
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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,6 @@ public static void NavigateTo(this IWebDriver webDriver, Uri url)
ApproveCertificateForInternetExplorer(webDriver);
}

/// <summary>
/// Navigates to given url and measure time for this action including or not Ajax.
/// </summary>
/// <example>Sample confirmation for java script alert: <code>
/// this.Driver.NavigateToAndMeasureTime("http://objectivity.co.uk", waitForAjax: true);
/// </code></example>
/// <param name="webDriver">The web driver.</param>
/// <param name="url">The URL.</param>
/// <param name="waitForAjax">Wait or not for Ajax</param>
public static void NavigateToAndMeasureTime(this IWebDriver webDriver, Uri url, bool waitForAjax)
{
PerformanceHelper.Instance.StartMeasure();
webDriver.Navigate().GoToUrl(url);
if (waitForAjax)
{
webDriver.WaitForAjax();
}

PerformanceHelper.Instance.StopMeasure(url.AbsolutePath);
}

/// <summary>
/// Waits for all ajax actions to be completed.
/// </summary>
Expand Down
74 changes: 25 additions & 49 deletions Objectivity.Test.Automation.Common/Helpers/PerformanceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ namespace Objectivity.Test.Automation.Common.Helpers
using System.Diagnostics;
using System.Globalization;
using System.Linq;

using NLog;

using Objectivity.Test.Automation.Common.Types;

/// <summary>
Expand Down Expand Up @@ -59,17 +57,35 @@ public PerformanceHelper()
}

/// <summary>
/// Gets or sets the performance manager.
/// Gets the scenario list
/// </summary>
/// <value>
/// The performance manager.
/// </value>
public static PerformanceHelper Instance { get; set; }
public IList<SavedTimes> GetloadTimeList => this.loadTimeList;

/// <summary>
/// Gets the scenario list
/// Gets all the durations milliseconds.
/// </summary>
public IList<SavedTimes> GetloadTimeList => this.loadTimeList;
/// <returns>Return average load times for particular scenarios and browsers.</returns>
public IEnumerable<AverageGroupedTimes> AllGroupedDurationsMilliseconds
{
get
{
var groupedList =
this.loadTimeList.OrderBy(dur => dur.Duration).GroupBy(
st => new { st.Scenario, BName = st.BrowserName },
(key, g) =>
{
var savedTimeses = g as IList<SavedTimes> ?? g.ToList();
return new AverageGroupedTimes
{
StepName = key.Scenario,
Browser = key.BName,
AverageDuration = Math.Round(savedTimeses.Average(dur => dur.Duration)),
Percentile90 = savedTimeses[(int)(Math.Ceiling(savedTimeses.Count * 0.9) - 1)].Duration
};
}).ToList().OrderBy(listElement => listElement.StepName);
return groupedList;
}
}

/// <summary>
/// Gets or sets measured time.
Expand Down Expand Up @@ -102,45 +118,5 @@ public void StopMeasure(string title)

this.loadTimeList.Add(savedTimes);
}

/// <summary>
/// Prints the performance summary.
/// </summary>
/// TODO: Decide what parameters must be printed
public void PrintAveragePercentiles90DurationMilliseconds()
{
var groupedDurations = this.AllGroupedDurationsMilliseconds().Select(v =>
"##teamcity[testStarted name='" + v.StepName + "." + v.Browser + ".Average']\n" +
"##teamcity[testFinished name='" + v.StepName + "." + v.Browser + ".Average' duration='" + v.AverageDuration + "']\n" +
"##teamcity[testStarted name='" + v.StepName + "." + v.Browser + ".Percentile90Line']\n" +
"##teamcity[testFinished name='" + v.StepName + "." + v.Browser + ".Percentile90Line' duration='" + v.Percentile90 + "']\n" +
v.StepName + " " + v.Browser + " Average: " + v.AverageDuration + "\n" +
v.StepName + " " + v.Browser + " Percentile90Line: " + v.Percentile90);

groupedDurations.ToList().ForEach(Console.WriteLine);
}

/// <summary>
/// All the durations milliseconds.
/// </summary>
/// <returns>Return average load times for particular scenarios and browsers.</returns>
private IEnumerable<AverageGroupedTimes> AllGroupedDurationsMilliseconds()
{
var groupedList =
this.loadTimeList.OrderBy(dur => dur.Duration).GroupBy(
st => new { st.Scenario, BName = st.BrowserName },
(key, g) =>
{
var savedTimeses = g as IList<SavedTimes> ?? g.ToList();
return new AverageGroupedTimes
{
StepName = key.Scenario,
Browser = key.BName,
AverageDuration = Math.Round(savedTimeses.Average(dur => dur.Duration)),
Percentile90 = savedTimeses[(int)(Math.Ceiling(savedTimeses.Count * 0.9) - 1)].Duration
};
}).ToList().OrderBy(listElement => listElement.StepName);
return groupedList;
}
}
}
Loading

0 comments on commit a9160c6

Please sign in to comment.