diff --git a/README.md b/README.md index 7ffa1ed..b7cfdf3 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,33 @@ It implements the fundamentals to support Protocol Test Suite, including logging PTF is based on Windows platform. You should install the softwares listed below based on your testing purpose, including their own dependencies. -* [Visual Studio 2017](https://visualstudio.microsoft.com/downloads/) with some individual components required by installing in Visual Studio Installer: - - |Individual Component\Purpose|Run test suites based on Protocol Test Framework (PTF)|Build Protocol Test Framework (PTF) from source code| - |---|---|---| - |.NET Framework 4.7.1 targeting pack|Required|Required| - |Testing tools core features|Required|Required| - |.NET Framework 4.7.1 SDK||Required| - |C# and Visual Basic Roslyn compilers||Required| -* [Spec Explorer 2010 v3.5.3146.0](https://visualstudiogallery.msdn.microsoft.com/271d0904-f178-4ce9-956b-d9bfa4902745/). It is required if you want to build Protocol Test Framework (PTF) from source code. -* [Wix Toolset v3.11](https://github.com/wixtoolset/wix3/releases/tag/wix3111rtm) and [Wix Toolset Visual Studio 2017 Extension](https://marketplace.visualstudio.com/items?itemName=RobMensching.WixToolsetVisualStudio2017Extension). It is required if you want to build Protocol Test Framework (PTF) from source code. +1. [Visual Studio](https://visualstudio.microsoft.com/downloads/) 2017 or higher ([Visual Studio 2017 Community](https://aka.ms/vs/15/release/vs_community.exe) recommended), installed with these individual components from the installer: + + |Section|Individual Component in Visual Studio 2017|Individual Component in Visual Studio 2019|Run Windows Protocol Test Suites|Build Windows Protocol Test Suites from source code| + |---|---|---|---|---| + |.NET|.NET Framework 4.7.1 SDK|.NET Framework 4.7.1 SDK||Required| + |.NET|.NET Framework 4.7.1 targeting pack|.NET Framework 4.7.1 targeting pack|Required|Required| + |Compilers, build tools, and runtime|C# and Visual Basic Roslyn compilers|C# and Visual Basic Roslyn compilers||Required| + |Debugging and testing|Testing tools core features||Required[1](#footnote1)|Required[1](#footnote1)| + + Note: + + 1: This individual component is installed in Visual Studio 2019 by default. + +1. [Spec Explorer 2010 v3.5.3146.0](https://visualstudiogallery.msdn.microsoft.com/271d0904-f178-4ce9-956b-d9bfa4902745/) + + It is only required if you want to build or run the test suites that contain Model-Based Test cases. If you want to regenerate Model-Based Test cases, you must install Visual Studio 2012. +1. Enable .NET Framework 3.5.1 + + 1. _Turn Windows features on or off_ + 1. Enable _.NET Framework 3.5 (includes .NET 2.0 and 3.0)_ + + This is necessary for WiX Toolset. +1. [WiX Toolset v3.14](https://wixtoolset.org/releases/v3-14-0-2927/) + +1. [WiX Toolset Visual Studio 2017 Extension](https://marketplace.visualstudio.com/items?itemName=WixToolset.WixToolsetVisualStudio2017Extension) or [Wix Toolset Visual Studio 2019 Extension](https://marketplace.visualstudio.com/items?itemName=WixToolset.WixToolsetVisualStudio2019Extension) + + WiX Toolset components required if you want to build test suites or Protocol Test Manager from source code. You can use the script in **InstallPrerequisites** folder to automatically download and install these software. @@ -56,7 +73,7 @@ Change to src directory and run build.cmd: build.cmd ``` -After the build succeeds, ProtocolTestFrameworkInstaller.msi should be generated in the folder drop\ProtocolTestFramework\installer\. +After the build succeeds, ProtocolTestFrameworkInstaller.msi should be generated in the folder `drop\ProtocolTestFramework\installer\`. ## Samples diff --git a/src/SharedAssemblyInfo.cs b/src/SharedAssemblyInfo.cs index 01e1ddf..87f0649 100644 --- a/src/SharedAssemblyInfo.cs +++ b/src/SharedAssemblyInfo.cs @@ -5,4 +5,4 @@ [assembly: AssemblyCompany("Microsoft")] [assembly: AssemblyProduct("Protocol Test Framework")] -[assembly: AssemblyVersion("1.0.6500.0")] +[assembly: AssemblyVersion("1.0.7000.0")] diff --git a/src/common/setBuildTool.cmd b/src/common/setBuildTool.cmd index 1dc82c0..0d22da7 100644 --- a/src/common/setBuildTool.cmd +++ b/src/common/setBuildTool.cmd @@ -1,23 +1,30 @@ :: Copyright (c) Microsoft. All rights reserved. :: Licensed under the MIT license. See LICENSE file in the project root for full license information. +:: Get the path to MSBuild.exe and set it to buildtool. +:: Calls to setVsPath.cmd. + @echo off -:: Find installed path of Visual Studio 2017 +set buildtool= + set _currentPath=%~dp0 -call "%_currentPath%setVs2017Path.cmd" +call "%_currentPath%setVsPath.cmd" if ErrorLevel 1 ( exit /b 1 ) -:: Set buildtool -if exist "%vs2017path%\MSBuild\15.0\Bin\MSBuild.exe" ( - set buildtool="%vs2017path%\MSBuild\15.0\Bin\MSBuild.exe" +if not exist "%vspath%\MSBuild" ( + echo Error: could not find MSBuild.exe, please make sure you have installed "C# and Visual Basic Roslyn compilers" in Visual Studio 2017 or later. + exit /b 1 ) -if not defined buildtool ( - echo No msbuild.exe was found. Please install visual studio 2017. - exit /b 1 +for /d %%i in ("%vspath%\MSBuild\*") do ( + if exist "%%~fi\Bin\MSBuild.exe" ( + set buildtool="%%~fi\Bin\MSBuild.exe" + exit /b 0 + ) ) -exit /b 0 +echo Error: could not find MSBuild.exe, please make sure you have installed "C# and Visual Basic Roslyn compilers" in Visual Studio 2017 or later. +exit /b 1 \ No newline at end of file diff --git a/src/common/setVs2017Path.cmd b/src/common/setVs2017Path.cmd deleted file mode 100644 index 0a536e0..0000000 --- a/src/common/setVs2017Path.cmd +++ /dev/null @@ -1,45 +0,0 @@ -:: Copyright (c) Microsoft. All rights reserved. -:: Licensed under the MIT license. See LICENSE file in the project root for full license information. - -@echo off - -:: Find vs2017path in registry -set REGEXE="%windir%\System32\reg.exe" -set KEY_NAME_32="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" -set KEY_NAME_64="HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\SxS\VS7" -set VALUE_NAME=15.0 -set REG_QUERY_VS2017_PATH_32BIT=%REGEXE% QUERY %KEY_NAME_32% /v %VALUE_NAME% -set REG_QUERY_VS2017_PATH_64BIT=%REGEXE% QUERY %KEY_NAME_64% /v %VALUE_NAME% - -set vs2017path= - -%REG_QUERY_VS2017_PATH_64BIT% -if ErrorLevel 1 ( - :: Cannot find 64-bit path, try to find 32-bit path - %REG_QUERY_VS2017_PATH_32BIT% - if ErrorLevel 1 ( - echo Visual Studio 2017 is not installed. - exit /b 0 - ) else ( - FOR /F "usebackq tokens=1-2*" %%A IN (`"%REG_QUERY_VS2017_PATH_32BIT%"`) DO ( - set name=%%A - set type=%%B - set vs2017path=%%C - ) - ) -) else ( - FOR /F "usebackq tokens=1-2*" %%A IN (`"%REG_QUERY_VS2017_PATH_64BIT%"`) DO ( - set name=%%A - set type=%%B - set vs2017path=%%C - ) -) - -if exist "%vs2017path%" ( - if not exist "%vs2017path%\MSBuild\Microsoft\WiX\v3.x\Wix.targets" ( - echo Error: "%vs2017path%\MSBuild\Microsoft\WiX\v3.x\Wix.targets" cannot be found. Please install Wix Toolset Visual Studio 2017 Extension from https://marketplace.visualstudio.com/items?itemName=RobMensching.WixToolsetVisualStudio2017Extension - exit /b 1 - ) else ( - exit /b 0 - ) -) diff --git a/src/common/setVsPath.cmd b/src/common/setVsPath.cmd index 7db1ad4..895400d 100644 --- a/src/common/setVsPath.cmd +++ b/src/common/setVsPath.cmd @@ -1,28 +1,32 @@ :: Copyright (c) Microsoft. All rights reserved. :: Licensed under the MIT license. See LICENSE file in the project root for full license information. +::Get the root path of Visual Studio installation folder and set it to vspath. + @echo off -:: Find installed path of Visual Studio 2017 -set _currentPath=%~dp0 -call "%_currentPath%setVs2017Path.cmd" -if ErrorLevel 1 ( - exit /b 1 +set vswhere= + +for /d %%i in ("%ProgramFiles(x86)%","%ProgramFiles%") do ( + if exist "%%~i\Microsoft Visual Studio\Installer\vswhere.exe" ( + set "vswhere=%%~i\Microsoft Visual Studio\Installer\vswhere.exe" + break + ) ) -:: Set VS150COMNTOOLS -if exist "%vs2017path%\Common7\Tools\" ( - set VS150COMNTOOLS="%vs2017path%\Common7\Tools\" +if [vswhere] equ [] ( + echo Error: please make sure you have installed Visual Studio 2017 or later. + exit /b 1 ) -:: Set vspath -if defined VS150COMNTOOLS ( - set vspath=%VS150COMNTOOLS% - goto end -) else ( - echo Error: Please install visual studio 2017. - exit /b 1 +set vspath= + +for /f "usebackq tokens=1*" %%i in (`"%vswhere%"`) do ( + if %%i equ installationPath: ( + set vspath=%%j + exit /b 0 + ) ) -:end -exit /b 0 +echo Error: please make sure you have installed Visual Studio 2017 or later. +exit /b 1 \ No newline at end of file diff --git a/src/common/setVsTestPath.cmd b/src/common/setVsTestPath.cmd new file mode 100644 index 0000000..6cf7a3c --- /dev/null +++ b/src/common/setVsTestPath.cmd @@ -0,0 +1,23 @@ +:: Copyright (c) Microsoft. All rights reserved. +:: Licensed under the MIT license. See LICENSE file in the project root for full license information. + +:: Get the path to vstest.console.exe and set it to vstest. +:: Calls to setVsPath.cmd. + +@echo off + +set vstest= + +set _currentPath=%~dp0 +call "%_currentPath%setVsPath.cmd" +if ErrorLevel 1 ( + exit /b 1 +) + +if not exist "%vspath%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" ( + echo Error: could not find vstest.console.exe, please make sure you have installed "Testing tools core features" in Visual Studio 2017 or later. + exit /b 1 +) + +set vstest="%vspath%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" +exit /b 0 diff --git a/src/deploy/Installer/PTFProduct.wxs b/src/deploy/Installer/PTFProduct.wxs index c3d84f3..7350cc8 100644 --- a/src/deploy/Installer/PTFProduct.wxs +++ b/src/deploy/Installer/PTFProduct.wxs @@ -55,37 +55,32 @@ Property="DOTNET471_NOT_INSTALLED_WARNING_TEXT" Value="• .NET Framework 4.7.1 targeting pack " /> - - - - + + + + + + + - - - + + + + + - + + Value="• Microsoft Visual Studio 2017 or higher " /> @@ -106,7 +101,18 @@ - + + + + + + + + + + + + @@ -225,9 +231,9 @@ Installed NOT Installed - + - + 1 1 diff --git a/src/deploy/Installer/ProtocolTestFrameworkSDK.wxs b/src/deploy/Installer/ProtocolTestFrameworkSDK.wxs index 3a89e61..83625c1 100644 --- a/src/deploy/Installer/ProtocolTestFrameworkSDK.wxs +++ b/src/deploy/Installer/ProtocolTestFrameworkSDK.wxs @@ -24,7 +24,14 @@ - + + + + + + + + @@ -33,6 +40,18 @@ + + + VSTEST2019 + + + + VSTEST2019 + + + VSTEST2017 @@ -250,12 +269,19 @@ - + + + + + VSTEST2019 + + - VS2017SEARCH + VSTEST2017 diff --git a/src/htmltestlogger/DataType.cs b/src/htmltestlogger/DataType.cs index f43c554..da3607c 100644 --- a/src/htmltestlogger/DataType.cs +++ b/src/htmltestlogger/DataType.cs @@ -90,18 +90,23 @@ public class TestCaseDetail /// /// The start time of the test case /// - public string StartTime; + public DateTimeOffset StartTime; /// /// The end time of the test case /// - public string EndTime; + public DateTimeOffset EndTime; /// /// The result of the test case /// public string Result; + /// + /// The source assembly of the test case + /// + public string Source; + /// /// The ErrorStackTrace log of the test case /// @@ -131,15 +136,17 @@ public class TestCaseDetail /// Set default value /// /// Test case name - /// The start time to run test case - /// The end time to run test case - /// The result to run the test case - public TestCaseDetail(string name, string startTime, string endTime, string result) + /// Start time of the test case + /// End time of the test case + /// Result of the test case + /// Assembly of the test case + public TestCaseDetail(string name, DateTimeOffset startTime, DateTimeOffset endTime, string result, string source) { this.Name = name; this.StartTime = startTime; this.EndTime = endTime; this.Result = result; + this.Source = source; this.ErrorStackTrace = new List(); this.ErrorMessage = new List(); this.StandardOut = new List(); diff --git a/src/htmltestlogger/HtmlTestLogger.cs b/src/htmltestlogger/HtmlTestLogger.cs index 2705e12..806445b 100644 --- a/src/htmltestlogger/HtmlTestLogger.cs +++ b/src/htmltestlogger/HtmlTestLogger.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Win32; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -105,6 +106,7 @@ private void TestMessageHandler(object sender, TestRunMessageEventArgs e) case TestMessageLevel.Error: break; + default: break; } @@ -115,64 +117,26 @@ private void TestMessageHandler(object sender, TestRunMessageEventArgs e) /// private void TestResultHandler(object sender, TestResultEventArgs e) { - if (e.Result.Outcome.ToString() == "NotFound") + if (e.Result.Outcome == TestOutcome.NotFound) { return; } - string caseName = !string.IsNullOrEmpty(e.Result.DisplayName) ? e.Result.DisplayName : e.Result.TestCase.FullyQualifiedName; - int dot = caseName.LastIndexOf('.'); - - if (-1 != dot) - caseName = caseName.Substring(dot + 1); - - string txtFileName = Path.Combine(txtResultFolderPath, e.Result.StartTime.ToLocalTime().ToString("yyyy-MM-dd-HH-mm-ss") + "_" - + (e.Result.Outcome == TestOutcome.Skipped ? "Inconclusive" : e.Result.Outcome.ToString()) + "_" + caseName + ".txt"); - StringBuilder sb = new StringBuilder(); - - if (DateTimeOffset.Compare(testRunStartTime, e.Result.StartTime.ToLocalTime()) > 0) - testRunStartTime = e.Result.StartTime.ToLocalTime(); - if (DateTimeOffset.Compare(testRunEndTime, e.Result.EndTime.ToLocalTime()) < 0) - testRunEndTime = e.Result.EndTime.ToLocalTime(); - try - { - sb.AppendLine(caseName); - sb.AppendLine("Start Time: " + e.Result.StartTime.ToLocalTime().ToString("MM/dd/yyyy HH:mm:ss")); - sb.AppendLine("End Time: " + e.Result.EndTime.ToLocalTime().ToString("MM/dd/yyyy HH:mm:ss")); - sb.AppendLine("Result: " + (e.Result.Outcome == TestOutcome.Skipped ? "Inconclusive" : e.Result.Outcome.ToString())); - sb.AppendLine(e.Result.TestCase.Source); - if (!String.IsNullOrEmpty(e.Result.ErrorStackTrace)) - { - sb.AppendLine("===========ErrorStackTrace==========="); - sb.AppendLine(e.Result.ErrorStackTrace); - } - if (!String.IsNullOrEmpty(e.Result.ErrorMessage)) - { - sb.AppendLine("===========ErrorMessage=============="); - sb.AppendLine(e.Result.ErrorMessage); - } - - foreach (TestResultMessage m in e.Result.Messages) - { - if (m.Category == TestResultMessage.StandardOutCategory && !String.IsNullOrEmpty(m.Text)) - { - sb.AppendLine("===========StandardOut==============="); - sb.AppendLine(m.Text); - } - } - } - catch (Exception ex) - { - sb.AppendLine("Exception: " + ex.Message); - } - finally - { - // Generate txt log file - File.WriteAllText(txtFileName, sb.ToString()); - // Generate html log file - string htmlFileName = Path.Combine(htmlResultFolderPath, caseName + ".html"); - File.WriteAllText(htmlFileName, ConstructCaseHtml(txtFileName, caseName)); - } + DataType.TestCaseDetail caseDetail = ConvertToTestCase(e.Result); + + // Generate txt log file + string txtFileName = Path.Combine( + txtResultFolderPath, + string.Format("{0}_{1}_{2}.txt", + caseDetail.StartTime.ToLocalTime().ToString("yyyy-MM-dd-HH-mm-ss"), + caseDetail.Result, + caseDetail.Name) + ); + File.WriteAllText(txtFileName, ConstructCaseTxtReport(caseDetail)); + + // Generate html log file + string htmlFileName = Path.Combine(htmlResultFolderPath, $"{caseDetail.Name}.html"); + File.WriteAllText(htmlFileName, ConstructCaseHtml(caseDetail)); } /// @@ -226,15 +190,118 @@ private void CreateReportFolder() File.WriteAllText(Path.Combine(jsFolderPath, jsFileName_Functions), Properties.Resources.functions); } + /// + /// Convert a vstest TestResult object to TestCaseDetail + /// + private DataType.TestCaseDetail ConvertToTestCase(TestResult result) + { + var eolSeparators = new char[] { '\r', '\n' }; + string caseName = !string.IsNullOrEmpty(result.DisplayName) ? result.DisplayName : result.TestCase.FullyQualifiedName.Split('.').Last(); + string outcome = result.Outcome == TestOutcome.Skipped ? "Inconclusive" : result.Outcome.ToString(); + + var ret = new DataType.TestCaseDetail(caseName, result.StartTime, result.EndTime, outcome, result.TestCase.Source); + + if (!String.IsNullOrEmpty(result.ErrorStackTrace)) + { + ret.ErrorStackTrace.AddRange(result.ErrorStackTrace.Split(eolSeparators, StringSplitOptions.RemoveEmptyEntries)); + } + + if (!String.IsNullOrEmpty(result.ErrorMessage)) + { + ret.ErrorMessage.AddRange(result.ErrorMessage.Split(eolSeparators, StringSplitOptions.RemoveEmptyEntries)); + } + + var stdout = new List(); + foreach (TestResultMessage m in result.Messages) + { + if (m.Category == TestResultMessage.StandardOutCategory && !String.IsNullOrEmpty(m.Text)) + { + stdout.AddRange(m.Text.Split(eolSeparators, StringSplitOptions.RemoveEmptyEntries)); + } + } + foreach (string line in stdout) + { + string pattern = @"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3} \[(\w+)\] "; + Regex r = new Regex(pattern, RegexOptions.IgnoreCase); + + Match m = r.Match(line); + if (m.Success) + { + string type = m.Groups[1].Value; + ret.StandardOut.Add(new DataType.StandardOutDetail() + { + Content = line, + Type = type + }); + } + else + { + // There must be at least one record in the list. + // Just to make the logger robust, let's do a check here. + // (But it won't happen) + int stdoutCount = ret.StandardOut.Count; + if (stdoutCount == 0) + { + continue; + } + else + { + var lastOutput = ret.StandardOut[stdoutCount - 1]; + lastOutput.Content = lastOutput.Content + '\n' + line; + } + } + } + + ret.StandardOutTypes = ret.StandardOut.Select(output => output.Type).Distinct().ToList(); + + return ret; + } + + /// + /// Inserts the corresponding script to the template html and generates the [testcase].html + /// + private string ConstructCaseTxtReport(DataType.TestCaseDetail caseDetail) + { + StringBuilder sb = new StringBuilder(); + + if (DateTimeOffset.Compare(testRunStartTime, caseDetail.StartTime.ToLocalTime()) > 0) + testRunStartTime = caseDetail.StartTime.ToLocalTime(); + if (DateTimeOffset.Compare(testRunEndTime, caseDetail.EndTime.ToLocalTime()) < 0) + testRunEndTime = caseDetail.EndTime.ToLocalTime(); + + sb.AppendLine(caseDetail.Name); + sb.AppendLine("Start Time: " + caseDetail.StartTime.ToLocalTime().ToString("MM/dd/yyyy HH:mm:ss")); + sb.AppendLine("End Time: " + caseDetail.EndTime.ToLocalTime().ToString("MM/dd/yyyy HH:mm:ss")); + sb.AppendLine("Result: " + caseDetail.Result); + sb.AppendLine(caseDetail.Source); + if (caseDetail.ErrorStackTrace.Count() > 0) + { + sb.AppendLine("===========ErrorStackTrace==========="); + caseDetail.ErrorStackTrace.ForEach(line => sb.AppendLine(line)); + } + if (caseDetail.ErrorMessage.Count() > 0) + { + sb.AppendLine("===========ErrorMessage=============="); + caseDetail.ErrorMessage.ForEach(line => sb.AppendLine(line)); + } + if (caseDetail.StandardOut.Count() > 0) + { + sb.AppendLine("===========StandardOut==============="); + caseDetail.StandardOut.ForEach(stdout => sb.AppendLine(stdout.Content)); + } + + return sb.ToString(); + } + /// /// Constructs detailObj used in each [caseName].html /// - private string ConstructDetailObj(string txtFileName) + private string ConstructDetailObj(DataType.TestCaseDetail caseDetail) { StringBuilder sb = new StringBuilder(); sb.AppendLine(); sb.Append("var detailObj="); - sb.Append(txtToJSON.ConstructCaseDetail(txtFileName, captureFolderPath)); + sb.Append(txtToJSON.ConstructCaseDetail(caseDetail, captureFolderPath)); sb.AppendLine(";"); return sb.ToString(); @@ -257,13 +324,13 @@ private string ConstructListAndSummaryObj(TestRunCompleteEventArgs e) /// /// Inserts the corresponding script to the template html and generates the [testcase].html /// - private string ConstructCaseHtml(string txtFileName, string caseName) + private string ConstructCaseHtml(DataType.TestCaseDetail caseDetail) { // Insert script to the template html (testcase.html) StringBuilder sb = new StringBuilder(); - sb.Append(ConstructDetailObj(txtFileName)); + sb.Append(ConstructDetailObj(caseDetail)); sb.AppendLine("var titleObj = document.getElementById(\"right_sidebar_case_title\");"); - sb.Append(string.Format("CreateText(titleObj, \"{0}\");", caseName)); + sb.Append(string.Format("CreateText(titleObj, \"{0}\");", caseDetail.Name)); return InsertScriptToTemplate(Properties.Resources.testcase, sb.ToString()); } diff --git a/src/htmltestlogger/Resources/functions.js b/src/htmltestlogger/Resources/functions.js index a7ee197..e96f5eb 100644 --- a/src/htmltestlogger/Resources/functions.js +++ b/src/htmltestlogger/Resources/functions.js @@ -398,6 +398,27 @@ function GetText(elem) return elem.innerText; } +// Get date string from json date +function FormatDate(value) { + function pad(number) { + if (number < 10) { + return '0' + number; + } + return number; + } + + var pattern = /Date\(([^)]+)\)/; + var results = pattern.exec(value); + var dt = new Date(parseFloat(results[1])); + return dt.getUTCFullYear() + + '-' + pad(dt.getUTCMonth() + 1) + + '-' + pad(dt.getUTCDate()) + + ' ' + pad(dt.getUTCHours()) + + ':' + pad(dt.getUTCMinutes()) + + ':' + pad(dt.getUTCSeconds()) + + '.' + (dt.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5); +} + // show detail in right_sidebar_case function ShowDetail(caseDetail, logTypes) { @@ -412,9 +433,9 @@ function ShowDetail(caseDetail, logTypes) var pStartTime = document.createElement("p"); var pEndTime = document.createElement("p"); var pResult = document.createElement("p"); - pStartTime.innerHTML = detailObj['StartTime']; - pEndTime.innerHTML = detailObj['EndTime']; - pResult.innerHTML = detailObj['Result']; + pStartTime.innerHTML = 'Start Time: ' + FormatDate(detailObj['StartTime']); + pEndTime.innerHTML = 'End Time: ' + FormatDate(detailObj['EndTime']); + pResult.innerHTML = 'Result: ' + detailObj['Result']; caseTime.appendChild(pStartTime); caseTime.appendChild(pEndTime); caseTime.appendChild(pResult); diff --git a/src/htmltestlogger/TxtToJSON.cs b/src/htmltestlogger/TxtToJSON.cs index 83568b8..da7bfd3 100644 --- a/src/htmltestlogger/TxtToJSON.cs +++ b/src/htmltestlogger/TxtToJSON.cs @@ -61,77 +61,13 @@ public string TestCasesString(string resultFolder, string captureFolder) /// /// The path to the log txt file which contains the detail log /// Returns the log information - public string ConstructCaseDetail(string txtfile, string captureFolder) + public string ConstructCaseDetail(DataType.TestCaseDetail caseDetail, string captureFolder) { - FileStream fs = new FileStream(txtfile, FileMode.Open); - string type = ""; // Help judge whether the line is the end of the file, help distinguish file content - StreamReader sr = new StreamReader(fs); - string line; - string content = ""; - string standardOutType = ""; - DataType.TestCaseDetail caseDetail = new DataType.TestCaseDetail(sr.ReadLine(), sr.ReadLine(), sr.ReadLine(), sr.ReadLine()); - DataType.StandardOutDetail stdDetail; - string dllFile = sr.ReadLine(); + string dllFile = caseDetail.Source; if (!dllFiles.Contains(dllFile)) { dllFiles.Add(dllFile); } - while ((line = sr.ReadLine()) != null) - { - if (line == "") //Rule out blank line - continue; - - if (line.StartsWith("===========")) - { - type = line.Replace("=", ""); - continue; - } - - LogType eType = (LogType)Enum.Parse(typeof(LogType), type); - switch (eType) - { - case LogType.ErrorStackTrace: - caseDetail.ErrorStackTrace.Add(line); - break; - case LogType.ErrorMessage: - caseDetail.ErrorMessage.Add(line); - break; - case LogType.StandardOut: - int begin = line.IndexOf('['); - int end = line.IndexOf(']'); - - if (begin != -1 && end != -1) - { - if (standardOutType != "") - { - stdDetail = new DataType.StandardOutDetail() - { - Content = content, - Type = standardOutType - }; - caseDetail.StandardOut.Add(stdDetail); - } - if (end > begin && end < line.Length) - { - standardOutType = line.Substring(begin + 1, end - begin - 1); - if (!caseDetail.StandardOutTypes.Contains(standardOutType)) - caseDetail.StandardOutTypes.Add(standardOutType); - } - content = line; - } - else - content += line; - break; - default: break; - } - } - stdDetail = new DataType.StandardOutDetail() - { - Content = content, - Type = standardOutType - }; - fs.Close(); - caseDetail.StandardOut.Add(stdDetail); caseDetail.CapturePath = CopyCaptureAndReturnPath(caseDetail.Name, captureFolder); diff --git a/src/test/runtest.cmd b/src/test/runtest.cmd index ebcaccc..f87b9a4 100644 --- a/src/test/runtest.cmd +++ b/src/test/runtest.cmd @@ -6,10 +6,10 @@ set currentPath=%~dp0 set PTFTEST_Root=%currentPath%..\..\ -call "%PTFTEST_Root%src\common\setVsPath.cmd" +call "%PTFTEST_Root%src\common\setVsTestPath.cmd" if ErrorLevel 1 ( exit /b 1 ) :: Does not run Interactive adapter cases in automation test -%vspath%..\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "TestProperties\bin\Debug\TestProperties.dll" "TestChecker\bin\Debug\TestChecker.dll" "TestLogging\bin\Debug\TestLogging.dll" "TestRequirementCapture\bin\Debug\TestRequirementCapture.dll" "TestAdapter\bin\Debug\TestAdapter.dll" /TestCaseFilter:"Name!=InteractiveAdapterAbort&Name!=InteractiveAdapterReturnInt&Name!=InteractiveAdapterReturnString" /Settings:Local.testsettings /Logger:trx +%vstest% "TestProperties\bin\Debug\TestProperties.dll" "TestChecker\bin\Debug\TestChecker.dll" "TestLogging\bin\Debug\TestLogging.dll" "TestRequirementCapture\bin\Debug\TestRequirementCapture.dll" "TestAdapter\bin\Debug\TestAdapter.dll" /TestCaseFilter:"Name!=InteractiveAdapterAbort&Name!=InteractiveAdapterReturnInt&Name!=InteractiveAdapterReturnString" /Settings:Local.testsettings /Logger:trx