Пример #1
0
        public string GenerateHtml(LoadTestRunResults loadTestRunResults)
        {
            var sb = new StringBuilder();

            sb.AppendLine(
                $"<br><span class=\"titleLabel\">Total Execution Time:</span>  <span class=\"titleLabelValue\">{loadTestRunResults.TotalExecutionTime}</span><br><br>");
            sb.AppendLine("<span class=\"titleLabel\">Test Scenarios Execution Times</span> <br>");
            sb.AppendLine("<div class=\"chart-container\" style=\"overflow: hidden; height: 500px; width: 800px\">");
            sb.AppendLine("<canvas id=\"testScenariosExecutionTimesChart\"></canvas>");
            sb.AppendLine("</div>");
            sb.AppendLine("<div id=\"allTests\">");
            int testScenarioCount = 1;

            foreach (var currentTestScenarioResults in loadTestRunResults.TestScenarioResults.Values)
            {
                sb.AppendLine($"<div id=\"test{testScenarioCount}\">");

                sb.AppendLine(
                    $"<span class=\"titleLabel\">Test Scenario:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.TestName}</span><br>");
                sb.AppendLine(
                    $"<span class=\"titleLabel\">Average Execution Time:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.AverageExecutionTimeSeconds} seconds</span><br>");
                sb.AppendLine(
                    $"<span class=\"titleLabel\">Max Execution Time:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.MaxExecutionTimeSeconds} seconds</span><br>");
                sb.AppendLine(
                    $"<span class=\"titleLabel\">Min Execution Time:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.MinExecutionTimeSeconds} seconds</span><br>");
                sb.AppendLine(
                    $"<span class=\"titleLabel\">Times Executed:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.TimesExecuted}</span><br>");
                sb.AppendLine(
                    $"<span class=\"titleLabel\">Times Passed:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.TimesPassed}</span><br>");
                sb.AppendLine(
                    $"<span class=\"titleLabel\">Times Failed:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.TimesFailed}</span><br>");
                sb.AppendLine(
                    $"<span class=\"titleLabel\">Weight:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.Weight}</span><br><br>");
                sb.AppendLine($"<div id=\"jsGridRequests{testScenarioCount}\"></div><br><br>");

                sb.AppendLine(
                    $"<span class=\"titleLabel\">Failed Assertions:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.FailedAssertionsCount}</span><br><br>");
                sb.AppendLine($"<div id=\"jsGridFailedAssertions{testScenarioCount}\"></div><br><br>");

                sb.AppendLine(
                    $"<span class=\"titleLabel\">All Assertions:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.TotalAssertionsCount}</span><br><br>");
                sb.AppendLine(
                    $"<span class=\"titleLabel\">Failed Assertions:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.FailedAssertionsCount}</span><br><br>");
                sb.AppendLine(
                    $"<span class=\"titleLabel\">Passed Assertions:</span>  <span class=\"titleLabelValue\">{currentTestScenarioResults.PassedAssertionsCount}</span><br><br>");
                sb.AppendLine($"<div id=\"jsGridAllAssertions{testScenarioCount}\"></div><br><br>");
                sb.AppendLine("</div>");

                testScenarioCount++;
            }

            sb.AppendLine("</div>");
            return(sb.ToString());
        }
        private string GenerateHtml(LoadTestRunResults loadTestRunResults)
        {
            var    testScenarioHtmlReportGenerator       = new TestScenarioHtmlReportGenerator();
            var    testScenarioJavaScriptReportGenerator = new TestScenarioJavaScriptReportGenerator();
            string htmlTemplate = File.ReadAllText("reportTemplate.html");
            string htmlPart     = testScenarioHtmlReportGenerator.GenerateHtml(loadTestRunResults);
            string jsPart       = testScenarioJavaScriptReportGenerator.GenerateJavaScript(loadTestRunResults);

            htmlTemplate = htmlTemplate.Replace("#htmlPlaceHolder#", htmlPart);
            htmlTemplate = htmlTemplate.Replace("#javaScriptPlaceHolder#", jsPart);
            return(htmlTemplate);
        }
