private Map<String, Object> createTestCase(TestCase testCase) { Map<String, Object> testCaseMap = new HashMap<String, Object>(); testCaseMap.put("name", testCase.getName()); TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile, testCase.getLine()); if (astNode != null) { ScenarioDefinition scenarioDefinition = TestSourcesModel.getScenarioDefinition(astNode); testCaseMap.put("keyword", scenarioDefinition.getKeyword()); testCaseMap.put("description", scenarioDefinition.getDescription() != null ? scenarioDefinition.getDescription() : ""); } if (!testCase.getTags().isEmpty()) { List<Map<String, Object>> tagList = new ArrayList<Map<String, Object>>(); for (PickleTag tag : testCase.getTags()) { Map<String, Object> tagMap = new HashMap<String, Object>(); tagMap.put("name", tag.getName()); tagList.add(tagMap); } testCaseMap.put("tags", tagList); } return testCaseMap; }
private Map<String, Object> createTestCase(TestCase testCase) { Map<String, Object> testCaseMap = new HashMap<String, Object>(); testCaseMap.put("name", testCase.getName()); testCaseMap.put("line", testCase.getLine()); testCaseMap.put("type", "scenario"); TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile, testCase.getLine()); if (astNode != null) { testCaseMap.put("id", TestSourcesModel.calculateId(astNode)); ScenarioDefinition scenarioDefinition = TestSourcesModel.getScenarioDefinition(astNode); testCaseMap.put("keyword", scenarioDefinition.getKeyword()); testCaseMap.put("description", scenarioDefinition.getDescription() != null ? scenarioDefinition.getDescription() : ""); } testCaseMap.put("steps", new ArrayList<Map<String, Object>>()); if (!testCase.getTags().isEmpty()) { List<Map<String, Object>> tagList = new ArrayList<Map<String, Object>>(); for (PickleTag tag : testCase.getTags()) { Map<String, Object> tagMap = new HashMap<String, Object>(); tagMap.put("name", tag.getName()); tagList.add(tagMap); } testCaseMap.put("tags", tagList); } return testCaseMap; }
private void printScenarioDefinition(TestCase testCase) { ScenarioDefinition scenarioDefinition = testSources.getScenarioDefinition(currentFeatureFile, testCase.getLine()); String definitionText = scenarioDefinition.getKeyword() + ": " + testCase.getName(); calculateLocationIndentation(SCENARIO_INDENT + definitionText, testCase.getTestSteps()); String locationPadding = createPaddingToLocation(SCENARIO_INDENT, definitionText); out.println(); printPickleTags(testCase.getTags(), SCENARIO_INDENT); out.println(SCENARIO_INDENT + definitionText + locationPadding + getLocationText(currentFeatureFile, testCase.getLine())); printDescription(scenarioDefinition.getDescription()); }
private Function<ScenarioDefinition, TestScenarioResult> scenarioToResult(CucumberFeature feature) { return scenarioDefinition -> { try { return new TestScenarioResult( feature.getGherkinFeature().getFeature().getName(), scenarioDefinition.getName(), scenarioStepCountFor(backgroundStepCountFor(feature), scenarioDefinition)); } catch (Exception e) { throw new IllegalStateException(String.format("Could not determine step count for scenario '%s'", scenarioDefinition.getDescription()), e); } }; }
private Function<ScenarioDefinition, TestScenarioResult> scenarioToResult(CucumberFeature feature) { return scenarioDefinition -> { try { return new TestScenarioResult( feature.getGherkinFeature().getFeature().getName(), scenarioDefinition.getName(), scenarioStepCountFor(backgroundStepCountFor(feature), scenarioDefinition)); } catch (Exception e) { throw new IllegalStateException(String.format("Could not determine step count for scenario '%s'", scenarioDefinition.getDescription()), e); } }; }
private ScenarioOutcome scenarioOutcomeFrom(Feature feature, ScenarioDefinition scenarioDefinition, TestOutcomes testOutcomes) { List<TestOutcome> outcomes = testOutcomes.testOutcomesWithName(scenarioDefinition.getName()); String scenarioTitle = scenarioDefinition.getName(); TestResult result = (outcomes.isEmpty()) ? TestResult.UNDEFINED : TestResultList.overallResultFrom(outcomes.stream().map(TestOutcome::getResult).collect(Collectors.toList())); List<String> reportBadges = ReportBadges.from(outcomes, scenarioDefinition.getName()); String featureReport = new ReportNameProvider().forRequirement(feature.getName(),"feature"); List<String> renderedSteps = scenarioDefinition.getSteps().stream() .map(RenderCucumber::step) .collect(Collectors.toList()); List<String> renderedExamples = (scenarioDefinition instanceof ScenarioOutline) ? RenderCucumber.examples(((ScenarioOutline) scenarioDefinition).getExamples(), feature.getName(), scenarioDefinition.getName()) : Collections.EMPTY_LIST; int exampleCount = (scenarioDefinition instanceof ScenarioOutline) ? ((ScenarioOutline) scenarioDefinition).getExamples().stream().mapToInt(examples -> examples.getTableBody().size()).sum() : 0; return new ScenarioSummaryOutcome(scenarioTitle, scenarioDefinition.getKeyword(), result, reportBadges, scenarioDefinition.getDescription(), renderedSteps, renderedExamples, exampleCount, feature.getName(), featureReport); }
private void updateManualResultsFrom(List<Tag> scenarioTags) { getStepEventBus(currentFeaturePath()).testIsManual(); manualResultDefinedIn(scenarioTags).ifPresent( result -> { if (result == TestResult.FAILURE) { String failureMessage = failureMessageFrom(currentScenarioDefinition.getDescription()).orElse("Failed manual test"); getStepEventBus(currentFeaturePath()).getBaseStepListener() .latestTestOutcome().ifPresent( outcome -> outcome.setTestFailureMessage(failureMessage)); } getStepEventBus(currentFeaturePath()).getBaseStepListener().overrideResultTo(result); } ); }
private void updateManualResultsFrom(List<Tag> scenarioTags) { getStepEventBus(currentFeaturePath()).testIsManual(); manualResultDefinedIn(scenarioTags).ifPresent( result -> { if (result == TestResult.FAILURE) { String failureMessage = failureMessageFrom(currentScenarioDefinition.getDescription()).orElse("Failed manual test"); getStepEventBus(currentFeaturePath()).getBaseStepListener() .latestTestOutcome().ifPresent( outcome -> outcome.setTestFailureMessage(failureMessage)); } getStepEventBus(currentFeaturePath()).getBaseStepListener().overrideResultTo(result); } ); }
String description = scenarioDefinition.getDescription(); List<Step> steps = new ArrayList<>(); List<String> tags = new ArrayList<>();
for (ScenarioDefinition scenarioDefinition : scenarioDefinitions) { String scenarioName = scenarioDefinition.getKeyword() + ": " + scenarioDefinition.getName(); String scenarioDescription = scenarioDefinition.getDescription();
private void startScenario(Feature currentFeature, ScenarioDefinition scenarioDefinition, String scenarioName) { getStepEventBus(currentFeaturePath()).setTestSource(TestSourceType.TEST_SOURCE_CUCUMBER.getValue()); getStepEventBus(currentFeaturePath()).testStarted(scenarioName, scenarioIdFrom(TestSourcesModel.convertToId(currentFeature.getName()), TestSourcesModel.convertToId(scenarioName))); getStepEventBus(currentFeaturePath()).addDescriptionToCurrentTest(scenarioDefinition.getDescription()); getStepEventBus(currentFeaturePath()).addTagsToCurrentTest(convertCucumberTags(currentFeature.getTags())); if (isScenario(scenarioDefinition)) { getStepEventBus(currentFeaturePath()).addTagsToCurrentTest(convertCucumberTags(((Scenario) scenarioDefinition).getTags())); } else if (isScenarioOutline(scenarioDefinition)) { getStepEventBus(currentFeaturePath()).addTagsToCurrentTest(convertCucumberTags(((ScenarioOutline) scenarioDefinition).getTags())); } registerFeatureJiraIssues(currentFeature.getTags()); List<Tag> tags = getTagsOfScenarioDefinition(scenarioDefinition); registerScenarioJiraIssues(tags); scenarioTags = tagsForScenario(scenarioDefinition); updateResultFromTags(scenarioTags); }
private void startScenario(Feature currentFeature, ScenarioDefinition scenarioDefinition, String scenarioName) { getStepEventBus(currentFeaturePath()).setTestSource(TestSourceType.TEST_SOURCE_CUCUMBER.getValue()); getStepEventBus(currentFeaturePath()).testStarted(scenarioName, scenarioIdFrom(TestSourcesModel.convertToId(currentFeature.getName()), TestSourcesModel.convertToId(scenarioName))); getStepEventBus(currentFeaturePath()).addDescriptionToCurrentTest(scenarioDefinition.getDescription()); getStepEventBus(currentFeaturePath()).addTagsToCurrentTest(convertCucumberTags(currentFeature.getTags())); if (isScenario(scenarioDefinition)) { getStepEventBus(currentFeaturePath()).addTagsToCurrentTest(convertCucumberTags(((Scenario) scenarioDefinition).getTags())); } else if (isScenarioOutline(scenarioDefinition)) { getStepEventBus(currentFeaturePath()).addTagsToCurrentTest(convertCucumberTags(((ScenarioOutline) scenarioDefinition).getTags())); } registerFeatureJiraIssues(currentFeature.getTags()); List<Tag> tags = getTagsOfScenarioDefinition(scenarioDefinition); registerScenarioJiraIssues(tags); scenarioTags = tagsForScenario(scenarioDefinition); updateResultFromTags(scenarioTags); }