balin / com.github.epadronu.balin.core / Page / click

click

open fun <T : Page> WebElement.click(factory: (Browser) -> T): T

Overrides ClickAndNavigateSupport.click

Click on an element and tells the browser it will navigate to the given page as consequence of such action.

// Given the Kotlin's reference page
class ReferencePage(browser: Browser) : Page(browser) {

    override val at = at {
        title == "Reference - Kotlin Programming Language"
    }

    val header by lazy {
        `$`("h1", 0).text
    }
}

// And the Kotlin's website index page
class IndexPage(browser: Browser) : Page(browser) {

    override val url = "https://kotlinlang.org/"

    override val at = at {
        title == "Kotlin Programming Language"
    }

    fun goToLearnPage() = `$`("div.nav-links a", 0).click(::ReferencePage)
}

Browser.drive(driverFactory) {
    // When I visit the Kotlin's website index page
    val indexPage = to(::IndexPage)

    // And I click on the Learn navigation link
    val referencePage = indexPage.goToLearnPage()

    // Then the browser should land on the Reference page
    assertEquals(referencePage.header, "Learn Kotlin")
}

Parameters

factory - provides an instance of the page given the driver being used by the browser.

Exceptions

PageImplicitAtVerificationException - if the page has an implicit at verification which have failed.

Receiver
the WebElement to be clicked on.

Returns
An instance of the page the browser will navigate to.