Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
https://github.com/serenity-bdd/serenity-cucumber/issues/19
Browse files Browse the repository at this point in the history
  • Loading branch information
cliviu committed Jan 6, 2016
1 parent b2d144f commit ed7551e
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/main/java/net/serenitybdd/cucumber/SerenityReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,17 +401,32 @@ public void startOfScenarioLifeCycle(Scenario scenario) {
}

private void startScenario(Scenario scenario) {
//getThucydidesListeners().withDriver(ThucydidesWebDriverSupport.getDriver());
StepEventBus.getEventBus().testStarted(scenario.getName());
StepEventBus.getEventBus().addDescriptionToCurrentTest(scenario.getDescription());
StepEventBus.getEventBus().addTagsToCurrentTest(convertCucumberTags(currentFeature.getTags()));
StepEventBus.getEventBus().addTagsToCurrentTest(convertCucumberTags(scenario.getTags()));

registerFeatureJiraIssues(currentFeature.getTags());
registerScenarioJiraIssues(scenario.getTags());

checkForSkipped(currentFeature);
checkForPending(currentFeature);
checkForManual(scenario);
}

private void registerFeatureJiraIssues(List<Tag> tags) {
List<String> issues = extractJiraIssueTags(tags);
if (!issues.isEmpty()) {
StepEventBus.getEventBus().addIssuesToCurrentStory(issues);
}
}

private void registerScenarioJiraIssues(List<Tag> tags) {
List<String> issues = extractJiraIssueTags(tags);
if (!issues.isEmpty()) {
StepEventBus.getEventBus().addIssuesToCurrentTest(issues);
}
}

private List<TestTag> convertCucumberTags(List<Tag> cucumberTags) {
List<TestTag> tags = Lists.newArrayList();
Expand All @@ -421,6 +436,21 @@ private List<TestTag> convertCucumberTags(List<Tag> cucumberTags) {
return ImmutableList.copyOf(tags);
}

private List<String> extractJiraIssueTags(List<Tag> cucumberTags) {
List<String> issues = Lists.newArrayList();
for (Tag tag : cucumberTags) {
if(tag.getName().startsWith("@issue:")) {
String tagIssueValue = tag.getName().substring("@issue:".length());
issues.add(tagIssueValue);
}
if(tag.getName().startsWith("@issues:")) {
String tagIssuesValues = tag.getName().substring("@issues:".length());
issues.addAll(Arrays.asList(tagIssuesValues.split(",")));
}
}
return issues;
}

@Override
public void endOfScenarioLifeCycle(Scenario scenario) {
if (examplesRunning) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.serenitybdd.cucumber.outcomes

import com.github.goldin.spock.extensions.tempdir.TempDir
import net.serenitybdd.cucumber.integration.FeatureWithMoreIssuesTag
import net.serenitybdd.cucumber.integration.FeatureWithNoName
import net.serenitybdd.cucumber.integration.ScenariosWithTableInBackgroundSteps
import net.serenitybdd.cucumber.integration.ScenarioThrowingPendingException
Expand Down Expand Up @@ -287,6 +288,47 @@ It goes for two lines"""
recordedTestOutcomes[0].tags.contains(TestTag.withName("ISSUE-456").andType("issue"))
}

def "should fill @issue keys"() {
given:
def runtime = serenityRunnerForCucumberTestRunner(BasicArithemticScenario.class, outputDirectory);

when:
runtime.run();
def recordedTestOutcomes = new TestOutcomeLoader().forFormat(OutcomeFormat.JSON).loadFrom(outputDirectory)

then:
recordedTestOutcomes.each { outcome ->
outcome.tags.contains(TestTag.withName("ISSUE-123").andType("issue"))
outcome.getIssueKeys().contains("ISSUE-123");
}
and:
recordedTestOutcomes[0].tags.contains(TestTag.withName("ISSUE-456").andType("issue"))
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-123");
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-456");
}

def "should fill @issues keys"() {
given:
def runtime = serenityRunnerForCucumberTestRunner(FeatureWithMoreIssuesTag.class, outputDirectory);

when:
runtime.run();
def recordedTestOutcomes = new TestOutcomeLoader().forFormat(OutcomeFormat.JSON).loadFrom(outputDirectory)

then:
recordedTestOutcomes.each { outcome ->
outcome.tags.contains(TestTag.withName("ISSUE-123,ISSUE-789").andType("issues"))
outcome.getIssueKeys().contains("ISSUE-123");
outcome.getIssueKeys().contains("ISSUE-789");
}
and:
recordedTestOutcomes[0].tags.contains(TestTag.withName("ISSUE-456,ISSUE-001").andType("issues"))
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-456");
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-001");
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-123");
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-789");
}

def "scenarios with the @pending tag should be reported as Pending"() {
given:
def runtime = serenityRunnerForCucumberTestRunner(MultipleScenariosWithPendingTag.class, outputDirectory);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.serenitybdd.cucumber.integration;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;


@RunWith(Cucumber.class)
@CucumberOptions(features="src/test/resources/samples/calculator/basic_arithmetic_more_issues.feature")
public class FeatureWithMoreIssuesTag {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@foo
@issues:ISSUE-123,ISSUE-789
Feature: Basic Arithmetic
Calculing additions

Background: A Calculator
Given a calculator I just turned on

@issues:ISSUE-456,ISSUE-001
Scenario: Addition
# Try to change one of the values below to provoke a failure
When I add 4 and 5
Then the result is 9

Scenario: Another Addition
# Try to change one of the values below to provoke a failure
When I add 4 and 7
Then the result is 11

0 comments on commit ed7551e

Please sign in to comment.