Forum Discussion

dyneck's avatar
Occasional Visitor
3 years ago

Problem with generating report after some code executed in @Before


this is my TestRunner:



        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);
        final String currency = restrictedCurrency;
        CurrencyRule currencyRule = rulesBackup
                .filter(rule -> rule.getCurrency().equals(currency))
        boolean isRuleSetToDefault = isRuleSetToDefault(currencyRule);
        if (isRuleSetToDefault) {
  "Currency rule for '%s' is set to to default", currency));
        } else {

    protected static List<PickleStepTestStep> extractSteps(Scenario scenario) throws NoSuchFieldException, IllegalAccessException {
        Field f = scenario.getClass().getDeclaredField("delegate");
        TestCaseState tcs = (TestCaseState) f.get(scenario);

        Field f2 = tcs.getClass().getDeclaredField("testCase");
        TestCase tc = (TestCase) f2.get(tcs);

        return tc.getTestSteps()
                .filter(x -> x instanceof PickleStepTestStep)
                .map(x -> (PickleStepTestStep) x)




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.

No RepliesBe the first to reply