Problem with generating report after some code executed in @Before
Hello,
this is my TestRunner:
@CucumberOptions(
features = {"src/test/resources/features/Mixed.source.feature"},
glue = "classpath:",
plugin = {"html:src/test/resources/execution/report/cucumber-reports.html"},
tags = EMPTY
)
public class MixedSourceCreateTestRunner extends AbstractTestRunner {
}
I test application which services currencies. There are some rules which can be set by user for each currencies. But there is a test suite which works on default settings so I wrote a code to reset all rules to default before the execution. But it is not effective when I run only one scenario because all other rules are unnecessary set to default as it could be only done one by one. So I prepare a code to extract currency in given test cases from test steps and only reset only this one which is used in given scenario. It's also done in @Before method. It's done like below:
protected void resetRuleForCurrencyToDefault() throws TestExecutionException, JsonProcessingException {
String restrictedCurrency = EMPTY;
List<PickleStepTestStep> steps = extractSteps(scenario);
for (PickleStepTestStep step : steps) {
if (step.getStep().getArgument() != null) {
DataTableArgument argument = (DataTableArgument) step.getStep().getArgument();
List<String> firstDataRow = argument.cells().get(1);
restrictedCurrency = Currency.getByCode(firstDataRow.get(1)).isRestricted() ? firstDataRow.get(1) : firstDataRow.get(2);
break;
}
}
final String currency = restrictedCurrency;
CurrencyRule currencyRule = rulesBackup
.stream()
.filter(rule -> rule.getCurrency().equals(currency))
.findFirst()
.get();
boolean isRuleSetToDefault = isRuleSetToDefault(currencyRule);
if (isRuleSetToDefault) {
LOGGER.info(String.format("Currency rule for '%s' is set to to default", currency));
} else {
RestFXRulesBackup.resetRuleForCurrencyToDefault(currencyRule);
}
}
protected static List<PickleStepTestStep> extractSteps(Scenario scenario) throws NoSuchFieldException, IllegalAccessException {
Field f = scenario.getClass().getDeclaredField("delegate");
f.setAccessible(true);
TestCaseState tcs = (TestCaseState) f.get(scenario);
Field f2 = tcs.getClass().getDeclaredField("testCase");
f2.setAccessible(true);
TestCase tc = (TestCase) f2.get(tcs);
return tc.getTestSteps()
.stream()
.filter(x -> x instanceof PickleStepTestStep)
.map(x -> (PickleStepTestStep) x)
.collect(Collectors.toList());
}
Unfortunately if I do it this way file generated report is not displayed in browser and there is completely strange error displayed browser console
I have no idea what is going on.