Extension functions to make Selenide tests with Kotlin awesome!
Gradle:
repositories {
maven {
url "https://dl.bintray.com/strangeway-org/libs"
}
}
dependencies {
testImplementation "org.strangeway:selenide-kelt:1.1.1"
}
-
Get element by any of standard By (with named arguments instead of By):
open("/login") // search by CSS as simple as possible: elt("#submit").click() // or you may specify selector explicitly: elt(css = "#submit").click() elt(cssClass = "message").shouldHave(text("Hello")) elt(text = "Sign in").click() elt(name = "password").setValue("qwerty").pressEnter() elt(xpath = "//*[@id='search-results']//a[contains(text(),'selenide.org')]").click()
-
Or many elements:
elts(id = "search-results").shouldBe(visible) elts("#search-results a").elt(text = "selenide.org").click()
-
Element inside of elements:
elt(tag = "header").elt(id = "menu").click() elt(tag = "header").elts(cssClass = "item").shouldHave(size(5))
-
Build PageObject classes easier:
import org.strangeway.kelt.* class GoogleResultsPage { val results = elt(id = "results") } class GoogleSearchPage { private val searchBox = elt(name = "q") fun search(query: String): GoogleResultsPage { searchBox.setValue(query).pressEnter() return page() // no need to duplicate <GoogleResultsPage> type } } // ... openPage<GoogleSearchPage>("http://google.com").search("Selenide!") // get page on demand without opening val googlePage = page<GoogleResultsPage>()
-
Check conditions with infix functions:
import org.strangeway.kelt.* import com.codeborne.selenide.Condition.* elt(tag = "header") shouldBe visible elt(css = ".footer") shouldHave text("text") elts(".all") shouldBe CollectionCondition.empty elts(".parts") shouldHave CollectionCondition.texts("1", "2")