net.thucydides.core.steps.StepData Maven / Gradle / Ivy
The newest version!
package net.thucydides.core.steps;
import com.google.common.collect.Lists;
import net.thucydides.core.csv.CSVTestDataSource;
import net.thucydides.core.csv.TestDataSource;
import net.thucydides.core.guice.Injectors;
import net.thucydides.core.model.DataTable;
import net.thucydides.core.util.EnvironmentVariables;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* Data-driven test step execution.
*/
public final class StepData {
private final String testDataSource;
private char separator = ',';
private StepFactory factory;
private static final ThreadLocal factoryThreadLocal = new ThreadLocal();
public StepData(final String testDataSource) {
FilePathParser testDataSourcePath
= new FilePathParser(Injectors.getInjector().getProvider(EnvironmentVariables.class).get() );
this.testDataSource = testDataSourcePath.getInstanciatedPath(testDataSource);
}
public static StepData withTestDataFrom(final String testDataSource) {
return new StepData(testDataSource);
}
@SuppressWarnings("unchecked")
public T run(final T steps) throws IOException {
useDefaultStepFactoryIfUnassigned();
TestDataSource testdata = new CSVTestDataSource(testDataSource, separator);
StepEventBus.getEventBus().useExamplesFrom(dataTable(testdata));
Class> scenarioStepsClass = steps.getClass().getSuperclass();
List instanciatedSteps = (List) testdata.getInstanciatedInstancesFrom(scenarioStepsClass, factory);
DataDrivenStepFactory dataDrivenStepFactory = new DataDrivenStepFactory(factory);
T stepsProxy = (T) dataDrivenStepFactory.newDataDrivenSteps(scenarioStepsClass, instanciatedSteps);
return stepsProxy;
}
private DataTable dataTable(TestDataSource testdata) {
return DataTable.withHeaders(testdata.getHeaders())
.andRows(rowsFrom(testdata)).build();
}
private List> rowsFrom(TestDataSource testdata) {
List> rows = Lists.newArrayList();
for (Map rowData : testdata.getData()) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy