Skip to content

Commit

Permalink
Merge pull request #85 from ObjectivityLtd/3.1.7
Browse files Browse the repository at this point in the history
3.1.7
  • Loading branch information
raczeja authored Sep 13, 2018
2 parents 2613773 + c4c92a7 commit 88964bf
Show file tree
Hide file tree
Showing 29 changed files with 414 additions and 128 deletions.
3 changes: 3 additions & 0 deletions .nuspec/Objectivity.Test.Automation.Nunit.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<dependency id="NPOI" version="2.3.0" />
<dependency id="SharpZipLib" version="0.86.0" />
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Configuration" />
</frameworkAssemblies>
</metadata>
<files>
<file src="..\Objectivity.Test.Automation.Tests.NUnit\ProjectTestBase.cs" target="content" />
Expand Down
108 changes: 41 additions & 67 deletions Objectivity.Test.Automation.Common/DriverContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ public Collection<ErrorDetail> VerifyMessages
/// </summary>
public string CurrentDirectory { get; set; }

private FirefoxProfile FirefoxProfile
private FirefoxOptions FirefoxOptions
{
get
{
FirefoxProfile profile;
FirefoxOptions options = new FirefoxOptions();

if (BaseConfiguration.UseDefaultFirefoxProfile)
{
Expand All @@ -194,38 +194,41 @@ private FirefoxProfile FirefoxProfile
var pathToCurrentUserProfiles = BaseConfiguration.PathToFirefoxProfile; // Path to profile
var pathsToProfiles = Directory.GetDirectories(pathToCurrentUserProfiles, "*.default", SearchOption.TopDirectoryOnly);

profile = new FirefoxProfile(pathsToProfiles[0]);
options.Profile = new FirefoxProfile(pathsToProfiles[0]);
}
catch (DirectoryNotFoundException e)
{
Logger.Info(CultureInfo.CurrentCulture, "problem with loading firefox profile {0}", e.Message);
profile = new FirefoxProfile();
}
}
else
{
profile = new FirefoxProfile();
}

profile.SetPreference("toolkit.startup.max_resumed_crashes", "999999");
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", BaseConfiguration.Host ?? string.Empty);
options.SetPreference("toolkit.startup.max_resumed_crashes", "999999");
options.SetPreference("network.automatic-ntlm-auth.trusted-uris", BaseConfiguration.Host ?? string.Empty);

// retrieving settings from config file
var firefoxPreferences = ConfigurationManager.GetSection("FirefoxPreferences") as NameValueCollection;
var firefoxExtensions = ConfigurationManager.GetSection("FirefoxExtensions") as NameValueCollection;

// preference for downloading files
profile.SetPreference("browser.download.dir", this.DownloadFolder);
profile.SetPreference("browser.download.folderList", 2);
profile.SetPreference("browser.download.managershowWhenStarting", false);
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.ms-excel, application/x-msexcel, application/pdf, text/csv, text/html, application/octet-stream");
options.SetPreference("browser.download.dir", this.DownloadFolder);
options.SetPreference("browser.download.folderList", 2);
options.SetPreference("browser.download.managershowWhenStarting", false);
options.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.ms-excel, application/x-msexcel, application/pdf, text/csv, text/html, application/octet-stream");

// disable Firefox's built-in PDF viewer
profile.SetPreference("pdfjs.disabled", true);
options.SetPreference("pdfjs.disabled", true);

// disable Adobe Acrobat PDF preview plugin
profile.SetPreference("plugin.scan.Acrobat", "99.0");
profile.SetPreference("plugin.scan.plid.all", false);
options.SetPreference("plugin.scan.Acrobat", "99.0");
options.SetPreference("plugin.scan.plid.all", false);

options.UseLegacyImplementation = BaseConfiguration.FirefoxUseLegacyImplementation;

// set browser proxy for Firefox
if (!string.IsNullOrEmpty(BaseConfiguration.Proxy))
{
options.Proxy = this.CurrentProxy();
}

// if there are any extensions
if (firefoxExtensions != null)
Expand All @@ -234,15 +237,15 @@ private FirefoxProfile FirefoxProfile
for (var i = 0; i < firefoxExtensions.Count; i++)
{
Logger.Trace(CultureInfo.CurrentCulture, "Installing extension {0}", firefoxExtensions.GetKey(i));
profile.AddExtension(firefoxExtensions.GetKey(i));
options.Profile.AddExtension(firefoxExtensions.GetKey(i));
}
}

// custom preferences
// if there are any settings
if (firefoxPreferences == null)
{
return profile;
return options;
}

