2

我试图使用 pico Container 实现 Cucumber 功能级别的并行执行。当我在如下上下文类中使用共享驱动程序时,我得到org.picocontainer.PicoCompositionException: Duplicate Keys not allowed。复制

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

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

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

//跑步者类

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();        
    }
}
4

0 回答 0