class ExecutedScenarioExtractorService {

    public List<ExecutedScenario> extractExecutedScenarios(List<Feature> features, List<String> stepDefinitions, String runJobUrl) {
        final List<ExecutedScenario> executedScenarios = new ArrayList<>();
        ExecutedScenario lastBackground = null;
        for (Feature feature : features) {
            for (Element element : feature.getElements()) {
                if (element.isBackground()) {
                    lastBackground = extractBackground(stepDefinitions, element);
                } else if (element.isScenario()) {
                    executedScenarios.add(extractExecutedScenario(stepDefinitions, feature, element, runJobUrl, lastBackground));
                    lastBackground = null;
                }
            }
            lastBackground = null;
        }
        return executedScenarios;
    }

}