gherkin.formatter.model.Scenario Java Examples

The following examples show how to use gherkin.formatter.model.Scenario. 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: GherkinKeyWordProvider.java    From xframium-java with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void scenario(Scenario xTest) {
	currentSection = Section.SCENARIOS;
       String tagNames = null;
       if ( xTest.getTags() != null && !xTest.getTags().isEmpty() )
       {
           tagNames = "";
           for ( Tag tagName : xTest.getTags() )
               tagNames = tagNames + tagName.getName() + ",";
           
           tagNames = tagNames.substring( 0, tagNames.length() - 1 );
       }
       
       this.currentScenario = new KeyWordTest( xTest.getName(), true, null, null, false, null, null, 0, xTest.getDescription(), tagNames, null, null, null, 0, null, null, null, null, 0, 0, TRACE.OFF.name() );

       for ( KeyWordStep xStep : backgroundSteps )
           this.currentScenario.addStep( xStep );
       
       log.info( "Adding " + xTest.getName() );
       scenarioList.add( currentScenario );
	
}
 
Example #2
Source File: AllureReporter.java    From allure-cucumberjvm with Apache License 2.0 6 votes vote down vote up
private TestCaseId getTestCaseIdAnnotation(Scenario scenario) {
    for (Tag tag : scenario.getTags()) {
        Matcher matcher = TEST_CASE_ID_PATTERN.matcher(tag.getName());
        if (matcher.matches()) {
            final String testCaseId = matcher.group(1);
            return new TestCaseId() {
                @Override
                public String value() {
                    return testCaseId;
                }

                @Override
                public Class<TestCaseId> annotationType() {
                    return TestCaseId.class;
                }
            };
        }
    }

    return null;
}
 
Example #3
Source File: XMLFormatter.java    From xframium-java with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void scenario( Scenario xTest )
{
    currentSection = Section.SCENARIOS;
    String tagNames = null;
    if ( xTest.getTags() != null && !xTest.getTags().isEmpty() )
    {
        tagNames = "";
        for ( Tag tagName : xTest.getTags() )
            tagNames = tagNames + tagName.getName() + ",";
        
        tagNames = tagNames.substring( 0, tagNames.length() - 1 );
    }
    
    this.currentScenario = new KeyWordTest( xTest.getName(), true, null, null, false, null, null, 0, xTest.getDescription(), tagNames, null, null, configProperties, 0, null, null, null, null, 0, 0, TRACE.OFF.name() );

    for ( KeyWordStep xStep : backgroundSteps )
        this.currentScenario.addStep( xStep );
    scenarioList.add( currentScenario );
}
 
Example #4
Source File: AllureCucumberJvm.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@Override
public void startOfScenarioLifeCycle(final Scenario scenario) {
    this.currentScenario = scenario;

    final Deque<Tag> tags = new LinkedList<>(scenario.getTags());

    if (SCENARIO_OUTLINE_KEYWORDS.contains(scenario.getKeyword())) {
        synchronized (gherkinSteps) {
            gherkinSteps.clear();
        }
    } else {
        tags.addAll(currentFeature.getTags());
    }

    final LabelBuilder labelBuilder = new LabelBuilder(currentFeature, scenario, tags);

    final String uuid = UUID.randomUUID().toString();
    scenarioUuids.put(scenario, uuid);

    final TestResult result = new TestResult()
            .setUuid(uuid)
            .setHistoryId(StepUtils.getHistoryId(scenario.getId()))
            .setFullName(String.format("%s: %s", currentFeature.getName(), scenario.getName()))
            .setName(scenario.getName())
            .setLabels(labelBuilder.getScenarioLabels())
            .setLinks(labelBuilder.getScenarioLinks());

    if (!currentFeature.getDescription().isEmpty()) {
        result.setDescription(currentFeature.getDescription());
    }

    lifecycle.scheduleTestCase(result);
    lifecycle.startTestCase(uuid);

}
 
Example #5
Source File: AllureCucumberJvm.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@Override
public void endOfScenarioLifeCycle(final Scenario scenario) {
    final StepUtils stepUtils = new StepUtils(currentFeature, currentScenario);
    synchronized (gherkinSteps) {
        while (gherkinSteps.peek() != null) {
            stepUtils.fireCanceledStep(gherkinSteps.remove());
        }
    }
    final String scenarioUuid = scenarioUuids.remove(scenario);
    lifecycle.stopTestCase(scenarioUuid);
    lifecycle.writeTestCase(scenarioUuid);
}
 
Example #6
Source File: AllureRunListener.java    From allure-cucumberjvm with Apache License 2.0 5 votes vote down vote up
/**
 * Find feature and story for given scenario
 *
 * @param scenarioName
 * @return {@link String[]} of ["<FEATURE_NAME>", "<STORY_NAME>"]s
 * @throws IllegalAccessException
 */
