Skip to content

Commit 4067f65

Browse files
authored
Fix RelativeElementFinder to throw the exception if the condition was not satisfied to fix #45 (#46)
1 parent ad787d6 commit 4067f65

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/RelativeElementFinder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ public override ReadOnlyCollection<IWebElement> FindElements(By locator, Desired
3131
var resultElements = new List<IWebElement>();
3232
try
3333
{
34-
ConditionalWait.WaitFor(() =>
34+
ConditionalWait.WaitForTrue(() =>
3535
{
3636
foundElements = SearchContextSupplier().FindElements(locator).ToList();
3737
resultElements = foundElements.Where(desiredState.ElementStateCondition).ToList();
3838
return resultElements.Any();
3939
}, timeout);
4040
}
41-
catch (WebDriverTimeoutException ex)
41+
catch (TimeoutException ex)
4242
{
43-
HandleTimeoutException(ex, desiredState, locator, foundElements);
43+
HandleTimeoutException(new WebDriverTimeoutException(ex.Message, ex), desiredState, locator, foundElements);
4444
}
4545
return resultElements.AsReadOnly();
4646
}

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/WindowsApp/Locators/CalculatorWindow.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ public static class CalculatorWindow
1818
public static By EqualsButton => By.Name("=");
1919

2020
public static By ResultsLabel => MobileBy.AccessibilityId("48");
21+
22+
public static By EmptyButton => By.XPath("//*[@AutomationId='7']");
2123
}
2224
}

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/WindowsApp/RelativeElementFinderTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using Aquality.Selenium.Core.Waitings;
66
using Microsoft.Extensions.DependencyInjection;
77
using NUnit.Framework;
8+
using OpenQA.Selenium;
9+
using System;
810

911
namespace Aquality.Selenium.Core.Tests.Applications.WindowsApp
1012
{
@@ -14,11 +16,23 @@ public class RelativeElementFinderTests : TestWithApplication
1416
AqualityServices.ServiceProvider.GetRequiredService<ILocalizedLogger>(),
1517
AqualityServices.ServiceProvider.GetRequiredService<ConditionalWait>(),
1618
() => AqualityServices.Application.Driver.FindElement(CalculatorWindow.WindowLocator));
19+
20+
private IElementStateProvider GetElementStateProvider(By locator) => new ElementStateProvider(
21+
locator,
22+
AqualityServices.ServiceProvider.GetRequiredService<ConditionalWait>(),
23+
ElementFinder);
1724

1825
[Test]
1926
public void Should_FindChildElements_ViaRelativeElementFinder()
2027
{
2128
Assert.IsNotNull(ElementFinder.FindElement(CalculatorWindow.OneButton));
2229
}
30+
31+
[Test]
32+
public void Should_ThrowException_IfWaitForClickableEnded()
33+
{
34+
var emptyButtonState = GetElementStateProvider(CalculatorWindow.EmptyButton);
35+
Assert.Throws<WebDriverTimeoutException>(() => emptyButtonState.WaitForClickable(TimeSpan.Zero));
36+
}
2337
}
2438
}

0 commit comments

Comments
 (0)