@@ -53,15 +53,13 @@ val WebElement.formValues: Map<String, Any?>
53
53
fun WebElement.hasFormValues (vararg values : Pair <String , Any ?>): Boolean =
54
54
values.toMap().all { formValues[it.key] == it.value }
55
55
56
-
57
56
private fun WebElement.hasStyle (css : Map <String , String >): Boolean {
58
57
val expectedCss = css.mapKeys { it.key.normalizeCssProp() }
59
58
val existingCss = expectedCss.keys
60
59
.associateWith(::getCssValue)
61
60
return expectedCss == existingCss
62
61
}
63
62
64
-
65
63
fun WebElement.hasStyle (css : String ): Boolean =
66
64
hasStyle(css.split(" ;" )
67
65
.filter(String ::isNotBlank)
@@ -72,7 +70,8 @@ fun WebElement.hasStyle(css: String): Boolean =
72
70
73
71
fun WebElement.hasStyle (vararg css : Pair <String , String >) = hasStyle(css.toMap())
74
72
75
- private fun String.normalizeCssProp () = " (?<=[a-zA-Z])[A-Z]" .toRegex().replace(this ) { " -${it.value} " }.lowercase()
73
+ private fun String.normalizeCssProp () =
74
+ " (?<=[a-zA-Z])[A-Z]" .toRegex().replace(this ) { " -${it.value} " }.lowercase()
76
75
77
76
val WebElement .isChecked: Boolean
78
77
get() {
@@ -156,16 +155,17 @@ val WebElement.accessibleDescription: String?
156
155
val WebElement .classes: Set <String >
157
156
get() = getAttribute(" class" ).takeIf (String ::isNotBlank)?.split(Regex (" \\ s+" ))?.toSet() ? : emptySet()
158
157
159
- fun WebElement.hasClass (vararg classNames : String , exact : Boolean = false): Boolean {
160
- val expectedClasses = classNames.map { it.split(Regex (" \\ s+" )) }.flatten().toSet()
161
- if (expectedClasses.isEmpty()) {
162
- return classes.isNotEmpty()
163
- }
164
- return when (exact) {
165
- false -> classes.containsAll(expectedClasses)
166
- true -> expectedClasses == classes
167
- }
168
- }
158
+ fun WebElement.hasClass (vararg classNames : String , exact : Boolean = false): Boolean =
159
+ classNames
160
+ .flatMap { it.split(Regex (" \\ s+" )) }
161
+ .toSet()
162
+ .ifEmpty { return classes.isNotEmpty() }
163
+ .let { expectedClasses ->
164
+ when (exact) {
165
+ false -> classes.containsAll(expectedClasses)
166
+ true -> expectedClasses == classes
167
+ }
168
+ }
169
169
170
170
val WebElement .errorMessage: String?
171
171
get() = when {
0 commit comments