public void ExecutionLogWriter() { string strLogText = Percentage.ToString(); string strLogText1 = Report.g1.ToString(); string strLogText2 = PassedIterartion.ToString(); string strLogText3 = FailedIteration.ToString(); // Create a writer and open the file: StreamWriter log; if (!File.Exists(loglocation)) { log = new StreamWriter(loglocation); } else { log = File.AppendText(loglocation); } // Write to the file: log.WriteLine("Execution Log - " + System.DateTime.Now.ToString("dd-MM-yyyy")); log.WriteLine("Pass Percentage - " + strLogText + "%"); log.WriteLine("Total Iteration - " + strLogText1); log.WriteLine("Passed Iteration - " + strLogText2); log.WriteLine("Failed Iteration - " + strLogText3); log.Close(); }
public string MainPageWriter() { //Main Page Writer string body = string.Empty; StreamReader reader = new StreamReader("\\\\192.169.1.55\\Automation reports\\SCUF\\Report Repository\\Templates\\HTML Template\\OverallResullt_Template.html"); body = reader.ReadToEnd(); body = body.Replace("{username}", Report.UserName); body = body.Replace("{platform}", Report.OSName); body = body.Replace("{URL}", Report.LURL); body = body.Replace("{Application}", Report.ApplicationName); body = body.Replace("{browsername}", Report.BrowserName.ToUpper()); body = body.Replace("{ProjectName}", Report.ProjName); //body = body.Replace("{ExecutionStartTime}", Class1.ExecutionStartTime); //body = body.Replace("{ExecutionEndTime}", Class1.ExecutionEndTime); IterartionExecutionDuration = Convert.ToDateTime(Report.ExecutionEndTime1) - Convert.ToDateTime(Report.ExecutionStartTime1); string duration = IterartionExecutionDuration.ToString().Substring(0, 12); body = body.Replace("{Duration}", duration); for (int r = 0; r <= Report.g1 - 1; r++) { if (FinalResultList[r].ToString() == "Pass") { PassedIterartion++; } if (FinalResultList[r].ToString() == "Fail") { FailedIteration++; } } body = body.Replace("{Iterations}", Report.g1.ToString()); body = body.Replace("{Passed}", PassedIterartion.ToString()); body = body.Replace("{Failed}", FailedIteration.ToString()); double PassedPercent = (double)PassedIterartion / Report.g1; double PassedPercent1 = PassedPercent * 180; double FailedPercent = (double)FailedIteration / Report.g1; double FailedPercent1 = FailedPercent * 180; body = body.Replace("{PassedPercent}", PassedPercent1.ToString()); body = body.Replace("{FailedPercent}", FailedPercent1.ToString()); decimal passed = System.Convert.ToDecimal(PassedIterartion); decimal total = System.Convert.ToDecimal(Report.RowCount); decimal percentage = (passed / total) * 100; Percentage = System.Convert.ToInt16(percentage); body = body.Replace("{Percentage}", Percentage.ToString()); body = body.Replace("{Maintable}", Maintable.ToString()); reader.Close(); string filelocation2 = Report.mplocation; StreamWriter sw1 = new StreamWriter(filelocation2); sw1.WriteLine(body); sw1.Close(); return(body); }
public string MainPageWriter1() { //Main Page Writer string body1 = string.Empty; StreamReader reader = new StreamReader("\\\\192.169.1.55\\Automation reports\\SCUF\\Report Repository\\Templates\\HTML Template\\MainPage_Template.html"); body1 = reader.ReadToEnd(); body1 = body1.Replace("{username}", Report.UserName); body1 = body1.Replace("{platform}", Report.OSName); body1 = body1.Replace("{URL}", Report.LURL); body1 = body1.Replace("{Application}", Report.ApplicationName); body1 = body1.Replace("{browsername}", Report.BrowserName.ToUpper()); body1 = body1.Replace("{ProjectName}", Report.ProjName); for (int r = 0; r <= Report.g1 - 1; r++) { if (FinalResultList[r].ToString() == "Passed") { PassedIterartion++; } if (FinalResultList[r].ToString() == "Failed") { FailedIteration++; } } body1 = body1.Replace("{Iterations}", Report.g1.ToString()); body1 = body1.Replace("{Passed}", PassedIterartion.ToString()); body1 = body1.Replace("{Failed}", FailedIteration.ToString()); double PassedPercent = (double)PassedIterartion / Report.g1; double PassedPercent1 = PassedPercent * 180; double FailedPercent = (double)FailedIteration / Report.g1; double FailedPercent1 = FailedPercent * 180; body1 = body1.Replace("{PassedPercent}", PassedPercent1.ToString()); body1 = body1.Replace("{FailedPercent}", FailedPercent1.ToString()); decimal passed = System.Convert.ToDecimal(PassedIterartion); decimal total = System.Convert.ToDecimal(Report.RowCount); decimal percentage = (passed / total) * 100; Percentage = System.Convert.ToInt16(percentage); body1 = body1.Replace("{Percentage}", Percentage.ToString()); //body = body.Replace("{Maintable}", Maintable.ToString()); for (int j = 0; j <= Report.RowCount - 1; j++) { var TestCaseDescription = TestCaseDescriptionList[j].ToString(); var ExpectedStatus = ExpectedStatusList[j].ToString(); var ExpectedResulted = ExpectedResultedList[j].ToString(); var FinalResult = FinalResultList[j].ToString(); ActualResult = IterationStatus[j].ToString(); var Filelocation = filelocation3List[j].ToString(); body1 = body1.Replace("{TestDescription}", TestCaseDescription); body1 = body1.Replace("{ExpectedResult}", ExpectedResulted); body1 = body1.Replace("{SlNo}", (j + 1).ToString()); string arcolour = ""; string ecolour = ""; string acolour = ""; if (FinalResult == "Pass") { acolour = "DARKGREEN"; } else { acolour = "MAROON"; } if ((ExpectedStatus == "Pass")) { ecolour = "DARKGREEN"; } else { ecolour = "MAROON"; } if ((ActualResult.ToString() == "Pass")) { arcolour = "DARKGREEN"; } else { arcolour = "MAROON"; } string close = ">"; string Filelocation1 = Regex.Replace(Filelocation, @"\\", @"\\");; string loc = string.Format("\"{0}\"", "location.href='" + Filelocation1 + "'"); //-----------------------For div1--------------------// string st = "<div onclick="; string string1 = " style="; string string2 = string.Format("\"{0}\"", "height:140px; width:950px; margin-left: 15px; margin-top: 7px; border: 3px solid black; float : left; box-shadow: 5px 3px 3px 3px;"); string s = st + loc + string1 + string2 + close; Console.WriteLine(s); //-----------------------For div2--------------------// string string3 = "<div style="; string string4 = string.Format("\"{0}\"", "height:135px; width:110px; border: 1.5px solid white; float : left;"); //close string string5 = "<h1>" + (j + 1).ToString() + "<h1></div>"; string s1 = string3 + string4 + close + string5; Console.WriteLine(s1); //-----------------------For div3--------------------// string string6 = "<div style="; string string7 = string.Format("\"{0}\"", "height:100px; width:833px; border: 1.5px solid white; float : left"); //Close string s2 = string6 + string7 + close; Console.WriteLine(s2); //-----------------------For Table--------------------// string string8 = "<table id = "; string string9 = string.Format("\"{0}\"", "mytable"); string string10 = "align="; string string11 = string.Format("\"{0}\"", "left"); string string12 = "cellpadding="; string string13 = string.Format("\"{0}\"", "1"); string string14 = "style ="; string string15 = string.Format("\"{0}\"", "width:825; height:90; border collapse: 1px solid gray; margin-left: 3; text-align: center; color: white;"); //close string s3 = string8 + string9 + string10 + string11 + string12 + string13 + string14 + string15 + close; Console.WriteLine(s3); //-----------------------For Col--------------------// string string16 = "<col width="; string string17 = string.Format("\"{0}\"", "169"); //Close string string18 = "<col width="; string string19 = string.Format("\"{0}\"", "auto"); //Close string s4 = string16 + string17 + close + string18 + string19 + close; Console.WriteLine(s4); //-----------------------For start tbody--------------------// string string20 = "<tbody>"; string s5 = string20; Console.WriteLine(s5); //-----------------------For 1st tr/td--------------------// string string21 = "<tr><td><b>Test Case Description</b></td><td>:</td><td>" + TestCaseDescription + "</td></tr>"; string s6 = string21; Console.WriteLine(s6); //-----------------------For 2nd tr/td--------------------// string string22 = "<tr><td><b>Expected/Resulted</b></td><td>:</td><td>" + ExpectedResulted + "</td></tr>"; string s7 = string22; Console.WriteLine(s7); //-----------------------For end tbody--------------------// string string23 = "</tbody>"; string s8 = string23; Console.WriteLine(s8); //-----------------------For end table--------------------// string string24 = "</table>"; string s9 = string24; Console.WriteLine(s9); //-----------------------For end div--------------------// string string25 = "</div>"; string s10 = string25; Console.WriteLine(s10); //-----------------------For div4--------------------// string string26 = "<div style="; string string27 = string.Format("\"{0}\"", "height:35px; width:833px; border: 0px solid white; float : left"); //Close string s11 = string26 + string27 + close; Console.WriteLine(s11); //-----------------------For div5--------------------// string string28 = "<div style="; string string29 = string.Format("\"{0}\"", "height:35px; width:277.5px; border: 1.5px solid white; float : left; background:" + arcolour + ";"); //Close string string30 = "<h2>Automation Result : " + ActualResult + "</h2></div>"; string s12 = string28 + string29 + close + string30; Console.WriteLine(s12); //-----------------------For div6--------------------// string string31 = "<div style="; string string32 = string.Format("\"{0}\"", "height:35px; width:277.5px; border: 1.5px solid white; float : left; background:" + ecolour + ";"); //Close string string33 = "<h2>Expected Result : " + ExpectedStatus + "</h2></div>"; string s13 = string31 + string32 + close + string33; Console.WriteLine(s13); //-----------------------For div6--------------------// string string34 = "<div style="; string string35 = string.Format("\"{0}\"", "height:35px; width:277.5px; border: 1.5px solid white; float : left; background:" + acolour + ";"); //Close string string36 = "<h2>Final Result : " + FinalResult + "</h2></div>"; string s14 = string34 + string35 + close + string36; Console.WriteLine(s14); //-----------------------For end div--------------------// string string37 = "</div>"; string s15 = string37; Console.WriteLine(s15); //-----------------------For end div--------------------// string string38 = "</div>"; string s16 = string38; Console.WriteLine(s16); arr.Add(s); arr.Add(s1); arr.Add(s2); arr.Add(s3); arr.Add(s4); arr.Add(s5); arr.Add(s6); arr.Add(s7); arr.Add(s8); arr.Add(s9); arr.Add(s10); arr.Add(s11); arr.Add(s12); arr.Add(s13); arr.Add(s14); arr.Add(s15); arr.Add(s16); if (Report.RowCount - 1 == j) { Table = new StringBuilder(); foreach (string id in arr) { Table.Append(id + ""); } body1 = body1.Replace("{Table}", Table.ToString()); ArrayList Date = new ArrayList(); ArrayList Passed = new ArrayList(); ArrayList Failed = new ArrayList(); ArrayList PassPercent = new ArrayList(); ArrayList TotalIteration = new ArrayList(); ArrayList passed1 = new ArrayList(); ArrayList failed1 = new ArrayList(); ArrayList pp = new ArrayList(); ArrayList ti = new ArrayList(); a2 = 0; string[] tr = File.ReadAllLines(loglocation); ArrayList a = new ArrayList(tr); int a1 = a.Count; Thread.Sleep(1000); for (int i = a1; i <= a1; i--) { int i1 = i; Date.Add(a[i1 - 5]); PassPercent.Add(a[i1 - 4]); TotalIteration.Add(a[i1 - 3]); Passed.Add(a[i1 - 2]); Failed.Add(a[i1 - 1]); i = i - 4; if (i == 1) { break; } } for (int sa = 0; sa <= Passed.Count - 1; sa++) { //-------------------------------------Pass Percent----------------------// string[] res = Regex.Split(PassPercent[sa].ToString(), "-"); foreach (string res1 in res) { Console.WriteLine(res1); pp.Add(res1); } //-------------------------------------Total Iteration----------------------// string[] toti = Regex.Split(TotalIteration[sa].ToString(), "-"); foreach (string toti1 in toti) { Console.WriteLine(toti1); ti.Add(toti1); } //-------------------------------------Passed----------------------// string[] passs = Regex.Split(Passed[sa].ToString(), "-"); foreach (string passs1 in passs) { Console.WriteLine(passs1); passed1.Add(passs1); } //-------------------------------------Failed----------------------// string[] failll = Regex.Split(Failed[sa].ToString(), "-"); foreach (string failll1 in failll) { Console.WriteLine(failll1); failed1.Add(failll1); } a2++; } string close1 = ">"; string cont = "<div class="; string cont1 = string.Format("\"{0}\"", "container"); string c = cont + cont1 + close1; sab = 1; for (int sb = 0; sb <= PassPercent.Count - 1; sb++) { //-----------------------For h1--------------------// string restring1 = string.Format("\"{0}\"", "Head2"); string restring2 = "<h2 class =" + restring1 + ">" + Date[sb] + "</h2>"; re = restring2; Console.WriteLine(re); //-----------------------For div2--------------------// string restring3 = c + cont + string.Format("\"{0}\"", "skills"); // string string4 = string3; string restring5 = "style="; string restring6 = string.Format("\"{0}\"", "width: " + pp[sb + sab].ToString() + "; background-color: #32CD32;"); //Close string restring7 = PassPercent[sb] + "</div></div>"; re2 = restring3 + restring5 + restring6 + close1 + restring7; Console.WriteLine(re2); string restring61 = string.Format("\"{0}\"", "width:100%; background-color: #008080;"); string restring71 = TotalIteration[sb] + "</div></div>"; re3 = restring3 + restring5 + restring61 + close1 + restring71; Console.WriteLine(re3); int Pass_Iteration = Convert.ToInt32(passed1[sb + sab]); int Total_Iteration = Convert.ToInt32(ti[sb + sab]); int Fail_Iteration = Convert.ToInt32(failed1[sb + sab]); double totalpass = (double)Pass_Iteration / Total_Iteration; double tp = totalpass * 100; double totalfail = (double)Fail_Iteration / Total_Iteration; double tf = totalfail * 100; string restring62 = string.Format("\"{0}\"", "width: " + tp.ToString() + "%; background-color: #2196F3;"); string restring72 = Passed[sb] + "</div></div>"; re4 = restring3 + restring5 + restring62 + close1 + restring72; Console.WriteLine(re4); string restring63 = string.Format("\"{0}\"", "width: " + tf.ToString() + "%; background-color: #f44336;"); string restring73 = Failed[sb] + "</div></div>"; re5 = restring3 + restring5 + restring63 + close1 + restring73; Console.WriteLine(re5); sab++; arr2.Add(re); arr2.Add(re2); arr2.Add(re3); arr2.Add(re4); arr2.Add(re5); } Table2 = new StringBuilder(); foreach (string id in arr2) { Table2.Append(id + ""); } body1 = body1.Replace("{Table2}", Table2.ToString()); reader.Close(); StreamWriter sw13 = new StreamWriter(folderpath + "\\OverallStatus.html"); sw13.WriteLine(body1); sw13.Close(); } } return(body1); }