Skip to content

Commit

Permalink
Merge pull request #58 from ObjectivityLtd/3.0.9
Browse files Browse the repository at this point in the history
3.0.9
  • Loading branch information
raczeja authored Sep 19, 2017
2 parents 3019b27 + f94b1dd commit f809a09
Show file tree
Hide file tree
Showing 34 changed files with 532 additions and 69 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.7.1" />
<dependency id="NUnit" version="3.8.1" />
<dependency id="NUnit.ConsoleRunner" version="3.7.0" />
</dependencies>
</metadata>
Expand Down
6 changes: 3 additions & 3 deletions .nuspec/Objectivity.Test.Automation.Nunit.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<copyright>Copyright 2015</copyright>
<tags>selenium webdriver testautomation tests nunit Objectivity.Test.Automation.Common</tags>
<dependencies>
<dependency id="NUnit" version="3.7.1" />
<dependency id="NUnit" version="3.8.1" />
<dependency id="NUnit.ConsoleRunner" version="3.7.0" />
<dependency id="NUnit.Runners" version="3.7.0" />
<dependency id="NUnit.Extension.NUnitProjectLoader" version="3.6.0" />
<dependency id="NUnit.Extension.NUnitV2Driver" version="3.6.0" />
<dependency id="NUnit.Extension.NUnitV2ResultWriter" version="3.5.0" />
<dependency id="NUnit.Extension.VSProjectLoader" version="3.5.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" />
</dependencies>
</metadata>
Expand Down
18 changes: 14 additions & 4 deletions Objectivity.Test.Automation.Common/DriverContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,14 @@ public void WindowMaximize()
this.driver.Manage().Window.Maximize();
}

/// <summary>
/// Deletes all cookies from the page.
/// </summary>
public void DeleteAllCookies()
{
this.driver.Manage().Cookies.DeleteAllCookies();
}

