Skip to content

Commit

Permalink
Add ability to create invisible elements (#21) +semver: feature
Browse files Browse the repository at this point in the history
* Add ability to create invisible elements. Removed redundant code.
  • Loading branch information
mialeska authored Oct 11, 2019
1 parent 4e801d4 commit f59575c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 54 deletions.

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
@@ -1,5 +1,6 @@
using Aquality.WinAppDriver.Elements.Interfaces;
using OpenQA.Selenium;
using ElementState = Aquality.Selenium.Core.Elements.ElementState;

namespace Aquality.WinAppDriver.Elements
{
Expand All @@ -8,7 +9,7 @@ namespace Aquality.WinAppDriver.Elements
/// </summary>
public class Button : Element, IButton
{
protected internal Button(By locator, string name) : base(locator, name)
protected internal Button(By locator, string name, ElementState elementState = ElementState.Displayed) : base(locator, name, elementState)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Aquality.WinAppDriver.Elements
{
public abstract class Element : CoreElement, IElement
{
protected Element(By locator, string name) : base(locator, name, ElementState.Displayed)
protected Element(By locator, string name, ElementState elementState = ElementState.Displayed) : base(locator, name, elementState)
{
}

Expand All @@ -34,11 +34,6 @@ protected Element(By locator, string name) : base(locator, name, ElementState.Di

public virtual IMouseActions MouseActions => new MouseActions(this, ElementType, () => Application, LocalizationLogger, ActionRetrier);

public T FindChildElement<T>(By childLocator, ElementSupplier<T> supplier = null) where T : IElement
{
return FindChildElement(childLocator, supplier, ElementState.Displayed);
}

protected override CoreElementFinder Finder => ApplicationManager.GetRequiredService<CoreElementFinder>();

protected override LocalizationLogger LocalizationLogger => ApplicationManager.GetRequiredService<LocalizationLogger>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Aquality.Selenium.Core.Elements;
using Aquality.Selenium.Core.Elements.Interfaces;
using Aquality.Selenium.Core.Localization;
Expand All @@ -25,48 +24,25 @@ public ElementFactory(ConditionalWait conditionalWait, IElementFinder elementFin
{
}

public IButton GetButton(By locator, string name)
public IButton GetButton(By locator, string name, ElementState elementState = ElementState.Displayed)
{
return GetCustomElement(ResolveSupplier<IButton>(null), locator, name);
return GetCustomElement(ResolveSupplier<IButton>(null), locator, name, elementState);
}

public ILabel GetLabel(By locator, string name)
public ILabel GetLabel(By locator, string name, ElementState elementState = ElementState.Displayed)
{
return GetCustomElement(ResolveSupplier<ILabel>(null), locator, name);
return GetCustomElement(ResolveSupplier<ILabel>(null), locator, name, elementState);
}

public ITextBox GetTextBox(By locator, string name)
public ITextBox GetTextBox(By locator, string name, ElementState elementState = ElementState.Displayed)
{
return GetCustomElement(ResolveSupplier<ITextBox>(null), locator, name);
return GetCustomElement(ResolveSupplier<ITextBox>(null), locator, name, elementState);
}

public T FindChildElement<T>(Window parentWindow, By childLocator, string childName, ElementSupplier<T> supplier = null) where T : IElement
public T FindChildElement<T>(Window parentWindow, By childLocator, string childName, ElementSupplier<T> supplier = null, ElementState elementState = ElementState.Displayed) where T : IElement
{
var elementSupplier = ResolveSupplier(supplier);
return elementSupplier(new ByChained(parentWindow.Locator, childLocator), $"{childName}' - {parentWindow.GetElementType()} '{parentWindow.Name}", ElementState.Displayed);
}

protected override ElementSupplier<T> ResolveSupplier<T>(ElementSupplier<T> supplier)
{
if (supplier != null)
{
return supplier;
}
else
{
var type = typeof(T);
var elementType = type.IsInterface ? ElementTypesMap[type] : type;
var elementCntr = elementType.GetConstructor(
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.CreateInstance | BindingFlags.Instance,
null,
new[] { typeof(By), typeof(string) },
null);
if(elementCntr == null)
{
return base.ResolveSupplier(supplier);
}
return (locator, name, state) => (T)elementCntr.Invoke(new object[] { locator, name });
}
return elementSupplier(new ByChained(parentWindow.Locator, childLocator), $"{childName}' - {parentWindow.GetElementType()} '{parentWindow.Name}", elementState);
}

protected override IDictionary<Type, Type> ElementTypesMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@ public interface IElementFactory : CoreElementFactory
/// </summary>
/// <param name="locator">Element locator</param>
/// <param name="name">Element name</param>
/// <param name="elementState">Element existance state</param>
/// <returns>Instance of element that implements IButton interface</returns>
IButton GetButton(By locator, string name);
IButton GetButton(By locator, string name, ElementState elementState = ElementState.Displayed);

/// <summary>
/// Creates element that implements ILabel interface.
/// </summary>
/// <param name="locator">Element locator</param>
/// <param name="name">Element name</param>
/// <param name="elementState">Element existance state</param>
/// <returns>Instance of element that implements ILabel interface</returns>
ILabel GetLabel(By locator, string name);
ILabel GetLabel(By locator, string name, ElementState elementState = ElementState.Displayed);

/// <summary>
/// Creates element that implements ITextBox interface.
/// </summary>
/// <param name="locator">Element locator</param>
/// <param name="name">Element name</param>
/// <param name="elementState">Element existance state</param>
/// <returns>Instance of element that implements ITextBox interface</returns>
ITextBox GetTextBox(By locator, string name);
ITextBox GetTextBox(By locator, string name, ElementState elementState = ElementState.Displayed);

/// <summary>
/// Finds element relative to parent window.
Expand All @@ -42,7 +45,8 @@ public interface IElementFactory : CoreElementFactory
/// <param name="childLocator">Locator of the element relative to parent window.</param>
/// <param name="childName">Name of the element.</param>
/// <param name="supplier">Delegate that defines constructor of element in case of custom element.</param>
/// <param name="elementState">Element existance state</param>
/// <returns>Instance of element.</returns>
T FindChildElement<T>(Window parentWindow, By childLocator, string childName, ElementSupplier<T> supplier = null) where T : IElement;
T FindChildElement<T>(Window parentWindow, By childLocator, string childName, ElementSupplier<T> supplier = null, ElementState elementState = ElementState.Displayed) where T : IElement;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Aquality.WinAppDriver.Elements.Interfaces;
using OpenQA.Selenium;
using ElementState = Aquality.Selenium.Core.Elements.ElementState;

namespace Aquality.WinAppDriver.Elements
{
Expand All @@ -8,7 +9,7 @@ namespace Aquality.WinAppDriver.Elements
/// </summary>
public class Label : Element, ILabel
{
protected internal Label(By locator, string name) : base(locator, name)
protected internal Label(By locator, string name, ElementState elementState = ElementState.Displayed) : base(locator, name, elementState)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Aquality.WinAppDriver.Elements.Interfaces;
using OpenQA.Selenium;
using ElementState = Aquality.Selenium.Core.Elements.ElementState;

namespace Aquality.WinAppDriver.Elements
{
Expand All @@ -10,7 +11,7 @@ public class TextBox : Element, ITextBox
{
private const string SecretMask = "*********";

protected internal TextBox(By locator, string name) : base(locator, name)
protected internal TextBox(By locator, string name, ElementState elementState = ElementState.Displayed) : base(locator, name, elementState)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ protected Window(By locator, string name) : base(locator, name)
/// <param name="childLocator">Locator of the element relative to current window.</param>
/// <param name="childName">Name of the element.</param>
/// <param name="supplier">Delegate that defines constructor of element in case of custom element.</param>
/// <param name="elementState">Element existance state</param>
/// <returns>Instance of element.</returns>
public T FindChildElement<T>(By childLocator, string childName, ElementSupplier<T> supplier = null) where T : IElement
public T FindChildElement<T>(By childLocator, string childName, ElementSupplier<T> supplier = null, ElementState elementState = ElementState.Displayed) where T : IElement
{
return ElementFactory.FindChildElement(this, childLocator, childName, supplier);
return ElementFactory.FindChildElement(this, childLocator, childName, supplier, elementState);
}

/// <summary>
Expand Down

0 comments on commit f59575c

Please sign in to comment.