Exemple #1
0
        public void ProcessResult()
        {
            string strStatus; string strAction;
            Regex  start       = new Regex("TESTCASE.START");
            Regex  stop        = new Regex("TESTCASE.STOP");
            bool   falied      = false;
            int    intStartRow = 0;
            var    dt          = workbook.Worksheet("Result");
            var    Summary     = workbook.Worksheet("Summary");
            int    iLoop       = 3;

            try
            {
                for (int intRowNumber = 2; intRowNumber < dt.RowCount(); intRowNumber++)
                {
                    strAction = dt.Cell("B" + intRowNumber).Value.ToString().ToUpper();
                    strStatus = dt.Cell("G" + intRowNumber).Value.ToString().ToUpper();

                    if (Constants.ResultStatus_Failed == strStatus)
                    {
                        dt.Range("G" + intRowNumber + ":G" + intRowNumber).Style.Font.FontColor = XLColor.Red;
                        falied = true;
                    }
                    else if (Constants.ResultStatus_Passed == strStatus)  // Passed
                    {
                        dt.Range("G" + intRowNumber + ":G" + intRowNumber).Style.Font.FontColor = XLColor.Green;
                    }
                    //Test Case Start
                    if (start.Match(strAction).Success)
                    {
                        intStartRow = intRowNumber;
                        falied      = false;
                    }
                    // Test Case Stop
                    if (stop.Match(strAction).Success)
                    {
                        // Update Test Case Start with status
                        if (falied)
                        {
                            dt.Cell("G" + intStartRow).Value = Constants.ResultStatus_Failed;
                            dt.Range("G" + intStartRow + ":G" + intStartRow).Style.Font.Bold      = true;
                            dt.Range("G" + intStartRow + ":G" + intStartRow).Style.Font.FontColor = XLColor.Red;

                            //format summary sheet
                            Summary.Cell("D" + iLoop).Style.Font.FontColor = XLColor.Red;
                        }
                        else
                        {
                            dt.Cell("G" + intStartRow).Value = Constants.ResultStatus_Passed;
                            dt.Range("G" + intStartRow + ":G" + intStartRow).Style.Font.FontColor = XLColor.Green;

                            //format summary sheet
                            Summary.Cell("D" + iLoop).Style.Font.FontColor = XLColor.Green;
                        }

                        //Test case row formating
                        dt.Range("A" + intStartRow + ":I" + intStartRow).Style.Font.Bold            = true;
                        dt.Range("A" + intStartRow + ":I" + intStartRow).Style.Fill.BackgroundColor = XLColor.FromHtml("#FFD7E4F2");
                        dt.Cell("G" + intRowNumber).Value = "";
                        dt.Range("A" + intRowNumber + ":I" + intRowNumber).Style.Font.Bold            = true;
                        dt.Range("A" + intRowNumber + ":I" + intRowNumber).Style.Fill.BackgroundColor = XLColor.FromHtml("#FFD7E4F2");

                        //Summary sheet
                        Summary.Cell("C" + iLoop).Value = dt.Cell("C" + intStartRow).Value.ToString();
                        Summary.Cell("D" + iLoop).Value = dt.Cell("G" + intStartRow).Value;
                        Summary.Cell("B" + iLoop).Value = iLoop - 2;
                        iLoop++;
                    }
                }

                // Format Result Sheet
                headerFormat(dt.Range("A1:I1"));
                commonFormat(dt.RangeUsed());

                //Format Summary sheet
                Summary.Cell("C2").Value = "TESTCASE NAME";
                Summary.Cell("D2").Value = "STATUS";
                Summary.Cell("B2").Value = "#";

                commonFormat(Summary.RangeUsed());
                //Summary sheet test setting details

                Summary.Cell("F2").Value = "APPLICATION";
                Summary.Cell("F3").Value = "ENVIRONMENT";
                Summary.Cell("F4").Value = "TEST SUITE";
                Summary.Cell("F5").Value = "DATE & TIME";
                Summary.Cell("F6").Value = "BROWSER";
                Summary.Cell("F7").Value = "MACHINE";

                Summary.Cell("G2").Value = "CLAW";
                Summary.Cell("G3").Value = "STAGING";
                Summary.Cell("G4").Value = testSuite;
                Summary.Cell("G5").Value = DateTime.Now.ToString();
                Summary.Cell("G6").Value = testBrowser;
                Summary.Cell("G7").Value = Environment.MachineName.ToUpper();

                headerFormat(Summary.Range("F2:F7"));
                commonFormat(Summary.Range("F2:G7"));
                headerFormat(Summary.Range("B2:D2"));

                foreach (var Col in dt.ColumnsUsed())
                {
                    Col.AdjustToContents();
                }
                dt.ShowGridLines = false;

                foreach (var Col in Summary.ColumnsUsed())
                {
                    Col.AdjustToContents();
                }
                Summary.ShowGridLines = false;
            }
            finally
            {
                dt.Dispose();
                Summary.Dispose();
            }
        }