2

Background: For quite some time I have ran automated tests using forked JVM processes, this proved quite easy when injecting a driver object using spring, I could simply provide the following:

@Bean(destroyMethod = "quit")
@Scope("singleton")
public Driver driver() {
    return new Driver();
}

Fast forward to today, I have built in a solution which takes my scenario / feature files and generates a runner for each one, an example runner generated looks like this:

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

    @CucumberOptions(
            strict = true,
            features = {"C:/Users/simonk/Desktop/proof-of-concept-framework/gui-tests/src/test/resources/features/forgot_password.feature:6"},
            plugin = {"io.qameta.allure.cucumber2jvm.AllureCucumber2Jvm"},
            monochrome = false,
            glue = {"confidential.package.gui.configurations.webdriver", "confidential.package.gui.stepdefinitions"})
    public class ForgotPassword01Test extends AbstractTestNGCucumberTests {
    }

When running these in parallel, obviously there is serious driver multi threaded issue(s), so how do I best go about writing a solution that can cater to this successfully?

 - I need a driver instance for each runner being executed, could be 10+ threads in parallel
 - Runners are generated automatically using `temyers github cucumber plugin`
 - Can i use my spring setup but instead of a singleton, somehow tell it to grab a driver for each thread which accesses it?

@Configuration
@PropertySource(value = {"classpath:/framework.properties"})
@Slf4j
public class SpringConfig {


    @Bean
    public CucumberWorld cucumberWorld() {
        return new CucumberWorld();
    }

    @Bean(destroyMethod = "quit")
    @Scope("singleton")
    public Driver driver() {
        return new Driver();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.