Skip to content

Commit

Permalink
fixed tests, non critical failures now a little more prominent in the…
Browse files Browse the repository at this point in the history
… report
  • Loading branch information
iantmoore committed Oct 22, 2016
1 parent 8647f2b commit 3a126cd
Show file tree
Hide file tree
Showing 15 changed files with 459 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ public void setFailure(SubstepExecutionFailure substepExecutionFailure) {
EnumSet<ExecutionResult> excluded = EnumSet.of(ExecutionResult.PARSE_FAILURE, ExecutionResult.SETUP_TEARDOWN_FAILURE);

if (!excluded.contains(this.result)) {
this.result = ExecutionResult.FAILED;

if(substepExecutionFailure.isNonCritical()){
this.result = ExecutionResult.NON_CRITICAL_FAILURE;
}
else {
this.result = ExecutionResult.FAILED;
}

}

this.substepExecutionFailure = substepExecutionFailure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,37 @@ public Set<String> getTags() {
return tags;
}



public static boolean hasNonCriticalFailure(ExecutionNode node) {

// TODO
boolean rtn = false;

if (node.getResult().getResult() == ExecutionResult.CHILD_FAILED){
// there is a failure at a parent level, is the cause critical ?
// any child nodes with failures that are critical ?

if (node instanceof NodeWithChildren){
List<ExecutionNode> children = ((NodeWithChildren) node).getChildren();

for (ExecutionNode child : children){
rtn = hasNonCriticalFailure(child);
if (rtn){
break;
}
}
}

}
else if (node.getResult().getResult() == ExecutionResult.NON_CRITICAL_FAILURE) {
// real failure, is it critical ?
rtn = node.getResult().getFailure().isNonCritical();
}
return rtn;
}


public static boolean hasCriticalFailure(ExecutionNode node) {
boolean rtn = false;

Expand All @@ -98,4 +129,5 @@ else if (node.getResult().getResult() == ExecutionResult.FAILED) {
}
return rtn;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.technophobia.substeps.execution.node;

import com.google.common.collect.Lists;
import com.technophobia.substeps.execution.ExecutionNodeResult;
import com.technophobia.substeps.execution.ExecutionNodeVisitor;

import java.util.List;
Expand All @@ -45,6 +46,11 @@ public RootNode(String featureSetDescription, List<FeatureNode> features, String
this.nonFatalTags = nonFatalTags;
}

@Override
public ExecutionNodeResult getResult() {
return super.getResult();
}

@Override
public <RETURN_TYPE> RETURN_TYPE dispatch(ExecutionNodeVisitor<RETURN_TYPE> executionNodeVisitor) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.technophobia.substeps.execution.AbstractExecutionNodeVisitor;
import com.technophobia.substeps.execution.ExecutionResult;
import com.technophobia.substeps.execution.node.IExecutionNode;
import com.technophobia.substeps.execution.node.NodeWithChildren;
import com.technophobia.substeps.execution.node.RootNode;
Expand Down Expand Up @@ -106,7 +107,7 @@ private void addFailuresToLists(IExecutionNode node, List<IExecutionNode> parent
List<IExecutionNode> path = Lists.newArrayList(parents);
path.add(node);

if (node.getResult().getResult().isFailure()) { // nodes in a state of child_failed won't have the actual failure : node.getResult().getFailure()
if (node.getResult().getResult().isFailure() || node.getResult().getResult() == ExecutionResult.NON_CRITICAL_FAILURE) { // nodes in a state of child_failed won't have the actual failure : node.getResult().getFailure()

// child first
if (node instanceof NodeWithChildren<?>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.base.Function;
import com.technophobia.substeps.execution.ExecutionResult;
import com.technophobia.substeps.execution.node.IExecutionNode;
import com.technophobia.substeps.execution.node.StepImplementationNode;

import java.io.Serializable;

Expand Down Expand Up @@ -52,6 +53,47 @@ public Long apply(final SubstepExecutionFailure failure) {

private final ThrowableInfo throwableInfo;

private SubstepExecutionFailure(Throwable cause, IExecutionNode executionNode, boolean setupOrTearDown, boolean nonCritical, byte[] screenshot) {
this.cause = cause;
this.executionNode = executionNode;
this.setupOrTearDown = setupOrTearDown;
this.nonCritical = nonCritical;
this.screenshot = screenshot;
this.throwableInfo = new ThrowableInfo(cause);
}




public static SubstepExecutionFailure criticalFailure(Throwable cause, IExecutionNode node, byte[] screenshotBytes) {
SubstepExecutionFailure sef = new SubstepExecutionFailure(cause, node, false, false, screenshotBytes);

node.getResult().setFailure(sef);

return sef;

}


public static SubstepExecutionFailure nonCriticalFailure(final Throwable cause, final IExecutionNode node, byte[] screenshotBytes) {

SubstepExecutionFailure sef = new SubstepExecutionFailure(cause, node, false, true, screenshotBytes);

node.getResult().setFailure(sef);

return sef;
}

/*
* @param cause the cause of the failure
* @param node the node that failed execution
* @param screenshot the bytes representing the screenshot taken when the node execution failed
*/
// public SubstepExecutionFailure(final Throwable cause, final IExecutionNode node, final byte[] screenshot) {
// this(cause, node);
// this.setScreenshot(screenshot);
// }


public SubstepExecutionFailure(final Throwable cause) {

Expand All @@ -74,16 +116,6 @@ public SubstepExecutionFailure(final Throwable cause, final IExecutionNode node)
}


/**
* @param cause the cause of the failure
* @param node the node that failed execution
* @param screenshot the bytes representing the screenshot taken when the node execution failed
*/
public SubstepExecutionFailure(final Throwable cause, final IExecutionNode node, final byte[] screenshot) {
this(cause, node);
this.setScreenshot(screenshot);
}


/**
* @param cause the cause of the failure
Expand All @@ -106,10 +138,16 @@ public SubstepExecutionFailure(final Throwable cause, final IExecutionNode node,
node.getResult().setResult(result);
}



public static void setResult(final Throwable cause, final IExecutionNode node, final ExecutionResult result) {
final SubstepExecutionFailure sef = new SubstepExecutionFailure(cause);
sef.executionNode = node;
sef.executionNode.getResult().setFailure(sef);


final SubstepExecutionFailure sef = SubstepExecutionFailure.criticalFailure(cause, node, null);


// sef.executionNode = node;
// sef.executionNode.getResult().setFailure(sef);
node.getResult().setResult(result);
}

Expand Down Expand Up @@ -184,4 +222,5 @@ public byte[] getScreenshot() {
public void setScreenshot(final byte[] screenshot) {
this.screenshot = screenshot;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,22 @@ public SetupAndTearDown getSetupAndTeardown() {
return setupAndTeardown;
}



public boolean isNodeFailureNonCritical(final IExecutionNode node) {

return this.nonFatalTagmanager != null && nonFatalTagmanager.isApplicable(node);
}

public void addFailure(final SubstepExecutionFailure failure) {

failures.add(failure);
logFailure(failure);

// set the criticality of this failure

if (!failure.isSetupOrTearDown() && this.nonFatalTagmanager != null
&& nonFatalTagmanager.isApplicable(failure.getExeccutionNode())) {
if (!failure.isSetupOrTearDown() && isNodeFailureNonCritical(failure.getExeccutionNode())) {
// if (!failure.isSetupOrTearDown() && this.nonFatalTagmanager != null
// && nonFatalTagmanager.isApplicable(failure.getExeccutionNode())) {

failure.setNonCritical(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public class TagManager extends AbstractExecutionNodeVisitor<Boolean> {
private Set<String> acceptedTags = null;
private Set<String> excludedTags = null;

public static TagManager fromTags(final String tags){
if (tags != null){
return new TagManager(tags);
}
else {
return null;
}
}

public TagManager(final String tagList) {

acceptedTags = new HashSet<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ protected void recordResult(final RootNode node, final boolean success, final Ro
rootNodeStateSet = true;
break;
}

if (FeatureNode.hasNonCriticalFailure(featureNode)){
SubstepsRuntimeException e = new SubstepsRuntimeException("At least one NON critical Feature failed");
SubstepExecutionFailure.setResult(e, node, ExecutionResult.NON_CRITICAL_FAILURE);

context.getNotificationDistributor().onNodeFailed(node, e);
rootNodeStateSet = true;
}
}

if (!rootNodeStateSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ protected boolean execute(StepImplementationNode node, RootNodeExecutionContext
private void addFailure(StepImplementationNode node, RootNodeExecutionContext context, Throwable t) {

byte[] screenshotBytes = attemptScreenshot(node, context);
context.addFailure(new SubstepExecutionFailure(t, node, screenshotBytes));

SubstepExecutionFailure failure;
if (context.isNodeFailureNonCritical(node)){
failure = SubstepExecutionFailure.nonCriticalFailure(t, node, screenshotBytes);
}
else {
failure = SubstepExecutionFailure.criticalFailure(t,node, screenshotBytes);
}

context.addFailure(failure);
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/resources/static/css/substeps.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,11 @@ i.jstree-icon.jstree-themeicon.PARSE_FAILURE.jstree-themeicon-custom
background-size: auto;
background-position: center center;
}

i.jstree-icon.jstree-themeicon.NON_CRITICAL_FAILURE.jstree-themeicon-custom
{
background-image: url("../img/NON_CRITICAL_FAILURE.png");
background-size: auto;
background-position: center center;
}

Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ class ExecutionResultsCollector extends IExecutionResultsCollector {

})

val result = if (Option(featureNode.getResult.getFailure).isDefined && featureNode.getResult.getFailure.isNonCritical) "NON_CRITICAL_FAILURE" else featureNode.getResult.getResult.name()

val data =
FeatureSummary("FeatureNode", featureNode.getFilename, featureNode.getResult.getResult.name(), featureNode.getId,
FeatureSummary("FeatureNode", featureNode.getFilename, result, featureNode.getId,
Some(featureNode.getResult.getRunningDuration), featureNode.getDescription, scenarios.toList, featureNode.getTags.toList)


Expand Down Expand Up @@ -299,7 +301,11 @@ class ExecutionResultsCollector extends IExecutionResultsCollector {
case _ => None
}

// TODO - add this into the node detail..
Option(result.getFailure).map(sef => {

log.info(" *** got Substep Exec Failure: critical : " + sef.isNonCritical)

})


val data =
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/scala/org/substeps/report/NodeDetail.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ case object NodeDetail {

val stackTrace = scenarioNode.getResult.getFailure.getCause.getStackTrace.toList.map(elem => elem.toString)

NodeDetail("BasicScenarioNode", scenarioNode.getParent.getFilename, scenarioNode.getLineNumber, scenarioNode.getResult.getResult.name(), scenarioNode.getId.toInt,
val result = if (scenarioNode.getResult.getFailure.isNonCritical) "NON_CRITICAL_FAILURE" else scenarioNode.getResult.getResult.name()


NodeDetail("BasicScenarioNode", scenarioNode.getParent.getFilename, scenarioNode.getLineNumber, result, scenarioNode.getId.toInt,
Option(scenarioNode.getResult.getRunningDuration), scenarioNode.getDescription, None, children,
Some(scenarioNode.getResult.getFailure.getCause.getMessage), Some(stackTrace), None, tags, None, None)

Expand Down
Loading

0 comments on commit 3a126cd

Please sign in to comment.