Skip to content
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
40 changes: 18 additions & 22 deletions src/Microsoft.TestPlatform.Extensions.HtmlLogger/Html.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@
<h1>Test run details</h1>
<xsl:apply-templates select ="/tp:TestRunDetails"/>
</body>
<script language="javascript">
function ToggleClass(id) {
var elem = document.getElementById(id);
if (elem.style.display == "none") {
elem.style.display = "block";
}
else {
elem.style.display = "none";
}
}
</script>
<style>
<style>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix indentation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is merged, if this bothers you, please start a new PR with the fix.

body { font-family: Calibri, Verdana, Arial, sans-serif; background-color: White; color: Black; }
h2 {
margin-top: 15px;
Expand Down Expand Up @@ -132,10 +121,12 @@
<xsl:for-each select ="tp:TestResultCollection">
<xsl:variable name="Source" select="tp:Id" />
<xsl:if test="tp:ResultList!=''">
<div class ="list-row" onclick="ToggleClass('{$Source}')"><xsl:value-of select = "tp:Source" /></div>
<div class ="inner-row" Id="{$Source}" style="display:none;">
<xsl:for-each select ="tp:ResultList/tp:TestResult"><xsl:call-template name ="TestResult"/></xsl:for-each>
</div>
<details>
<summary><xsl:value-of select = "tp:Source" /></summary>
<div class ="inner-row" Id="{$Source}">
<xsl:for-each select ="tp:ResultList/tp:TestResult"><xsl:call-template name ="TestResult"/></xsl:for-each>
</div>
</details>
</xsl:if>
</xsl:for-each>
</xsl:template>
Expand All @@ -144,10 +135,13 @@
<xsl:for-each select ="tp:TestResultCollection">
<xsl:variable name="Source" select="tp:Id" />
<xsl:if test="tp:FailedResultList!=''">
<div class ="list-row" onclick="ToggleClass('{concat($Source,'-failedResult')}')"><xsl:value-of select = "tp:Source" /> </div>
<div class ="inner-row" Id="{concat($Source,'-failedResult')}" style="display:block;">
<xsl:for-each select ="tp:FailedResultList/tp:TestResult"><xsl:call-template name ="TestResult"/></xsl:for-each>
</div>
<details>
<xsl:attribute name="open"/>
<summary><xsl:value-of select = "tp:Source" /></summary>
<div class ="inner-row" Id="{concat($Source,'-failedResult')}">
<xsl:for-each select ="tp:FailedResultList/tp:TestResult"><xsl:call-template name ="TestResult"/></xsl:for-each>
</div>
</details>
</xsl:if>
</xsl:for-each>
</xsl:template>
Expand All @@ -156,8 +150,10 @@
<xsl:variable name="TestResultId" select="tp:TestResultId" />

<xsl:if test ="tp:InnerTestResults!=''">
<div class ="row" onclick="ToggleClass('{concat($TestResultId,'-',name(..))}')"><xsl:call-template name = "Result" /></div>
<a Id="{concat($TestResultId,'-',name(..))}" style="display:none;"><xsl:apply-templates select = "tp:InnerTestResults" /></a>
<details>
<summary><xsl:call-template name = "Result" /></summary>
<a Id="{concat($TestResultId,'-',name(..))}"><xsl:apply-templates select = "tp:InnerTestResults" /></a>
</details>
</xsl:if>

<xsl:if test ="tp:InnerTestResults=''">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ public void HtmlLoggerWithFriendlyNameShouldProperlyOverwriteFile(RunnerInfo run
IsFileAndContentEqual(htmlLogFilePath);
}

[TestMethod]
[TestCategory("Windows-Review")]
[NetFullTargetFrameworkDataSource(inIsolation: true, inProcess: true)]
public void HtmlLoggerWithFriendlyNameContainsExpectedContent(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);

var arguments = PrepareArguments(GetSampleTestAssembly(), GetTestAdapterPath(), string.Empty, FrameworkArgValue, runnerInfo.InIsolationValue, TempDirectory.Path);
var htmlFileName = "TestResults.html";
arguments = string.Concat(arguments, $" /logger:\"html;LogFileName={htmlFileName}\"");
InvokeVsTest(arguments);

var htmlLogFilePath = Path.Combine(TempDirectory.Path, htmlFileName);
XmlDocument report = new();
report.Load(htmlLogFilePath);

AssertExpectedHtml(report.DocumentElement!);
}

[TestMethod]
[NetCoreTargetFrameworkDataSource]
public void TrxLoggerWithExecutorUriShouldProperlyOverwriteFile(RunnerInfo runnerInfo)
Expand Down Expand Up @@ -163,6 +182,21 @@ public void TrxLoggerResultSummaryOutcomeValueShouldNotChangeIfNoTestsExecutedAn
Assert.AreEqual("Completed", outcomeValue);
}

private static void AssertExpectedHtml(XmlElement root)
{
XmlNodeList elementList = root.GetElementsByTagName("details");
Assert.AreEqual(2, elementList.Count);

foreach (XmlElement element in elementList)
{
Assert.AreEqual("summary", element.FirstChild?.Name);
if (element.HasAttributes)
{
Assert.AreEqual("open", element.Attributes[0].Name);
}
}
}

private static bool IsValidXml(string xmlFilePath)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ <h2>Results</h2>
.duration{float:right;}

</style>
</html>
</html>