Search code examples
kotlincucumbergherkin

Cucumber parameter type with kotlin


I wonder, is there any example of implementing parameter type with Cucumber in Kotlin?

I've read the official doc but it doesn't explain how to wire it up.

I was looking around but haven't found anything really meaningful.

Any help with this?


Solution

  • I found the solution to this. It seems that by just adding a class in the plug package all works

    class NumberParameterTypeConfigurer : TypeRegistryConfigurer {
    override fun locale(): Locale {
        return Locale.ENGLISH
    }
    
    override fun configureTypeRegistry(typeRegistry: TypeRegistry?) {
        typeRegistry?.defineParameterType(ParameterType(
                "number",
                """\b(no|\d)\b""",
                Int::class.java,
                Transformer {
                    when (it) {
                        "no" -> 0
                        else -> it.toInt()
                    }
                }
        ))
    }
    

    }

    hope this can help somebody else