/// <summary>
/// Stop browser instance.
/// </summary>
Expand Down Expand Up @@ -509,8 +517,9 @@ public string SaveScreenshot(ErrorDetail errorDetail, string folder, string titl
try
{
errorDetail.Screenshot.SaveAsFile(filePath, ScreenshotImageFormat.Png);
FilesHelper.WaitForFileOfGivenName(BaseConfiguration.ShortTimeout, correctFileName, folder);
Logger.Error(CultureInfo.CurrentCulture, "Test failed: screenshot saved to {0}.", filePath);
Logger.Info(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath);
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath));
return filePath;
}
catch (NullReferenceException)
Expand All @@ -532,7 +541,8 @@ public string SavePageSource(string fileName)
{
var fileNameShort = Regex.Replace(fileName, "[^0-9a-zA-Z._]+", "_");
fileNameShort = NameHelper.ShortenFileName(this.PageSourceFolder, fileNameShort, "_", 255);
var path = Path.Combine(this.PageSourceFolder, string.Format(CultureInfo.CurrentCulture, "{0}{1}", fileNameShort, ".html"));
var fileNameWithExtension = string.Format(CultureInfo.CurrentCulture, "{0}{1}", fileNameShort, ".html");
var path = Path.Combine(this.PageSourceFolder, fileNameWithExtension);
if (File.Exists(path))
{
File.Delete(path);
Expand All @@ -541,9 +551,9 @@ public string SavePageSource(string fileName)
var pageSource = this.driver.PageSource;
pageSource = pageSource.Replace("<head>", string.Format(CultureInfo.CurrentCulture, "<head><base href=\"http://{0}\" target=\"_blank\">", 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);
Logger.Info(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", path);
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", path));
return path;
}

Expand Down
69 changes: 69 additions & 0 deletions Objectivity.Test.Automation.Common/DriversCustomSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// <copyright file="DriversCustomSettings.cs" company="Objectivity Bespoke Software Specialists">
// Copyright (c) Objectivity Bespoke Software Specialists. All rights reserved.
// </copyright>
// <license>
// 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.
// </license>

namespace Objectivity.Test.Automation.Common
{
using System.Collections.Generic;
using OpenQA.Selenium;

/// <summary>
/// To keep drivers custom setting
/// </summary>
public static class DriversCustomSettings
{
private static Dictionary<IWebDriver, bool> driversAngularSynchronizationEnable =
new Dictionary<IWebDriver, bool>();

/// <summary>
/// Method return true or false is driver is synchronized with angular.
/// </summary>
/// <param name="driver">Provide driver.</param>
/// <returns>If driver is synchornized with angular return true if not return false.</returns>
public static bool IsDriverSynchronizationWithAngular(IWebDriver driver)
{
return driversAngularSynchronizationEnable.ContainsKey(driver) && driversAngularSynchronizationEnable[driver];
}

/// <summary>
/// Set angular synchronization for driver.
/// </summary>
/// <param name="driver">Provide driver.</param>
/// <param name="enable">Set true to enable.</param>
public static void SetAngularSynchronizationForDriver(IWebDriver driver, bool enable)
{
if (enable == false && driversAngularSynchronizationEnable.ContainsKey(driver))
{
driversAngularSynchronizationEnable.Remove(driver);
}

if (enable && !driversAngularSynchronizationEnable.ContainsKey(driver))
{
driversAngularSynchronizationEnable.Add(driver, true);
}

if (enable && driversAngularSynchronizationEnable.ContainsKey(driver))
{
driversAngularSynchronizationEnable[driver] = true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@ public static IWebElement GetElement(this ISearchContext element, ElementLocator
/// </code></example>
public static IWebElement GetElement(this ISearchContext element, ElementLocator locator, double timeout, Func<IWebElement, bool> condition, [Optional] string customMessage)
{
if (BaseConfiguration.SynchronizationWithAngularEnabled)
var driver = element.ToDriver();
if (DriversCustomSettings.IsDriverSynchronizationWithAngular(driver))
{
element.ToDriver().WaitForAngular();
driver.WaitForAngular();
}

var by = locator.ToBy();

var wait = new WebDriverWait(element.ToDriver(), TimeSpan.FromSeconds(timeout)) { Message = customMessage };
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout)) { Message = customMessage };
wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException));

wait.Until(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// <copyright file="WebDriverExtensions.cs" company="Objectivity Bespoke Software Specialists">
// Copyright (c) Objectivity Bespoke Software Specialists. All rights reserved.
// </copyright>
// <license>
// 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.
// </copyright>
// <license>
// 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.
// </license>

namespace Objectivity.Test.Automation.Common.Extensions
Expand Down Expand Up @@ -323,6 +323,16 @@ public static void WaitForAngular(this IWebDriver webDriver, double timeout)
}
}

/// <summary>
/// Enable synchronization with angular.
/// </summary>
/// <param name="webDriver">The WebDriver.</param>
/// <param name="enable">Enable or disable synchronization.</param>
public static void SynchronizeWithAngular(this IWebDriver webDriver, bool enable)
{
DriversCustomSettings.SetAngularSynchronizationForDriver(webDriver, enable);
}

/// <summary>
/// Approves the trust certificate for internet explorer.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Objectivity.Test.Automation.Common/Helpers/TakeScreenShot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public static string Save(Bitmap bitmap, ImageFormat format, string folder, stri
bitmap.Save(filePath, format);
bitmap.Dispose();
Logger.Error(CultureInfo.CurrentCulture, "Test failed: full screenshot saved to {0}.", filePath);
Logger.Info(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath);
FilesHelper.WaitForFileOfGivenName(BaseConfiguration.ShortTimeout, fileName, folder);
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "##teamcity[publishArtifacts '{0}']", filePath));
return filePath;
}

Expand Down
4 changes: 3 additions & 1 deletion Objectivity.Test.Automation.Common/Helpers/WaitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public static void Wait(Func<bool> condition, TimeSpan timeout, TimeSpan sleepIn
/// </code></example>
public static bool Wait(Func<bool> condition, TimeSpan timeout, TimeSpan sleepInterval)
{
var result = false;
var start = DateTime.Now;
var canceller = new CancellationTokenSource();
var task = Task.Factory.StartNew(condition, canceller.Token);
Expand All @@ -124,6 +125,7 @@ public static bool Wait(Func<bool> condition, TimeSpan timeout, TimeSpan sleepIn
{
if (task.Result)
{
result = true;
canceller.Cancel();
break;
}
Expand All @@ -143,7 +145,7 @@ public static bool Wait(Func<bool> condition, TimeSpan timeout, TimeSpan sleepIn
}

canceller.Cancel();
return false;
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Compile Include="CapabilitiesSetEventArgs.cs" />
<Compile Include="BrowserType.cs" />
<Compile Include="DriverContext.cs" />
<Compile Include="DriversCustomSettings.cs" />
<Compile Include="Exceptions\WaitTimeoutException.cs" />
<Compile Include="Exceptions\DataDrivenReadException.cs" />
<Compile Include="Helpers\WaitHelper.cs" />
Expand Down Expand Up @@ -176,11 +177,11 @@
<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.Firefox.WebDriver.0.15.0\build\Selenium.Firefox.WebDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.Firefox.WebDriver.0.15.0\build\Selenium.Firefox.WebDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.28.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.28.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.18.0\build\Selenium.WebDriver.GeckoDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.GeckoDriver.0.18.0\build\Selenium.WebDriver.GeckoDriver.targets'))" />
</Target>
<Import Project="..\packages\Selenium.Firefox.WebDriver.0.15.0\build\Selenium.Firefox.WebDriver.targets" Condition="Exists('..\packages\Selenium.Firefox.WebDriver.0.15.0\build\Selenium.Firefox.WebDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.28.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.28.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.GeckoDriver.0.18.0\build\Selenium.WebDriver.GeckoDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.18.0\build\Selenium.WebDriver.GeckoDriver.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 @@ -4,10 +4,10 @@
<package id="NLog" version="4.3.5" targetFramework="net45" />
<package id="NLog.Schema" version="4.3.4" targetFramework="net40" />
<package id="PhantomJS" version="2.1.1" targetFramework="net40" />
<package id="Selenium.Firefox.WebDriver" version="0.15.0" targetFramework="net45" />
<package id="Selenium.Support" version="3.4.0" targetFramework="net45" />
<package id="Selenium.WebDriver" version="3.4.0" targetFramework="net45" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.28.0" targetFramework="net45" />
<package id="Selenium.WebDriver.GeckoDriver" version="0.18.0" targetFramework="net45" />
<package id="Selenium.WebDriver.IEDriver" version="3.4.0" targetFramework="net45" />
<package id="StyleCop.Analyzers" version="1.0.0" targetFramework="net40" developmentDependency="true" />
</packages>
6 changes: 2 additions & 4 deletions Objectivity.Test.Automation.Tests.Angular/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<add key="host" value="www.protractortest.org"/>
<add key="url" value=""/>
<!--<add key="browser" value="Safari" />-->
<!--<add key="browser" value="Chrome" />-->
<add key="browser" value="Chrome" />
<!--<add key="browser" value="InternetExplorer" />-->
<!--<add key="browser" value="FirefoxPortable" />-->
<!--<add key="browser" value="PhantomJs" />-->
<add key="browser" value="Firefox"/>
<!--<add key="browser" value="Firefox"/>-->
<!--<add key="browser" value="RemoteWebDriver" />-->
<add key="FirefoxUseLegacyImplementation" value="true"/>
<add key="FireFoxPath" value="\..\..\..\FirefoxPortable\FirefoxPortable.exe"/>
Expand All @@ -32,8 +32,6 @@
<add key="mediumTimeout" value="10"/>
<add key="shortTimeout" value="3"/>
<add key="ImplicitlyWaitMilliseconds" value="200"/>
<!--Enable or disable synchronization with AngularJS-->
<add key="SynchronizationWithAngularEnabled" value="true"/>
<!--nlog trace level must be set to "trace" for at least one logger to see EventFiringWebDriver logs-->
<add key="EnableEventFiringWebDriver" value="false"/>
<!--User credentials-->
Expand Down
Loading

0 comments on commit f809a09

Please sign in to comment.