Example #1
0
        public static void setTestStepFinish(String status, Exception e)
        {
            try
            {
                // Test Step Error & ScreenShot Style
                testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Style.WrapText      = true;
                testStepWorkSheet.Cells[ts_RowIndex, ts_testStepScreenShot_ColIndex].Style.WrapText = true;

                if (status.Equals("Pass"))
                {
                    //Set Test Step Result to Pass
                    testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Value = status;

                    testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                    testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Green);

                    //set Test Step Error to NA
                    testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Value = "NA";

                    //set Test Step Screenshot location to NA
                    testStepWorkSheet.Cells[ts_RowIndex, ts_testStepScreenShot_ColIndex].Value = "NA";

                    if (tc_Hierachy_Counter > 0)
                    {
                        subTestFailure = false;
                    }
                }

                else
                {
                    // Check for sub test case failure
                    if (!subTestFailure)
                    {
                        //Set Test Step Result to Fail
                        testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Value = status;

                        //Set the color of the status
                        testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                        testStepWorkSheet.Cells[ts_RowIndex, ts_testStepResult_ColIndex].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red);



                        //Write Error Message in Excel
                        testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Value = e.Message;

                        //set the width of the error column
                        testStepWorkSheet.Column(ts_testStepError_ColIndex).Width = 50;
                        testStepWorkSheet.Cells[ts_RowIndex, ts_testStepError_ColIndex].Style.WrapText = true;
                        testStepWorkSheet.Row(ts_RowIndex).Height = 50;
                        //testStepWorkSheet.Column(ts_testStepError_ColIndex).AutoFit();

                        CommonUtilities.CreateAndSaveScreenShot(resultFolderPath + "\\" + currentTestname + ".png");

                        Thread.Sleep(3 * 1000);

                        var uri = new Uri(resultFolderPath + "\\" + currentTestname + ".png");

                        errorTestResultFilePath = resultFolderPath + "\\" + currentTestname + ".png";

                        var cell = testStepWorkSheet.Cells[ts_RowIndex, ts_testStepScreenShot_ColIndex];

                        //cell.Hyperlink = new Uri(Environment.CurrentDirectory + "\\" + currentTestname + ".png");

                        // cell.Hyperlink = new Uri(Environment.CurrentDirectory + "\\" + currentTestname + ".png");

                        if (!(namedStyle != null))
                        {
                            namedStyle = testStepWorkSheet.Workbook.Styles.CreateNamedStyle("HyperLink");
                            namedStyle.Style.Font.UnderLine = true;
                            namedStyle.Style.Font.Color.SetColor(Color.Blue);
                        }

                        cell.Hyperlink = new ExcelHyperLink(uri.AbsoluteUri.ToString());

                        cell.StyleName = "HyperLink";
                        cell.Value     = currentTestname + ".png";
                        if (tc_Hierachy_Counter > 0)
                        {
                            subTestFailure = true;
                        }
                    }
                }

                //Increment the Row Counter
                ts_RowIndex++;
            }
            catch (Exception ex)
            {
                SAFINCALog.Info("Error Writing data to excel " + ex);
            }
        }