问题
Context
I want to use qaf-cucumber to take advantage of QAF features while still using Cucumber with JUnit. Mainly, I need QAF for its data provider feature, allowing to externalize scenario examples in .csv in order to use them across several scenarios and features.
Junit: 4.12
Cucumber: 5.0.0-RC2
QAF: 2.1.15
qaf-cucumber: 2.1.15-beta-3 (most recent version, as there is no release yet)
Problem
When using the QAF tag @dataFile
above a scenario to specify the location of the .csv:
I get the INFO trace "c.qmetry.qaf.automation.util.CSVUtil - loading csv data file: src/test/resources/data/testdata.csv", as expected.
the scenario is executed as many times as there are lines of examples in the .csv, as expected.
In the steps, references like
<column1>
or${column1}
are considered as string instead of referencing the value of columns in the .csv.
Also (but I don't seek any solutions for those):
The QAF documentation about CSV says that
@dataFile:resources/data/logintestdata.csv
is equivalent toExamples: {"dataFile":"resources/data/logintestdata.csv"}
for BDD2, but the second one does not trigger any scenario, as if no examples where given.The QAF documentation about BDD2 syntax says that the Gherkin keyword
Scenario
should be used when using the QAF tag@dataFile
. Nonetheless, doing so gives the stack trace below. Instead, the keywordScenario Outline
must be used.
java.lang.NullPointerException
at java.util.Collections$UnmodifiableCollection.<init>(Collections.java:1026)
at java.util.Collections$UnmodifiableList.<init>(Collections.java:1302)
at java.util.Collections.unmodifiableList(Collections.java:1287)
at gherkin.ast.ScenarioOutline.<init>(ScenarioOutline.java:13)
at com.qmetry.qaf.automation.cucumber.Bdd2Compiler.compile(Unknown Source)
at io.cucumber.core.feature.FeatureParser.compilePickles(FeatureParser.java:59)
at io.cucumber.core.feature.FeatureParser.parseResource(FeatureParser.java:37)
at io.cucumber.core.runtime.FeaturePathFeatureSupplier.lambda$new$0(FeaturePathFeatureSupplier.java:39)
at java.util.function.BiFunction.lambda$andThen$0(BiFunction.java:70)
at io.cucumber.core.resource.ResourceScanner.lambda$null$2(ResourceScanner.java:128)
at io.cucumber.core.resource.PathScanner$ResourceFileVisitor.visitFile(PathScanner.java:67)
at io.cucumber.core.resource.PathScanner$ResourceFileVisitor.visitFile(PathScanner.java:52)
at java.nio.file.Files.walkFileTree(Files.java:2670)
at java.nio.file.Files.walkFileTree(Files.java:2742)
at io.cucumber.core.resource.PathScanner.findResourcesForPath(PathScanner.java:46)
at io.cucumber.core.resource.PathScanner.findResourcesForUri(PathScanner.java:26)
at io.cucumber.core.resource.ResourceScanner.findResourcesForUri(ResourceScanner.java:111)
at io.cucumber.core.resource.ResourceScanner.scanForResourcesUri(ResourceScanner.java:88)
at io.cucumber.core.runtime.FeaturePathFeatureSupplier.loadFeatures(FeaturePathFeatureSupplier.java:62)
at io.cucumber.core.runtime.FeaturePathFeatureSupplier.get(FeaturePathFeatureSupplier.java:46)
at io.cucumber.junit.Cucumber.<init>(Cucumber.java:138)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Example
Cucumber runner at src/java/com
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/features",
glue = "com.steps",
plugin = {"com.qmetry.qaf.automation.cucumber.QAFCucumberPlugin", "pretty"})
public class RunCucumber {
}
Feature at src/test/resources/features
Feature: Cucumber scenario with QAF data provider
@dataFile:src/test/resources/data/testdata.csv
Scenario Outline: Test
Given my scenario works with the examples "<column1>" and "<column2>"
testdata.csv at src/test/resources/data
#col.seperator=|
column1|column2
example1_column1|example1_column2
example2_column1|example2_column2
Step at src/test/java/com/steps
public class TestSteps {
@Given("my scenario works with the examples {string} and {string}")
public void myScenarioWorks(String value1, String value2) {
// value1 equals "<column1>" and value2 equals "<column2>" !
}
}
回答1:
I tried with 2.1.15 and it worked for me. I was also getting above behavior with qaf-cucumber 2.1.15-beta-3 but when updated to qaf-cucumber 2.1.15 it worked fine.
来源:https://stackoverflow.com/questions/59055379/qaf-cucumber-can-not-reference-data-from-csv-data-provider-in-bdd2-scenario-ou