gherkin.ast.Feature Java Examples
The following examples show how to use
gherkin.ast.Feature.
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 | 6 votes |
static String calculateId(AstNode astNode) { Node node = astNode.node; if (node instanceof ScenarioDefinition) { return calculateId(astNode.parent) + ";" + convertToId(((ScenarioDefinition) node).getName()); } if (node instanceof ExamplesRowWrapperNode) { return calculateId(astNode.parent) + ";" + Integer.toString(((ExamplesRowWrapperNode) node).bodyRowIndex + 2); } if (node instanceof TableRow) { return calculateId(astNode.parent) + ";" + Integer.toString(1); } if (node instanceof Examples) { return calculateId(astNode.parent) + ";" + convertToId(((Examples) node).getName()); } if (node instanceof Feature) { return convertToId(((Feature) node).getName()); } return ""; }
Example #2
Source File: ExtentCucumberAdapter.java From extentreports-cucumber4-adapter with Apache License 2.0 | 6 votes |
private synchronized void createFeature(TestCase testCase) { Feature feature = testSources.getFeature(testCase.getUri()); if (feature != null) { if (featureMap.containsKey(feature.getName())) { featureTestThreadLocal.set(featureMap.get(feature.getName())); return; } if (featureTestThreadLocal.get() != null && featureTestThreadLocal.get().getModel().getName().equals(feature.getName())) { return; } ExtentTest t = ExtentService.getInstance() .createTest(com.aventstack.extentreports.gherkin.model.Feature.class, feature.getName(), feature.getDescription()); featureTestThreadLocal.set(t); featureMap.put(feature.getName(), t); List<String> tagList = createTagsList(feature.getTags()); tagList.forEach(featureTestThreadLocal.get()::assignCategory); } }
Example #3
Source File: BddParser.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private void createTestCases(Scenario scenario, Feature feature) { for (ScenarioDefinition scenarioDef : feature.getChildren()) { String scenDefName = scenarioDef.getName(); TestCase testCase = updateInfo(createTestCase(scenario, scenDefName), scenarioDef); testCase.clearSteps(); for (Step step : scenarioDef.getSteps()) { String reusableName = convert(step.getText()); TestCase reusable = updateInfo(createReusable(create("StepDefinitions"), reusableName), step); if (reusable != null) { reusable.addNewStep() .setInput(getInputField(testCase.getName(), step.getText())) .setDescription(getDescription(step)); } testCase.addNewStep() .asReusableStep("StepDefinitions", reusableName) .setDescription(getDescription(step)); } if (scenarioDef instanceof ScenarioOutline) { ScenarioOutline scOutline = (ScenarioOutline) scenarioDef; createTestData(testCase, scOutline.getExamples()); } } }
Example #4
Source File: TestSourcesModel.java From extentreports-cucumber4-adapter with Apache License 2.0 | 5 votes |
static Background getBackgroundForTestCase(AstNode astNode) { Feature feature = getFeatureForTestCase(astNode); ScenarioDefinition backgound = feature.getChildren().get(0); if (backgound instanceof Background) { return (Background) backgound; } else { return null; } }
Example #5
Source File: CucumberSourceUtils.java From allure-java with Apache License 2.0 | 5 votes |
public Feature getFeature(final String path) { if (!pathToAstMap.containsKey(path)) { parseGherkinSource(path); } if (pathToAstMap.containsKey(path)) { return pathToAstMap.get(path).getFeature(); } return null; }
Example #6
Source File: CucumberSourceUtils.java From allure-java with Apache License 2.0 | 5 votes |
public String getKeywordFromSource(final String uri, final int stepLine) { final Feature feature = getFeature(uri); if (feature != null) { final TestSourceRead event = getTestSourceReadEvent(uri); final String trimmedSourceLine = event.source.split("\n")[stepLine - 1].trim(); final GherkinDialect dialect = new GherkinDialectProvider(feature.getLanguage()).getDefaultDialect(); for (String keyword : dialect.getStepKeywords()) { if (trimmedSourceLine.startsWith(keyword)) { return keyword; } } } return ""; }
Example #7
Source File: BddParser.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
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 #8
Source File: BddParser.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
private Scenario updateInfo(Scenario scn, Feature feature) { String desc = feature.getDescription(); List<Tag> tags = toTag(feature.getTags()); Meta metaRes = pModel().findScenario(scn.getName()) .orElseGet(() -> { Meta meta = Meta.createScenario(scn.getName()); pModel().addMeta(meta); return meta; }); metaRes.setTags(tags); metaRes.getAttributes().add(Attribute.create("feature.line", feature.getLocation().getLine())); metaRes.setDesc(desc); return scn; }
Example #9
Source File: TestSourcesModelProxy.java From allure-java with Apache License 2.0 | 5 votes |
private String getKeywordFromSourceInternal(final URI uri, final int stepLine) { final Feature feature = getFeature(uri); if (feature != null) { final TestSourceRead event = this.getTestSourceReadEvent(uri); final String trimmedSourceLine = event.getSource().split("\n")[stepLine - 1].trim(); final GherkinDialect dialect = new GherkinDialectProvider(feature.getLanguage()).getDefaultDialect(); for (String keyword : dialect.getStepKeywords()) { if (trimmedSourceLine.startsWith(keyword)) { return keyword; } } } return ""; }
Example #10
Source File: TestSourcesModel.java From allure-java with Apache License 2.0 | 5 votes |
public Feature getFeature(final URI path) { if (!pathToAstMap.containsKey(path)) { parseGherkinSource(path); } if (pathToAstMap.containsKey(path)) { return pathToAstMap.get(path).getFeature(); } return null; }
Example #11
Source File: CucumberSourceUtils.java From allure-java with Apache License 2.0 | 5 votes |
public String getKeywordFromSource(final String uri, final int stepLine) { final Feature feature = getFeature(uri); if (feature != null) { final TestSourceRead event = getTestSourceReadEvent(uri); final String trimmedSourceLine = event.source.split("\n")[stepLine - 1].trim(); final GherkinDialect dialect = new GherkinDialectProvider(feature.getLanguage()).getDefaultDialect(); for (String keyword : dialect.getStepKeywords()) { if (trimmedSourceLine.startsWith(keyword)) { return keyword; } } } return ""; }
Example #12
Source File: CucumberSourceUtils.java From allure-java with Apache License 2.0 | 5 votes |
public Feature getFeature(final String path) { if (!pathToAstMap.containsKey(path)) { parseGherkinSource(path); } if (pathToAstMap.containsKey(path)) { return pathToAstMap.get(path).getFeature(); } return null; }
Example #13
Source File: TestSourcesModel.java From extentreports-cucumber4-adapter with Apache License 2.0 | 5 votes |
String getFeatureName(String uri) { Feature feature = getFeature(uri); if (feature != null) { return feature.getName(); } return ""; }
Example #14
Source File: TestSourcesModel.java From extentreports-cucumber4-adapter with Apache License 2.0 | 5 votes |
String getKeywordFromSource(String uri, int stepLine) { Feature feature = getFeature(uri); if (feature != null) { TestSourceRead event = getTestSourceReadEvent(uri); String trimmedSourceLine = event.source.split("\n")[stepLine - 1].trim(); GherkinDialect dialect = new GherkinDialectProvider(feature.getLanguage()).getDefaultDialect(); for (String keyword : dialect.getStepKeywords()) { if (trimmedSourceLine.startsWith(keyword)) { return keyword; } } } return ""; }
Example #15
Source File: TestSourcesModel.java From extentreports-cucumber4-adapter with Apache License 2.0 | 5 votes |
Feature getFeature(String path) { if (!pathToAstMap.containsKey(path)) { parseGherkinSource(path); } if (pathToAstMap.containsKey(path)) { return pathToAstMap.get(path).getFeature(); } return null; }
Example #16
Source File: CucumberITGeneratorByFeature.java From cucumber-jvm-parallel-plugin with Apache License 2.0 | 4 votes |
private void setParsedFeature(final Feature feature) { parsedFeature = feature; }
Example #17
Source File: TestSourcesModel.java From extentreports-cucumber4-adapter with Apache License 2.0 | 4 votes |
static Feature getFeatureForTestCase(AstNode astNode) { while (astNode.parent != null) { astNode = astNode.parent; } return (Feature) astNode.node; }
Example #18
Source File: LabelBuilder.java From allure-java with Apache License 2.0 | 4 votes |
LabelBuilder(final Feature feature, final TestCase scenario, final Deque<PickleTag> tags) { final TagParser tagParser = new TagParser(feature, scenario); getScenarioLabels().add(createFeatureLabel(feature.getName())); getScenarioLabels().add(createStoryLabel(scenario.getName())); 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(createSeverityLabel(tagValue.toLowerCase())); break; case TMS_LINK: getScenarioLinks().add(createTmsLink(tagValue)); break; case ISSUE_LINK: getScenarioLinks().add(createIssueLink(tagValue)); break; case PLAIN_LINK: getScenarioLinks().add(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(createSeverityLabel(tagString.substring(1))); } else if (!tagParser.isResultTag(tag)) { getScenarioLabels().add(getTagLabel(tag)); } } getScenarioLabels().addAll(Arrays.asList( createHostLabel(), createThreadLabel(), createPackageLabel(feature.getName()), createSuiteLabel(feature.getName()), createTestClassLabel(scenario.getName()), createFrameworkLabel("cucumber3jvm"), createLanguageLabel("java") )); }
Example #19
Source File: TagParser.java From allure-java with Apache License 2.0 | 4 votes |
TagParser(final Feature feature, final TestCase scenario) { this.feature = feature; this.scenario = scenario; }
Example #20
Source File: CucumberITGeneratorByScenario.java From cucumber-jvm-parallel-plugin with Apache License 2.0 | 4 votes |
private void setParsedFeature(final Feature feature) { parsedFeature = feature; }
Example #21
Source File: LabelBuilder.java From allure-java with Apache License 2.0 | 4 votes |
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); }
Example #22
Source File: TagParser.java From allure-java with Apache License 2.0 | 4 votes |
TagParser(final Feature feature, final TestCase scenario) { this.feature = feature; this.scenario = scenario; }
Example #23
Source File: AllureCucumber4Jvm.java From allure-java with Apache License 2.0 | 4 votes |
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 #24
Source File: TestSourcesModelProxy.java From allure-java with Apache License 2.0 | 4 votes |
public Feature getFeature(final String path) { return testSources.getFeature(path); }
Example #25
Source File: LabelBuilder.java From allure-java with Apache License 2.0 | 4 votes |
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 #26
Source File: TagParser.java From allure-java with Apache License 2.0 | 4 votes |
TagParser(final Feature feature, final TestCase scenario) { this.feature = feature; this.scenario = scenario; }
Example #27
Source File: TestSourcesModelProxy.java From allure-java with Apache License 2.0 | 4 votes |
public Feature getFeature(final URI path) { return testSources.getFeature(path); }
Example #28
Source File: LabelBuilder.java From allure-java with Apache License 2.0 | 4 votes |
LabelBuilder(final Feature feature, final TestCase scenario, final Deque<PickleTag> tags) { final TagParser tagParser = new TagParser(feature, scenario); getScenarioLabels().add(createFeatureLabel(feature.getName())); getScenarioLabels().add(createStoryLabel(scenario.getName())); 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(createSeverityLabel(tagValue.toLowerCase())); break; case TMS_LINK: getScenarioLinks().add(createTmsLink(tagValue)); break; case ISSUE_LINK: getScenarioLinks().add(createIssueLink(tagValue)); break; case PLAIN_LINK: getScenarioLinks().add(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(createSeverityLabel(tagString.substring(1))); } else if (!tagParser.isResultTag(tag)) { getScenarioLabels().add(getTagLabel(tag)); } } getScenarioLabels().addAll(Arrays.asList( createHostLabel(), createThreadLabel(), createPackageLabel(feature.getName()), createSuiteLabel(feature.getName()), createTestClassLabel(scenario.getName()), createFrameworkLabel("cucumber2jvm"), createLanguageLabel("java") )); }
Example #29
Source File: TagParser.java From allure-java with Apache License 2.0 | 4 votes |
TagParser(final Feature feature, final TestCase scenario) { this.feature = feature; this.scenario = scenario; }