Skip to content

Commit

Permalink
Update element wrapper base implementation to be usable as standalone…
Browse files Browse the repository at this point in the history
… elements enabling advantages of Legerity features
  • Loading branch information
jamesmcroft committed Feb 16, 2023
1 parent 502bdb5 commit 7363c45
Show file tree
Hide file tree
Showing 4 changed files with 488 additions and 346 deletions.
163 changes: 103 additions & 60 deletions src/Legerity.Android/Elements/AndroidElementWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,80 +1,123 @@
namespace Legerity.Android.Elements
namespace Legerity.Android.Elements;

using System;

using Legerity.Exceptions;

using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;

/// <summary>
/// Defines an element wrapper for a <see cref="AndroidElement"/>.
/// </summary>
public class AndroidElementWrapper : ElementWrapper<AndroidElement>
{
using System;
/// <summary>
/// Initializes a new instance of the <see cref="AndroidElementWrapper"/> class.
/// </summary>
/// <param name="element">
/// The <see cref="AndroidElement"/> reference.
/// </param>
public AndroidElementWrapper(AndroidElement element)
: base(element)
{
}

using Legerity.Exceptions;
/// <summary>
/// Gets the instance of the Appium driver for the Android application.
/// </summary>
public AndroidDriver<AndroidElement> Driver => this.ElementDriver as AndroidDriver<AndroidElement>;

using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Support.UI;
/// <summary>
/// Allows conversion of a <see cref="AndroidElement"/> to the <see cref="AndroidElementWrapper"/> without direct casting.
/// </summary>
/// <param name="element">
/// The <see cref="AndroidElement"/>.
/// </param>
/// <returns>
/// The <see cref="AndroidElementWrapper"/>.
/// </returns>
public static implicit operator AndroidElementWrapper(AndroidElement element)
{
return new AndroidElementWrapper(element);
}

/// <summary>
/// Defines an element wrapper for a <see cref="AndroidElement"/>.
/// Allows conversion of a <see cref="AppiumWebElement"/> to the <see cref="AndroidElementWrapper"/> without direct casting.
/// </summary>
public abstract class AndroidElementWrapper : ElementWrapper<AndroidElement>
/// <param name="element">
/// The <see cref="AppiumWebElement"/>.
/// </param>
/// <returns>
/// The <see cref="AndroidElementWrapper"/>.
/// </returns>
public static implicit operator AndroidElementWrapper(AppiumWebElement element)
{
/// <summary>
/// Initializes a new instance of the <see cref="AndroidElementWrapper"/> class.
/// </summary>
/// <param name="element">
/// The <see cref="AndroidElement"/> reference.
/// </param>
protected AndroidElementWrapper(AndroidElement element)
: base(element)
{
}
return new AndroidElementWrapper(element as AndroidElement);
}

/// <summary>
/// Gets the instance of the Appium driver for the Android application.
/// </summary>
public AndroidDriver<AndroidElement> Driver => this.ElementDriver as AndroidDriver<AndroidElement>;
/// <summary>
/// Allows conversion of a <see cref="RemoteWebElement"/> to the <see cref="AndroidElementWrapper"/> without direct casting.
/// </summary>
/// <param name="element">
/// The <see cref="RemoteWebElement"/>.
/// </param>
/// <returns>
/// The <see cref="AndroidElementWrapper"/>.
/// </returns>
public static implicit operator AndroidElementWrapper(RemoteWebElement element)
{
return new AndroidElementWrapper(element as AndroidElement);
}

/// <summary>
/// Determines whether the specified element is shown with the specified timeout.
/// </summary>
/// <param name="locator">The locator to find a specific element.</param>
/// <param name="timeout">
/// The amount of time the driver should wait when searching for the <paramref name="locator"/> if it is not immediately present.
/// </param>
protected void VerifyDriverElementShown(By locator, TimeSpan? timeout)
/// <summary>
/// Determines whether the specified element is shown with the specified timeout.
/// </summary>
/// <param name="locator">The locator to find a specific element.</param>
/// <param name="timeout">
/// The amount of time the driver should wait when searching for the <paramref name="locator"/> if it is not immediately present.
/// </param>
protected void VerifyDriverElementShown(By locator, TimeSpan? timeout)
{
if (timeout == null)
{
if (timeout == null)
{
if (this.Driver.FindElement(locator) == null)
{
throw new ElementNotShownException(locator.ToString());
}
}
else
if (this.Driver.FindElement(locator) == null)
{
var wait = new WebDriverWait(this.Driver, timeout.Value);
wait.Until(driver => driver.FindElement(locator) != null);
throw new ElementNotShownException(locator.ToString());
}
}
else
{
var wait = new WebDriverWait(this.Driver, timeout.Value);
wait.Until(driver => driver.FindElement(locator) != null);
}
}

/// <summary>
/// Determines whether the specified elements are shown with the specified timeout.
/// </summary>
/// <param name="locator">
/// The locator to find a collection of elements.
/// </param>
/// <param name="timeout">
/// The amount of time the driver should wait when searching for the <paramref name="locator"/> if it is not immediately present.
/// </param>
protected void VerifyDriverElementsShown(By locator, TimeSpan? timeout)
/// <summary>
/// Determines whether the specified elements are shown with the specified timeout.
/// </summary>
/// <param name="locator">
/// The locator to find a collection of elements.
/// </param>
/// <param name="timeout">
/// The amount of time the driver should wait when searching for the <paramref name="locator"/> if it is not immediately present.
/// </param>
protected void VerifyDriverElementsShown(By locator, TimeSpan? timeout)
{
if (timeout == null)
{
if (timeout == null)
if (this.Driver.FindElements(locator).Count == 0)
{
if (this.Driver.FindElements(locator).Count == 0)
{
throw new ElementNotShownException(locator.ToString());
}
}
else
{
var wait = new WebDriverWait(this.Driver, timeout.Value);
wait.Until(driver => driver.FindElements(locator).Count != 0);
throw new ElementNotShownException(locator.ToString());
}
}
else
{
var wait = new WebDriverWait(this.Driver, timeout.Value);
wait.Until(driver => driver.FindElements(locator).Count != 0);
}
}
}
163 changes: 103 additions & 60 deletions src/Legerity.IOS/Elements/IOSElementWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,80 +1,123 @@
namespace Legerity.IOS.Elements
namespace Legerity.IOS.Elements;

