Alkemy
Alkemy is a browser automation framework written in Kotlin and based on Selenium and Kotest. The objective is to provide more fluent definitions for Selenium tests, using a functional style and Kotlin extension functions. Alkemy currently supports Chrome and Firefox browsers.
See Documentation for further information.
For a full working example please check the sample-project in this repository.
Dependency
testImplementation "io.resoluteworks:alkemy:${alkemyVersion}"
Writing tests
Alkemy enables a variety of approaches for writing Selenium tests in Kotlin. A set of extensions functions can be
used against String
to perform lookups and assertions.
Alternatively, similar extensions are available for WebDriver
and WebElement
, including
helper methods like fillForm
, typeIn
and assertions like shouldBeVisible
, shoulHaveClass
, etc.
Alkemy also provides a very basic framework for Page Object Model approaches. This includes all the extensions and
assertions available for WebDriver
.
Lastly, any Kotest assertions can be used natively in combination with the Alkemy or Selenium objects.
class MyTest(val context: AlkemyContext) : StringSpec({
"string selectors and assertions" {
// To use String extensions the context.apply{} construct is required
context.apply {
get("/dynamic_controls")
val form = "#input-example"
"$form button".shouldHaveText("Enable")
.shouldBeEnabled()
.click()
.shouldBeDisabled()
"$form #loading".shouldBeVisible()
"$form input[type='text']".shouldBeEnabled(maxWaitSeconds = 10)
}
}
"login with fillForm" {
context.get("/login")
.fillForm(
"username" to "tomsmith",
"password" to "SuperSecretPassword!"
)
.submit() shouldHaveText "Welcome to the Secure Area"
}
"login with page object model" {
val securePage = context
.goTo<LoginPage>()
.login("tomsmith", "SuperSecretPassword!")
securePage shouldHaveText "Welcome to the Secure Area"
}
"using native Kotest assertions" {
val driver = context.get("/login")
driver.findElements("input") shouldHaveSize 2
driver.find("h2").text shouldContain "Login Page"
}
})
class LoginPage(context: AlkemyContext) : Page(context, "/login") {
fun login(username: String, password: String): SecurePage {
fillForm("username" to username, "password" to password)
.submit()
return next<SecurePage>()
}
}
class SecurePage(context: AlkemyContext) : Page(context, "/secure")
Documentation
See Documentation for further information.