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

Commit ed7551e

Browse files
committed
https://github.com/serenity-bdd/serenity-cucumber/issues/19
1 parent b2d144f commit ed7551e

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

src/main/java/net/serenitybdd/cucumber/SerenityReporter.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -401,17 +401,32 @@ public void startOfScenarioLifeCycle(Scenario scenario) {
401401
}
402402

403403
private void startScenario(Scenario scenario) {
404-
//getThucydidesListeners().withDriver(ThucydidesWebDriverSupport.getDriver());
405404
StepEventBus.getEventBus().testStarted(scenario.getName());
406405
StepEventBus.getEventBus().addDescriptionToCurrentTest(scenario.getDescription());
407406
StepEventBus.getEventBus().addTagsToCurrentTest(convertCucumberTags(currentFeature.getTags()));
408407
StepEventBus.getEventBus().addTagsToCurrentTest(convertCucumberTags(scenario.getTags()));
409408

409+
registerFeatureJiraIssues(currentFeature.getTags());
410+
registerScenarioJiraIssues(scenario.getTags());
411+
410412
checkForSkipped(currentFeature);
411413
checkForPending(currentFeature);
412414
checkForManual(scenario);
413415
}
414416

417+
private void registerFeatureJiraIssues(List<Tag> tags) {
418+
List<String> issues = extractJiraIssueTags(tags);
419+
if (!issues.isEmpty()) {
420+
StepEventBus.getEventBus().addIssuesToCurrentStory(issues);
421+
}
422+
}
423+
424+
private void registerScenarioJiraIssues(List<Tag> tags) {
425+
List<String> issues = extractJiraIssueTags(tags);
426+
if (!issues.isEmpty()) {
427+
StepEventBus.getEventBus().addIssuesToCurrentTest(issues);
428+
}
429+
}
415430

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

439+
private List<String> extractJiraIssueTags(List<Tag> cucumberTags) {
440+
List<String> issues = Lists.newArrayList();
441+
for (Tag tag : cucumberTags) {
442+
if(tag.getName().startsWith("@issue:")) {
443+
String tagIssueValue = tag.getName().substring("@issue:".length());
444+
issues.add(tagIssueValue);
445+
}
446+
if(tag.getName().startsWith("@issues:")) {
447+
String tagIssuesValues = tag.getName().substring("@issues:".length());
448+
issues.addAll(Arrays.asList(tagIssuesValues.split(",")));
449+
}
450+
}
451+
return issues;
452+
}
453+
424454
@Override
425455
public void endOfScenarioLifeCycle(Scenario scenario) {
426456
if (examplesRunning) {

src/test/groovy/net/serenitybdd/cucumber/outcomes/WhenCreatingSerenityTestOutcomes.groovy

+42
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.serenitybdd.cucumber.outcomes
22

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

291+
def "should fill @issue keys"() {
292+
given:
293+
def runtime = serenityRunnerForCucumberTestRunner(BasicArithemticScenario.class, outputDirectory);
294+
295+
when:
296+
runtime.run();
297+
def recordedTestOutcomes = new TestOutcomeLoader().forFormat(OutcomeFormat.JSON).loadFrom(outputDirectory)
298+
299+
then:
300+
recordedTestOutcomes.each { outcome ->
301+
outcome.tags.contains(TestTag.withName("ISSUE-123").andType("issue"))
302+
outcome.getIssueKeys().contains("ISSUE-123");
303+
}
304+
and:
305+
recordedTestOutcomes[0].tags.contains(TestTag.withName("ISSUE-456").andType("issue"))
306+
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-123");
307+
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-456");
308+
}
309+
310+
def "should fill @issues keys"() {
311+
given:
312+
def runtime = serenityRunnerForCucumberTestRunner(FeatureWithMoreIssuesTag.class, outputDirectory);
313+
314+
when:
315+
runtime.run();
316+
def recordedTestOutcomes = new TestOutcomeLoader().forFormat(OutcomeFormat.JSON).loadFrom(outputDirectory)
317+
318+
then:
319+
recordedTestOutcomes.each { outcome ->
320+
outcome.tags.contains(TestTag.withName("ISSUE-123,ISSUE-789").andType("issues"))
321+
outcome.getIssueKeys().contains("ISSUE-123");
322+
outcome.getIssueKeys().contains("ISSUE-789");
323+
}
324+
and:
325+
recordedTestOutcomes[0].tags.contains(TestTag.withName("ISSUE-456,ISSUE-001").andType("issues"))
326+
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-456");
327+
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-001");
328+
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-123");
329+
recordedTestOutcomes[0].getIssueKeys().contains("ISSUE-789");
330+
}
331+
290332
def "scenarios with the @pending tag should be reported as Pending"() {
291333
given:
292334
def runtime = serenityRunnerForCucumberTestRunner(MultipleScenariosWithPendingTag.class, outputDirectory);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package net.serenitybdd.cucumber.integration;
2+
3+
import cucumber.api.CucumberOptions;
4+
import cucumber.api.junit.Cucumber;
5+
import org.junit.runner.RunWith;
6+
7+
8+
@RunWith(Cucumber.class)
9+
@CucumberOptions(features="src/test/resources/samples/calculator/basic_arithmetic_more_issues.feature")
10+
public class FeatureWithMoreIssuesTag {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@foo
2+
@issues:ISSUE-123,ISSUE-789
3+
Feature: Basic Arithmetic
4+
Calculing additions
5+
6+
Background: A Calculator
7+
Given a calculator I just turned on
8+
9+
@issues:ISSUE-456,ISSUE-001
10+
Scenario: Addition
11+
# Try to change one of the values below to provoke a failure
12+
When I add 4 and 5
13+
Then the result is 9
14+
15+
Scenario: Another Addition
16+
# Try to change one of the values below to provoke a failure
17+
When I add 4 and 7
18+
Then the result is 11

0 commit comments

Comments
 (0)