Cucumber では、ステップ定義クラス間で変数を渡すにはどうすればよいですか。Scalaで実装しようとしています。
周りを見回すと、Guice や Picocontainer、その他の DI フレームワークの使用を提案する人がいます。しかし、実際には Scala での例に出くわしたことはありません。
たとえば、以下の例では、 DI を使用して変数を渡すにはどうすればよいですか?
Provider.scala、
class Provider extends ScalaDsl with EN with Matchers with WebBrowser {
......
When("""I click the Done button$""") {
val doneButton = getElement(By.id(providerConnectionButton))
doneButton.click()
}
Then("""a new object should be created successfully""") {
// Pass the provider ID created in this step to Consumer definition
}
}
Consumer.scala、
class Consumer extends ScalaDsl with EN with Matchers with WebBrowser {
......
When("""^I navigate to Consumer page$""") { () =>
// providerId is the id from Provider above
webDriver.navigate().to(s"${configureUrl}${providerId}")
}
}