Skip to content

Commit

Permalink
Merge pull request #75 from ObjectivityLtd/SpecFlowBrowserStack
Browse files Browse the repository at this point in the history
Spec flow cloud testing support
  • Loading branch information
raczeja authored May 24, 2018
2 parents 927888a + c90d676 commit 6ec5c91
Show file tree
Hide file tree
Showing 24 changed files with 380 additions and 246 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ LastBuild.log
/myresults.xml
/opencoverCoverage.xml
/.nuget/NuGet.exe
/.vs/TestFramework/v15/Server/sqlite3
9 changes: 7 additions & 2 deletions Objectivity.Test.Automation.Common/BrowserType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public enum BrowserType
/// </summary>
InternetExplorer,

/// <summary>
/// InternetExplorer browser
/// </summary>
IE,

/// <summary>
/// Chrome browser
/// </summary>
Expand All @@ -63,9 +68,9 @@ public enum BrowserType
Edge,

/// <summary>
/// BrowserStack parallel cross browsers testing
/// CloudProvider parallel cross browsers testing
/// </summary>
BrowserStack,
CloudProvider,

/// <summary>
/// Not supported browser
Expand Down
331 changes: 197 additions & 134 deletions Objectivity.Test.Automation.Common/DriverContext.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static bool IsDriverSynchronizationWithAngular(IWebDriver driver)
/// <param name="enable">Set true to enable.</param>
public static void SetAngularSynchronizationForDriver(IWebDriver driver, bool enable)
{
if (enable == false && driversAngularSynchronizationEnable.ContainsKey(driver))
if (!enable && driversAngularSynchronizationEnable.ContainsKey(driver))
{
driversAngularSynchronizationEnable.Remove(driver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,28 @@ public static IWebElement GetElement(this ISearchContext element, ElementLocator
/// <example>How to use it: <code>
/// this.Driver.GetElement(this.loginButton, timeout);
/// </code></example>
public static IWebElement GetElement(this ISearchContext element, ElementLocator locator, double timeout, [Optional] string customMessage)
public static IWebElement GetElement(this ISearchContext element, ElementLocator locator, double timeout, string customMessage)
{
return element.GetElement(locator, timeout, e => e.Displayed & e.Enabled, customMessage);
}

/// <summary>
/// Finds and waits for an element that is visible and displayed at specified time.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="locator">The locator.</param>
/// <param name="timeout">Specified time to wait.</param>
/// <returns>
/// Found element
/// </returns>
/// <example>How to use it: <code>
/// this.Driver.GetElement(this.loginButton, timeout);
/// </code></example>
public static IWebElement GetElement(this ISearchContext element, ElementLocator locator, double timeout)
{
return element.GetElement(locator, timeout, e => e.Displayed & e.Enabled);
}

/// <summary>
/// Finds and waits for an element that meets specified conditions for long timeout.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public static void WaitForAjax(this IWebDriver webDriver, double timeout)
}
catch (InvalidOperationException)
{
Logger.Error(CultureInfo.CurrentCulture, "Invalid Operation Exception");
}
}

Expand Down Expand Up @@ -206,14 +207,11 @@ public static void ScrollIntoMiddle(this IWebDriver webDriver, ElementLocator lo
var js = (IJavaScriptExecutor)webDriver;
var element = webDriver.ToDriver().GetElement(locator);

if (webDriver != null)
{
int height = webDriver.Manage().Window.Size.Height;
var height = webDriver.Manage().Window.Size.Height;

var hoverItem = (ILocatable)element;
var locationY = hoverItem.LocationOnScreenOnceScrolledIntoView.Y;
js.ExecuteScript(string.Format(CultureInfo.InvariantCulture, "javascript:window.scrollBy(0,{0})", locationY - (height / 2)));
}
var hoverItem = (ILocatable)element;
var locationY = hoverItem.LocationOnScreenOnceScrolledIntoView.Y;
js.ExecuteScript(string.Format(CultureInfo.InvariantCulture, "javascript:window.scrollBy(0,{0})", locationY - (height / 2)));
}

/// <summary>
Expand Down Expand Up @@ -318,7 +316,7 @@ public static void SynchronizeWithAngular(this IWebDriver webDriver, bool enable
/// <param name="webDriver">The web driver.</param>
private static void ApproveCertificateForInternetExplorer(this IWebDriver webDriver)
{
if (BaseConfiguration.TestBrowser.Equals(BrowserType.InternetExplorer) && webDriver.Title.Contains("Certificate"))
if ((BaseConfiguration.TestBrowser.Equals(BrowserType.InternetExplorer) || BaseConfiguration.TestBrowser.Equals(BrowserType.IE)) && webDriver.Title.Contains("Certificate"))
{
webDriver.FindElement(By.Id("overridelink")).JavaScriptClick();
}
Expand Down
32 changes: 1 addition & 31 deletions Objectivity.Test.Automation.Common/Helpers/WaitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,7 @@ public static void Wait(Func<bool> condition, TimeSpan timeout, string message)
/// </code></example>
public static void Wait(Func<bool> condition, TimeSpan timeout, TimeSpan sleepInterval, string message)
{
var start = DateTime.Now;
var result = false;
var canceller = new CancellationTokenSource();
var task = Task.Factory.StartNew(condition, canceller.Token);

while ((DateTime.Now - start).TotalSeconds < timeout.TotalSeconds)
{
if (task.IsCompleted)
{
if (task.Result)
{
result = true;
canceller.Cancel();
break;
}

task = Task.Factory.StartNew(
() =>
{
using (canceller.Token.Register(Thread.CurrentThread.Abort))
{
return condition();
}
},
canceller.Token);
}

Thread.Sleep(sleepInterval);
}

canceller.Cancel();
var result = Wait(condition, timeout, sleepInterval);

if (!result)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@
<Import Project="..\packages\Selenium.WebDriver.GeckoDriver.0.20.0\build\Selenium.WebDriver.GeckoDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.20.0\build\Selenium.WebDriver.GeckoDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.IEDriver.3.11.1\build\Selenium.WebDriver.IEDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.IEDriver.3.11.1\build\Selenium.WebDriver.IEDriver.targets')" />
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.36.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.36.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
<PropertyGroup>
<PreBuildEvent>taskkill /F /IM IEDriverServer.exe 2&gt;nul &amp;set errorlevel=0
taskkill /F /IM chromedriver.exe 2&gt;nul &amp;set errorlevel=0
taskkill /F /IM geckodriver.exe 2&gt;nul &amp;set errorlevel=0
cd $(TargetDir)
del *.log</PreBuildEvent>
</PropertyGroup>
<!-- 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
5 changes: 0 additions & 5 deletions Objectivity.Test.Automation.Common/Types/SavedTimes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ namespace Objectivity.Test.Automation.Common.Types
/// </summary>
public class SavedTimes
{
/// <summary>
/// The browser key
/// </summary>
private const string BrowserKey = "browser";

/// <summary>
/// The scenario
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Objectivity.Test.Automation.Common/WebElements/Checkbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Checkbox(IWebElement webElement)
/// </summary>
public void TickCheckbox()
{
if (this.webElement.Selected == false)
if (!this.webElement.Selected)
{
this.webElement.Click();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
<add key="FirefoxUseLegacyImplementation" value="false"/>
<add key="FireFoxPath" value="\..\..\..\FirefoxPortable\FirefoxPortable.exe"/>
<add key="RemoteWebDriverHub" value="http://hub-cloud.browserstack.com/wd/hub"/>
<!--<add key="RemoteWebDriverHub" value="http://hub-cloud.browserstack.com/wd/hub"/>-->
<add key="DriverCapabilities" value="BrowserStack"/>
<!--<add key="RemoteWebDriverHub" value="http://ondemand.saucelabs.com:80/wd/hub"/>-->
<!--<add key="RemoteWebDriverHub" value="https://hub.testingbot.com/wd/hub/"/>-->
<add key="DriverCapabilities" value="CloudProvider"/>
<!--<add key="proxy" value="127.0.0.1:9999" />-->
<!--Timeouts-->
<add key="longTimeout" value="30"/>
Expand Down Expand Up @@ -61,7 +62,7 @@
</appSettings>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="true" throwExceptions="false" internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<targets>
<target name="logfile" xsi:type="File" fileName="${basedir}\TestBrowserStackNUnit.log" layout="${longdate}|${level}|${callsite}|${message}"/>
<target name="logfile" xsi:type="File" fileName="${basedir}\TestCloudProviderNUnit.log" layout="${longdate}|${level}|${callsite}|${message}"/>
<target name="console" xsi:type="ColoredConsole" layout="${longdate}|${level}|${callsite}|${message}"/>
</targets>
<rules>
Expand All @@ -86,7 +87,15 @@
<add key="browserstack.key" value=""/>
<add key="project" value="Test.Automation"/>
<add key="browserstack.debug" value="true" />
<add key="build" value="Objectivity.Test.Automation.Tests.BrowserStackCrossBrowser" />
<add key="build" value="Objectivity.Test.Automation.Tests.CloudProviderCrossBrowser" />
<add key="browserstack.networkLogs" value="true" />
<!-->testingbot Settings/-->
<add key="key" value=""/>
<add key="secret" value=""/>
<!-->saucelabs Settings/-->
<add key="username" value=""/>
<add key="accessKey" value=""/>
<add key="extendedDebugging" value="true"/>
</DriverCapabilities>
<environments>
<Chrome>
Expand All @@ -106,6 +115,9 @@
<add key="os" value="OS X"/>
<add key="os_version" value="High Sierra"/>
<add key="name" value="parallel_test" />
<!-->testingbot Settings/-->
<add key="platform" value="HIGH-SIERRA" />
<add key="version" value="11" />
</Safari>
<Edge>
<add key="browser" value="edge" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<ProjectGuid>{F5B79C58-AC3B-448A-8325-5EF9A962B4A3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Objectivity.Test.Automation.Tests.NUnit</RootNamespace>
<AssemblyName>Objectivity.Test.Automation.Tests.NUnit</AssemblyName>
<RootNamespace>Objectivity.Test.Automation.Tests.CloudProviderCrossBrowser</RootNamespace>
<AssemblyName>Objectivity.Test.Automation.Tests.CloudProviderCrossBrowser</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
// SOFTWARE.
// </license>

namespace Objectivity.Test.Automation.Tests.NUnit
namespace Objectivity.Test.Automation.Tests.CloudProviderCrossBrowser
{
using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Globalization;
using Common;
using Common.Logger;
using global::NUnit.Framework;
using global::NUnit.Framework.Interfaces;
using NLog;
using Objectivity.Test.Automation.Common;
using Objectivity.Test.Automation.Common.Logger;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

/// <summary>
/// The base class for all tests <see href="https://github.com/ObjectivityLtd/Test.Automation/wiki/ProjectTestBase-class">More details on wiki</see>
Expand All @@ -42,11 +42,9 @@ public class ProjectTestBase : TestBase
private readonly DriverContext
driverContext = new DriverContext();

private string environment;

public ProjectTestBase(string environment)
{
this.environment = environment;
this.DriverContext.CrossBrowserEnvironment = environment;
this.driverContext.CapabilitiesSet += this.DriverContext_CapabilitiesSet;
}

Expand Down Expand Up @@ -104,6 +102,15 @@ public void BeforeTest()
{
this.DriverContext.TestTitle = TestContext.CurrentContext.Test.Name;
this.LogTest.LogTestStarting(this.driverContext);

if (BaseConfiguration.RemoteWebDriverHub.ToString().ToLower(CultureInfo.CurrentCulture).Contains("testingbot"))
{
Logger.Info("\nTestingBotSessionID=" + ((RemoteWebDriver)this.driverContext.Driver).SessionId);
}
else if (BaseConfiguration.RemoteWebDriverHub.ToString().ToLower(CultureInfo.CurrentCulture).Contains("saucelabs"))
{
Logger.Info("\nSauceOnDemandSessionID={0} job-name={1}", ((RemoteWebDriver)this.driverContext.Driver).SessionId, "saucelabs_test");
}
}

/// <summary>
Expand All @@ -116,31 +123,17 @@ public void AfterTest()
var filePaths = this.SaveTestDetailsIfTestFailed(this.driverContext);
this.SaveAttachmentsToTestContext(filePaths);
this.LogTest.LogTestEnding(this.driverContext);
if (this.IsVerifyFailedAndClearMessages(this.driverContext) && TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Failed)

// Logs the result to Sauce Labs
if (BaseConfiguration.RemoteWebDriverHub.ToString().ToLower(CultureInfo.CurrentCulture).Contains("saucelabs"))
{
Assert.Fail();
((IJavaScriptExecutor)this.DriverContext.Driver).ExecuteScript("sauce:job-result=" + (this.DriverContext.IsTestFailed ? "failed" : "passed"));
}
}

private void DriverContext_CapabilitiesSet(object sender, CapabilitiesSetEventArgs args)
{
if (args == null || args.Capabilities == null)
if (this.IsVerifyFailedAndClearMessages(this.driverContext) && TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Failed)
{
throw new ArgumentNullException();
Assert.Fail();
}

var settings = ConfigurationManager.GetSection("environments/" + this.environment) as NameValueCollection;

// if there are any settings
if (settings != null)
{
// loop through all of them
foreach (string key in settings.AllKeys)
{
Logger.Trace(CultureInfo.CurrentCulture, "Adding driver capability {0}", key);
args.Capabilities.SetCapability(key, settings[key]);
}
}
}

private void SaveAttachmentsToTestContext(string[] filePaths)
Expand All @@ -154,5 +147,16 @@ private void SaveAttachmentsToTestContext(string[] filePaths)
}
}
}

private void DriverContext_CapabilitiesSet(object sender, CapabilitiesSetEventArgs args)
{
if (args == null || args.Capabilities == null)
{
throw new ArgumentNullException();
}

// Set the capability
args.Capabilities.SetCapability("name", TestContext.CurrentContext.Test.FullName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// </license>

namespace Objectivity.Test.Automation.Tests.NUnit.Tests
namespace Objectivity.Test.Automation.Tests.CloudProviderCrossBrowser.Tests
{
using System.Collections.Generic;
using Automation.Tests.PageObjects.PageObjects.TheInternet;
using Common;
using global::NUnit.Framework;
using PageObjects.PageObjects.TheInternet;

[TestFixture("Chrome")]
[TestFixture("Firefox")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +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.10.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.GeckoDriver.0.20.0\build\Selenium.WebDriver.GeckoDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.GeckoDriver.0.20.0\build\Selenium.WebDriver.GeckoDriver.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.10.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.GeckoDriver.0.20.0\build\Selenium.WebDriver.GeckoDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.GeckoDriver.0.20.0\build\Selenium.WebDriver.GeckoDriver.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
Loading

0 comments on commit 6ec5c91

Please sign in to comment.