Skip to content

Commit

Permalink
Merge pull request #63 from ObjectivityLtd/3.1.1
Browse files Browse the repository at this point in the history
3.1.1
  • Loading branch information
bglubiak authored Feb 21, 2018
2 parents 28ceb71 + ffdbaf0 commit 268f8d7
Show file tree
Hide file tree
Showing 41 changed files with 893 additions and 170 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ TestFramework.sln.DotSettings.user
/Objectivity.Test.Automation.Tests.Features/TestFeatures/*.feature.cs
*.user
LastBuild.log
/Objectivity.Test.Automation.Common.Documentation/Help
/TestResult.xml
/myresults.xml
/opencoverCoverage.xml
/.nuget/NuGet.exe
3 changes: 3 additions & 0 deletions Objectivity.Test.Automation.Common/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<add key="FullDesktopScreenShotEnabled" value="true"/>
<add key="SeleniumScreenShotEnabled" value="true"/>
<add key="GetPageSourceEnabled" value="true"/>
<add key="JavaScriptErrorLogging" value="true"/>
<!--JavaScript errors type to be search on browser logs-->
<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-->
<add key="SynchronizationWithAngularEnabled" value="false"/>
<!--Use default firefox profile?-->
Expand Down
53 changes: 51 additions & 2 deletions Objectivity.Test.Automation.Common/BaseConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
namespace Objectivity.Test.Automation.Common
{
using System;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Globalization;

using NLog;
using OpenQA.Selenium.Remote;

/// <summary>
/// SeleniumConfiguration that consume app.config file <see href="https://github.com/ObjectivityLtd/Test.Automation/wiki/Description%20of%20App.config%20file">More details on wiki</see>
Expand Down Expand Up @@ -245,6 +244,56 @@ public static bool FullDesktopScreenShotEnabled
}
}

/// <summary>
/// Gets a value indicating whether logs JavaScript errors from a browser. False by default.
/// </summary>
public static bool JavaScriptErrorLogging
{
get
{
Logger.Trace(CultureInfo.CurrentCulture, "JavaScript error logging value from App.config '{0}'", ConfigurationManager.AppSettings["JavaScriptErrorLogging"]);
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["JavaScriptErrorLogging"]))
{
return false;
}

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

return false;
}
}

/// <summary>
/// Gets JavaScript error types from a browser. "SyntaxError,EvalError,ReferenceError,RangeError,TypeError,URIError,Refused to display,Internal Server Error,Cannot read property" by default.
/// </summary>
public static Collection<string> JavaScriptErrorTypes
{
get
{
Logger.Trace(CultureInfo.CurrentCulture, "JavaScript error logging value from App.config '{0}'", ConfigurationManager.AppSettings["JavaScriptErrorTypes"]);
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["JavaScriptErrorTypes"]))
{
return new Collection<string>
{
"SyntaxError",
"EvalError",
"ReferenceError",
"RangeError",
"TypeError",
"URIError",
"Refused to display",
"Internal Server Error",
"Cannot read property"
};
}

return new Collection<string>(ConfigurationManager.AppSettings["JavaScriptErrorTypes"].Split(new char[] { ',' }));
}
}

/// <summary>
/// Gets a value indicating whether enable legacy implementation for Firefox.
/// </summary>
Expand Down
26 changes: 26 additions & 0 deletions Objectivity.Test.Automation.Common/DriverContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,32 @@ public string[] TakeAndSaveScreenshot()
return filePaths.ToArray();
}

/// <summary>
/// Logs JavaScript errors
/// </summary>
/// <returns>True if Javascript errors found</returns>
public bool LogJavaScriptErrors()
{
IEnumerable<LogEntry> jsErrors = null;
bool javScriptErrors = false;

// Check JavaScript browser logs for errors.
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)));

if (jsErrors.Any())
{
// Show JavaScript erros 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;
}

/// <summary>
/// Set web driver capabilities.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.34.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.34.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
</Target>
<Import Project="..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.34.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.34.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
2 changes: 1 addition & 1 deletion Objectivity.Test.Automation.Common/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<package id="PhantomJS" version="2.1.1" targetFramework="net40" />
<package id="Selenium.Support" version="3.8.0" targetFramework="net45" />
<package id="Selenium.WebDriver" version="3.8.0" targetFramework="net45" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.34.0" targetFramework="net45" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.35.0" targetFramework="net45" />
<package id="Selenium.WebDriver.GeckoDriver" version="0.19.1" targetFramework="net45" />
<package id="Selenium.WebDriver.IEDriver" version="3.8.0" targetFramework="net45" />
<package id="StyleCop.Analyzers" version="1.0.2" targetFramework="net45" developmentDependency="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.34.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.34.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
</Target>
<Import Project="..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.34.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.34.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
2 changes: 1 addition & 1 deletion Objectivity.Test.Automation.Tests.Angular/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<package id="PhantomJS" version="2.1.1" targetFramework="net452" />
<package id="Selenium.Support" version="3.8.0" targetFramework="net452" />
<package id="Selenium.WebDriver" version="3.8.0" targetFramework="net452" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.34.0" targetFramework="net452" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.35.0" targetFramework="net452" />
<package id="Selenium.WebDriver.GeckoDriver" version="0.19.1" targetFramework="net452" />
<package id="Selenium.WebDriver.IEDriver" version="3.8.0" targetFramework="net452" />
</packages>
3 changes: 3 additions & 0 deletions Objectivity.Test.Automation.Tests.Features/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<add key="FullDesktopScreenShotEnabled" value="true" />
<add key="SeleniumScreenShotEnabled" value="true" />
<add key="GetPageSourceEnabled" value="true" />
<add key="JavaScriptErrorLogging" value="true" />
<!--JavaScript errors type to be search on browser logs-->
<add key="JavaScriptErrorTypes" value="SyntaxError,EvalError,ReferenceError,RangeError,TypeError,URIError,Refused to display,Internal Server Error,Cannot read property" />
<!--Use default firefox profile?-->
<add key="UseDefaultFirefoxProfile" value="false" />
<add key="PathToFirefoxProfile" value="C:\Users\ci_objectivity\AppData\Roaming\Mozilla\Firefox\Profiles" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<RestorePackages>true</RestorePackages>
<StyleCopOverrideSettingsFile>Settings.StyleCop</StyleCopOverrideSettingsFile>
<BuildToolsStyleCopVersion>4.7.44.0</BuildToolsStyleCopVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -125,7 +127,13 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets'))" />
</Target>
<Import Project="..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets')" />
<!--Import Project="..\packages\SpecFlow.1.9.0\tools\TechTalk.SpecFlow.targets" /-->
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
6 changes: 6 additions & 0 deletions Objectivity.Test.Automation.Tests.Features/ProjectTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,17 @@ public void AfterTest()
this.DriverContext.IsTestFailed = this.scenarioContext.TestError != null || !this.driverContext.VerifyMessages.Count.Equals(0);
var filePaths = this.SaveTestDetailsIfTestFailed(this.driverContext);
this.SaveAttachmentsToTestContext(filePaths);
var javaScriptErrors = this.DriverContext.LogJavaScriptErrors();
this.DriverContext.Stop();
this.LogTest.LogTestEnding(this.driverContext);
if (this.IsVerifyFailedAndClearMessages(this.driverContext) && this.scenarioContext.TestError == null)
{
Assert.Fail();
}

if (javaScriptErrors)
{
Assert.Fail("JavaScript errors found. See the logs for details");
}
}

Expand Down
3 changes: 3 additions & 0 deletions Objectivity.Test.Automation.Tests.Features/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<package id="NUnit.Extension.TeamCityEventListener" version="1.0.3" targetFramework="net45" />
<package id="NUnit.Extension.VSProjectLoader" version="3.7.0" targetFramework="net45" />
<package id="NUnit.Runners" version="3.7.0" targetFramework="net45" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.35.0" targetFramework="net45" />
<package id="Selenium.WebDriver.GeckoDriver" version="0.19.1" targetFramework="net45" />
<package id="Selenium.WebDriver.IEDriver" version="3.8.0" targetFramework="net45" />
<package id="SpecFlow" version="2.2.0" targetFramework="net45" />
<package id="StyleCop.Analyzers" version="1.0.2" targetFramework="net45" developmentDependency="true" />
</packages>
3 changes: 3 additions & 0 deletions Objectivity.Test.Automation.Tests.MsTest/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<add key="FullDesktopScreenShotEnabled" value="true"/>
<add key="SeleniumScreenShotEnabled" value="true"/>
<add key="GetPageSourceEnabled" value="true"/>
<add key="JavaScriptErrorLogging" value="true"/>
<!--JavaScript errors type to be search on browser logs-->
<add key="JavaScriptErrorTypes" value="SyntaxError,EvalError,ReferenceError,RangeError,TypeError,URIError,Refused to display,Internal Server Error,Cannot read property" />
<!--Use default firefox profile?-->
<add key="UseDefaultFirefoxProfile" value="false"/>
<add key="PathToFirefoxProfile" value="C:\Users\ci_objectivity\AppData\Roaming\Mozilla\Firefox\Profiles"/>
Expand Down
3 changes: 3 additions & 0 deletions Objectivity.Test.Automation.Tests.MsTest/DDT.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user, password, message
tomsmith,SuperSecretPassword!,You logged into a secure area!
wronguser,wrongpassword,Your username is invalid!
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="DDT.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="NLog.xsd">
<SubType>Designer</SubType>
</None>
Expand Down Expand Up @@ -137,7 +140,13 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
</Target>
<Import Project="..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.19.1\build\Selenium.WebDriver.GeckoDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.IEDriver.3.8.0\build\Selenium.WebDriver.IEDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.35.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
6 changes: 6 additions & 0 deletions Objectivity.Test.Automation.Tests.MsTest/ProjectTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,18 @@ public void AfterTest()
this.DriverContext.IsTestFailed = this.TestContext.CurrentTestOutcome == UnitTestOutcome.Failed || !this.driverContext.VerifyMessages.Count.Equals(0);
var filePaths = this.SaveTestDetailsIfTestFailed(this.driverContext);
this.SaveAttachmentsToTestContext(filePaths);
var javaScriptErrors = this.DriverContext.LogJavaScriptErrors();
this.DriverContext.Stop();
this.LogTest.LogTestEnding(this.driverContext);
if (this.IsVerifyFailedAndClearMessages(this.driverContext) && this.TestContext.CurrentTestOutcome != UnitTestOutcome.Failed)
{
Assert.Fail("Look at stack trace logs for more details");
}

if (javaScriptErrors)
{
Assert.Fail("JavaScript errors found. See the logs for details");
}
}

private void SaveAttachmentsToTestContext(string[] filePaths)
Expand Down
Loading

0 comments on commit 268f8d7

Please sign in to comment.