open val at: Browser.() -> Any
Defines an optional implicit verification to be checked as soon as the browser navigates to the page.
Useful for performing early failure.
// 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())
}
}
@JvmStatic fun at(block: Browser.() -> Any): Browser.() -> Any
This method eases the definition of a page's implicit at verification.
// 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())
}
}
block
- context within which you can interact with the browser.
Return
The block unchanged.