using System;

using Legerity.Exceptions;

using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.iOS;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;

/// <summary>
/// Defines an element wrapper for a <see cref="IOSElement"/>.
/// </summary>
public class IOSElementWrapper : ElementWrapper<IOSElement>
{
using System;
/// <summary>
/// Initializes a new instance of the <see cref="IOSElementWrapper"/> class.
/// </summary>
/// <param name="element">
/// The <see cref="IOSElement"/> reference.
/// </param>
public IOSElementWrapper(IOSElement element)
: base(element)
{
}

using Legerity.Exceptions;
/// <summary>
/// Gets the instance of the Appium driver for the iOS application.
/// </summary>
public IOSDriver<IOSElement> Driver => this.ElementDriver as IOSDriver<IOSElement>;

using OpenQA.Selenium;
using OpenQA.Selenium.Appium.iOS;
using OpenQA.Selenium.Support.UI;
/// <summary>
/// Allows conversion of a <see cref="IOSElement"/> to the <see cref="IOSElementWrapper"/> without direct casting.
/// </summary>
/// <param name="element">
/// The <see cref="IOSElement"/>.
/// </param>
/// <returns>
/// The <see cref="IOSElementWrapper"/>.
/// </returns>
public static implicit operator IOSElementWrapper(IOSElement element)
{
return new IOSElementWrapper(element);
}

/// <summary>
/// Defines an element wrapper for a <see cref="IOSElement"/>.
/// Allows conversion of a <see cref="AppiumWebElement"/> to the <see cref="IOSElementWrapper"/> without direct casting.
/// </summary>
public abstract class IOSElementWrapper : ElementWrapper<IOSElement>
/// <param name="element">
/// The <see cref="AppiumWebElement"/>.
/// </param>
/// <returns>
/// The <see cref="IOSElementWrapper"/>.
/// </returns>
public static implicit operator IOSElementWrapper(AppiumWebElement element)
{
/// <summary>
/// Initializes a new instance of the <see cref="IOSElementWrapper"/> class.
/// </summary>
/// <param name="element">
/// The <see cref="IOSElement"/> reference.
/// </param>
protected IOSElementWrapper(IOSElement element)
: base(element)
{
}
return new IOSElementWrapper(element as IOSElement);
}

/// <summary>
/// Gets the instance of the Appium driver for the iOS application.
/// </summary>
public IOSDriver<IOSElement> Driver => this.ElementDriver as IOSDriver<IOSElement>;
/// <summary>
/// Allows conversion of a <see cref="RemoteWebElement"/> to the <see cref="IOSElementWrapper"/> without direct casting.
/// </summary>
/// <param name="element">
/// The <see cref="RemoteWebElement"/>.
/// </param>
/// <returns>
/// The <see cref="IOSElementWrapper"/>.
/// </returns>
public static implicit operator IOSElementWrapper(RemoteWebElement element)
{
return new IOSElementWrapper(element as IOSElement);
}

/// <summary>
/// Determines whether the specified element is shown with the specified timeout.
/// </summary>
/// <param name="locator">The locator to find a specific element.</param>
/// <param name="timeout">
/// The amount of time the driver should wait when searching for the <paramref name="locator"/> if it is not immediately present.
/// </param>
protected void VerifyDriverElementShown(By locator, TimeSpan? timeout)
/// <summary>
/// Determines whether the specified element is shown with the specified timeout.
/// </summary>
/// <param name="locator">The locator to find a specific element.</param>
/// <param name="timeout">
/// The amount of time the driver should wait when searching for the <paramref name="locator"/> if it is not immediately present.
/// </param>
protected void VerifyDriverElementShown(By locator, TimeSpan? timeout)
{
if (timeout == null)
{
if (timeout == null)
{
if (this.Driver.FindElement(locator) == null)
{
throw new ElementNotShownException(locator.ToString());
}
}
else
if (this.Driver.FindElement(locator) == null)
{
var wait = new WebDriverWait(this.Driver, timeout.Value);
wait.Until(driver => driver.FindElement(locator) != null);
throw new ElementNotShownException(locator.ToString());
}
}
else
{
var wait = new WebDriverWait(this.Driver, timeout.Value);
wait.Until(driver => driver.FindElement(locator) != null);
}
}

/// <summary>
/// Determines whether the specified elements are shown with the specified timeout.
/// </summary>
/// <param name="locator">
/// The locator to find a collection of elements.
/// </param>
/// <param name="timeout">
/// The amount of time the driver should wait when searching for the <paramref name="locator"/> if it is not immediately present.
/// </param>
protected void VerifyDriverElementsShown(By locator, TimeSpan? timeout)
/// <summary>
/// Determines whether the specified elements are shown with the specified timeout.
/// </summary>
/// <param name="locator">
/// The locator to find a collection of elements.
/// </param>
/// <param name="timeout">
/// The amount of time the driver should wait when searching for the <paramref name="locator"/> if it is not immediately present.
/// </param>
protected void VerifyDriverElementsShown(By locator, TimeSpan? timeout)
{
if (timeout == null)
{
if (timeout == null)
if (this.Driver.FindElements(locator).Count == 0)
{
if (this.Driver.FindElements(locator).Count == 0)
{
throw new ElementNotShownException(locator.ToString());
}
}
else
{
var wait = new WebDriverWait(this.Driver, timeout.Value);
wait.Until(driver => driver.FindElements(locator).Count != 0);
throw new ElementNotShownException(locator.ToString());
}
}
else
{
var wait = new WebDriverWait(this.Driver, timeout.Value);
wait.Until(driver => driver.FindElements(locator).Count != 0);
}
}
}
Loading

0 comments on commit 7363c45

Please sign in to comment.