Skip to content

Commit 3a9d37c

Browse files
committed
Updated page object with FindElement methods
1 parent b15a178 commit 3a9d37c

File tree

2 files changed

+63
-32
lines changed

2 files changed

+63
-32
lines changed

src/Legerity.Core/Extensions/PageExtensions.cs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,6 @@ namespace Legerity.Extensions
1212
/// </summary>
1313
public static class PageExtensions
1414
{
15-
/// <summary>
16-
/// Finds the first element in the given element that matches the <see cref="By" /> locator.
17-
/// </summary>
18-
/// <typeparam name="TPage">
19-
/// The type of <see cref="BasePage"/>.
20-
/// </typeparam>
21-
/// <param name="page">The page object.</param>
22-
/// <param name="locator">The locator to find the element.</param>
23-
/// <returns>A <see cref="RemoteWebElement"/>.</returns>
24-
public static RemoteWebElement FindWebElement<TPage>(this TPage page, By locator)
25-
where TPage : BasePage
26-
{
27-
return page.App.FindWebElement(locator);
28-
}
29-
30-
/// <summary>
31-
/// Finds all the elements in the given element that matches the <see cref="By" /> locator.
32-
/// </summary>
33-
/// <typeparam name="TPage">
34-
/// The type of <see cref="BasePage"/>.
35-
/// </typeparam>
36-
/// <param name="page">The page object.</param>
37-
/// <param name="locator">The locator to find the elements.</param>
38-
/// <returns>A readonly collection of <see cref="RemoteWebElement"/>.</returns>
39-
public static ReadOnlyCollection<RemoteWebElement> FindWebElements<TPage>(this TPage page, By locator)
40-
where TPage : BasePage
41-
{
42-
return page.App.FindWebElements(locator);
43-
}
44-
4515
/// <summary>
4616
/// Waits until a specified page condition is met, with an optional timeout.
4717
/// </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)