@@ -40,6 +40,14 @@ private static readonly Func<IElementStateProvider, bool>[] StateFunctionsTrueWh
40
40
state => ! state . WaitForNotEnabled ( TimeSpan . Zero ) ,
41
41
} ;
42
42
43
+ private static readonly Func < IElementStateProvider , bool > [ ] StateFunctionsThrowNoSuchElementException
44
+ = new Func < IElementStateProvider , bool > [ ]
45
+ {
46
+ state => state . IsEnabled ,
47
+ state => state . WaitForEnabled ( TimeSpan . Zero ) ,
48
+ state => ! state . WaitForNotEnabled ( TimeSpan . Zero ) ,
49
+ } ;
50
+
43
51
private IConditionalWait ConditionalWait => AqualityServices . ServiceProvider . GetRequiredService < IConditionalWait > ( ) ;
44
52
45
53
[ SetUp ]
@@ -108,30 +116,35 @@ public void Should_RefreshElement_WhenItIsStale()
108
116
}
109
117
110
118
[ Test ]
111
- [ Ignore ( "Tests should be updated: find out more stable example" ) ]
112
- public void Should_ReturnCorrectState_False_WhenWindowIsRefreshed ( [ ValueSource ( nameof ( StateFunctionsFalseWhenElementStale ) ) ] Func < IElementStateProvider , bool > stateCondition )
119
+ public void Should_ThrowNoSuchElementException_ForAbsentElement ( [ ValueSource ( nameof ( StateFunctionsThrowNoSuchElementException ) ) ] Func < IElementStateProvider , bool > stateCondition )
120
+ {
121
+ var label = new Label ( By . Name ( "Absent element" ) , "Absent element" , ElementState . Displayed ) ;
122
+ Assert . Throws < NoSuchElementException > ( ( ) => stateCondition . Invoke ( label . State ) ) ;
123
+ }
124
+
125
+ [ Test ]
126
+ public void Should_ReturnCorrectState_False_WhenWindowIsReopened ( [ ValueSource ( nameof ( StateFunctionsFalseWhenElementStale ) ) ] Func < IElementStateProvider , bool > stateCondition )
113
127
{
114
- AssertStateConditionAfterRefresh ( stateCondition , expectedValue : false ) ;
128
+ AssertStateConditionAfterReopen ( stateCondition , expectedValue : false ) ;
115
129
}
116
130
117
131
[ Test ]
118
- [ Ignore ( "Tests should be updated: find out more stable example" ) ]
119
- public void Should_ReturnCorrectState_True_WhenWindowIsRefreshed ( [ ValueSource ( nameof ( StateFunctionsTrueWhenElementStaleWhichRetriveElement ) ) ] Func < IElementStateProvider , bool > stateCondition )
132
+ public void Should_ReturnCorrectState_True_WhenWindowIsReopened ( [ ValueSource ( nameof ( StateFunctionsTrueWhenElementStaleWhichRetriveElement ) ) ] Func < IElementStateProvider , bool > stateCondition )
120
133
{
121
- AssertStateConditionAfterRefresh ( stateCondition , expectedValue : true ) ;
134
+ AssertStateConditionAfterReopen ( stateCondition , expectedValue : true ) ;
122
135
}
123
136
124
- private void AssertStateConditionAfterRefresh ( Func < IElementStateProvider , bool > stateCondition , bool expectedValue )
137
+ private void AssertStateConditionAfterReopen ( Func < IElementStateProvider , bool > stateCondition , bool expectedValue )
125
138
{
126
139
OpenDynamicContent ( ) ;
127
140
var testElement = new Label ( ContentLoc , "Example" , ElementState . ExistsInAnyState ) ;
128
141
testElement . State . WaitForClickable ( ) ;
129
- new Label ( RemoveButtonLoc , "Remove" , ElementState . Displayed ) . Click ( ) ;
130
- ConditionalWait . WaitForTrue ( ( ) => testElement . Cache . IsStale , message : "Element should be stale when it disappeared." ) ;
131
- AqualityServices . Application . Driver . Navigate ( ) . Refresh ( ) ;
132
- Assert . IsTrue ( testElement . Cache . IsStale , "Element should remain stale after the page refresh." ) ;
142
+ AqualityServices . Application . Quit ( ) ;
143
+ StartLoading ( ) ;
144
+ ConditionalWait . WaitForTrue ( ( ) => testElement . Cache . IsStale , message : "Element should be stale after page is closed." ) ;
145
+ OpenDynamicContent ( ) ;
133
146
Assert . AreEqual ( expectedValue , stateCondition ( testElement . State ) ,
134
- "Element state condition is not expected after refreshing the window" ) ;
147
+ "Element state condition is not expected after reopening the window" ) ;
135
148
}
136
149
137
150
[ TearDown ]
0 commit comments