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

Page

abstract class Page : ClickAndNavigateSupport, ComponentMappingSupport, JavaScriptSupport, SearchContext, WaitingSupport

This class is the corner stone for Balin's implementation of the Page Object Design Pattern. All classes that model a Web page/view most extend this one.

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

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

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

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

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

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

Browser.drive(driverFactory) {
    // When I visit such page and get the content's elements
    to(::IndexPage).run {
        // Then I should get the navigation items
        assertEquals(navItems, listOf("Learn", "Community", "Try Online"))

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

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

Parameters

browser - the browser used by the page in order to interact with the underlying web content.

Constructors

<init>

Page(browser: Browser)

Create a new instance with the given browser as its bridge with the web content the page care about.

Properties

at

open val at: Browser.() -> Any

Defines an optional implicit verification to be checked as soon as the browser navigates to the page.

browser

val browser: Browser

the browser used by the page in order to interact with the underlying web content.

url

open val url: String?

Defines an optional URL, which will be used when invoking Browser.to with a page factory.

Functions

click

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

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

component

open fun <T : Component> WebElement.component(factory: (Page, WebElement) -> T): T

Create a new component with the given WebElement as its root element.

open fun <T : Component> List<WebElement>.component(factory: (Page, WebElement) -> T): List<T>

Map the given collection of WebElement into a collection of com.github.epadronu.balin.core.Component.

Companion Object Functions

at

fun at(block: Browser.() -> Any): Browser.() -> Any

This method eases the definition of a page's implicit at verification.

Extension Functions

$

fun SearchContext.$(selector: String, index: Int): WebElement

Find the nth element that can be located by the given CSS selector.

fun SearchContext.$(selector: String, range: IntRange): List<WebElement>

Find all the elements that can be located by the given CSS selector, restricted by the specified range.

fun SearchContext.$(selector: String, vararg indices: Int): List<WebElement>

Find all the elements that can be located by the given CSS selector, restricted by the specified indices. (If no index is provided, then all matching elements will be returned.)

find

fun SearchContext.find(selector: String, index: Int): WebElement

Find the nth element that can be located by the given CSS selector.

fun SearchContext.find(selector: String, range: IntRange): List<WebElement>

Find all the elements that can be located by the given CSS selector, restricted by the specified range.

fun SearchContext.find(selector: String, vararg indices: Int): List<WebElement>

Find all the elements that can be located by the given CSS selector, restricted by the specified indices. (If no index is provided, then all matching elements will be returned.)