Skip to content

Commit

Permalink
fix: Add new methods for extended element finding in AppiumElement
Browse files Browse the repository at this point in the history
  • Loading branch information
Dor-bl committed Sep 21, 2023
1 parent eb74195 commit 5d9df88
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Appium.Net/Appium/AppiumElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,30 @@ AppiumElement IFindsByFluentSelector<AppiumElement>.FindElement(string by, strin

IReadOnlyCollection<AppiumElement> IFindsByFluentSelector<AppiumElement>.FindElements(string selector, string value)
{
return ConvertToExtendedWebElementCollection(base.FindElements(selector, value));
return ConvertToAppiumElementCollection(base.FindElements(selector, value));
}

internal static ReadOnlyCollection<AppiumElement> ConvertToExtendedWebElementCollection(IEnumerable collection)
/// <summary>
/// Finds the first element that matches the specified <paramref name="by"/> selector and returns it as an <see cref="AppiumElement"/>.
/// </summary>
/// <param name="by">The <see cref="By"/> selector used to locate the element.</param>
/// <returns>The first <see cref="AppiumElement"/> that matches the <paramref name="by"/> selector.</returns>
public new AppiumElement FindElement(By by)
{
return (AppiumElement)base.FindElement(by);
}

/// <summary>
/// Finds all elements that match the specified <paramref name="by"/> selector and returns them as a read-only collection of <see cref="AppiumElement"/>.
/// </summary>
/// <param name="by">The <see cref="By"/> selector used to locate the elements.</param>
/// <returns>A read-only collection of <see cref="AppiumElement"/> objects matching the <paramref name="by"/> selector.</returns>
public new ReadOnlyCollection<AppiumElement> FindElements(By by)
{
return ConvertToAppiumElementCollection(base.FindElements(by));
}

internal static ReadOnlyCollection<AppiumElement> ConvertToAppiumElementCollection(IEnumerable collection)
{
return collection.Cast<AppiumElement>().ToList().AsReadOnly();
}
Expand Down
16 changes: 16 additions & 0 deletions test/integration/Android/ElementTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ public void ScrollingToSubElementUsingBuilder()
Assert.NotNull(radioGroup.Location);
}

[Test]
public void FindAppiumElementUsingNestedElement()
{
var myElement = _driver.FindElement(MobileBy.Id("android:id/content"));
AppiumElement nestedElement = myElement.FindElement(By.Id("android:id/text1"));
Assert.NotNull(nestedElement);
}

[Test]
public void FindAppiumElementsListUsingNestedElement()
{
var myElement = _driver.FindElement(MobileBy.Id("android:id/content"));
IList<AppiumElement> myDerivedElements = myElement.FindElements(By.Id("android:id/text1"));
Assert.AreNotEqual(myDerivedElements.Count,0);
}

[OneTimeTearDown]
public void AfterAll()
{
Expand Down

0 comments on commit 5d9df88

Please sign in to comment.