private static ReportSectionText SectionText(String text, Color fontColor, FontStyle fontStyle = FontStyle.Regular, ContentAlignment alignment = ContentAlignment.BottomLeft, float fSize = 16.0f) { ReportSectionText sectionText = new ReportSectionText(text); sectionText.FontText = new Font("Verdana", fSize, fontStyle); sectionText.ForeColor = fontColor; sectionText.Alignment = alignment; return(sectionText); }
public static void GenerateReport(String environment, String fileName) { Logger.Info("Generating report"); try { int passed = GetScenarioSummary(environment, fileName)["Passed"]; int failed = GetScenarioSummary(environment, fileName)["Failed"]; string str = fileName.Remove(fileName.LastIndexOf('.')); string htmlFormatter = @"<style>body {font: 11px Verdana,sans-serif;margin-left: 70px;margin-right: 70px;}table {margin-top: 5px;} p {margin-bottom: 0px;} .summary {width: 200px;border-style: none!important;font-size: 12px!important;} td,tr[style] {font-size: 11px!important;border-width: 1px!important;border-style: solid!important;border-color: rgb(0, 0, 0) !important;}</style>"; string resultsSummary = @"<table class=""summary""><thead></thead><tr><td class=""summary""><b>Total Executed:</b></td><td class=""summary"">" + (passed + failed) + @"</td></tr><tr><td class=""summary""><b>Passed:</b></td><td class=""summary"">" + passed + @"</td></tr><tr><td class=""summary""><b>Failed:</b></td><td class=""summary"">" + failed + "</td></tr></table>"; DocumentHTML documentHTML = new DocumentHTML(); DataTable tcDataTable = GetTestResultData(environment, str); DataTable dataTable = GetStepResultData(environment, str); DataTable dtCarrier = dataTable.DefaultView.ToTable(true, "Test Case"); ReportSectionText blankline = new ReportSectionText("<br/>"); ReportSectionData reportSectionDataTestResult = new ReportSectionData(tcDataTable, false); reportSectionDataTestResult.Alignment = ContentAlignment.MiddleCenter; reportSectionDataTestResult.TotalWidth = 510; reportSectionDataTestResult.Position = Position.left; reportSectionDataTestResult.HighLightColor = Color.FromArgb(204, 230, 255); reportSectionDataTestResult.ColWidth = new int[3] { 100, 310, 100 }; reportSectionDataTestResult.setAlternatingRowBgColorAlgo1(Color.White, Color.WhiteSmoke); //Build HTML documentHTML.addSectionText(SectionText(htmlFormatter, Color.Black)); documentHTML.addSectionText(SectionText("Test Scenario: " + str + "<br/>", Color.DarkRed, FontStyle.Bold, ContentAlignment.MiddleCenter, 25.0f)); //Results Summary documentHTML.addSectionText(SectionText("<p>" + environment + " Results Summary:</p>", Color.Black, FontStyle.Bold)); documentHTML.addSectionText(SectionText(resultsSummary, Color.Black, FontStyle.Regular)); documentHTML.addSectionText(blankline); documentHTML.addSectionData(reportSectionDataTestResult); documentHTML.addSectionText(blankline); documentHTML.addSectionText(blankline); //Detailed Results documentHTML.addSectionText(SectionText("<p>Detailed Results:</p>", Color.Black, FontStyle.Bold)); documentHTML.addSectionText(blankline); //Loop for each test case for (int i = 0; i < dtCarrier.Rows.Count; i++) { DataView dataView = new DataView(dataTable); dataView.RowFilter = "[Test Case]='" + dtCarrier.Rows[i]["Test Case"].ToString() + "'"; ReportSectionData reportSectionDataTestStepsResult = new ReportSectionData(dataView.ToTable(), false); reportSectionDataTestStepsResult.Alignment = ContentAlignment.MiddleCenter; reportSectionDataTestStepsResult.Position = Position.center; reportSectionDataTestStepsResult.TotalWidth = 1150; reportSectionDataTestStepsResult.HighLightColor = Color.FromArgb(204, 230, 255); reportSectionDataTestStepsResult.ColWidth = new int[6] { 100, 325, 100, 400, 125, 200 }; reportSectionDataTestStepsResult.setAlternatingRowBgColorAlgo1(Color.White, Color.WhiteSmoke); documentHTML.addSectionText(SectionText(@"<a name=""" + dtCarrier.Rows[i]["Test Case"].ToString() + @""">" + dtCarrier.Rows[i]["Test Case"].ToString() + "</a>", Color.DarkRed, FontStyle.Bold, ContentAlignment.BottomLeft, 14.0f)); documentHTML.addSectionData(reportSectionDataTestStepsResult); documentHTML.addSectionText(blankline); } System.IO.StreamWriter systemWriter = new System.IO.StreamWriter(resultsDirectory + environment + "\\" + str + "\\" + str + ".html"); systemWriter.WriteLine(documentHTML.getResult(true, true)); systemWriter.Close(); } catch (Exception ex) { Logger.Error(String.Format("GenerateReport: {0}, {1}, {2}", environment, fileName, ex.ToString())); } }
public static void GenerateReportOverall(String environment, String fileName) { try { DocumentHTML documentHTML = new DocumentHTML(); ReportSectionText blankline = new ReportSectionText("<br/>"); string htmlFormatter = @"<style>body {font: 11px Verdana,sans-serif;margin-left: 70px;margin-right: 70px;}table {margin-top: 5px;} p {margin-bottom: 0px;} .summary {width: 200px;border-style: none!important;font-size: 12px!important;} td,tr[style] {font-size: 11px!important;border-width: 1px!important;border-style: solid!important;border-color: rgb(0, 0, 0) !important;}</style>"; //Title documentHTML.addSectionText(SectionText(htmlFormatter, Color.Black)); documentHTML.addSectionText(SectionText(environment + " Overall Test Report (" + System.DateTime.Now.ToShortDateString() + ")<br/>", Color.DarkRed, FontStyle.Bold, ContentAlignment.MiddleCenter, 25.0f)); //Results Summary documentHTML.addSectionText(SectionText("<p>Summary:</p>", Color.Black, FontStyle.Bold)); DataTable moduleDataTable = GetModResultsSummary(environment, fileName); ReportSectionData reportSectionDataModResult = new ReportSectionData(moduleDataTable, false); reportSectionDataModResult.Alignment = ContentAlignment.MiddleCenter; reportSectionDataModResult.TotalWidth = 1150; reportSectionDataModResult.Position = Position.left; reportSectionDataModResult.HighLightColor = Color.FromArgb(204, 230, 255); reportSectionDataModResult.ColWidth = new int[5] { 100, 260, 260, 260, 260 }; reportSectionDataModResult.setAlternatingRowBgColorAlgo1(Color.White, Color.WhiteSmoke); documentHTML.addSectionData(reportSectionDataModResult); documentHTML.addSectionText(blankline); //Latest Runs documentHTML.addSectionText(SectionText("<p>Latest Runs:</p>", Color.Black, FontStyle.Bold)); DataTable latestRunsDataTable = GetLatestRuns(environment, fileName); DataView sortByMod = new DataView(latestRunsDataTable); sortByMod.Sort = "Module"; ReportSectionData reportSectionDataLatestResult = new ReportSectionData(sortByMod.ToTable(), false); reportSectionDataLatestResult.Alignment = ContentAlignment.MiddleCenter; reportSectionDataLatestResult.Position = Position.center; reportSectionDataLatestResult.TotalWidth = 1150; reportSectionDataLatestResult.HighLightColor = Color.FromArgb(204, 230, 255); reportSectionDataLatestResult.ColWidth = new int[9] { 100, 290, 100, 100, 100, 100, 100, 100, 160 }; reportSectionDataLatestResult.setAlternatingRowBgColorAlgo1(Color.White, Color.WhiteSmoke); documentHTML.addSectionData(reportSectionDataLatestResult); documentHTML.addSectionText(blankline); //Detailed Runs documentHTML.addSectionText(SectionText("<p>All Runs:</p>", Color.Black, FontStyle.Bold)); DataTable dataTable = GetTSOverallResult(environment, fileName); DataTable dtCarrier = dataTable.DefaultView.ToTable(true, "Module"); for (int i = 0; i < dtCarrier.Rows.Count; i++) { DataView dataView = new DataView(dataTable); dataView.RowFilter = "[Module]='" + dtCarrier.Rows[i]["Module"].ToString() + "'"; ReportSectionData reportSectionDataTestStepsResult = new ReportSectionData(dataView.ToTable(), false); reportSectionDataTestStepsResult.Alignment = ContentAlignment.MiddleCenter; reportSectionDataTestStepsResult.Position = Position.center; reportSectionDataTestStepsResult.TotalWidth = 1150; reportSectionDataTestStepsResult.HighLightColor = Color.FromArgb(204, 230, 255); reportSectionDataTestStepsResult.ColWidth = new int[9] { 100, 290, 100, 100, 100, 100, 100, 100, 160 }; reportSectionDataTestStepsResult.setAlternatingRowBgColorAlgo1(Color.White, Color.WhiteSmoke); documentHTML.addSectionText(SectionText(dtCarrier.Rows[i]["Module"].ToString(), Color.DarkRed, FontStyle.Bold, ContentAlignment.BottomLeft, 14.0f)); documentHTML.addSectionData(reportSectionDataTestStepsResult); documentHTML.addSectionText(blankline); } System.IO.StreamWriter sw = new System.IO.StreamWriter(datedResultsDirectory + environment + "\\" + fileName + "\\" + fileName + ".html"); sw.WriteLine(documentHTML.getResult(true, true)); sw.Close(); } catch (Exception ex) { Logger.Error("Error generating overall report! " + ex.ToString()); } }