Skip to content

Commit

Permalink
localize step definition report
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed Nov 23, 2009
1 parent dac6651 commit 2c43124
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 55 deletions.
75 changes: 70 additions & 5 deletions Reporting/Common/Common.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,57 @@
xmlns:sfr="urn:TechTalk:SpecFlow.Report"
exclude-result-prefixes="msxsl">

<xsl:param name="tool-language" select="'en'" />
<xsl:param name="base-tool-language" select="substring-before($tool-language, '-')" />

<xsl:include href="GherkinElements.xslt"/>

<xsl:param name="common-tool-text">
<Language code="en">
<GeneratedByPre>Generated by SpecFlow at </GeneratedByPre>
<GeneratedByPost></GeneratedByPost>
<See>see </See>
<Show>show</Show>
<Hide>hide</Hide>
<Copy>copy</Copy>
</Language>
</xsl:param>

<xsl:template name="get-common-tool-text">
<xsl:param name="text-key" />

<xsl:call-template name="get-tool-text-base">
<xsl:with-param name="text-key" select="$text-key" />
<xsl:with-param name="local-tool-texts" select="msxsl:node-set($common-tool-text)" />
</xsl:call-template>
</xsl:template>

<xsl:template name="get-tool-text-base">
<xsl:param name="text-key" />
<xsl:param name="local-tool-texts" />

<xsl:choose>
<xsl:when test="$local-tool-texts//Language[@code = $tool-language]">
<xsl:value-of select="$local-tool-texts//Language[@code = $tool-language]/node()[local-name() = $text-key]"/>
</xsl:when>
<xsl:when test="$local-tool-texts//Language[@code = $base-tool-language]">
<xsl:value-of select="$local-tool-texts//Language[@code = $base-tool-language]/node()[local-name() = $text-key]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$local-tool-texts//Language[@code = 'en']/node()[local-name() = $text-key]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="sfr:ScenarioStep" priority="-0.1" mode="clipboardCopy">
<xsl:variable name="step-id" select="generate-id()" />

<xsl:text> </xsl:text>
<a href="#" onclick="copyStepToClipboard('{$step-id}'); return false;" class="button">[<xsl:call-template name="get-common-tool-text">
<xsl:with-param name="text-key" select="'Copy'" />
</xsl:call-template>]</a>
</xsl:template>

<xsl:template name="html-common-header">
<xsl:param name="title" />

