Hari Krishna
Hari Krishna

Reputation: 21

Error org.picocontainer.PicoCompositionException: Duplicate Keys not allowed. Duplicate

I was trying to achieve, Cucumber feature level parallel execution using pico Container. When I am using a shared Driver in a context Class as below, I get org.picocontainer.PicoCompositionException: Duplicate Keys not allowed. Duplicate

    public class Context{
    private ThreadLocal<WebDriver> drivers = new ThreadLocal<>();

    public void setDriver(WebDriver wd) {
        drivers.set(wd);
      }

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

//Runner Class

import java.net.MalformedURLException;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.CucumberFeatureWrapper;
import cucumber.api.testng.TestNGCucumberRunner;
import net.thumbtack.cucumber.picocontainer.example.step.SharedDriver;
import cucumber.api.testng.*;

@CucumberOptions (glue = {"net.thumbtack.cucumber.picocontainer.example.step"},
features = "src/main/resources/"
,tags = {"@Scenario2,@Scenario3"})
public class TestRunner {

    public TestRunner() throws MalformedURLException {
        super();
        // TODO Auto-generated constructor stub
    }

    private TestNGCucumberRunner testNGCucumberRunner;

    @BeforeClass(alwaysRun = true)
    public void setUpClass() throws Exception {     
        testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
        System.setProperty("ExecEnv","Docker");
    }

//    @Test(dataProvider = "features")
//    public void feature(PickleEventWrapper eventwrapper,CucumberFeatureWrapper cucumberFeature) throws Throwable {
    @Test(groups="cucumber", description="Runs CucumberFeature",dataProvider = "features")    
    public void feature(CucumberFeatureWrapper cucumberFeature){
        testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
//      testNGCucumberRunner.runScenario(eventwrapper.getPickleEvent());
    }

    @DataProvider(parallel=true)
    public Object[][] features() {
        return testNGCucumberRunner.provideFeatures();      
//       return testNGCucumberRunner.provideScenarios();
    }

    @AfterClass(alwaysRun = true)
    public void tearDownClass() throws Exception {      
        testNGCucumberRunner.finish();        
    }
}

Upvotes: 2

Views: 1255

Answers (0)

Related Questions