我想为黄瓜方案创建Dynamic TestNG XML,并希望以并行模式执行。
我对黄瓜API进行了必要的修改,以在以下链接的帮助下并行运行黄瓜方案。
访问https://github.com/cucumber/cucumber-jvm/pull/1118/commits/ab8a0d38ace369a756f201d240c906fdd8111c74
我修改了从特征文件中提取场景的方法,但是我不知道在下面的代码行中应该提到哪个类
List myClasses = new ArrayList ();
myClasses.add(new XmlClass("src.test.java.cucumber.api.testng.TestNGCucumberRunner.java"));
下面的方法是读取所有功能文件和方案并转换为TestNG XML。
public Object[][] provideScenariosForXML(boolean blnRunOnGrid, boolean blnPreserveFeatureOrder, boolean blnPreserveScenarioOrder) {
TestNG myTestNG=new TestNG();
try {
int i=0;
XmlSuite mySuite = new XmlSuite();
System.out.println("Feature:");
mySuite.setName("Features");
mySuite.setParallel(XmlSuite.ParallelMode.TESTS);
if(blnRunOnGrid){
if(blnPreserveFeatureOrder){
mySuite.setPreserveOrder("Yes");
}
}else{
mySuite.setPreserveOrder("");
mySuite.setThreadCount(1);
mySuite.setDataProviderThreadCount(1); //To Control Iteration Parallel Threads
}
List features = getFeatures();
List scenarioList = new ArrayList(features.size());
for (CucumberFeature feature: features) {
System.out.println(feature.getPath());
List lsTests = new ArrayList();
List scenarios = feature.getFeatureElements();
for (CucumberTagStatement scenario: scenarios) {
XmlTest eachTest = new XmlTest(mySuite);
List myClasses = new ArrayList ();
myClasses.add(new XmlClass("src.test.java.cucumber.api.testng.TestNGCucumberRunner.java"));
if (scenario instanceof CucumberScenarioOutline) {
List cucumberExamplesList = ((CucumberScenarioOutline) scenario).getCucumberExamplesList();
for (CucumberExamples cucumberExamples : cucumberExamplesList) {
List exampleScenarios = cucumberExamples.createExampleScenarios();
for (CucumberScenario exampleScenario : exampleScenarios) {
eachTest.setName(scenario.getVisualName()+" : "+exampleScenario.getVisualName());
eachTest.setClasses(myClasses);
System.out.println("\t"+scenario.getVisualName()+" : "+exampleScenario.getVisualName());
scenarioList.add(new Object[]{new CucumberTagStatementWrapperImpl(exampleScenario)});
i++;
}
}
}else{
System.out.println("\t"+scenario.getVisualName());
i++;
scenarioList.add(new Object[]{new CucumberTagStatementWrapperImpl(scenario)});
}
}
mySuite.setTests(lsTests);
}
System.out.println("Total Number of Scenarios :"+i);
List mySuites = new ArrayList();
mySuites.add(mySuite);
myTestNG.setXmlSuites(mySuites);
return scenarioList.toArray(new Object[][]{});
} catch (CucumberException e) {
return new Object[][]{new Object[]{new CucumberExceptionWrapper(e)}};
}
}
正在尝试这样做
1.控制总体线程数(不是数据提供者线程数)
2.在需要时保留执行顺序(@Suite级别或@Test级别)
如果有人对此有解决方案,请帮助我。