Expand Down Expand Up @@ -137,18 +186,24 @@
}
]]></style>
<script>
var showButtonText = "[<xsl:call-template name="get-common-tool-text">
<xsl:with-param name="text-key" select="'Show'" />
</xsl:call-template>]";
var hideButtonText = "[<xsl:call-template name="get-common-tool-text">
<xsl:with-param name="text-key" select="'Hide'" />
</xsl:call-template>]";
<![CDATA[
function toggle(sdid){
e=window.event.srcElement;
toToggle=document.getElementById(sdid);
if (e.innerText=="[show]")
if (e.innerText==showButtonText)
{
e.innerText="[hide]";
e.innerText=hideButtonText;
toToggle.style.display="block";
}
else
{
e.innerText="[show]";
e.innerText=showButtonText;
toToggle.style.display="none";
}
}
Expand Down Expand Up @@ -226,8 +281,18 @@
<h1>
<xsl:value-of select="$title"/>
</h1>

Generated by SpecFlow at <xsl:value-of select="$generatedAt"/> (see <a href="http://www.specflow.org/">http://www.specflow.org/</a>).

<xsl:call-template name="get-common-tool-text">
<xsl:with-param name="text-key" select="'GeneratedByPre'" />
</xsl:call-template>
<xsl:value-of select="$generatedAt"/>
<xsl:call-template name="get-common-tool-text">
<xsl:with-param name="text-key" select="'GeneratedByPost'" />
</xsl:call-template>
<xsl:text> (</xsl:text>
<xsl:call-template name="get-common-tool-text">
<xsl:with-param name="text-key" select="'See'" />
</xsl:call-template>
<a href="http://www.specflow.org/">http://www.specflow.org/</a>).
</xsl:template>
</xsl:stylesheet>
42 changes: 39 additions & 3 deletions Reporting/Common/GherkinElements.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,58 @@
xmlns:sfr="urn:TechTalk:SpecFlow.Report"
exclude-result-prefixes="msxsl">

<xsl:param name="feature-language" select="'en'" />
<xsl:param name="languages" select="document('Languages.xml')" />

<xsl:template name="get-keyword">
<xsl:param name="keyword" />
<xsl:param name="language">
<xsl:choose>
<xsl:when test="ancestor::sfr:Feature[1]/sfr:Language">
<xsl:value-of select="ancestor::sfr:Feature[1]/sfr:Language"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$feature-language" />
</xsl:otherwise>
</xsl:choose>
</xsl:param>

<xsl:variable name="local-keyword">
<xsl:choose>
<xsl:when test="$languages//Language[@code = $language]">
<xsl:value-of select="$languages//Language[@code = $language]/node()[local-name() = $keyword]"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="base-language" select="substring-before($language, '-')" />
<xsl:value-of select="$languages//Language[@code = $base-language]/node()[local-name() = $keyword]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:value-of select="$local-keyword"/>
</xsl:template>

<xsl:template match="sfr:ScenarioStep">
<xsl:variable name="step-id" select="generate-id()" />
<xsl:variable name="step-keyword" select="@xsi:type" />
<span id="txt{$step-id}">
<span class="stepKeyword">
<xsl:value-of select="$step-keyword"/>
<xsl:call-template name="get-keyword">
<xsl:with-param name="keyword" select="$step-keyword" />
</xsl:call-template>
</span>
<xsl:text> </xsl:text>
<xsl:apply-templates select="sfr:Text" />
</span>
<xsl:text> </xsl:text>
<a href="#" onclick="copyStepToClipboard('{$step-id}'); return false;" class="button">[copy]</a>
<xsl:apply-templates select="." mode="clipboardCopy"/>
<xsl:apply-templates select="sfr:TableArg" />
<xsl:apply-templates select="sfr:MultiLineTextArgument" />
</xsl:template>

<xsl:template match="sfr:ScenarioStep" priority="-0.5" mode="clipboardCopy">
<!-- nop -->
</xsl:template>

<xsl:template match="sfr:Text" priority="-0.1">
<xsl:value-of select="string(node())"/>
</xsl:template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void TransformReport(string outputFilePath)
}
else
{
XsltHelper.TransformHtml(serializer, report, GetType(), outputFilePath);
XsltHelper.TransformHtml(serializer, report, GetType(), outputFilePath, specFlowProject.GeneratorConfiguration);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Reporting/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void StepDefinitionReport(
List<BindingInfo> bindings = BindingCollector.CollectBindings(specFlowProject, basePath);

StepDefinitionReportGenerator generator = new StepDefinitionReportGenerator(specFlowProject, bindings, parsedFeatures,
true, false);
true);
generator.GenerateReport();

string outputFilePath = Path.GetFullPath(outputFile);
Expand Down
8 changes: 8 additions & 0 deletions Reporting/ReflectionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System;
using System.Reflection;

namespace TechTalk.SpecFlow.Reporting
{
static class ReflectionHelper
Expand All @@ -6,5 +9,10 @@ public static T GetProperty<T>(this object source, string propertyName)
{
return (T)source.GetType().GetProperty(propertyName).GetValue(source, null);
}

public static void PreserveStackTrace(this Exception ex)
{
typeof(Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(ex, new object[0]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class StepDefinitionReport
public string GeneratedAt;
[XmlAttribute("showBindingsWithoutInsance")]
public bool ShowBindingsWithoutInsance;
[XmlAttribute("onlySelectedFeatures")]
public bool OnlySelectedFeatures;

[XmlElement("StepDefinition")]
public List<StepDefinition> StepDefinitions = new List<StepDefinition>();
Expand Down
115 changes: 80 additions & 35 deletions Reporting/StepDefinitionReport/StepDefinitionReport.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,46 @@

<xsl:include href="..\Common\Common.xslt"/>

<xsl:param name="tool-text">
<Language code="en">
<Title>Step Definition Report</Title>
<Givens>Givens</Givens>
<Whens>Whens</Whens>
<Thens>Thens</Thens>
<StepDefinition>Step Definition</StepDefinition>
<Instances>Instances</Instances>
<BindingsWithoutInstancesMessage>Bindings without instances are not included in this report.</BindingsWithoutInstancesMessage>
<ParameterValuesPre>Used values for parameter </ParameterValuesPre>
<ParameterValuesPost>:</ParameterValuesPost>
<ScenarioOutlineExampleMessage>(scenario outline example)</ScenarioOutlineExampleMessage>
</Language>
</xsl:param>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template name="get-tool-text">
<xsl:param name="text-key" />

<xsl:call-template name="get-tool-text-base">
<xsl:with-param name="text-key" select="$text-key" />
<xsl:with-param name="local-tool-texts" select="msxsl:node-set($tool-text)" />
</xsl:call-template>
</xsl:template>


<xsl:key name="step-usage-variation" match="sfr:Instance" use="normalize-space(string(sfr:ScenarioStep))"/>

<xsl:template match="/">
<xsl:variable name="title">
<xsl:value-of select="sfr:StepDefinitionReport/@projectName"/> Step Definition Report
<xsl:call-template name="get-tool-text">
<xsl:with-param name="text-key" select="'Title'" />
</xsl:call-template>
<xsl:text> - </xsl:text>
<xsl:value-of select="sfr:StepDefinitionReport/@projectName"/>
</xsl:variable>
<html>
<head>
Expand Down Expand Up @@ -49,44 +78,34 @@
<xsl:call-template name="html-body-header">
<xsl:with-param name="title" select="$title" />
</xsl:call-template>
<xsl:if test="(/sfr:StepDefinitionReport/@onlySelectedFeatures='true')">
<div class="legend">
Only the following features from the project are included in this report:
<xsl:variable name="featureRefs">
<FeatureRefs>
<xsl:for-each select="//sfr:FeatureRef">
<FeatureName>
<xsl:value-of select="@name"/>
</FeatureName>
</xsl:for-each>
</FeatureRefs>
</xsl:variable>
<ul>
<xsl:for-each select="msxsl:node-set($featureRefs)/*/*">
<xsl:variable name="feature-name" select="string(text())" />
<xsl:if test="not(preceding-sibling::FeatureName[string(text())=$feature-name])">
<li>
<xsl:value-of select="$feature-name"/>
</li>
</xsl:if>
</xsl:for-each>
</ul>
</div>
</xsl:if>
<xsl:if test="(/sfr:StepDefinitionReport/@showBindingsWithoutInsance!='true')">
<div class="legend">
Bindings without instances are not included in this report.
<xsl:call-template name="get-tool-text">
<xsl:with-param name="text-key" select="'BindingsWithoutInstancesMessage'" />
</xsl:call-template>
</div>
</xsl:if>
<h2>Givens</h2>
<h2>
<xsl:call-template name="get-tool-text">
<xsl:with-param name="text-key" select="'Givens'" />
</xsl:call-template>
</h2>
<xsl:call-template name="process-block">
<xsl:with-param name="block-name" select="'Given'" />
</xsl:call-template>
<h2>Whens</h2>
<h2>
<xsl:call-template name="get-tool-text">
<xsl:with-param name="text-key" select="'Whens'" />
</xsl:call-template>
</h2>
<xsl:call-template name="process-block">
<xsl:with-param name="block-name" select="'When'" />
</xsl:call-template>
<h2>Thens</h2>
<h2>
<xsl:call-template name="get-tool-text">
<xsl:with-param name="text-key" select="'Thens'" />
</xsl:call-template>
</h2>
<xsl:call-template name="process-block">
<xsl:with-param name="block-name" select="'Then'" />
</xsl:call-template>
Expand All @@ -99,8 +118,16 @@

<table class="reportTable" cellpadding="0" cellspacing="0">
<tr>
<th class="top left">Step Definition</th>
<th class="top">Instances</th>
<th class="top left">
<xsl:call-template name="get-tool-text">
<xsl:with-param name="text-key" select="'StepDefinition'" />
</xsl:call-template>
</th>
<th class="top">
<xsl:call-template name="get-tool-text">
<xsl:with-param name="text-key" select="'Instances'" />
</xsl:call-template>
</th>
</tr>
<xsl:for-each select="sfr:StepDefinitionReport/sfr:StepDefinition[@type=$block-name]">
<xsl:sort order="ascending" select="sfr:ScenarioStep/sfr:Text" data-type="text"/>
Expand All @@ -121,7 +148,9 @@
<xsl:value-of select="count(./sfr:Instances/sfr:Instance)"/>
<xsl:if test="sfr:Instances">
<xsl:text> </xsl:text>
<a href="#" onclick="toggle('{$stepdef-id}'); return false;" class="button">[show]</a>
<a href="#" onclick="toggle('{$stepdef-id}'); return false;" class="button">[<xsl:call-template name="get-common-tool-text">
<xsl:with-param name="text-key" select="'Show'" />
</xsl:call-template>]</a>
</xsl:if>
</td>
</tr>
Expand All @@ -130,7 +159,12 @@
<td class="left" colspan="2">
<table class="subReportTable" cellpadding="0" cellspacing="0">
<tr>
<th class="top left">Instances:</th>
<th class="top left">
<xsl:call-template name="get-tool-text">
<xsl:with-param name="text-key" select="'Instances'" />
</xsl:call-template>
<xsl:text>:</xsl:text>
</th>
</tr>
<xsl:for-each select="sfr:Instances/sfr:Instance">
<xsl:variable name="current-key" select="normalize-space(string(sfr:ScenarioStep))" />
Expand Down Expand Up @@ -164,7 +198,10 @@
<xsl:text> / </xsl:text>
<xsl:value-of select="sfr:ScenarioRef/@name"/>
<xsl:if test="@fromScenarioOutline = 'true'">
<xsl:text> (scenario outline example)</xsl:text>
<xsl:text> </xsl:text>
<xsl:call-template name="get-tool-text">
<xsl:with-param name="text-key" select="'ScenarioOutlineExampleMessage'" />
</xsl:call-template>
</xsl:if>
</a>
</b>
Expand All @@ -187,7 +224,15 @@

</xsl:variable>
<xsl:variable name="param-values">
<xsl:text>Used values for parameter '</xsl:text><xsl:value-of select="$param-name"/>'<xsl:text>:
<xsl:call-template name="get-tool-text">
<xsl:with-param name="text-key" select="'ParameterValuesPre'" />
</xsl:call-template>
<xsl:text>'</xsl:text><xsl:value-of select="$param-name"/>
<xsl:text>'</xsl:text>
<xsl:call-template name="get-tool-text">
<xsl:with-param name="text-key" select="'ParameterValuesPost'" />
</xsl:call-template>
<xsl:text>
</xsl:text>
<xsl:for-each select="$instances-root/sfr:Instance/sfr:Parameters/sfr:Parameter[@name=$param-name]">
<xsl:variable name="param-value" select="string(text())" />
Expand Down
Loading

0 comments on commit 2c43124

Please sign in to comment.