Skip to content

Commit

Permalink
Merge pull request #39 from aristotelos/fix-find-elements-empty
Browse files Browse the repository at this point in the history
Return empty list from Find elements
  • Loading branch information
aristotelos authored May 8, 2024
2 parents c87c586 + cbc3f04 commit 4857093
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
24 changes: 12 additions & 12 deletions src/FlaUI.WebDriver.UITests/FindElementsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void FindElement_ByTagName_ReturnsElement()
}

[Test]
public void FindElement_NotExisting_TimesOut()
public void FindElement_NotExisting_ThrowsNoSuchElementException()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
Expand All @@ -142,7 +142,7 @@ public void FindElementFromElement_InsideElement_ReturnsElement()
}

[Test]
public void FindElementFromElement_OutsideElement_TimesOut()
public void FindElementFromElement_OutsideElement_ThrowsNoSuchElementException()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
Expand All @@ -166,15 +166,15 @@ public void FindElementsFromElement_InsideElement_ReturnsElement()
}

[Test]
public void FindElementsFromElement_OutsideElement_TimesOut()
public void FindElementsFromElement_OutsideElement_ReturnsEmptyList()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
var fromElement = driver.FindElement(ExtendedBy.AccessibilityId("ListBox"));

var findElements = () => fromElement.FindElements(ExtendedBy.AccessibilityId("TextBox"));
var foundElements = fromElement.FindElements(ExtendedBy.AccessibilityId("TextBox"));

Assert.That(findElements, Throws.TypeOf<NoSuchElementException>());
Assert.That(foundElements, Is.Empty);
}

[Test]
Expand All @@ -189,18 +189,18 @@ public void FindElements_Default_ReturnsElements()
}

[Test]
public void FindElements_NotExisting_TimesOut()
public void FindElements_NotExisting_ReturnsEmptyList()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);

var findElements = () => driver.FindElements(ExtendedBy.AccessibilityId("NotExisting"));
var foundElements = driver.FindElements(ExtendedBy.AccessibilityId("NotExisting"));

Assert.That(findElements, Throws.TypeOf<NoSuchElementException>());
Assert.That(foundElements, Is.Empty);
}

[Test]
public void FindElement_InOtherWindow_TimesOut()
public void FindElement_InOtherWindow_ThrowsNoSuchElementException()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
Expand All @@ -214,15 +214,15 @@ public void FindElement_InOtherWindow_TimesOut()
}

[Test]
public void FindElements_InOtherWindow_TimesOut()
public void FindElements_InOtherWindow_ReturnsEmptyList()
{
var driverOptions = FlaUIDriverOptions.TestApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);
OpenAndSwitchToAnotherWindow(driver);

var findElements = () => driver.FindElements(ExtendedBy.AccessibilityId("TextBox"));
var foundElements = driver.FindElements(ExtendedBy.AccessibilityId("TextBox"));

Assert.That(findElements, Throws.TypeOf<NoSuchElementException>());
Assert.That(foundElements, Is.Empty);
var elementsInNewWindow = driver.FindElements(ExtendedBy.AccessibilityId("Window1TextBox"));
Assert.That(elementsInNewWindow, Has.Count.EqualTo(1));
}
Expand Down
5 changes: 0 additions & 5 deletions src/FlaUI.WebDriver/Controllers/FindElementsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ private static async Task<ActionResult> FindElementsFrom(Func<AutomationElement>
elements = await Wait.Until(() => startNode().FindAllDescendants(condition), elements => elements.Length > 0, session.ImplicitWaitTimeout);
}

if (elements.Length == 0)
{
return NoSuchElement(findElementRequest);
}

var knownElements = elements.Select(session.GetOrAddKnownElement);
return await Task.FromResult(WebDriverResult.Success(

Expand Down

0 comments on commit 4857093

Please sign in to comment.