Skip to content

Extension functions to make Selenide tests with Kotlin awesome

License

Notifications You must be signed in to change notification settings

strangeway-org/selenide-kelt

Repository files navigation

Kelt Helmet

Selenide Kelt

Extension functions to make Selenide tests with Kotlin awesome!

license Download

Maven dependency:

Gradle:

repositories {
    maven {
        url "https://dl.bintray.com/strangeway-org/libs" 
    }
}

dependencies {
    testImplementation "org.strangeway:selenide-kelt:1.1.1"
}

Examples:

  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()
  2. Or many elements:

    elts(id = "search-results").shouldBe(visible)
    elts("#search-results a").elt(text = "selenide.org").click()
  3. Element inside of elements:

    elt(tag = "header").elt(id = "menu").click()
    elt(tag = "header").elts(cssClass = "item").shouldHave(size(5))
  4. 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>()
  5. 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")

If you want to support the project

Buy Me A Coffee