I've updated my Cucumber version to 5.4.2 and this piece of code stopped working due to a Inconvertible types; cannot cast 'io.cucumber.java.Scenario' to 'cucumber.runtime.ScenarioImpl'
error.
Field field = FieldUtils.getField((scenario).getClass(), "stepResults", true);
Any way I could get it back to working?
This is the whole piece of code as per this SO post
private static String logError(Scenario scenario) {
Field field = FieldUtils.getField((scenario).getClass(), "stepResults", true);
if (field != null) {
field.setAccessible(true);
try {
ArrayList<Result> results = (ArrayList<Result>) field.get(scenario);
for (Result result : results) {
if (result.getErrorMessage() != null)
if (result.getErrorMessage().length() >= 10000) {
return FAILED_COMMENT + "\n" + result.getErrorMessage().substring(0, 10000);
} else {
return FAILED_COMMENT + "\n" + result.getErrorMessage();
}
}
} catch (Exception e) {
return FAILED_COMMENT;
}
}
return FAILED_COMMENT;
}
Many thanks.