Skip to content

Latest commit

 

History

History
58 lines (43 loc) · 1.71 KB

README.md

File metadata and controls

58 lines (43 loc) · 1.71 KB

Alkemy Spring Module

Module to configure Alkemy using Spring configuration properties

Usage

Gradle:

// build.gradle
testImplementation "io.resoluteworks:alkemy-spring:${alkemyVersion}"

Autowire AlkemyProperties in the constructor together with other Spring beans, then use it to register the AlkemyExtension, e.g.

class MySpec(alkemyProperties: AlkemyProperties, service: UserService) : WordSpec({
    val alkemyContext = alkemyContext(alkemyProperties)

Configure Alkemy using Spring configuration properties, e.g.

# src/test/resources/application.yml
alkemy:
  base-url: https://the-internet.herokuapp.com
  headless: true

Dynamic Configuration

To configure Alkemy dynamically, use AlkemyProperties' copy constructor to overwrite any properties.

For example, to configure alkemy.base-url with the webserver port that was randomly assigned by Spring Boot Test:

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class DynamicConfigurationTest(alkemyProperties: AlkemyProperties, @LocalServerPort serverPort: Int) : WordSpec() {
    init {
        val alkemyContext = alkemyContext(
            alkemyProperties.copy(
                baseUrl = "http://localhost:${serverPort}",
            )
        )

Disabling Kotest Auto Scan

If Kotest auto scan is disabled, you will need to manually load the AlkemyWebDriverPoolExtension and SpringAutowireConstructorExtension extension in your Project config, e.g.

class ProjectConfig : AbstractProjectConfig() {
    override fun extensions() = listOf(AlkemyWebDriverPoolExtension, SpringAutowireConstructorExtension)
}