All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.automation.remarks.kirk.conditions.ColectionCondition.kt Maven / Gradle / Ivy

There is a newer version: 0.8.5
Show newest version
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"
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy