Java Code Examples for gherkin.ast.Feature#getName()

The following examples show how to use gherkin.ast.Feature#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSourcesModel.java    From extentreports-cucumber4-adapter with Apache License 2.0 5 votes vote down vote up
String getFeatureName(String uri) {
    Feature feature = getFeature(uri);
    if (feature != null) {
        return feature.getName();
    }
    return "";
}
 
Example 2
Source File: BddParser.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public void parse(File file) {
    if (file != null && file.exists()) {
        try {
            Feature feature = GHERKIN_PARSER.parse(new FileReader(file)).getFeature();
            String featureName = feature.getName();
            createTestCases(updateInfo(create(featureName), feature),
                    feature);
            File tp = new File(sMainFrame.getProject().getLocation(), "TestPlan");
            Files.copy(file, new File(tp, file.getName()));
        } catch (Exception ex) {
            Logger.getLogger(BddParser.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
 
Example 3
Source File: LabelBuilder.java    From allure-java with Apache License 2.0 4 votes vote down vote up
LabelBuilder(final Feature feature, final TestCase scenario, final Deque<String> tags) {
    final TagParser tagParser = new TagParser(feature, scenario);

    while (tags.peek() != null) {
        final String tag = tags.remove();

        if (tag.contains(COMPOSITE_TAG_DELIMITER)) {

            final String[] tagParts = tag.split(COMPOSITE_TAG_DELIMITER, 2);
            if (tagParts.length < 2 || Objects.isNull(tagParts[1]) || tagParts[1].isEmpty()) {
                // skip empty tags, e.g. '@tmsLink=', to avoid formatter errors
                continue;
            }

            final String tagKey = tagParts[0].toUpperCase();
            final String tagValue = tagParts[1];

            // Handle composite named links
            if (tagKey.startsWith(PLAIN_LINK + ".")) {
                tryHandleNamedLink(tag);
                continue;
            }

            switch (tagKey) {
                case SEVERITY:
                    getScenarioLabels().add(ResultsUtils.createSeverityLabel(tagValue.toLowerCase()));
                    break;
                case TMS_LINK:
                    getScenarioLinks().add(ResultsUtils.createTmsLink(tagValue));
                    break;
                case ISSUE_LINK:
                    getScenarioLinks().add(ResultsUtils.createIssueLink(tagValue));
                    break;
                case PLAIN_LINK:
                    getScenarioLinks().add(ResultsUtils.createLink(null, tagValue, tagValue, null));
                    break;
                default:
                    LOGGER.warn("Composite tag {} is not supported. adding it as RAW", tagKey);
                    getScenarioLabels().add(getTagLabel(tag));
                    break;
            }
        } else if (tagParser.isPureSeverityTag(tag)) {
            getScenarioLabels().add(ResultsUtils.createSeverityLabel(tag.substring(1)));
        } else if (!tagParser.isResultTag(tag)) {
            getScenarioLabels().add(getTagLabel(tag));
        }
    }

    final String featureName = feature.getName();
    final URI uri = scenario.getUri();

    getScenarioLabels().addAll(Arrays.asList(
            createHostLabel(),
            createThreadLabel(),
            createFeatureLabel(featureName),
            createStoryLabel(scenario.getName()),
            createSuiteLabel(featureName),
            createTestClassLabel(scenario.getName()),
            createFrameworkLabel("cucumber4jvm"),
            createLanguageLabel("java"),
            createLabel("gherkin_uri", uri.toString())
    ));

    featurePackage(uri.toString(), featureName)
            .map(ResultsUtils::createPackageLabel)
            .ifPresent(getScenarioLabels()::add);
}
 
Example 4
Source File: AllureCucumber4Jvm.java    From allure-java with Apache License 2.0 4 votes vote down vote up
private void handleTestCaseStarted(final TestCaseStarted event) {
    currentFeatureFile.set(event.testCase.getUri());
    currentFeature.set(testSources.getFeature(currentFeatureFile.get()));
    currentTestCase.set(event.testCase);
    currentContainer.set(UUID.randomUUID().toString());
    forbidTestCaseStatusChange.set(false);

    final Deque<PickleTag> tags = new LinkedList<>(currentTestCase.get().getTags());

    final Feature feature = currentFeature.get();
    final LabelBuilder labelBuilder = new LabelBuilder(feature, currentTestCase.get(), tags);

    final String name = currentTestCase.get().getName();
    final String featureName = feature.getName();

    final TestResult result = new TestResult()
            .setUuid(getTestCaseUuid(currentTestCase.get()))
            .setHistoryId(getHistoryId(currentTestCase.get()))
            .setFullName(featureName + ": " + name)
            .setName(name)
            .setLabels(labelBuilder.getScenarioLabels())
            .setLinks(labelBuilder.getScenarioLinks());

    final ScenarioDefinition scenarioDefinition =
            testSources.getScenarioDefinition(currentFeatureFile.get(), currentTestCase.get().getLine());
    if (scenarioDefinition instanceof ScenarioOutline) {
        result.setParameters(
                getExamplesAsParameters((ScenarioOutline) scenarioDefinition, currentTestCase.get())
        );
    }

    final String description = Stream.of(feature.getDescription(), scenarioDefinition.getDescription())
            .filter(Objects::nonNull)
            .filter(s -> !s.isEmpty())
            .collect(Collectors.joining("\n"));

    if (!description.isEmpty()) {
        result.setDescription(description);
    }

    final TestResultContainer resultContainer = new TestResultContainer()
            .setName(String.format("%s: %s", scenarioDefinition.getKeyword(), scenarioDefinition.getName()))
            .setUuid(getTestContainerUuid())
            .setChildren(Collections.singletonList(getTestCaseUuid(currentTestCase.get())));

    lifecycle.scheduleTestCase(result);
    lifecycle.startTestContainer(getTestContainerUuid(), resultContainer);
    lifecycle.startTestCase(getTestCaseUuid(currentTestCase.get()));
}
 
Example 5
Source File: LabelBuilder.java    From allure-java with Apache License 2.0 4 votes vote down vote up
LabelBuilder(final Feature feature, final TestCase scenario, final Deque<PickleTag> tags) {
    final TagParser tagParser = new TagParser(feature, scenario);

    while (tags.peek() != null) {
        final PickleTag tag = tags.remove();

        final String tagString = tag.getName();

        if (tagString.contains(COMPOSITE_TAG_DELIMITER)) {

            final String[] tagParts = tagString.split(COMPOSITE_TAG_DELIMITER, 2);
            if (tagParts.length < 2 || Objects.isNull(tagParts[1]) || tagParts[1].isEmpty()) {
                // skip empty tags, e.g. '@tmsLink=', to avoid formatter errors
                continue;
            }

            final String tagKey = tagParts[0].toUpperCase();
            final String tagValue = tagParts[1];

            // Handle composite named links
            if (tagKey.startsWith(PLAIN_LINK + ".")) {
                tryHandleNamedLink(tagString);
                continue;
            }

            switch (tagKey) {
                case SEVERITY:
                    getScenarioLabels().add(ResultsUtils.createSeverityLabel(tagValue.toLowerCase()));
                    break;
                case TMS_LINK:
                    getScenarioLinks().add(ResultsUtils.createTmsLink(tagValue));
                    break;
                case ISSUE_LINK:
                    getScenarioLinks().add(ResultsUtils.createIssueLink(tagValue));
                    break;
                case PLAIN_LINK:
                    getScenarioLinks().add(ResultsUtils.createLink(null, tagValue, tagValue, null));
                    break;
                default:
                    LOGGER.warn("Composite tag {} is not supported. adding it as RAW", tagKey);
                    getScenarioLabels().add(getTagLabel(tag));
                    break;
            }
        } else if (tagParser.isPureSeverityTag(tag)) {
            getScenarioLabels().add(ResultsUtils.createSeverityLabel(tagString.substring(1)));
        } else if (!tagParser.isResultTag(tag)) {
            getScenarioLabels().add(getTagLabel(tag));
        }
    }

    final String featureName = feature.getName();
    final String uri = scenario.getUri();

    getScenarioLabels().addAll(Arrays.asList(
            createHostLabel(),
            createThreadLabel(),
            createFeatureLabel(featureName),
            createStoryLabel(scenario.getName()),
            createSuiteLabel(featureName),
            createTestClassLabel(scenario.getName()),
            createFrameworkLabel("cucumber4jvm"),
            createLanguageLabel("java"),
            createLabel("gherkin_uri", uri)
    ));

    featurePackage(uri, featureName)
            .map(ResultsUtils::createPackageLabel)
            .ifPresent(getScenarioLabels()::add);
}