Skip to content

Commit c234f49

Browse files
committed
simplify
1 parent 78d934f commit c234f49

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

lib/src/main/kotlin/seleniumtestinglib/Core.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ abstract class TLBy internal constructor(private val textMatch: TextMatch) : Sel
323323
}
324324

325325
override fun toString(): String {
326-
val prefix = if (options.entries.isEmpty()) "" else ", "
326+
val prefix = if (options.isEmpty()) "" else ", "
327327
return "$by($textMatch$prefix${options.entries.joinToString { "${it.key}: ${it.value}" }})"
328328
}
329329
}

lib/src/main/kotlin/seleniumtestinglib/WebElement.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,13 @@ val WebElement.formValues: Map<String, Any?>
5353
fun WebElement.hasFormValues(vararg values: Pair<String, Any?>): Boolean =
5454
values.toMap().all { formValues[it.key] == it.value }
5555

56-
5756
private fun WebElement.hasStyle(css: Map<String, String>): Boolean {
5857
val expectedCss = css.mapKeys { it.key.normalizeCssProp() }
5958
val existingCss = expectedCss.keys
6059
.associateWith(::getCssValue)
6160
return expectedCss == existingCss
6261
}
6362

64-
6563
fun WebElement.hasStyle(css: String): Boolean =
6664
hasStyle(css.split(";")
6765
.filter(String::isNotBlank)
@@ -72,7 +70,8 @@ fun WebElement.hasStyle(css: String): Boolean =
7270

7371
fun WebElement.hasStyle(vararg css: Pair<String, String>) = hasStyle(css.toMap())
7472

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()
7675

7776
val WebElement.isChecked: Boolean
7877
get() {
@@ -156,16 +155,17 @@ val WebElement.accessibleDescription: String?
156155
val WebElement.classes: Set<String>
157156
get() = getAttribute("class").takeIf(String::isNotBlank)?.split(Regex("\\s+"))?.toSet() ?: emptySet()
158157

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+
}
169169

170170
val WebElement.errorMessage: String?
171171
get() = when {

0 commit comments

Comments
 (0)