private String[] findFeatureByScenarioName(String scenarioName) throws IllegalAccessException {
    List<Description> testClasses = findTestClassesLevel(parentDescription.getChildren());

    for (Description testClass : testClasses) {

        List<Description> features = findFeaturesLevel(testClass.getChildren());
        //Feature cycle
        for (Description feature : features) {
            //Story cycle
            for (Description story : feature.getChildren()) {
                Object scenarioType = getTestEntityType(story);

                //Scenario
                if (scenarioType instanceof Scenario
                        && story.getDisplayName().equals(scenarioName)) {
                    return new String[]{feature.getDisplayName(), scenarioName};

                    //Scenario Outline
                } else if (scenarioType instanceof ScenarioOutline) {
                    List<Description> examples = story.getChildren().get(0).getChildren();
                    // we need to go deeper :)
                    for (Description example : examples) {
                        if (example.getDisplayName().equals(scenarioName)) {
                            return new String[]{feature.getDisplayName(), story.getDisplayName()};
                        }
                    }
                }
            }
        }
    }
    return new String[]{"Feature: Undefined Feature", scenarioName};
}
 
Example #7
Source File: CucumberListener.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
public void createAppiumInstance(Scenario scenario) {
    String[] tagsArray = getTagArray(scenario.getTags());
    String tags = String.join(",", tagsArray);
    try {
        startAppiumServer(scenario, tags);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #8
Source File: AllureReporter.java    From allure-cucumberjvm with Apache License 2.0 5 votes vote down vote up
private Issues getIssuesAnnotation(Scenario scenario) {
    List<String> issues = new ArrayList<>();
    for (Tag tag : scenario.getTags()) {
        Matcher matcher = ISSUE_PATTERN.matcher(tag.getName());
        if (matcher.matches()) {
            issues.add(matcher.group(1));
        }
    }
    return !issues.isEmpty() ? getIssuesAnnotation(issues) : null;
}
 
Example #9
Source File: AllureReporter.java    From allure-cucumberjvm with Apache License 2.0 5 votes vote down vote up
private SeverityLevel getSeverityLevel(Scenario scenario) {
    SeverityLevel level = null;
    List<SeverityLevel> severityLevels = Arrays.asList(
            SeverityLevel.BLOCKER,
            SeverityLevel.CRITICAL,
            SeverityLevel.NORMAL,
            SeverityLevel.MINOR,
            SeverityLevel.TRIVIAL);
    for (Tag tag : scenario.getTags()) {
        Matcher matcher = SEVERITY_PATTERN.matcher(tag.getName());
        if (matcher.matches()) {
            SeverityLevel levelTmp;
            String levelString = matcher.group(1);
            try {
                levelTmp = SeverityLevel.fromValue(levelString.toLowerCase());
            } catch (IllegalArgumentException e) {
                LOG.warn(String.format("Unexpected Severity level [%s]. SeverityLevel.NORMAL will be used instead", levelString), e);
                levelTmp = SeverityLevel.NORMAL;
            }

            if (level == null || severityLevels.indexOf(levelTmp) < severityLevels.indexOf(level)) {
                level = levelTmp;
            }
        }
    }
    return level;
}
 
Example #10
Source File: AllureReporter.java    From allure-cucumberjvm with Apache License 2.0 5 votes vote down vote up
@Override
public void endOfScenarioLifeCycle(Scenario scenario) {
    synchronized (gherkinSteps) {
        while (gherkinSteps.peek() != null) {
            fireCanceledStep(gherkinSteps.remove());
        }
    }
    ALLURE_LIFECYCLE.fire(new TestCaseFinishedEvent());
}
 
Example #11
Source File: HtmlFormatter.java    From scott with MIT License 4 votes vote down vote up
@Override
public void endOfScenarioLifeCycle(Scenario scenario) {
    // NoOp
}
 
Example #12
Source File: CucumberListener.java    From AppiumTestDistribution with GNU General Public License v3.0 4 votes vote down vote up
public void startAppiumServer(Scenario scenario, String tags) throws Exception {
    appiumDriverManager.startAppiumDriverInstance();
    ///This portion should be Broken : TODO
}
 
Example #13
Source File: AllureReporter.java    From allure-cucumberjvm with Apache License 2.0 4 votes vote down vote up
@Override
public void startOfScenarioLifeCycle(Scenario scenario) {

    //to avoid duplicate steps in case of Scenario Outline
    if (SCENARIO_OUTLINE_KEYWORDS.contains(scenario.getKeyword())) {
        synchronized (gherkinSteps) {
            gherkinSteps.clear();
        }
    }

    currentStatus = PASSED;

    TestCaseStartedEvent event = new TestCaseStartedEvent(uid, scenario.getName());
    event.setTitle(scenario.getName());

    Collection<Annotation> annotations = new ArrayList<>();

    SeverityLevel level = getSeverityLevel(scenario);

    if (level != null) {
        annotations.add(getSeverityAnnotation(level));
    }

    Issues issues = getIssuesAnnotation(scenario);
    if (issues != null) {
        annotations.add(issues);
    }

    TestCaseId testCaseId = getTestCaseIdAnnotation(scenario);
    if (testCaseId != null) {
        annotations.add(testCaseId);
    }

    annotations.add(getFeaturesAnnotation(feature.getName()));
    annotations.add(getStoriesAnnotation(scenario.getName()));
    annotations.add(getDescriptionAnnotation(scenario.getDescription()));

    AnnotationManager am = new AnnotationManager(annotations);
    am.update(event);

    event.withLabels(AllureModelUtils.createTestFrameworkLabel("CucumberJVM"));

    ALLURE_LIFECYCLE.fire(event);
}
 
Example #14
Source File: CukesHooks.java    From Decision with Apache License 2.0 4 votes vote down vote up
@Override
    public void startOfScenarioLifeCycle(Scenario scenario) {
//         logger.info("Got to scenario {} life cycle start",
//        scenario.getName());

    }
 
Example #15
Source File: CukesHooks.java    From Decision with Apache License 2.0 4 votes vote down vote up
@Override
public void endOfScenarioLifeCycle(Scenario scenario) {
    // logger.info("Got to scenario {} life cycle end", scenario.getName());
}
 
Example #16
Source File: WrappedJSONFormatter.java    From senbot with MIT License 4 votes vote down vote up
@Override
public void scenario(Scenario arg0) {
	wrapped.scenario(arg0);
}
 
Example #17
Source File: ParameterizedCucumber.java    From senbot with MIT License 4 votes vote down vote up
@Override
public void scenario(Scenario arg0) {
	getWrapped().scenario(arg0);
	
}
 
Example #18
Source File: HtmlFormatter.java    From scott with MIT License 4 votes vote down vote up
@Override
public void startOfScenarioLifeCycle(Scenario scenario) {
    // NoOp
}
 
Example #19
Source File: CucumberListener.java    From AppiumTestDistribution with GNU General Public License v3.0 4 votes vote down vote up
public void endOfScenarioLifeCycle(Scenario scenario) {
    AppiumDriverManager.getDriver().quit();
}
 
Example #20
Source File: StepUtils.java    From allure-java with Apache License 2.0 4 votes vote down vote up
StepUtils(final Feature feature, final Scenario scenario) {
    this.lifecycle = Allure.getLifecycle();
    this.feature = feature;
    this.scenario = scenario;
}
 
Example #21
Source File: CucumberListener.java    From AppiumTestDistribution with GNU General Public License v3.0 4 votes vote down vote up
public void startOfScenarioLifeCycle(Scenario scenario) {
    createAppiumInstance(scenario);
    this.testSteps = new LinkedList<Step>();
    System.out.println(testSteps);
}
 
Example #22
Source File: XMLFormatter.java    From xframium-java with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void endOfScenarioLifeCycle( Scenario arg0 )
{
    System.out.println("end life" );

}
 
Example #23
Source File: GherkinKeyWordProvider.java    From xframium-java with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void startOfScenarioLifeCycle(Scenario arg0) {
	// TODO Auto-generated method stub
	
}
 
Example #24
Source File: GherkinKeyWordProvider.java    From xframium-java with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void endOfScenarioLifeCycle(Scenario arg0) {
	// TODO Auto-generated method stub
	
}
 
Example #25
Source File: LabelBuilder.java    From allure-java with Apache License 2.0 4 votes vote down vote up
LabelBuilder(final Feature feature, final Scenario scenario, final Deque<Tag> tags) {
    final TagParser tagParser = new TagParser(feature, scenario);

    getScenarioLabels().add(createFeatureLabel(feature.getName()));
    getScenarioLabels().add(createStoryLabel(scenario.getName()));

    while (tags.peek() != null) {
        final Tag 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(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(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("cucumberjvm"),
            createLanguageLabel("java")
    ));

}
 
Example #26
Source File: AllureCucumberJvm.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void scenario(final Scenario scnr) {
    //Nothing to do with Allure
}
 
Example #27
Source File: TagParser.java    From allure-java with Apache License 2.0 4 votes vote down vote up
TagParser(final Feature feature, final Scenario scenario) {
    this.feature = feature;
    this.scenario = scenario;
}
 
Example #28
Source File: XMLFormatter.java    From xframium-java with GNU General Public License v3.0 3 votes vote down vote up
@Override
public void startOfScenarioLifeCycle( Scenario arg0 )
{
    
    System.out.println("start life" );

}