// loop through all of them
Expand All @@ -255,12 +258,12 @@ private FirefoxProfile FirefoxProfile
{
// if current settings value is "true"
case "true":
profile.SetPreference(firefoxPreferences.GetKey(i), true);
options.SetPreference(firefoxPreferences.GetKey(i), true);
break;

// if "false"
case "false":
profile.SetPreference(firefoxPreferences.GetKey(i), false);
options.SetPreference(firefoxPreferences.GetKey(i), false);
break;

// otherwise
Expand All @@ -270,31 +273,22 @@ private FirefoxProfile FirefoxProfile
// an attempt to parse current settings value to an integer. Method TryParse returns True if the attempt is successful (the string is integer) or return False (if the string is just a string and cannot be cast to a number)
if (int.TryParse(firefoxPreferences.Get(i), out temp))
{
profile.SetPreference(firefoxPreferences.GetKey(i), temp);
options.SetPreference(firefoxPreferences.GetKey(i), temp);
}
else
{
profile.SetPreference(firefoxPreferences.GetKey(i), firefoxPreferences[i]);
options.SetPreference(firefoxPreferences.GetKey(i), firefoxPreferences[i]);
}

break;
}
}

return profile;
}
}

private FirefoxOptions FirefoxOptions
{
get
{
FirefoxOptions options = new FirefoxOptions();
return options;
}
}

private ChromeOptions ChromeProfile
private ChromeOptions ChromeOptions
{
get
{
Expand Down Expand Up @@ -390,7 +384,7 @@ private ChromeOptions ChromeProfile
}
}

private InternetExplorerOptions InternetExplorerProfile
private InternetExplorerOptions InternetExplorerOptions
{
get
{
Expand Down Expand Up @@ -437,7 +431,7 @@ private InternetExplorerOptions InternetExplorerProfile
}
}

private EdgeOptions EdgeProfile
private EdgeOptions EdgeOptions
{
get
{
Expand All @@ -453,7 +447,7 @@ private EdgeOptions EdgeProfile
}
}

