State management for cucumber-scala + cucumber-piococcontainer
nizamudeeen opened this issue · 6 comments
Describe the bug
State management required for cucumber-Scala. like how cucumber-java+ cucumber-picocontainer handling state management
To Reproduce
This world class in the state need within scenario to record the state after each step and global background setup
class world{
var globalFlag: String = _
var scenarioFlag : String = _
var result : String = _
}
below is the stepDefinition class contains all glue code and step definition
class stepDefinition(implicit world : World) extends scalaDsl with En{
Given("do this"){
(input : String) => { world.scenarioFlag = input }
}
}
getting exception trying to inject world instance to step definition. where its works fine in cucumber-java and cucumber-piococontainer
Expected behavior
should get world instance available in the step definition class
Versions:
- Cucumber Scala: [6.9.1]
- Scala: [2.12]
To clarify what you would expect is that a unique World instance is created automatically and provided to the StepDefinition class, right?
To clarify what you would expect is that a unique
Worldinstance is created automatically and provided to theStepDefinitionclass, right?
Yes unique World instance needs pass to step definition for each scenario
Until we look at the injection mechanism (related to #4 ), would something like following be good enough for you:
trait WorldSteps {
val world = new World()
}
class StepDefinition extends ScalaDsl with En with WorldSteps {
}This would instantiate a World instance for each scenario.
Note that the instance wouldn't be a singleton shared with other Steps classes though. To do that, you could workaround something with an object.
Something like:
object WorldWrapper {
var world: World = _
}
class WorldInitializer extends ScalaDsl {
Before {
WorldWrapper.world = new World()
}
}
class StepDefinition extends ScalaDsl with En with WorldSteps {
// Use the WorldWrapper.world
}Just a thought.. I didn't actually try to see if it behaves as expected.
Hey guys, are there any updates ? how to use pico container with cucumber-scala to share context between steps?
Hi @eniqen and @nizamudeeen , this should be working as expected with version 8.4.0 of Cucumber Scala (being published right now).
See documentation at https://github.com/cucumber/cucumber-jvm-scala/blob/main/docs/usage.md#using-dependency-injection
Keep us informed in case you encounter any issue.