Skip to content

Commit

Permalink
Merge pull request #138 from MADE-Apps/feature/page-extensions
Browse files Browse the repository at this point in the history
Added FindElement methods to BasePage
  • Loading branch information
tom-made authored Jun 4, 2022
2 parents 3da1624 + 3a9d37c commit fd5387a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Legerity.Core/Extensions/PageExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace Legerity.Extensions
{
using System;
using System.Collections.ObjectModel;
using Legerity.Pages;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;

/// <summary>
Expand Down
65 changes: 63 additions & 2 deletions src/Legerity.Core/Pages/BasePage.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace Legerity.Pages
{
using System;

using System.Collections.ObjectModel;
using System.Linq;
using Legerity.Exceptions;

using Legerity.Extensions;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.iOS;
Expand Down Expand Up @@ -75,6 +76,66 @@ protected BasePage(TimeSpan? traitTimeout)
/// </summary>
protected abstract By Trait { get; }

/// <summary>
/// Finds the first element in the page that matches the <see cref="By" /> locator.
/// </summary>
/// <param name="locator">The locator to find the element.</param>
/// <returns>A <see cref="RemoteWebElement"/>.</returns>
public RemoteWebElement FindElement(By locator)
{
return this.App.FindWebElement(locator);
}

/// <summary>
/// Finds all the elements in the page that matches the <see cref="By" /> locator.
/// </summary>
/// <param name="locator">The locator to find the elements.</param>
/// <returns>A readonly collection of <see cref="RemoteWebElement"/>.</returns>
public ReadOnlyCollection<RemoteWebElement> FindElements(By locator)
{
return this.App.FindWebElements(locator);
}

/// <summary>
/// Finds the first element in the page that matches the specified XPath.
/// </summary>
/// <param name="xpath">The XPath to find the element.</param>
/// <returns>A <see cref="RemoteWebElement"/>.</returns>
public RemoteWebElement FindElementByXPath(string xpath)
{
return this.App.FindElementByXPath(xpath) as RemoteWebElement;
}

/// <summary>
/// Finds all the elements in the page that matches the specified XPath.
/// </summary>
/// <param name="xpath">The XPath to find the elements.</param>
/// <returns>A readonly collection of <see cref="RemoteWebElement"/>.</returns>
public ReadOnlyCollection<RemoteWebElement> FindElementsByXPath(string xpath)
{
return this.App.FindElementsByXPath(xpath).Cast<RemoteWebElement>().ToList().AsReadOnly();
}

/// <summary>
/// Finds the first element in the page that matches the specified ID.
/// </summary>
/// <param name="id">The ID of the element.</param>
/// <returns>A <see cref="RemoteWebElement"/>.</returns>
public RemoteWebElement FindElementById(string id)
{
return this.App.FindElementById(id) as RemoteWebElement;
}

/// <summary>
/// Finds the first of element in the page that matches the specified name.
/// </summary>
/// <param name="name">The name of the element.</param>
/// <returns>A <see cref="RemoteWebElement"/>.</returns>
public RemoteWebElement FindElementByName(string name)
{
return this.App.FindElementByName(name) as RemoteWebElement;
}

/// <summary>
/// Determines whether the current page is shown immediately.
/// </summary>
Expand Down

0 comments on commit fd5387a

Please sign in to comment.