cucumber/cucumber-jvm

cucumber-scala instantiates step definition classes per test JVM instead of per scenario

Closed this issue · 4 comments

From https://groups.google.com/forum/#!topic/cukes/eOhisAzEvQo, written by @tristanmccarthy:

"The problem I am hitting is that step def classes appear to be instantiated only once, at the start of the test run. Based on reading around (and previous experience with Java) I'd expect the glue code classes to be instantiated once per scenario instead, and the way I am trying to set everything up requires this."

"...I've stuck a quick and dirty example up on github for some context:
https://github.com/tristanmccarthy/cucumber-scala-webtest"

Sure enough, this is still a problem. I assume the java classes are loaded each time?

I think it has to do with how the scala DSL is similar to the Ruby DSL than the Java DSL. New classes aren't made each time, the file is loaded once and then the step definitions are called. You could probably solve this problem by putting your yahooSearchPage somewhere else...? You could certainly put it in a Before hook.

I think I see what's going on in the scala code, it's loading and instantiating everything in the loadGlue method, whereas the java backend only figures out what it needs to load. If we were to move the glue classes around it'd probably work more correctly.

I'm gonna try to work on this.

Take a look at how it's done with the java8 module's lambda stepdefs. You might be able to use a similar approach.

lock commented

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.