Пример #3
0
        public string GenerateJavaScript(LoadTestRunResults loadTestRunResults)
        {
            var sb = new StringBuilder();

            GenerateAllRequestsGridJS(loadTestRunResults, sb);
            GenerateFailedAssertionsGridJS(loadTestRunResults, sb);
            GenerateAllAssertionsGridJS(loadTestRunResults, sb);
            GenerateTestScenariosChartJS(loadTestRunResults, sb);
            var javaScriptCompressor = new JavaScriptCompressor();
            var minifiedString       = javaScriptCompressor.Compress(sb.ToString());

            return(minifiedString);
        }
        public void Execute(string resultsFilePath)
        {
            InitializeTestScenarios();
            InitializeTestScenarioMixtureDeterminers();
            var loadTestExecutionWatch        = Stopwatch.StartNew();
            var loadTestRunResults            = new LoadTestRunResults();
            var loadTestService               = new LoadTestService();
            var testScenarioMixtureDeterminer = _testScenarioMixtureDeterminer.GetTestScenarioMixtureDeterminer();

            if (Settings.LoadTestType == LoadTestType.ExecuteForTime)
            {
                loadTestService.ExecuteForTime(Settings.NumberOfProcesses, Settings.PauseBetweenStartSeconds,
                                               Settings.SecondsToBeExecuted, ExecuteTestScenario);
            }
            else if (Settings.LoadTestType == LoadTestType.ExecuteNumberOfTimes)
            {
                loadTestService.ExecuteNumberOfTimes(Settings.NumberOfProcesses, Settings.PauseBetweenStartSeconds,
                                                     Settings.TimesToBeExecuted, ExecuteTestScenario);
            }

            void ExecuteTestScenario()
            {
                var testScenarioResults = new TestScenarioResults();
                var testScenario        = testScenarioMixtureDeterminer.GetTestScenario();

                if (loadTestRunResults.TestScenarioResults.ContainsKey(testScenario.TestName))
                {
                    testScenarioResults = loadTestRunResults.TestScenarioResults[testScenario.TestName];
                }
                else
                {
                    testScenarioResults.TestName = testScenario.TestName;
                    loadTestRunResults.TestScenarioResults.GetOrAdd(testScenario.TestName, testScenarioResults);
                }

                _testScenarioExecutor.Execute(testScenario, testScenarioResults,
                                              Settings.ShouldExecuteRecordedRequestPauses, Settings.IgnoreUrlRequestsPatterns);
            }

            loadTestExecutionWatch.Stop();

            loadTestRunResults.TotalExecutionTime = loadTestExecutionWatch.Elapsed;

            var loadTestReportGenerator = new LoadTestReportGenerator();

            loadTestReportGenerator.GenerateReport(loadTestRunResults, resultsFilePath);
        }
Пример #5
0
        private void GenerateTestScenariosChartJS(LoadTestRunResults loadTestRunResults, StringBuilder sb)
        {
            int testScenarioCount = 1;

            sb.AppendLine("var ctx = document.getElementById(\"testScenariosExecutionTimesChart\").getContext('2d');");
            sb.AppendLine("var myChart = new Chart(ctx, {");
            sb.AppendLine("type: 'line',");
            sb.AppendLine("data: {");
            sb.Append("labels: [");
            int maxTestScenarioRunCount = 0;

            foreach (var currentTestScenarioResults in loadTestRunResults.TestScenarioResults.Values)
            {
                if (currentTestScenarioResults.TimesExecuted > maxTestScenarioRunCount)
                {
                    maxTestScenarioRunCount = currentTestScenarioResults.TimesExecuted;
                }
            }

            for (int i = 1; i < maxTestScenarioRunCount + 1; i++)
            {
                sb.Append($"\"{i}\",");
            }

            sb.AppendLine("],");
            sb.AppendLine("datasets: [");
            int colorIndex = 0;

            foreach (var currentTestScenarioResults in loadTestRunResults.TestScenarioResults.Values)
            {
                sb.AppendLine("{");
                sb.AppendLine($"label: '{currentTestScenarioResults.TestName}',");
                sb.Append($"data: [");
                foreach (var testScenarioRunResults in currentTestScenarioResults.TestScenarioRunResults.Values)
                {
                    sb.Append($"\"{testScenarioRunResults.ExecutionTime.TotalSeconds}\",");
                }

                sb.AppendLine("],");
                sb.AppendLine($"backgroundColor: 'rgba({hexChartColors[colorIndex]}, 0.2)',");
                sb.AppendLine($"borderColor: 'rgba({hexChartColors[colorIndex]}, 1)',");
                sb.AppendLine("fill: false,");
                sb.AppendLine("borderWidth: 2");
                sb.AppendLine(" },");

                colorIndex++;
            }

            sb.AppendLine("]");
            sb.AppendLine("},");
            sb.AppendLine("options: {");
            sb.AppendLine("scales: {");
            sb.AppendLine("yAxes: [{");
            sb.AppendLine("ticks: {");
            sb.AppendLine("beginAtZero: true");
            sb.AppendLine("}");
            sb.AppendLine("}]");
            sb.AppendLine("}");
            sb.AppendLine("}");
            sb.AppendLine(" });");
        }
