Home > Enterprise >  Any one able to run parallel tests: Using Cucumber 6.10.2 or newer versions, cucumber-Spring, Junit
Any one able to run parallel tests: Using Cucumber 6.10.2 or newer versions, cucumber-Spring, Junit

Time:11-25

Using below combination of versions, the parallel execution through surefire is not working properly. If we change Cucumber to 4.8.1, then the parallel execution through surefire works.

**Cucumber 6.10.2 or newer versions, cucumber-Spring, Junit 4.13.2 and Maven surefire 3.0.0.M3 and above **

But once the cucumber version is changed to 6.10.2, it does not work. The specific problem is, the webdriver session is getting leaked among the threads, or in simple word multiple threads acting on the same webdriver session.

I did lot of research and tried multiple configurations in the POM, but it did not work: Trial 1. Excluded junit-jupiter and jupiter-vintage-engine from cucumber-junit, excluded junit-jupiter and jupiter-vintage-engine from cucumber-Spring, Added surefire-junit47 dependency to surefire plugin Trial 2. Added jupiter-vintage-engine as dependency to surefire plugin Trial 3. Using Spring Boot version 2.6.2, Cucumber 6.10.2 or newer versions, cucumber-Spring, Junit 5 and surefire 3.0.0.M7

Will appreciate any help.

CodePudding user response:

If we change Cucumber to 4.8.1, then the parallel execution through surefire works. But once the cucumber version is changed to 6.10.2, it does not work.

Projects typically publish a change log with all relevant changes in it. You should consult it when upgrading major versions.

https://github.com/cucumber/cucumber-jvm/blob/main/CHANGELOG.md

The specific problem is, the webdriver session is getting leaked among the threads, or in simple word multiple threads acting on the same webdriver session.

This is a feature of Spring! When using Spring you'll share the same application context between all tests.

You can prevent this by marking the bean with your web driver as scenario scoped.

@Component
@ScenarioScope
public class WebDriverComponent {

    private WebDriver driver = // create WebDriverhere

    public WebDriver getDriver() {
        return driver;
    }

} 

https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-spring#sharing-state

And if you want to reuse the WebDriver between scenarios on the same thread you can use a Thread local:

@Component
@ScenarioScope
public class WebDriverComponent {

    private static ThreadLocal<WebDriver> driver = ThreadLocal.withInitial( create WebDriverhere );

    public WebDriver getDriver() {
        return driver.get();
    }

} 

  • Related