Skip to content

Commit 9f92979

Browse files
knyshpaveliam
authored andcommitted
#13 implemented ElementStateProvider (#32)
* #13 implemented ElementStateProvider * fixes for Element State * #13 added documentation for class * #13 fixed documentation
1 parent 21ee30e commit 9f92979

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using Aquality.Selenium.Configurations;
2-
using Aquality.Selenium.Elements.Interfaces;
1+
using Aquality.Selenium.Elements.Interfaces;
2+
using Aquality.Selenium.Waitings;
33
using OpenQA.Selenium;
44
using System;
5+
using System.Collections.ObjectModel;
6+
using System.Linq;
57

68
namespace Aquality.Selenium.Elements
79
{
@@ -14,30 +16,33 @@ internal ElementStateProvider(By elementLocator)
1416
this.elementLocator = elementLocator;
1517
}
1618

17-
public bool IsDisplayed => throw new NotImplementedException();
18-
19-
public bool IsExist => throw new NotImplementedException();
20-
21-
public TimeSpan DefaultTimeout => Configuration.Instance.TimeoutConfiguration.Condition;
19+
public bool IsDisplayed => WaitForDisplayed(TimeSpan.Zero);
2220

21+
public bool IsExist => WaitForExist(TimeSpan.Zero);
22+
2323
public bool WaitForDisplayed(TimeSpan? timeout = null)
2424
{
25-
throw new NotImplementedException();
25+
return FindElements(timeout, ElementState.Displayed).Any();
2626
}
2727

2828
public bool WaitForExist(TimeSpan? timeout = null)
2929
{
30-
throw new NotImplementedException();
30+
return FindElements(timeout, ElementState.ExistsInAnyState).Any();
3131
}
3232

3333
public bool WaitForNotDisplayed(TimeSpan? timeout = null)
3434
{
35-
throw new NotImplementedException();
35+
return ConditionalWait.WaitForTrue(driver => !IsDisplayed, timeout);
3636
}
3737

3838
public bool WaitForNotExist(TimeSpan? timeout = null)
3939
{
40-
throw new NotImplementedException();
40+
return ConditionalWait.WaitForTrue(driver => !IsExist, timeout);
41+
}
42+
43+
private ReadOnlyCollection<IWebElement> FindElements(TimeSpan? timeout, ElementState state)
44+
{
45+
return ElementFinder.Instance.FindElements(elementLocator, state, timeout);
4146
}
4247
}
4348
}

Aquality.Selenium/src/Aquality.Selenium/Elements/Interfaces/IElementStateProvider.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,48 @@
22

33
namespace Aquality.Selenium.Elements.Interfaces
44
{
5+
/// <summary>
6+
/// Provides ability to define of element's state (whether it is displayed, exist or not)
7+
/// Also provides respective positive and negative waiting functions
8+
/// </summary>
59
public interface IElementStateProvider
610
{
11+
/// <summary>
12+
/// Is an element displayed on the page.
13+
/// </summary>
714
bool IsDisplayed { get; }
815

16+
/// <summary>
17+
/// Is an element exist in DOM (without visibility check)
18+
/// </summary>
919
bool IsExist { get; }
1020

11-
TimeSpan DefaultTimeout { get; }
12-
21+
/// <summary>
22+
/// Waits for element is displayed on the page.
23+
/// </summary>
24+
/// <param name="timeout">Timeout for waiting. Default: Configuration.TimeoutConfiguration.Condition</param>
25+
/// <returns>true if element displayed after waiting, false otherwise</returns>
1326
bool WaitForDisplayed(TimeSpan? timeout = null);
1427

28+
/// <summary>
29+
/// Waits for element is not displayed on the page.
30+
/// </summary>
31+
/// <param name="timeout">Timeout for waiting. Default: Configuration.TimeoutConfiguration.Condition</param>
32+
/// <returns>true if element does not display after waiting, false otherwise</returns>
1533
bool WaitForNotDisplayed(TimeSpan? timeout = null);
1634

35+
/// <summary>
36+
/// Waits until element is exist in DOM (without visibility check).
37+
/// </summary>
38+
/// <param name="timeout">Timeout for waiting. Default: Configuration.TimeoutConfiguration.Condition</param>
39+
/// <returns>true if element exist after waiting, false otherwise</returns>
1740
bool WaitForExist(TimeSpan? timeout = null);
1841

42+
/// <summary>
43+
/// Waits until element does not exist in DOM (without visibility check).
44+
/// </summary>
45+
/// <param name="timeout">Timeout for waiting. Default: Configuration.TimeoutConfiguration.Condition</param>
46+
/// <returns>true if element does not exist after waiting, false otherwise</returns>
1947
bool WaitForNotExist(TimeSpan? timeout = null);
2048
}
2149
}

0 commit comments

Comments
 (0)