Пример #6
0
        private void GenerateAllAssertionsGridJS(LoadTestRunResults loadTestRunResults, StringBuilder sb)
        {
            int testScenarioCount = 1;

            foreach (var currentTestScenarioResults in loadTestRunResults.TestScenarioResults.Values)
            {
                sb.AppendLine($"var dballAssertions{testScenarioCount} = {{");
                sb.AppendLine("loadData: function (filter) {");
                sb.AppendLine($"return $.grep(this.allAssertions{testScenarioCount}, function (allAssertion) {{");
                sb.AppendLine(
                    "return (!filter.URL || allAssertion.URL.toLowerCase().indexOf(filter.URL.toLowerCase()) > -1)");
                sb.AppendLine("&& (!filter.IsSuccessful || allAssertion.IsSuccessful === filter.IsSuccessful)");
                sb.AppendLine(
                    "&& (!filter.AssertionType || allAssertion.AssertionType.toLowerCase().indexOf(filter.AssertionType.toLowerCase()) > -1)");
                sb.AppendLine(
                    "&& (!filter.Exception || allAssertion.Exception.toLowerCase().indexOf(filter.Exception.toLowerCase()) > -1);");
                sb.AppendLine("});");
                sb.AppendLine("}");
                sb.AppendLine("};");

                sb.AppendLine($"dballAssertions{testScenarioCount}.allAssertions{testScenarioCount} = [");
                foreach (var currentTestScenarioRunResult in currentTestScenarioResults.TestScenarioRunResults.Values)
                {
                    foreach (var requestResults in currentTestScenarioRunResult.RequestResults)
                    {
                        foreach (var responseAssertionResult in requestResults.ResponseAssertionResults)
                        {
                            sb.AppendLine("{");
                            sb.AppendLine(
                                $" \"URL\": \"{HttpUtility.JavaScriptStringEncode(requestResults?.RequestUrl)}\",");
                            sb.AppendLine($" \"IsSuccessful\": \"{responseAssertionResult?.Passed}\",");
                            sb.AppendLine($" \"AssertionType\": \"{responseAssertionResult?.AssertionType}\",");
                            sb.AppendLine(
                                $" \"Exception\": \"{HttpUtility.JavaScriptStringEncode(responseAssertionResult?.FailedMessage)}\",");
                            sb.AppendLine("},");
                        }
                    }
                }

                sb.AppendLine("];");
                sb.AppendLine($"$(\"#jsGridAllAssertions{testScenarioCount}\").jsGrid({{");
                sb.AppendLine("width: \"100 % \",");
                sb.AppendLine("height: \"400px\",");
                sb.AppendLine("filtering: true,");
                sb.AppendLine("sorting: true,");
                sb.AppendLine("paging: true,");
                sb.AppendLine("autoload: true,");
                sb.AppendLine("pageSize: 5,");
                sb.AppendLine("pageButtonCount: 5,");
                sb.AppendLine($"controller: dballAssertions{testScenarioCount},");
                sb.AppendLine("fields: [{");
                sb.AppendLine(" name: \"URL\",");
                sb.AppendLine(" type: \"text\",");
                sb.AppendLine(" width: 250");
                sb.AppendLine("},");
                sb.AppendLine("{");
                sb.AppendLine(" name: \"IsSuccessful\",");
                sb.AppendLine(" type: \"text\",");
                sb.AppendLine(" width: 50");
                sb.AppendLine("},");
                sb.AppendLine("{");
                sb.AppendLine(" name: \"AssertionType\",");
                sb.AppendLine(" type: \"text\",");
                sb.AppendLine(" width: 150");
                sb.AppendLine("},");
                sb.AppendLine("{");
                sb.AppendLine(" name: \"Exception\",");
                sb.AppendLine(" type: \"text\",");
                sb.AppendLine(" title: \"Exception Message\",");
                sb.AppendLine(" width: 300");
                sb.AppendLine("}");
                sb.AppendLine("]");
                sb.AppendLine("});");

                testScenarioCount++;
            }
        }
        public void GenerateReport(LoadTestRunResults loadTestRunResults, string reportPath)
        {
            string htmlReportContent = GenerateHtml(loadTestRunResults);

            File.WriteAllText(reportPath, htmlReportContent);
        }