com.automation.remarks.kirk.conditions.ColectionCondition.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kirk Show documentation
Show all versions of kirk Show documentation
Kirk - pragmatic UI test automation
package com.automation.remarks.kirk.conditions
import com.automation.remarks.kirk.core.Select
import org.openqa.selenium.WebElement
/**
* Created by sergey on 28.06.17.
*/
abstract class CollectionCondition : BaseCondition>()
class CollectionSize(val size: Int) : CollectionCondition() {
override fun matches(item: List): Boolean {
return item.size == size
}
override fun description(item: List): Description {
return Description(item.size, size)
}
}
class CollectionMinimumSize(val index: Int) : CollectionCondition() {
override fun matches(item: List): Boolean {
return item.size-1 >= index
}
override fun description(item: List): Description {
return MinimumSizeConditionDesc(item.size-1, index, this)
}
class MinimumSizeConditionDesc(actual: Any, expected: Any, val condition: CollectionCondition):
Description(actual, expected) {
override val reason: String? = "required index $actual exceeds collections size"
}
}
class CollectionExactText(val text: Array) : CollectionCondition() {
override fun matches(item: List): Boolean {
return item.map { it.text } == text.toList()
}
override fun description(item: List): Description {
return Description(item.map { it.text }, text.toList())
}
}
class CollectionContainText(val text: String) : CollectionCondition() {
override fun matches(item: List): Boolean {
return item.any { it.text == text }
}
override fun description(item: List): Description {
return Description(item.map { it.text }, text)
}
override fun toString(): String {
return "collection have element with text"
}
}