Esempio n. 1
0
        public static void setTestClassStart(String testClassName, String dateTime)
        {
            try
            {
                SAFEBBALog.Info("Executing Test Cases for Class Started for Class : " + testClassName);

                errorTestResultFilePath = null;

                //For Directory
                if (!Directory.Exists(resultFolderPath))
                {
                    resultFolderPath = resultFolderPath + "_" + dateTime;
                    Directory.CreateDirectory(resultFolderPath);
                    System.IO.File.Copy(@Environment.CurrentDirectory + "\\Test_Results_Template.xlsx", resultFolderPath + "\\Test_Results" + "_" + dateTime + ".xlsx");
                }

                testResultFilePath = resultFolderPath + "\\Test_Results" + "_" + dateTime + ".xlsx";

                testResultFile = new FileInfo(testResultFilePath);

                excelPackage = new ExcelPackage(testResultFile);

                testCaseWorkSheet = excelPackage.Workbook.Worksheets.First();

                testStepWorkSheet = excelPackage.Workbook.Worksheets.Last();
            }

            catch (Exception e)
            {
                SAFEBBALog.TestCaseErrorMessage(e);
            }
        }
Esempio n. 2
0
        public void SeleniumQuit()
        {
            Console.WriteLine("Quitting Driver...........");
            try
            {
                if (driver != null)
                {
                    driver.Quit();
                    driver = null;
                }

                SAFEBBALog.Info("Closing Web Driver...........");
                ProcessMgn.killProcessByNames("IEDriverServer");    //Make sure the process is killed

                //Try to add the link to the Result file and screenshots if necessary
                this.TestContext.AddResultFile(WriteTestResultsExcel.testResultFilePath);
                if (WriteTestResultsExcel.errorTestResultFilePath != null)
                {
                    this.TestContext.AddResultFile(WriteTestResultsExcel.errorTestResultFilePath);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
Esempio n. 3
0
        public static void setTestClassFinish(String testClassName)
        {
            try

            {
                SAFEBBALog.Info("Executing Test Cases Finished for Class  : " + testClassName);

                excelPackage.SaveAs(testResultFile);

                excelPackage.Dispose();

                // excelPackage.Load(holdingStream);

                SAFEBBALog.Info("Saving Test Results for Class : " + testClassName + " in path -> " + testResultFilePath);
            }
            catch (Exception e)
            {
                SAFEBBALog.TestCaseErrorMessage(e);
            }
            finally
            {
                //tc_RowIndex = 7; ts_RowIndex = 7; testCaseIDCounter = 1;
                testStepIDCounter = 1;
            }
        }
Esempio n. 4
0
 public void RunStarted(string name, int testCount)
 {
     SAFEBBALog.Info(CommonUtilities.GetClassAndMethodName());
     failedTestCasesToReRun            += ConfigParameters.PATH_NUNIT_PACKAGE_CONSOLE_EXE;
     SAFEBBALog.TotalNumberOfTestsToRun = testCount;
     SAFEBBALog.PrintApplicationConfigurations();
 }
Esempio n. 5
0
 public void SuiteFinished(TestResult result)
 {
     SAFEBBALog.Info(CommonUtilities.GetClassAndMethodName());
     if (SAFEBBALog.NumberOfExecutedTests == 0 && !isScreenShotTaken)
     {
         CreatScreenShotOnFailure(result);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Used Only wiht JQuery based web runningApplication
 /// </summary>
 public void WaitForAjaxCallToFinish()
 {
     SAFEBBALog.Debug(CommonUtilities.GetClassAndMethodName());
     try
     {
         AjaxCallToFinish();
     }
     catch
     {
         SAFEBBALog.Info(CommonUtilities.GetClassAndMethodName(), "CALLING THE JAVA SCRIPT THE FIST TIME FAILED. TRYING THE ONE MORE TIME");
         AjaxCallToFinish();
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Take a print screen and save the image as .png file.
        /// </summary>
        /// <param name="imageFullPathAndName"></param>
        public static void CreateAndSaveScreenShot(string imageFullPathAndName)
        {
            SAFEBBALog.Debug(GetClassAndMethodName());
            Screen   screen   = Screen.PrimaryScreen;
            Bitmap   bmp      = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
            Graphics graphics = Graphics.FromImage(bmp);

            graphics.CopyFromScreen(0, 0, 0, 0, new Size(screen.Bounds.Width, screen.Bounds.Height));
            bmp.Save(imageFullPathAndName, ImageFormat.Png);
            string imageFullPathAndNameWithoutC    = imageFullPathAndName.Replace("C:", "").Replace("C:", "");
            string imageFullPathAndNameIncludeFile = "file://///" + System.Environment.MachineName + imageFullPathAndNameWithoutC;

            SAFEBBALog.Info("The screenshot is saved: " + imageFullPathAndNameIncludeFile);
        }
Esempio n. 8
0
        /// <summary>
        /// Create a screen shot when a test case fail
        /// The screen shot is saved in
        /// </summary>
        /// <param name="result"></param>
        private void CreatScreenShotOnFailure(TestResult result)
        {
            SAFEBBALog.Info(CommonUtilities.GetClassAndMethodName());
            SAFEBBALog.IsPreviousTestCaseSucceeded = true;
            string fullname = result.FullName;

            if (result.ResultState == ResultState.Error || result.ResultState == ResultState.Failure)
            {
                string testCaseName = result.Name;
                string fullNameWithoutTestCaseName = fullname.Substring(0, (fullname.Length - testCaseName.Length - 1));
                int    startIndexForTestClass      = fullNameWithoutTestCaseName.LastIndexOf(".");
                string testClassName        = fullNameWithoutTestCaseName.Substring(startIndexForTestClass + 1);
                string fullFolderPath       = CommonUtilities.CreateFolder("bin\\Debug\\ScreenShots\\" + testClassName);
                string imageFullPathAndName = fullFolderPath + "\\" + testCaseName + CommonUtilities.GetCurrentDate() + ".png";
                CommonUtilities.CreateAndSaveScreenShot(imageFullPathAndName);

                isScreenShotTaken = true;
                SAFEBBALog.IsPreviousTestCaseSucceeded = false;
                failedTestCasesToReRun += fullname + ",";
            }
        }
Esempio n. 9
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)
            {
                SAFEBBALog.Info("Error Writing data to excel " + ex);
            }
        }
Esempio n. 10
0
 public void TestStarted(TestName testName)
 {
     SAFEBBALog.Info(CommonUtilities.GetClassAndMethodName());
 }
Esempio n. 11
0
 public void SuiteStarted(TestName testName)
 {
     SAFEBBALog.Info(CommonUtilities.GetClassAndMethodName());
     isScreenShotTaken = false;
 }
Esempio n. 12
0
 public void RunFinished(TestResult result)
 {
     SAFEBBALog.Info(CommonUtilities.GetClassAndMethodName());
     createReRunFailesTestCaseFile();
 }
Esempio n. 13
0
 public void RunFinished(Exception exception)
 {
     SAFEBBALog.Info(CommonUtilities.GetClassAndMethodName());
 }
Esempio n. 14
0
 public void TestFinished(TestResult result)
 {
     SAFEBBALog.Info(CommonUtilities.GetClassAndMethodName());
     CreatScreenShotOnFailure(result);
     SAFEBBALog.TestCaseEnd(result);
 }