Skip to content

Commit fd5387a

Browse files
authored
Merge pull request #138 from MADE-Apps/feature/page-extensions
Added FindElement methods to BasePage
2 parents 3da1624 + 3a9d37c commit fd5387a

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

src/Legerity.Core/Extensions/PageExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
namespace Legerity.Extensions
22
{
33
using System;
4+
using System.Collections.ObjectModel;
45
using Legerity.Pages;
56
using OpenQA.Selenium;
7+
using OpenQA.Selenium.Remote;
68
using OpenQA.Selenium.Support.UI;
79

810
/// <summary>

src/Legerity.Core/Pages/BasePage.cs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
namespace Legerity.Pages
22
{
33
using System;
4-
4+
using System.Collections.ObjectModel;
5+
using System.Linq;
56
using Legerity.Exceptions;
6-
7+
using Legerity.Extensions;
78
using OpenQA.Selenium;
89
using OpenQA.Selenium.Appium.Android;
910
using OpenQA.Selenium.Appium.iOS;
@@ -75,6 +76,66 @@ protected BasePage(TimeSpan? traitTimeout)
7576
/// </summary>
7677
protected abstract By Trait { get; }
7778

79+
/// <summary>
80+
/// Finds the first element in the page that matches the <see cref="By" /> locator.
81+
/// </summary>
82+
/// <param name="locator">The locator to find the element.</param>
83+
/// <returns>A <see cref="RemoteWebElement"/>.</returns>
84+
public RemoteWebElement FindElement(By locator)
85+
{
86+
return this.App.FindWebElement(locator);
87+
}
88+
89+
/// <summary>
90+
/// Finds all the elements in the page that matches the <see cref="By" /> locator.
91+
/// </summary>
92+
/// <param name="locator">The locator to find the elements.</param>
93+
/// <returns>A readonly collection of <see cref="RemoteWebElement"/>.</returns>
94+
public ReadOnlyCollection<RemoteWebElement> FindElements(By locator)
95+
{
96+
return this.App.FindWebElements(locator);
97+
}
98+
99+
/// <summary>
100+
/// Finds the first element in the page that matches the specified XPath.
101+
/// </summary>
102+
/// <param name="xpath">The XPath to find the element.</param>
103+
/// <returns>A <see cref="RemoteWebElement"/>.</returns>
104+
public RemoteWebElement FindElementByXPath(string xpath)
105+
{
106+
return this.App.FindElementByXPath(xpath) as RemoteWebElement;
107+
}
108+
109+
/// <summary>
110+
/// Finds all the elements in the page that matches the specified XPath.
111+
/// </summary>
112+
/// <param name="xpath">The XPath to find the elements.</param>
113+
/// <returns>A readonly collection of <see cref="RemoteWebElement"/>.</returns>
114+
public ReadOnlyCollection<RemoteWebElement> FindElementsByXPath(string xpath)
115+
{
116+
return this.App.FindElementsByXPath(xpath).Cast<RemoteWebElement>().ToList().AsReadOnly();
117+
}
118+
119+
/// <summary>
120+
/// Finds the first element in the page that matches the specified ID.
121+
/// </summary>
122+
/// <param name="id">The ID of the element.</param>
123+
/// <returns>A <see cref="RemoteWebElement"/>.</returns>
124+
public RemoteWebElement FindElementById(string id)
125+
{
126+
return this.App.FindElementById(id) as RemoteWebElement;
127+
}
128+
129+
/// <summary>
130+
/// Finds the first of element in the page that matches the specified name.
131+
/// </summary>
132+
/// <param name="name">The name of the element.</param>
133+
/// <returns>A <see cref="RemoteWebElement"/>.</returns>
134+
public RemoteWebElement FindElementByName(string name)
135+
{
136+
return this.App.FindElementByName(name) as RemoteWebElement;
137+
}
138+
78139
/// <summary>
79140
/// Determines whether the current page is shown immediately.
80141
/// </summary>

0 commit comments

Comments
 (0)