Skip to content

Commit

Permalink
Update Aquality.Selenium.Core library version. (#191)
Browse files Browse the repository at this point in the history
* Update Aquality.Selenium.Core library version.

* Allow overriding of browser capabilities and options via environment variables.

* Remove core library dependencies duplication.

* Add documentation to form methods.

* Mark some form methods and properties as obsolete with explanation what to use instead.

* Replace LocalizationLogger with Logger property in form.

* Make ElementFactory property in Form static in to make it possible to be used during the field initialization.
  • Loading branch information
mialeska authored Jun 8, 2020
1 parent d0c1979 commit be6fa7b
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aquality.Selenium.Core" Version="1.1.0" />
<PackageReference Include="NLog" Version="4.7.0" />
<PackageReference Include="Selenium.Support" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="Aquality.Selenium.Core" Version="1.1.1" />
<PackageReference Include="WebDriverManager" Version="2.9.1" />
</ItemGroup>

Expand Down
89 changes: 84 additions & 5 deletions Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public virtual string DownloadDir

public abstract string DownloadDirCapabilityKey { get; }

protected IDictionary<string, object> BrowserCapabilities => SettingsFile.GetValueOrNew<Dictionary<string, object>>($"{DriverSettingsPath}.capabilities");
protected IReadOnlyDictionary<string, object> BrowserCapabilities => SettingsFile.GetValueDictionaryOrEmpty<object>($"{DriverSettingsPath}.capabilities");

protected IDictionary<string, object> BrowserOptions => SettingsFile.GetValueOrNew<Dictionary<string, object>>($"{DriverSettingsPath}.options");
protected IReadOnlyDictionary<string, object> BrowserOptions => SettingsFile.GetValueDictionaryOrEmpty<object>($"{DriverSettingsPath}.options");

protected IReadOnlyList<string> BrowserStartArguments => SettingsFile.GetValueListOrEmpty<string>($"{DriverSettingsPath}.startArguments");

Expand Down
58 changes: 37 additions & 21 deletions Aquality.Selenium/src/Aquality.Selenium/Forms/Form.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Aquality.Selenium.Elements.Interfaces;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Drawing;
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Core.Localization;
using OpenQA.Selenium;
using Aquality.Selenium.Core.Elements;
using System.Collections.Generic;
using Aquality.Selenium.Core.Logging;
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Elements.Interfaces;
using IElementStateProvider = Aquality.Selenium.Core.Elements.Interfaces.IElementStateProvider;

namespace Aquality.Selenium.Forms
{
Expand All @@ -13,6 +15,7 @@ namespace Aquality.Selenium.Forms
/// </summary>
public abstract class Form
{
private readonly ILabel formLabel;
/// <summary>
/// Constructor with parameters.
/// </summary>
Expand All @@ -22,29 +25,32 @@ protected Form(By locator, string name)
{
Locator = locator;
Name = name;
formLabel = ElementFactory.GetLabel(Locator, Name);
}

private ILabel FormLabel => ElementFactory.GetLabel(Locator, Name);
/// <summary>
/// Gets Form element defined by its locator and name.
/// Could be used to find child elements relative to form element.
/// </summary>
protected IElement FormElement => formLabel;

/// <summary>
/// Instance of logger <see cref="Logging.Logger">
/// Instance of logger <see cref="Core.Logging.Logger"/>
/// </summary>
/// <value>Logger instance.</value>
protected ILocalizedLogger Logger => AqualityServices.LocalizedLogger;
protected static Logger Logger => AqualityServices.Logger;

/// <summary>
/// Element factory <see cref="IElementFactory">
/// Element factory <see cref="IElementFactory"/>
/// </summary>
/// <value>Element factory.</value>
protected IElementFactory ElementFactory => AqualityServices.Get<IElementFactory>();
protected static IElementFactory ElementFactory => AqualityServices.Get<IElementFactory>();

/// <summary>
/// Locator of specified form.
/// Locator of the form.
/// </summary>
public By Locator { get; }

/// <summary>
/// Name of specified form.
/// Name of the form.
/// </summary>
public string Name { get; }

Expand All @@ -53,12 +59,18 @@ protected Form(By locator, string name)
/// </summary>
/// <value>True - form is opened,
/// False - form is not opened.</value>
public bool IsDisplayed => FormLabel.State.WaitForDisplayed();
[Obsolete("This property will be removed in the future release. Use State.WaitForDisplayed() if needed")]
public bool IsDisplayed => FormElement.State.WaitForDisplayed();

/// <summary>
/// Provides ability to get form's state (whether it is displayed, exists or not) and respective waiting functions.
/// </summary>
public IElementStateProvider State => FormElement.State;

/// <summary>
/// Gets size of form element defined by its locator.
/// </summary>
public Size Size => FormLabel.GetElement().Size;
public Size Size => FormElement.GetElement().Size;

/// <summary>
/// Scroll form without scrolling entire page
Expand All @@ -67,7 +79,7 @@ protected Form(By locator, string name)
/// <param name="y">vertical coordinate</param>
public void ScrollBy(int x, int y)
{
FormLabel.JsActions.ScrollBy(x, y);
FormElement.JsActions.ScrollBy(x, y);
}

/// <summary>
Expand All @@ -79,9 +91,11 @@ public void ScrollBy(int x, int y)
/// <param name="supplier">Delegate that defines constructor of child element in case of custom element.</param>
/// <param name="state">Child element state.</param>
/// <returns>Instance of child element.</returns>
protected T FindChildElement<T>(By childLocator, string name = null, ElementSupplier<T> supplier = null, ElementState state = ElementState.Displayed) where T : Core.Elements.Interfaces.IElement
[Obsolete("This method will be removed in the future release. Use FormElement property methods to find child element")]
protected T FindChildElement<T>(By childLocator, string name = null, ElementSupplier<T> supplier = null, ElementState state = ElementState.Displayed)
where T : IElement
{
return FormLabel.FindChildElement(childLocator, name, supplier, state);
return FormElement.FindChildElement(childLocator, name, supplier, state);
}

/// <summary>
Expand All @@ -94,9 +108,11 @@ protected T FindChildElement<T>(By childLocator, string name = null, ElementSupp
/// <param name="expectedCount">Expected number of elements that have to be found (zero, more then zero, any).</param>
/// <param name="state">Child elements state.</param>
/// <returns>List of child elements.</returns>
protected IList<T> FindChildElements<T>(By childLocator, string name = null, ElementSupplier<T> supplier = null, ElementsCount expectedCount = ElementsCount.Any, ElementState state = ElementState.Displayed) where T : Core.Elements.Interfaces.IElement
[Obsolete("This method will be removed in the future release. Use FormElement property methods to find child elements")]
protected IList<T> FindChildElements<T>(By childLocator, string name = null, ElementSupplier<T> supplier = null, ElementsCount expectedCount = ElementsCount.Any, ElementState state = ElementState.Displayed)
where T : IElement
{
return FormLabel.FindChildElements(childLocator, name, supplier, expectedCount, state);
return FormElement.FindChildElements(childLocator, name, supplier, expectedCount, state);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public IList<Label> GetListElementsByCss(ElementState state, ElementsCount count

public Label GetChildElementByNonXPath(ElementState state)
{
return FindChildElement<Label>(BestSellersById, state: state);
return FormElement.FindChildElement<Label>(BestSellersById, state: state);
}

public IList<Label> GetListElementsByDottedXPath(ElementState state, ElementsCount count)
Expand All @@ -55,7 +55,7 @@ public IList<Label> GetListElementsByDottedXPath(ElementState state, ElementsCou

public IList<Label> GetChildElementsByDottedXPath(ElementState state, ElementsCount count)
{
return FindChildElements<Label>(DottedXPath, state: state, expectedCount: count);
return FormElement.FindChildElements<Label>(DottedXPath, state: state, expectedCount: count);
}
}
}
2 changes: 2 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ stages:
- task: DotNetCoreCLI@2
displayName: 'Build solution'
env:
MSBUILDSINGLELOADCONTEXT: 1 # https://github.com/SpecFlowOSS/SpecFlow/issues/1912
inputs:
command: 'build'
projects: Aquality.Selenium/Aquality.Selenium.sln
Expand Down

0 comments on commit be6fa7b

Please sign in to comment.