1
1
package com .github .markusbernhardt .seleniumlibrary .keywords ;
2
2
3
+ import com .github .markusbernhardt .seleniumlibrary .RunOnFailureKeywordsAdapter ;
4
+ import com .github .markusbernhardt .seleniumlibrary .SeleniumLibraryNonFatalException ;
5
+ import com .github .markusbernhardt .seleniumlibrary .utils .Robotframework ;
3
6
import org .apache .commons .lang3 .exception .ExceptionUtils ;
4
7
import org .openqa .selenium .JavascriptExecutor ;
5
8
import org .robotframework .javalib .annotation .ArgumentNames ;
6
9
import org .robotframework .javalib .annotation .Autowired ;
7
10
import org .robotframework .javalib .annotation .RobotKeyword ;
8
11
import org .robotframework .javalib .annotation .RobotKeywords ;
9
12
10
- import com .github .markusbernhardt .seleniumlibrary .RunOnFailureKeywordsAdapter ;
11
- import com .github .markusbernhardt .seleniumlibrary .SeleniumLibraryNonFatalException ;
12
- import com .github .markusbernhardt .seleniumlibrary .utils .Robotframework ;
13
-
14
13
@ RobotKeywords
15
14
public class Waiting extends RunOnFailureKeywordsAdapter {
16
15
@@ -52,8 +51,10 @@ public void waitForCondition(final String condition, String...params) {
52
51
if (message == null ) {
53
52
message = String .format ("Condition '%s' did not become true in <TIMEOUT>" , condition );
54
53
}
55
- waitUntil (timeout , message , () -> Boolean .TRUE .equals (((JavascriptExecutor ) browserManagement .getCurrentWebDriver ())
56
- .executeScript (condition )));
54
+ waitUntil (
55
+ timeout ,
56
+ message ,
57
+ () -> Boolean .TRUE .equals (((JavascriptExecutor ) browserManagement .getCurrentWebDriver ()).executeScript (condition )));
57
58
}
58
59
59
60
@ RobotKeyword ("Waits until the current page contains ``text``.\r \n " +
@@ -68,7 +69,10 @@ public void waitUntilPageContains(final String text, String...params) {
68
69
if (message == null ) {
69
70
message = String .format ("Text '%s' did not appear in <TIMEOUT>" , text );
70
71
}
71
- waitUntil (timeout , message , () -> element .isTextPresent (text ));
72
+ waitUntil (
73
+ timeout ,
74
+ message ,
75
+ () -> element .isTextPresent (text ));
72
76
}
73
77
74
78
@ RobotKeyword ("Waits until the current page does not contain ``text``.\r \n " +
@@ -83,7 +87,10 @@ public void waitUntilPageNotContains(final String text, String...params) {
83
87
if (message == null ) {
84
88
message = String .format ("Text '%s' did not disappear in <TIMEOUT>" , text );
85
89
}
86
- waitUntil (timeout , message , () -> !element .isTextPresent (text ));
90
+ waitUntil (
91
+ timeout ,
92
+ message ,
93
+ () -> !element .isTextPresent (text ));
87
94
}
88
95
89
96
@ RobotKeyword ("Waits until the current page does not contain ``text``.\r \n " +
@@ -110,7 +117,10 @@ public void waitUntilPageContainsElement(final String locator, String...params)
110
117
if (message == null ) {
111
118
message = String .format ("Element '%s' did not appear in <TIMEOUT>" , locator );
112
119
}
113
- waitUntil (timeout , message , () -> element .isElementPresent (locator ));
120
+ waitUntil (
121
+ timeout ,
122
+ message ,
123
+ () -> element .isElementPresent (locator ));
114
124
}
115
125
116
126
@ RobotKeyword ("Waits until the element identified by ``locator`` is not found on the current page.\r \n " +
@@ -125,7 +135,10 @@ public void waitUntilPageNotContainsElement(final String locator, String...param
125
135
if (message == null ) {
126
136
message = String .format ("Element '%s' did not disappear in <TIMEOUT>" , locator );
127
137
}
128
- waitUntil (timeout , message , () -> !element .isElementPresent (locator ));
138
+ waitUntil (
139
+ timeout ,
140
+ message ,
141
+ () -> !element .isElementPresent (locator ));
129
142
}
130
143
131
144
@ RobotKeyword ("Waits until the element identified by ``locator`` is not found on the current page.\r \n " +
@@ -152,7 +165,10 @@ public void waitUntilElementIsVisible(final String locator, String...params) {
152
165
if (message == null ) {
153
166
message = String .format ("Element '%s' not visible in <TIMEOUT>" , locator );
154
167
}
155
- waitUntil (timeout , message , () -> element .isVisible (locator ));
168
+ waitUntil (
169
+ timeout ,
170
+ message ,
171
+ () -> element .isVisible (locator ));
156
172
}
157
173
158
174
@ RobotKeyword ("Waits until the element identified by ``locator`` is not visible.\r \n " +
@@ -167,7 +183,10 @@ public void waitUntilElementIsNotVisible(final String locator, String...params)
167
183
if (message == null ) {
168
184
message = String .format ("Element '%s' still visible in <TIMEOUT>" , locator );
169
185
}
170
- waitUntil (timeout , message , () -> !element .isVisible (locator ));
186
+ waitUntil (
187
+ timeout ,
188
+ message ,
189
+ () -> !element .isVisible (locator ));
171
190
}
172
191
173
192
@ RobotKeyword ("Waits until the element identified by ``locator`` is clickable.\r \n " +
@@ -182,7 +201,10 @@ public void waitUntilElementIsClickable(final String locator, String...params) {
182
201
if (message == null ) {
183
202
message = String .format ("Element '%s' not clickable in <TIMEOUT>" , locator );
184
203
}
185
- waitUntil (timeout , message , () -> element .isClickable (locator ));
204
+ waitUntil (
205
+ timeout ,
206
+ message ,
207
+ () -> element .isClickable (locator ));
186
208
}
187
209
188
210
@ RobotKeyword ("Waits until the element identified by ``locator`` is not clickable.\r \n " +
@@ -197,7 +219,10 @@ public void waitUntilElementIsNotClickable(final String locator, String...params
197
219
if (message == null ) {
198
220
message = String .format ("Element '%s' still clickable in <TIMEOUT>" , locator );
199
221
}
200
- waitUntil (timeout , message , () -> !element .isClickable (locator ));
222
+ waitUntil (
223
+ timeout ,
224
+ message ,
225
+ () -> !element .isClickable (locator ));
201
226
}
202
227
203
228
@ RobotKeyword ("Waits until the element identified by ``locator`` is succesfully clicked on.\r \n " +
@@ -212,10 +237,13 @@ public void waitUntilElementIsSuccessfullyClicked(final String locator, String..
212
237
if (message == null ) {
213
238
message = String .format ("Element '%s' not successfully clicked in <TIMEOUT>" , locator );
214
239
}
215
- waitUntil (timeout , message , () -> {
216
- element .clickElement (locator );
217
- return true ;
218
- });
240
+ waitUntil (
241
+ timeout ,
242
+ message ,
243
+ () -> {
244
+ element .clickElement (locator );
245
+ return true ;
246
+ });
219
247
}
220
248
221
249
@ RobotKeyword ("Waits until the element identified by ``locator`` is selected.\r \n " +
@@ -230,7 +258,10 @@ public void waitUntilElementIsSelected(final String locator, String...params) {
230
258
if (message == null ) {
231
259
message = String .format ("Element '%s' not selected in <TIMEOUT>" , locator );
232
260
}
233
- waitUntil (timeout , message , () -> element .isSelected (locator ));
261
+ waitUntil (
262
+ timeout ,
263
+ message ,
264
+ () -> element .isSelected (locator ));
234
265
}
235
266
236
267
@ RobotKeyword ("Waits until the element identified by ``locator`` is not selected.\r \n " +
@@ -245,7 +276,10 @@ public void waitUntilElementIsNotSelected(final String locator, String...params)
245
276
if (message == null ) {
246
277
message = String .format ("Element '%s' still selected in <TIMEOUT>" , locator );
247
278
}
248
- waitUntil (timeout , message , () -> !element .isSelected (locator ));
279
+ waitUntil (
280
+ timeout ,
281
+ message ,
282
+ () -> !element .isSelected (locator ));
249
283
}
250
284
251
285
@ RobotKeyword ("Waits until the current page title contains ``title``.\r \n " +
@@ -260,10 +294,13 @@ public void waitUntilTitleContains(final String title, String...params) {
260
294
if (message == null ) {
261
295
message = String .format ("Title '%s' did not appear in <TIMEOUT>" , title );
262
296
}
263
- waitUntil (timeout , message , () -> {
264
- String currentTitle = browserManagement .getTitle ();
265
- return currentTitle != null && currentTitle .contains (title );
266
- });
297
+ waitUntil (
298
+ timeout ,
299
+ message ,
300
+ () -> {
301
+ String currentTitle = browserManagement .getTitle ();
302
+ return currentTitle != null && currentTitle .contains (title );
303
+ });
267
304
}
268
305
269
306
@ RobotKeyword ("Waits until the current page title does not contain ``title``.\r \n " +
@@ -278,10 +315,13 @@ public void waitUntilTitleNotContains(final String title, String...params) {
278
315
if (message == null ) {
279
316
message = String .format ("Title '%s' did not appear in <TIMEOUT>" , title );
280
317
}
281
- waitUntil (timeout , message , () -> {
282
- String currentTitle = browserManagement .getTitle ();
283
- return currentTitle == null || !currentTitle .contains (title );
284
- });
318
+ waitUntil (
319
+ timeout ,
320
+ message ,
321
+ () -> {
322
+ String currentTitle = browserManagement .getTitle ();
323
+ return currentTitle == null || !currentTitle .contains (title );
324
+ });
285
325
}
286
326
287
327
@ RobotKeyword ("Waits until the current page title is exactly ``title``.\r \n " +
@@ -296,10 +336,13 @@ public void waitUntilTitleIs(final String title, String...params) {
296
336
if (message == null ) {
297
337
message = String .format ("Title '%s' did not appear in <TIMEOUT>" , title );
298
338
}
299
- waitUntil (timeout , message , () -> {
300
- String currentTitle = browserManagement .getTitle ();
301
- return currentTitle != null && currentTitle .equals (title );
302
- });
339
+ waitUntil (
340
+ timeout ,
341
+ message ,
342
+ () -> {
343
+ String currentTitle = browserManagement .getTitle ();
344
+ return currentTitle != null && currentTitle .equals (title );
345
+ });
303
346
}
304
347
305
348
@ RobotKeyword ("Waits until the current page title is not exactly ``title``.\r \n " +
@@ -314,10 +357,13 @@ public void waitUntilTitleIsNot(final String title, String...params) {
314
357
if (message == null ) {
315
358
message = String .format ("Title '%s' did not appear in <TIMEOUT>" , title );
316
359
}
317
- waitUntil (timeout , message , () -> {
318
- String currentTitle = browserManagement .getTitle ();
319
- return currentTitle == null || !currentTitle .equals (title );
320
- });
360
+ waitUntil (
361
+ timeout ,
362
+ message ,
363
+ () -> {
364
+ String currentTitle = browserManagement .getTitle ();
365
+ return currentTitle == null || !currentTitle .equals (title );
366
+ });
321
367
}
322
368
323
369
// ##############################
@@ -348,6 +394,7 @@ protected void waitUntil(String timestr, String message, WaitUntilFunction funct
348
394
}
349
395
}
350
396
397
+ @ FunctionalInterface
351
398
protected interface WaitUntilFunction {
352
399
353
400
boolean isFinished ();
0 commit comments