Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include step comments in report #1012

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .README/feature-failed.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .README/tag-report.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions src/main/java/net/masterthought/cucumber/json/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.apache.commons.lang3.ArrayUtils;

import net.masterthought.cucumber.json.deserializers.OutputsDeserializer;
import net.masterthought.cucumber.json.support.Argument;
import net.masterthought.cucumber.json.support.Resultsable;
import net.masterthought.cucumber.json.support.Status;
import net.masterthought.cucumber.json.support.StatusCounter;
import org.apache.commons.lang3.ArrayUtils;

import java.util.ArrayList;
import java.util.List;

public class Step implements Resultsable {

// Start: attributes from JSON file report
private String name = null;
private final String keyword = null;
private Integer line = null;
private List<String> comments = new ArrayList<>();
// create empty Result for all cases where step has no result
// - happens for old or different cucumber implementation of the library
private final Result result = new Result();
Expand Down Expand Up @@ -109,6 +112,10 @@ public Status getAfterStatus() {
return afterStatus;
}

public List<String> getComments() {
return comments;
}

public void setMetaData() {
beforeStatus = new StatusCounter(before).getFinalStatus();
afterStatus = new StatusCounter(after).getFinalStatus();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/css/cucumber.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ a:hover {
box-shadow: -3px 0 #6ce;
}

.description {
.description, .comment {
font-style: italic;
background-color: beige;
white-space: pre;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/templates/macros/json/steps.vm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<div id="steps-$stepsId" class="inner-level collapse collapsable-details #if (!$element.getStatus().isPassed() || $expand_all_steps) in #end">
#foreach($step in $element.getSteps())
<div class="step">
#foreach($comment in $step.getComments())
<div class="comment indention">$comment</div>
#end
#includeStepName($step.getKeyword(), $step.getName(), $step.getMatch().getArguments(), $step.getResult().getStatus(), $step.getResult())
#set($isPassed = $step.getResult().getStatus().isPassed())
#includeHooks("Before", $step.getBefore(), $step.getBeforeStatus(), "step")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package net.masterthought.cucumber.generators.integrations;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;

import org.apache.commons.lang.StringUtils;
import org.junit.Test;

import net.masterthought.cucumber.generators.FeatureReportPage;
import net.masterthought.cucumber.generators.integrations.helpers.BriefAssertion;
import net.masterthought.cucumber.generators.integrations.helpers.DocumentAssertion;
Expand All @@ -31,6 +22,14 @@
import net.masterthought.cucumber.json.Result;
import net.masterthought.cucumber.json.Row;
import net.masterthought.cucumber.json.Step;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Damian Szczepanik (damianszczepanik@github)
Expand Down Expand Up @@ -235,6 +234,7 @@ public void generatePage_generatesSteps() {
assertThat(brief.getKeyword()).isEqualTo(step.getKeyword());
assertThat(brief.getName()).isEqualTo(step.getName());
brief.hasDuration(step.getDuration());
steps[i].hasComments(step.getComments());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package net.masterthought.cucumber.generators.integrations.helpers;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.List;

import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Damian Szczepanik (damianszczepanik@github)
*/
Expand Down Expand Up @@ -37,4 +45,12 @@ public HooksAssertion getBefore() {
public HooksAssertion getAfter() {
return oneByClass("hooks-step-after", HooksAssertion.class);
}

public void hasComments(List<String> expectedComments) {
Elements elements = element.getElementsByClass("comment");
List<String> comments = elements.stream()
.map(Element::text)
.collect(toList());
assertThat(comments).isEqualTo(expectedComments);
}
}
37 changes: 32 additions & 5 deletions src/test/java/net/masterthought/cucumber/json/StepTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package net.masterthought.cucumber.json;

import static org.assertj.core.api.Assertions.assertThat;

import net.masterthought.cucumber.generators.integrations.PageTest;
import net.masterthought.cucumber.json.support.Status;
import org.junit.Before;
import org.junit.Test;

import net.masterthought.cucumber.generators.integrations.PageTest;
import net.masterthought.cucumber.json.support.Status;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Damian Szczepanik (damianszczepanik@github)
Expand Down Expand Up @@ -262,4 +263,30 @@ public void getAfterStatus_OnEmptyHooks_ReturnsPassed() {
// then
assertThat(status).isEqualTo(Status.PASSED);
}
}

@Test
public void getComments_ReturnsComments() {

// given
Step step = features.get(0).getElements()[0].getSteps()[0];

// when
List<String> keyword = step.getComments();

// then
assertThat(keyword).containsExactly("# Some comments", "# Some more comments");
}

@Test
public void getComments_ReturnsEmptyCommentList() {

// given
Step step = features.get(0).getElements()[0].getSteps()[1];

// when
List<String> keyword = step.getComments();

// then
assertThat(keyword).isEmpty();
}
}
13 changes: 12 additions & 1 deletion src/test/resources/json/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"type": "text/plain"
}
}
],
"comments": [
"# Some comments",
"# Some more comments"
]
},
{
Expand Down Expand Up @@ -378,6 +382,9 @@
"status": "failed"
}
}
],
"comments": [
"# Setting the account balance to 100"
]
},
{
Expand Down Expand Up @@ -407,6 +414,10 @@
"location": "StepHook.afterStep()"
}
}
],
"comments": [
"# The card is valid",
"# Processing should continue"
]
},
{
Expand Down Expand Up @@ -657,4 +668,4 @@
],
"uri": "net/masterthought/example/ATMK.feature"
}
]
]