private SafariOptions SafariProfile
private SafariOptions SafariOptions
{
get
{
Expand Down Expand Up @@ -498,47 +492,28 @@ public void Start()
switch (BaseConfiguration.TestBrowser)
{
case BrowserType.Firefox:
var fireFoxOptionsLegacy = new FirefoxOptions { Profile = this.FirefoxProfile, UseLegacyImplementation = BaseConfiguration.FirefoxUseLegacyImplementation };

// set browser proxy for Firefox
if (!string.IsNullOrEmpty(BaseConfiguration.Proxy))
{
fireFoxOptionsLegacy.Proxy = this.CurrentProxy();
}

fireFoxOptionsLegacy = this.AddFirefoxArguments(fireFoxOptionsLegacy);

this.driver = new FirefoxDriver(this.SetDriverOptions(fireFoxOptionsLegacy));
this.driver = new FirefoxDriver(this.SetDriverOptions(this.FirefoxOptions));
break;
case BrowserType.FirefoxPortable:
var fireFoxOptions = new FirefoxOptions { BrowserExecutableLocation = BaseConfiguration.FirefoxPath, Profile = this.FirefoxProfile, UseLegacyImplementation = BaseConfiguration.FirefoxUseLegacyImplementation };

// set browser proxy for Firefox
if (!string.IsNullOrEmpty(BaseConfiguration.Proxy))
{
fireFoxOptions.Proxy = this.CurrentProxy();
}

fireFoxOptions = this.AddFirefoxArguments(fireFoxOptions);

this.driver = new FirefoxDriver(this.SetDriverOptions(fireFoxOptions));
this.FirefoxOptions.BrowserExecutableLocation = BaseConfiguration.FirefoxPath;
this.driver = new FirefoxDriver(this.SetDriverOptions(this.FirefoxOptions));
break;
case BrowserType.InternetExplorer:
case BrowserType.IE:
this.driver = new InternetExplorerDriver(this.SetDriverOptions(this.InternetExplorerProfile));
this.driver = new InternetExplorerDriver(this.SetDriverOptions(this.InternetExplorerOptions));
break;
case BrowserType.Chrome:
this.driver = new ChromeDriver(this.SetDriverOptions(this.ChromeProfile));
this.driver = new ChromeDriver(this.SetDriverOptions(this.ChromeOptions));
break;
case BrowserType.Safari:
this.driver = new SafariDriver(this.SetDriverOptions(this.SafariProfile));
this.driver = new SafariDriver(this.SetDriverOptions(this.SafariOptions));
this.CheckIfProxySetForSafari();
break;
case BrowserType.RemoteWebDriver:
this.driver = new RemoteWebDriver(BaseConfiguration.RemoteWebDriverHub, this.SetCapabilities());
break;
case BrowserType.Edge:
this.driver = new EdgeDriver(this.SetDriverOptions(this.EdgeProfile));
this.driver = new EdgeDriver(this.SetDriverOptions(this.EdgeOptions));
break;
default:
throw new NotSupportedException(
Expand Down Expand Up @@ -728,21 +703,20 @@ private DesiredCapabilities SetCapabilities()
{
case BrowserType.Firefox:
capabilities = (DesiredCapabilities)this.SetDriverOptions(this.FirefoxOptions).ToCapabilities();
capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, this.FirefoxProfile.ToBase64String());
break;
case BrowserType.InternetExplorer:
case BrowserType.IE:
capabilities = (DesiredCapabilities)this.SetDriverOptions(this.InternetExplorerProfile).ToCapabilities();
capabilities = (DesiredCapabilities)this.SetDriverOptions(this.InternetExplorerOptions).ToCapabilities();
break;
case BrowserType.Chrome:
capabilities = (DesiredCapabilities)this.SetDriverOptions(this.ChromeProfile).ToCapabilities();
capabilities = (DesiredCapabilities)this.SetDriverOptions(this.ChromeOptions).ToCapabilities();
break;
case BrowserType.Safari:
capabilities = (DesiredCapabilities)this.SetDriverOptions(this.SafariProfile).ToCapabilities();
capabilities = (DesiredCapabilities)this.SetDriverOptions(this.SafariOptions).ToCapabilities();
this.CheckIfProxySetForSafari();
break;
case BrowserType.Edge:
capabilities = (DesiredCapabilities)this.SetDriverOptions(this.EdgeProfile).ToCapabilities();
capabilities = (DesiredCapabilities)this.SetDriverOptions(this.EdgeOptions).ToCapabilities();
break;
case BrowserType.CloudProvider:
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// <copyright file="SearchContextExtensions.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 All @@ -28,9 +28,8 @@ namespace Objectivity.Test.Automation.Common.Extensions
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;

using Objectivity.Test.Automation.Common.Helpers;
using Objectivity.Test.Automation.Common.Types;

using OpenQA.Selenium;
using OpenQA.Selenium.Internal;
using OpenQA.Selenium.Support.UI;
Expand Down Expand Up @@ -267,7 +266,7 @@ public static T GetElement<T>(this ISearchContext searchContext, ElementLocator
}

/// <summary>
/// Finds elements that are visible and displayed.
/// Finds elements that are enabled and displayed.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="locator">The locator.</param>
Expand All @@ -282,6 +281,52 @@ public static IList<IWebElement> GetElements(this ISearchContext element, Elemen
return element.GetElements(locator, e => e.Displayed && e.Enabled).ToList();
}

/// <summary>
/// Finds and waits for given timeout for at least minimum number of elements that meet specified conditions.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="locator">The locator.</param>
/// <param name="timeout">Specified time to wait.</param>
/// <param name="condition">Condition to be fulfilled by elements</param>
/// <param name="minNumberOfElements">The minimum number of elements to get</param>
/// <returns>
/// Return all found and displayed and enabled elements
/// </returns>
/// <example>How to find elements : <code>
/// var checkboxes = this.Driver.GetElements(this.stackOverFlowCheckbox, timeout, e =&gt; e.Displayed &amp;&amp; e.Enabled, 1);
/// </code></example>
public static IList<IWebElement> GetElements(this ISearchContext element, ElementLocator locator, double timeout, Func<IWebElement, bool> condition, int minNumberOfElements)
{
IList<IWebElement> elements = null;
WaitHelper.Wait(
() => (elements = GetElements(element, locator, condition).ToList()).Count >= minNumberOfElements,
TimeSpan.FromSeconds(timeout),
"Timeout while getting elements");
return elements;
}

/// <summary>
/// Finds and waits for LongTimeout timeout for at least minimum number of elements that are enabled and displayed.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="locator">The locator.</param>
/// <param name="minNumberOfElements">The minimum number of elements to get</param>
/// <returns>
/// Return all found and displayed and enabled elements
/// </returns>
/// <example>How to find elements : <code>
/// var checkboxes = this.Driver.GetElements(this.stackOverFlowCheckbox, 1);
/// </code></example>
public static IList<IWebElement> GetElements(this ISearchContext element, ElementLocator locator, int minNumberOfElements)
{
IList<IWebElement> elements = null;
WaitHelper.Wait(
() => (elements = GetElements(element, locator, e => e.Displayed && e.Enabled).ToList()).Count >= minNumberOfElements,
TimeSpan.FromSeconds(BaseConfiguration.LongTimeout),
"Timeout while getting elements");
return elements;
}

/// <summary>
/// Finds elements that meet specified conditions.
/// </summary>
Expand Down
Loading

0 comments on commit 88964bf

Please sign in to comment.