@@ -9,12 +9,14 @@ namespace Aquality.Selenium.Core.Elements
9
9
public class ElementStateProvider : IElementStateProvider
10
10
{
11
11
private readonly By elementLocator ;
12
+ private readonly LogElementState logElementState ;
12
13
13
- public ElementStateProvider ( By elementLocator , IConditionalWait conditionalWait , IElementFinder elementFinder )
14
+ public ElementStateProvider ( By elementLocator , IConditionalWait conditionalWait , IElementFinder elementFinder , LogElementState logElementState )
14
15
{
15
16
this . elementLocator = elementLocator ;
16
17
ConditionalWait = conditionalWait ;
17
18
ElementFinder = elementFinder ;
19
+ this . logElementState = logElementState ;
18
20
}
19
21
20
22
private IConditionalWait ConditionalWait { get ; }
@@ -31,22 +33,22 @@ public ElementStateProvider(By elementLocator, IConditionalWait conditionalWait,
31
33
32
34
public bool WaitForDisplayed ( TimeSpan ? timeout = null )
33
35
{
34
- return IsAnyElementFound ( timeout , ElementState . Displayed ) ;
36
+ return DoAndLogWaitForState ( ( ) => IsAnyElementFound ( timeout , ElementState . Displayed ) , "displayed" ) ;
35
37
}
36
38
37
39
public bool WaitForNotDisplayed ( TimeSpan ? timeout = null )
38
40
{
39
- return ConditionalWait . WaitFor ( ( ) => ! IsDisplayed , timeout ) ;
41
+ return DoAndLogWaitForState ( ( ) => ConditionalWait . WaitFor ( ( ) => ! IsDisplayed , timeout ) , "not.displayed" ) ;
40
42
}
41
43
42
44
public bool WaitForExist ( TimeSpan ? timeout = null )
43
45
{
44
- return IsAnyElementFound ( timeout , ElementState . ExistsInAnyState ) ;
46
+ return DoAndLogWaitForState ( ( ) => IsAnyElementFound ( timeout , ElementState . ExistsInAnyState ) , "exist" ) ;
45
47
}
46
48
47
49
public bool WaitForNotExist ( TimeSpan ? timeout = null )
48
50
{
49
- return ConditionalWait . WaitFor ( ( ) => ! IsExist , timeout ) ;
51
+ return DoAndLogWaitForState ( ( ) => ConditionalWait . WaitFor ( ( ) => ! IsExist , timeout ) , "not.exist" ) ;
50
52
}
51
53
52
54
private bool IsAnyElementFound ( TimeSpan ? timeout , ElementState state )
@@ -56,12 +58,12 @@ private bool IsAnyElementFound(TimeSpan? timeout, ElementState state)
56
58
57
59
public bool WaitForEnabled ( TimeSpan ? timeout = null )
58
60
{
59
- return IsElementInDesiredState ( element => IsElementEnabled ( element ) , "ENABLED" , timeout ) ;
61
+ return DoAndLogWaitForState ( ( ) => IsElementInDesiredState ( element => IsElementEnabled ( element ) , "ENABLED" , timeout ) , "enabled" ) ;
60
62
}
61
63
62
64
public bool WaitForNotEnabled ( TimeSpan ? timeout = null )
63
65
{
64
- return IsElementInDesiredState ( element => ! IsElementEnabled ( element ) , "NOT ENABLED" , timeout ) ;
66
+ return DoAndLogWaitForState ( ( ) => IsElementInDesiredState ( element => ! IsElementEnabled ( element ) , "NOT ENABLED" , timeout ) , "not.enabled" ) ;
65
67
}
66
68
67
69
protected virtual bool IsElementEnabled ( IWebElement element )
@@ -81,7 +83,17 @@ private bool IsElementInDesiredState(Func<IWebElement, bool> elementStateConditi
81
83
82
84
public void WaitForClickable ( TimeSpan ? timeout = null )
83
85
{
84
- IsElementClickable ( timeout , false ) ;
86
+ var conditionKey = "loc.el.state.clickable" ;
87
+ try
88
+ {
89
+ logElementState ( "loc.wait.for.state" , conditionKey ) ;
90
+ IsElementClickable ( timeout , false ) ;
91
+ }
92
+ catch
93
+ {
94
+ logElementState ( "loc.wait.for.state.failed" , conditionKey ) ;
95
+ throw ;
96
+ }
85
97
}
86
98
87
99
private bool IsElementClickable ( TimeSpan ? timeout , bool catchTimeoutException )
@@ -97,5 +109,23 @@ private bool IsElementInDesiredCondition(TimeSpan? timeout, DesiredState element
97
109
{
98
110
return ElementFinder . FindElements ( elementLocator , elementStateCondition , timeout ) . Any ( ) ;
99
111
}
112
+
113
+ private bool DoAndLogWaitForState ( Func < bool > waitingAction , string conditionKeyPart , TimeSpan ? timeout = null )
114
+ {
115
+ if ( TimeSpan . Zero == timeout )
116
+ {
117
+ return waitingAction ( ) ;
118
+ }
119
+
120
+ var conditionKey = $ "loc.el.state.{ conditionKeyPart } ";
121
+ logElementState ( "loc.wait.for.state" , conditionKey ) ;
122
+ var result = waitingAction ( ) ;
123
+ if ( ! result )
124
+ {
125
+ logElementState ( "loc.wait.for.state.failed" , conditionKey ) ;
126
+ }
127
+
128
+ return result ;
129
+ }
100
130
}
101
131
}
0 commit comments