balin / com.github.epadronu.balin.core / Browser / at

at

open fun <T : Page> at(factory: (Browser) -> T): T

Tells the browser at what page it should be located.

If the page defines an implicit at verification, then it will be invoked immediately. If such verification fails, Balin will throw a PageImplicitAtVerificationException in order to perform an early failure.

// Given the Kotlin's website index page with content elements and no URL
class IndexPage(browser: Browser) : Page(browser) {

    override val at = at {
        title == this@IndexPage.title
    }

    val title = "Kotlin Programming Language"

    val navItems by lazy {
        `$`("a.nav-item").map { it.text }
    }

    val tryItBtn by lazy {
        `$`(".try-button", 0).text
    }

    val features by lazy {
        `$`("li.kotlin-feature").`$`("h3:nth-child(2)").map { it.text }
    }
}

Browser.drive(driverFactory) {
    // When I navigate to the Kotlin's page URL
    to("https://kotlinlang.org/")

    // And set the browser's page with `at`
    val page = at(::IndexPage)

    // Then I should change the browser's page to the given one
    assertEquals(title, page.title)

    // And I should get the navigation items
    assertEquals(page.navItems, listOf("Learn", "Community", "Try Online"))

    // And I should get the try-it button
    assertEquals(page.tryItBtn, "Try online")

    // And I should get the coolest features
    assertEquals(page.features, listOf("Concise", "Safe", "Interoperable", "Tool-friendly"))
}

Parameters

T - the page's type.

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.

Returns
An instance of the current page.