32
32
import java .util .Arrays ;
33
33
import java .util .List ;
34
34
import java .util .Optional ;
35
- import java .util .regex .Matcher ;
36
35
import java .util .regex .Pattern ;
37
36
38
37
/**
@@ -144,16 +143,13 @@ public String toString() {
144
143
*/
145
144
public static ExpectedCondition <Boolean > urlMatches (final String regex ) {
146
145
return new ExpectedCondition <Boolean >() {
146
+ private final Pattern pattern = Pattern .compile (regex );
147
147
private String currentUrl ;
148
- private Pattern pattern ;
149
- private Matcher matcher ;
150
148
151
149
@ Override
152
150
public Boolean apply (WebDriver driver ) {
153
151
currentUrl = driver .getCurrentUrl ();
154
- pattern = Pattern .compile (regex );
155
- matcher = pattern .matcher (currentUrl );
156
- return matcher .find ();
152
+ return pattern .matcher (currentUrl ).find ();
157
153
}
158
154
159
155
@ Override
@@ -881,7 +877,7 @@ public Boolean apply(WebDriver driver) {
881
877
@ Override
882
878
public String toString () {
883
879
return String .format ("element found by %s to have value \" %s\" . Current value: \" %s\" " ,
884
- locator , value , currentValue );
880
+ locator , value , currentValue );
885
881
}
886
882
};
887
883
}
@@ -1051,8 +1047,8 @@ public Boolean apply(WebDriver driver) {
1051
1047
1052
1048
@ Override
1053
1049
public String toString () {
1054
- return String .format (property + " to be \" %s \" . Current " + property + ": \" %s \" " , value ,
1055
- currentValue );
1050
+ return String .format ("DOM property '%s' to be '%s' . Current value: '%s'" ,
1051
+ property , value , currentValue );
1056
1052
}
1057
1053
};
1058
1054
}
@@ -1079,8 +1075,8 @@ public Boolean apply(WebDriver driver) {
1079
1075
1080
1076
@ Override
1081
1077
public String toString () {
1082
- return String .format (attribute + " to be \" %s \" . Current " + attribute + ": \" %s \" " , value ,
1083
- currentValue );
1078
+ return String .format ("DOM attribute '%s' to be '%s' . Current value: '%s'" ,
1079
+ attribute , value , currentValue );
1084
1080
}
1085
1081
};
1086
1082
}
@@ -1110,8 +1106,8 @@ public Boolean apply(WebDriver driver) {
1110
1106
1111
1107
@ Override
1112
1108
public String toString () {
1113
- return String .format (attribute + " to be \" %s \" . Current " + attribute + ": \" %s \" " , value ,
1114
- currentValue );
1109
+ return String .format ("Attribute or property '%s' to be '%s' . Current value: '%s'" ,
1110
+ attribute , value , currentValue );
1115
1111
}
1116
1112
};
1117
1113
}
@@ -1132,8 +1128,8 @@ public static ExpectedCondition<Boolean> attributeContains(final WebElement elem
1132
1128
@ Override
1133
1129
public Boolean apply (WebDriver driver ) {
1134
1130
return getAttributeOrCssValue (element , attribute )
1135
- .map (seen -> seen .contains (value ))
1136
- .orElse (false );
1131
+ .map (seen -> seen .contains (value ))
1132
+ .orElse (false );
1137
1133
}
1138
1134
1139
1135
@ Override
@@ -1159,16 +1155,13 @@ public static ExpectedCondition<Boolean> attributeContains(final By locator,
1159
1155
@ Override
1160
1156
public Boolean apply (WebDriver driver ) {
1161
1157
return getAttributeOrCssValue (driver .findElement (locator ), attribute )
1162
- .map (seen -> seen .contains (value ))
1163
- .orElse (false );
1158
+ .map (seen -> seen .contains (value ))
1159
+ .orElse (false );
1164
1160
}
1165
1161
1166
1162
@ Override
1167
1163
public String toString () {
1168
- return String .format (
1169
- "value found by %s to contain \" %s\" ." ,
1170
- locator ,
1171
- value );
1164
+ return String .format ("value found by %s to contain \" %s\" ." , locator , value );
1172
1165
}
1173
1166
};
1174
1167
}
@@ -1271,8 +1264,8 @@ public String toString() {
1271
1264
* @return subelement
1272
1265
*/
1273
1266
public static ExpectedCondition <WebElement > presenceOfNestedElementLocatedBy (
1274
- final By locator ,
1275
- final By childLocator ) {
1267
+ final By locator , final By childLocator )
1268
+ {
1276
1269
return new ExpectedCondition <WebElement >() {
1277
1270
1278
1271
@ Override
@@ -1295,8 +1288,8 @@ public String toString() {
1295
1288
* @return subelement
1296
1289
*/
1297
1290
public static ExpectedCondition <WebElement > presenceOfNestedElementLocatedBy (
1298
- final WebElement element ,
1299
- final By childLocator ) {
1291
+ final WebElement element , final By childLocator )
1292
+ {
1300
1293
1301
1294
return new ExpectedCondition <WebElement >() {
1302
1295
@@ -1321,8 +1314,8 @@ public String toString() {
1321
1314
* @return subelement
1322
1315
*/
1323
1316
public static ExpectedCondition <List <WebElement >> presenceOfNestedElementsLocatedBy (
1324
- final By parent ,
1325
- final By childLocator ) {
1317
+ final By parent , final By childLocator )
1318
+ {
1326
1319
return new ExpectedCondition <List <WebElement >>() {
1327
1320
1328
1321
@ Override
@@ -1345,8 +1338,7 @@ public String toString() {
1345
1338
* @param elements used to check their invisibility
1346
1339
* @return Boolean true when all elements are not visible anymore
1347
1340
*/
1348
- public static ExpectedCondition <Boolean > invisibilityOfAllElements (
1349
- final WebElement ... elements ) {
1341
+ public static ExpectedCondition <Boolean > invisibilityOfAllElements (final WebElement ... elements ) {
1350
1342
return invisibilityOfAllElements (Arrays .asList (elements ));
1351
1343
}
1352
1344
@@ -1356,8 +1348,7 @@ public static ExpectedCondition<Boolean> invisibilityOfAllElements(
1356
1348
* @param elements used to check their invisibility
1357
1349
* @return Boolean true when all elements are not visible anymore
1358
1350
*/
1359
- public static ExpectedCondition <Boolean > invisibilityOfAllElements (
1360
- final List <WebElement > elements ) {
1351
+ public static ExpectedCondition <Boolean > invisibilityOfAllElements (final List <WebElement > elements ) {
1361
1352
return new ExpectedCondition <Boolean >() {
1362
1353
1363
1354
@ Override
@@ -1446,7 +1437,6 @@ public String toString() {
1446
1437
};
1447
1438
}
1448
1439
1449
-
1450
1440
/**
1451
1441
* An expectation with the logical and condition of the given list of conditions.
1452
1442
*
@@ -1484,7 +1474,6 @@ public String toString() {
1484
1474
};
1485
1475
}
1486
1476
1487
-
1488
1477
/**
1489
1478
* An expectation to check if js executable.
1490
1479
*
0 commit comments