Example #1
0
        public void AfterTest()
        {
            _test.Log(Status.Debug, "Old website loading time: " + oldTime.Elapsed);
            _test.Log(Status.Debug, "New website loading time: " + newTime.Elapsed);

            var status     = TestContext.CurrentContext.Result.Outcome.Status;
            var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.Message)
                    ? ""
                    : string.Format("{0}", TestContext.CurrentContext.Result.Message);
            Status logstatus;

            switch (status)
            {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                string oldScreenShotPath = GetScreenShot.Capture(OldSiteDriver, this.GetType().ToString() + "OldSiteScreenShot");
                string newScreenShotPath = GetScreenShot.Capture(NewSiteDriver, this.GetType().ToString() + "NewSiteScreenShot");
                _test.Log(Status.Debug, "Old website snapshot below: " + _test.AddScreenCaptureFromPath(oldScreenShotPath));
                _test.Log(Status.Debug, "New website snapshot below: " + _test.AddScreenCaptureFromPath(newScreenShotPath));
                break;

            case TestStatus.Inconclusive:
                logstatus = Status.Warning;
                break;

            case TestStatus.Skipped:
                logstatus = Status.Skip;
                break;

            default:
                logstatus = Status.Pass;
                break;
            }
            _test.Log(logstatus, "Test ended with " + logstatus + Environment.NewLine + stacktrace);
        }
        public void LogAddScrren(IWebDriver driver, String name)
        {
            string screenShotPath1;

            screenShotPath1 = Capture(driver, "errorScreen");
            _test.Log(Status.Error, name + _test.AddScreenCaptureFromPath(screenShotPath1));
        }
        public void AddTestResultAndQuitBrowser()
        {
            string testName = TestContext.CurrentContext.Test.Name;

            TestStatus status = TestContext.CurrentContext.Result.Outcome.Status;

            if (status == TestStatus.Failed)
            {
                var stackTrace   = "<pre>" + TestContext.CurrentContext.Result.StackTrace + "</pre>";
                var errorMessage = TestContext.CurrentContext.Result.Message;
                TakeScreenShot(testName);
                test.Log(Status.Fail, stackTrace + errorMessage);
                test.Log(Status.Fail, "Failed - Snapshot below:");
                test.AddScreenCaptureFromPath(screenShotPath, title: testName);
            }
            else if (status == TestStatus.Passed)
            {
                TakeScreenShot(testName);
                test.Log(Status.Pass, "Passed - Snapshot below:");
                test.AddScreenCaptureFromPath(screenShotPath, title: testName);
            }
            else if (status == TestStatus.Skipped)
            {
                test.Log(Status.Skip, "Skipped - " + testName);
            }
            driver.Quit();
        }
        public void AfterStep(ScenarioContext context)
        {
            if (context.TestError == null)
            {
                _step.Log(Status.Pass, "<U><h4 style='color: orange'>" + context.StepContext.StepInfo.StepDefinitionType + "</h4></U> ::   " + context.StepContext.StepInfo.Text);

                if (context.StepContext.Keys.Count > 0)
                {
                    foreach (var result in context.StepContext)
                    {
                        _step.Log(Status.Info, result.Value.ToString());
                    }
                }

                if (context.StepContext.StepInfo.Text.Contains("displayed in output"))
                {
                    var listOfResults = context.Get <IList <string> >("ResultTitles");
                    _step.Log(Status.Info, "----------------------------------List Of Search Titles-------------------------------");
                    foreach (var item in listOfResults)
                    {
                        _step.Log(Status.Info, item);
                    }
                    _step.Log(Status.Info, "------------------------------------------------------------------------------------");
                    var path = GenericHelper.TakeScreenshot("ResultTitles");
                    _scenario.AddScreenCaptureFromPath(path);
                }
            }
            else if (context.TestError != null)
            {
                _step.Log(Status.Fail, "<U><h4 style='color: orange'>" + context.StepContext.StepInfo.StepDefinitionType + "</h4></U> ::   " + context.StepContext.StepInfo.Text);
                _step.Log(Status.Info, context.TestError.Message);
                var path = GenericHelper.TakeScreenshot(context.ScenarioInfo.Title);
                _scenario.AddScreenCaptureFromPath(path);
            }
        }
Example #5
0
        public void ExtentFlush()
        {
            test = extent.CreateTest(TestContext.CurrentContext.Test.Name).Info("Test Started");
            var error = TestContext.CurrentContext.Result.Message;

            if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
            {
                test.Log(Status.Info, error);
                string path = Screenshot.Capture(driver, TestContext.CurrentContext.Test.Name + "   " + "Failed");
                test.AddScreenCaptureFromPath(path);
                test.Fail(MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name, ExtentColor.Red));
                test.Log(Status.Fail, "Test Failed");
                log.Error("Test Failed");
                SendEmailMain.SendEmail(error, TestContext.CurrentContext.Result.StackTrace);
            }
            else if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed)
            {
                string path = Screenshot.Capture(driver, TestContext.CurrentContext.Test.Name);
                test.AddScreenCaptureFromPath(path);
                test.Pass(MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name, ExtentColor.Green));
                test.Log(Status.Pass, "Test pass");
            }
            driver.Navigate().Refresh(); // every test must refresh the webpage ..use in negative test
            extent.Flush();
        }
 public void Close()
 {
     try
     {
         test = extent.CreateTest(TestContext.CurrentContext.Test.Name);
         if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
         {
             string path = Utility.TakeScreenshot(driver, TestContext.CurrentContext.Test.Name);
             test.Log(Status.Fail, "Test Failed");
             test.AddScreenCaptureFromPath(path);
             test.Fail(MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name, ExtentColor.Red));
         }
         else if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed)
         {
             string path = Utility.TakeScreenshot(driver, TestContext.CurrentContext.Test.Name);
             test.Log(Status.Pass, "Test Sucessful");
             test.AddScreenCaptureFromPath(path);
             test.Pass(MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name, ExtentColor.Green));
         }
     }
     catch (Exception e)
     {
         throw e;
     }
     driver.Navigate().Refresh();
     Thread.Sleep(5000);
     extent.Flush();
 }
        public void CleansUp()
        {

            try
            {
                var status = TestContext.CurrentContext.Result.Outcome.Status;
                var stacktrace = "stackTrace" + TestContext.CurrentContext.Result.StackTrace + "stackTrace";
                var errorMessage = TestContext.CurrentContext.Result.Message;
                Status logstatus;
                switch (status)
                {
                    case TestStatus.Failed:
                        logstatus = Status.Fail;
                        //string screenShotPath = Helper.Capture1(driver, TestContext.CurrentContext.Test.Name);
                        test.Log(logstatus, "Test ended with " + logstatus + " – " + errorMessage);
                        test.Log(logstatus, "Snapshot below: " + test.AddScreenCaptureFromPath(Capture(driver, "SSS")));
                        break;
                    case TestStatus.Skipped:
                        logstatus = Status.Skip;
                        test.Log(logstatus, "Test ended with " + logstatus);
                        break;
                    default:
                        logstatus = Status.Pass;
                        test.Log(logstatus, "Test ended with " + logstatus);
                        test.Log(logstatus, "Snapshot below: " + test.AddScreenCaptureFromPath(Capture(driver, "SSS")));
                        break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw (e);
            }

        }
        public void insertLog(ExtentTest test, IWebDriver driver, checkResult result, bool takeScreenShot)
        {
            String screenShotPath = String.Empty;

            if (takeScreenShot)
            {
                screenShotPath = Capture((ChromeDriver)driver);
            }
            if (result.logType == LogType.FAIL)
            {
                test.Log(Status.Fail, "Fail : " + result.log);
                if (takeScreenShot)
                {
                    test.AddScreenCaptureFromPath(screenShotPath);
                }
            }
            else if (result.logType == LogType.SUCCESS)
            {
                test.Log(Status.Pass, "Success : " + result.log);
                if (takeScreenShot)
                {
                    test.AddScreenCaptureFromPath(screenShotPath);
                }
            }
            else if (result.logType == LogType.WARNING)
            {
                test.Log(Status.Warning, "Warning : " + result.log);
                if (takeScreenShot)
                {
                    test.AddScreenCaptureFromPath(screenShotPath);
                }
            }
            else if (result.logType == LogType.INFO)
            {
                test.Log(Status.Info, "Info : " + result.log);
                if (takeScreenShot)
                {
                    test.AddScreenCaptureFromPath(screenShotPath);
                }
            }
            else if (result.logType == LogType.FATAL)
            {
                test.Log(Status.Fatal, "Fatal (Exception) : " + result.log);
                if (takeScreenShot)
                {
                    test.AddScreenCaptureFromPath(screenShotPath);
                }
            }
        }
Example #9
0
 public void ExtentFlush()
 {
     try
     {
         test = extent.CreateTest(TestContext.CurrentContext.Test.Name).Info("Test Started");
         var error = TestContext.CurrentContext.Result.Message;
         if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
         {
             log.Error(TestContext.CurrentContext.Test.Name + "Failed");
             test.Log(Status.Info, error);
             string path = Screenshot.Capture(driver, TestContext.CurrentContext.Test.Name + "   " + "Failed");
             test.AddScreenCaptureFromPath(path);
             test.Fail(MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name, ExtentColor.Red));
             test.Log(Status.Fail, "Test Failed");
             log.Error("Test Failed");
             SendEmailMain.SendEmail(error, TestContext.CurrentContext.Result.StackTrace);
         }
         else if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed)
         {
             log.Info(TestContext.CurrentContext.Test.Name + "Passed");
             test.Pass(MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name, ExtentColor.Green));
             test.Log(Status.Pass, "Test pass");
             log.Info(TestContext.CurrentContext.Test.Name + "Test Completed");
         }
         extent.Flush();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Example #10
0
        /*----------------------------------------------------------------------------------------------------*/
        /// <author>Justinas Abramavicius</author>                                           <date>2019 10</date>
        /// <summary>
        /// Reports test outcome to html reporter
        /// </summary>
        /*--------------+---------------+---------------+---------------+---------------+---------------+------*/
        protected void ReportTestOutcome()
        {
            var    status       = TestContext.CurrentContext.Result.Outcome.Status;
            var    errorMessage = TestContext.CurrentContext.Result.Message;
            Status logstatus;
            string outcome = "Test outcome - ";

            switch (status)
            {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                string screenShotPath = new Uri(ScreenShotPath).LocalPath;
                Test.Log(logstatus, outcome + logstatus + " – " + errorMessage);
                Test.Log(logstatus, "Snapshot below: " + Test.AddScreenCaptureFromPath(screenShotPath));
                break;

            case TestStatus.Skipped:
                logstatus = Status.Skip;
                Test.Log(logstatus, outcome + logstatus);
                break;

            default:
                logstatus = Status.Pass;
                Test.Log(logstatus, outcome + logstatus);
                break;
            }
        }
Example #11
0
        public void ValidateLoginWithValidCredentials()
        {
            String expected = "Unity - Game Engine";

            test = extent.CreateTest("Validate Login With Valid Credentials",
                                     "When user enters valid credentials, user should navigate to home page.");
            loginPage = new LoginPage(driver, test);

            try
            {
                loginPage.EnterUserName("pravin");
                loginPage.EnterPassword("pravin");
                loginPage.ClickLogin();
                String actual = loginPage.GetTitle();

                test.AddScreenCaptureFromPath(TakeScreenshot(driver));
                Assert.AreEqual(expected, actual, "Page Navigated to Home Page.");
                addTestCaseStatus("Pass", testcaseID, "Test Case Passed");
                test.Pass("User navigated to home page.");
            }
            catch (AssertionException)
            {
                addTestCaseStatus("Fail", testcaseID, "Test Case Failed");
                test.Fail("User did navigate to home page.");
                throw;
            }
        }
Example #12
0
        public void close()
        {
            try
            {
                Utility.InternetConnection();
                test = extent.CreateTest(TestContext.CurrentContext.Test.Name);
                if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
                {
                    string path = Utility.TakeScreenshot(driver, TestContext.CurrentContext.Test.Name);
                    test.Log(Status.Fail, "Test Failed");
                    test.AddScreenCaptureFromPath(path);
                    test.Fail(MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name, ExtentColor.Red));
                }
                else if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed)
                {
                    test.Log(Status.Pass, "Test Sucessful");
                    test.Pass(MarkupHelper.CreateLabel(TestContext.CurrentContext.Test.Name, ExtentColor.Green));
                }

                Utility.SendEmail();
            }
            catch (Exception e)
            {
                log.Error("error: " + e);
                Console.Out.WriteLine(e.StackTrace);
                Console.Out.WriteLine(e.Message);
            }

            Thread.Sleep(5000);
            extent.Flush();
        }
Example #13
0
        public void DragAndDropTest()
        {
            test = extent.CreateTest("Create new Post").Info("Test Started");
            driver.Manage().Window.Maximize();

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            driver.Url = "http://www.dhtmlgoodies.com/scripts/drag-drop-custom/demo-drag-drop-3.html";


            IWebElement source = driver.FindElement(By.XPath("//body//div[14]")); // take source postion to drop

            Thread.Sleep(2000);

            IWebElement dest = driver.FindElement(By.XPath("//div[contains(text(),'United States')]")); // drop to destination

            Thread.Sleep(2000);

            Actions action = new Actions(driver); // actions class

            //  action.ClickAndHold(source).MoveToElement(dest).Release().Build().Perform();
            //  Thread.Sleep(2000);
            //user will click and hold source position then move to dest postion and release to that postion

            //Another method to drap and drop
            action.DragAndDrop(source, dest).Build().Perform();
            Thread.Sleep(2000);
            String path = Screenshot.Capture(driver, "DragAndDropTest");

            test.AddScreenCaptureFromPath(path);
            test.Log(Status.Info, "Chrome Browser Launched");


            driver.Quit();
        }
Example #14
0
        public static void AfterTest()
        {
            var    status       = TestContext.CurrentContext.Result.Outcome.Status;
            var    stacktrace   = "" + TestContext.CurrentContext.Result.StackTrace + "";
            var    errorMessage = TestContext.CurrentContext.Result.Message;
            Status logstatus;

            switch (status)
            {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                string screenShotPath = Capture(Globalclass.driver, TestContext.CurrentContext.Test.Name);
                _test.Log(logstatus, "Test ended with " + logstatus + " – " + errorMessage);
                _test.Log(logstatus, "Snapshot below: " + _test.AddScreenCaptureFromPath(screenShotPath));
                break;

            case TestStatus.Skipped:
                logstatus = Status.Skip;
                _test.Log(logstatus, "Test ended with " + logstatus);
                break;

            default:
                logstatus = Status.Pass;
                _test.Log(logstatus, "Test ended with " + logstatus);
                break;
            }
        }
Example #15
0
        public void ValidateLoginWithoutCredentials()
        {
            String expected = "Please enter at least 5 characters.";

            test = extent.CreateTest("Validate Login Without Credentials",
                                     "When user enters no credentials, user should be displayed with error message.");
            loginPage = new LoginPage(driver, test);

            try
            {
                loginPage.EnterUserName("p");

                String actual = loginPage.GetUserNameError();

                test.AddScreenCaptureFromPath(TakeScreenshot(driver));
                Assert.AreEqual(expected, actual, "User displayed with error message.");
                addTestCaseStatus("Pass", testcaseID, "Test Case Passed");
                test.Pass("User displayed with error message.");
            }
            catch (AssertionException)
            {
                addTestCaseStatus("Fail", testcaseID, "Test Case Failed");
                test.Fail("User is not displayed with error message.");
                throw;
            }
        }
Example #16
0
        public static void ReportTestOutcome(string screenshotPath)
        {
            var status       = TestContext.CurrentContext.Result.Outcome.Status;
            var errorMessage = TestContext.CurrentContext.Result.Message;

            switch (status)
            {
            case TestStatus.Failed:
                ExtentTest.Log(Status.Fail, "Test Failed <br/>" + errorMessage);
                ExtentTest.AddScreenCaptureFromPath(screenshotPath);
                break;

            case TestStatus.Inconclusive:
                ExtentTest.AddScreenCaptureFromPath(screenshotPath);
                ExtentTest.Warning("Inconclusive");
                break;

            case TestStatus.Skipped:
                ExtentTest.Skip("Test Skipped");
                break;

            case TestStatus.Passed:
                ExtentTest.Pass("Test Passed");
                break;

            default:
                ExtentTest.Pass("Test Passed");
                break;
            }
            ReportManager.Flush();
        }
Example #17
0
 public void reportFail(ExtentReports extent, string reportName, ExtentTest test)
 {
     test = extent.CreateTest("Fail Test");
     test.Log(Status.Fail, "test failed" + test.AddScreenCaptureFromPath(reportName));
     // extent.AttachReporter(test);
     extent.Flush();
 }
        public void TestCaseResult(ExtentTest test, ExtentReports extent, IWebDriver driver)
        {
            var status     = TestContext.CurrentContext.Result.Outcome.Status;
            var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace)
            ? "" : string.Format("{0}", TestContext.CurrentContext.Result.StackTrace);
            Status logstatus;

            switch (status)
            {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                DateTime time     = DateTime.Now;
                String   fileName = "Screenshot_" + time.ToString("h_mm_ss") + ".png";
                Capture(driver, fileName);
                test.Log(Status.Fail, "Fail");
                test.Log(Status.Fail, "Snapshot below: " + test.AddScreenCaptureFromPath("Screenshots\\" + fileName));
                break;

            case TestStatus.Inconclusive:
                logstatus = Status.Warning;
                break;

            case TestStatus.Skipped:
                logstatus = Status.Skip;
                break;

            default:
                logstatus = Status.Pass;
                break;
            }
            test.Log(logstatus, "Test ended with " + logstatus + stacktrace);
            extent.Flush();
        }
Example #19
0
 public static void AddScreenCaptureFromPath(string imageFullFilePath)
 {
     if (step != null)
     {
         step.AddScreenCaptureFromPath(imageFullFilePath);
     }
 }
        public void StopTest()
        {
            var    status            = TestContext.CurrentContext.Result.Outcome.Status;
            var    testCaseArguments = TestContext.CurrentContext.Test.Arguments;
            var    keyword           = testCaseArguments[0];
            var    expectedTitle     = testCaseArguments[1];
            string screenshotPath    = Capture(driver, keyword.ToString());

            if (status == TestStatus.Failed)
            {
                if (!isTestPassed)
                {
                    test.Log(Status.Fail, $"<strong>Test Case Failed due to dependency on a previous test.</strong>");
                }
                else
                {
                    test.Log(Status.Fail, $"<strong>Test Case Failed.</strong><br />Expected Title : {expectedTitle}, but was: {driver.Title}");
                    isTestPassed = false;
                }
            }
            else
            {
                test.Log(Status.Pass, $"<strong>Test Case Passed.</strong>");
                isTestPassed = true;
            }
            test.AddScreenCaptureFromPath(screenshotPath, keyword.ToString());
            extentReport.Flush();
        }
Example #21
0
        /// <summary>
        /// Método responsável por finalizar o relatório de teste.
        /// </summary>
        /// <param name="driver">Driver atual.</param>
        public static void FinalizaRelatorio(IWebDriver driver)
        {
            try
            {
                var    status       = TestContext.CurrentContext.Result.Outcome.Status;
                var    stacktrace   = "" + TestContext.CurrentContext.Result.StackTrace + "";
                var    errorMessage = TestContext.CurrentContext.Result.Message;
                Status logstatus;
                switch (status)
                {
                case TestStatus.Failed:
                    logstatus = Status.Fail;
                    string screenShotPath = CapturaImagensHelper.CapturaPrintTela(driver, TestContext.CurrentContext.Test.Name);
                    _test.Log(logstatus, "Test ended with " + logstatus + " – " + errorMessage);
                    _test.Log(logstatus, "Snapshot below: " + _test.AddScreenCaptureFromPath(screenShotPath));
                    break;

                case TestStatus.Skipped:
                    logstatus = Status.Skip;
                    _test.Log(logstatus, "Test ended with " + logstatus);
                    break;

                default:
                    logstatus = Status.Pass;
                    _test.Log(logstatus, "Test ended with " + logstatus);
                    break;
                }
            }
            catch (Exception)
            {
                throw new Exception("Não foi possível finalizar o relatório");
            }
        }
        public void AfterTest()
        {
            var status     = TestContext.CurrentContext.Result.Outcome.Status;
            var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace)
            ? "": string.Format("{0}", TestContext.CurrentContext.Result.StackTrace);
            Status logstatus;

            switch (status)
            {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                String fileName       = "Screenshot_" + DateTime.Now.ToString("h_mm_ss") + ".png";
                String screenShotPath = Capture((ChromeDriver)_driver);
                _test.Log(Status.Fail, "Fail");
                _test.Log(Status.Fail, "Snapshot below: " + _test.AddScreenCaptureFromPath("Screenshots\\" + fileName));
                break;

            case TestStatus.Inconclusive:
                logstatus = Status.Warning;
                break;

            case TestStatus.Skipped:
                logstatus = Status.Skip;
                break;

            default:
                logstatus = Status.Pass;
                break;
            }
            _test.Log(logstatus, "Test ended with " + logstatus + stacktrace);
            _extent.Flush();
            _sr.StopRecording();
        }
Example #23
0
        public void Destroy()
        {
            var status     = TestContext.CurrentContext.Result.Outcome.Status;
            var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace)
                    ? ""
                    : string.Format("{0}", TestContext.CurrentContext.Result.StackTrace);
            Status logstatus;

            switch (status)
            {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                String fileName = "Screenshot_" + DateTime.Now.ToString("HHmmss") + ".png";
                Capture(Browser.Driver, fileName);
                _test.Log(Status.Fail, "Fail");
                _test.Log(Status.Fail, "Snapshot below: " + _test.AddScreenCaptureFromPath($@"{_projectPath}\Screenshots\{fileName}"));
                break;

            case TestStatus.Inconclusive:
                logstatus = Status.Warning;
                break;

            case TestStatus.Skipped:
                logstatus = Status.Skip;
                break;

            default:
                logstatus = Status.Pass;
                break;
            }

            _test.Log(logstatus, $"Test ended with {logstatus} {stacktrace}");

            Browser.Destroy();
        }
Example #24
0
        public void CloseReport(IWebDriver driver, ExtentTest test, bool screenshot = false)
        {
            //StackTrace details for failed Testcases
            var status     = NUnit.Framework.TestContext.CurrentContext.Result.Outcome.Status;
            var message    = NUnit.Framework.TestContext.CurrentContext.Result.Message;
            var stackTrace = "<pre>" + NUnit.Framework.TestContext.CurrentContext.Result.StackTrace + "</pre>";

            if (status == TestStatus.Failed)
            {
                if (screenshot == true)
                {
                    string screenShotPath = Capture(driver, "ScreenShotName");
                    test.Log(Status.Fail, "Snapshot below: " + test.AddScreenCaptureFromPath(screenShotPath));
                }
                test.Log(Status.Fail, stackTrace + " : " + message);
                extent.Flush();
            }
            else if (status == TestStatus.Skipped)
            {
                //test.Log(Status.Info, "Test case Skipped");
                test.Log(Status.Skip, message);
                extent.Flush();
            }
            else if (status == TestStatus.Passed)
            {
                test.Log(Status.Info, "Test case passed");
                test.Log(Status.Pass, message);
                extent.Flush();
            }
        }
        public void CreateReport()
        {
            try
            {
                var    status       = TestContext.CurrentContext.Result.Outcome.Status;
                var    stacktrace   = "" + TestContext.CurrentContext.Result.StackTrace + "";
                var    errorMessage = TestContext.CurrentContext.Result.Message;
                Status logstatus;
                switch (status)
                {
                case TestStatus.Failed:
                    logstatus = Status.Fail;
                    string screenShotPath = Capture((IWebDriver)Application.Session.Browser, TestContext.CurrentContext.Test.Name);
                    _test.Log(logstatus, "Test ended with " + logstatus + " – " + errorMessage);
                    _test.Log(logstatus, "Snapshot below: " + _test.AddScreenCaptureFromPath(screenShotPath));
                    break;

                case TestStatus.Skipped:
                    logstatus = Status.Skip;
                    _test.Log(logstatus, "Test ended with " + logstatus);
                    break;

                default:
                    logstatus = Status.Pass;
                    _test.Log(logstatus, "Test ended with " + logstatus);
                    break;
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
            _extent.Flush();
        }
Example #26
0
        public void TearDown()
        {
            Console.WriteLine("TearDown method in base is called");
            try
            {
                var    status       = TestContext.CurrentContext.Result.Outcome.Status;
                var    stacktrace   = "" + TestContext.CurrentContext.Result.StackTrace + "";
                var    errorMessage = TestContext.CurrentContext.Result.Message + "\n" + stacktrace;
                Status logstatus;
                switch (status)
                {
                case TestStatus.Failed:
                    logstatus = Status.Fail;
                    string screenShotPath = Utilities.Utility.Capture(driver, TestContext.CurrentContext.Test.Name);
                    _test.Log(logstatus, "Test ended with " + logstatus + " – " + errorMessage);
                    _test.Log(logstatus, "Snapshot below: " + _test.AddScreenCaptureFromPath(screenShotPath));
                    break;

                case TestStatus.Skipped:
                    logstatus = Status.Skip;
                    _test.Log(logstatus, "Test ended with " + logstatus);
                    break;

                default:
                    logstatus = Status.Pass;
                    _test.Log(logstatus, "Test ended with " + logstatus);
                    break;
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
        public void CloseReport(RemoteWebDriver driver, string status, bool screenshot = true)
        {
            //StackTrace details for failed Testcases
            var message    = NUnit.Framework.TestContext.CurrentContext.Result.Message;
            var stackTrace = "<pre>" + NUnit.Framework.TestContext.CurrentContext.Result.StackTrace + "</pre>";

            if (status == "Failed")
            {
                test.Log(Status.Fail, "Test case failed" + "\n");
                if (screenshot == true)
                {
                    string screenShotPath = Capture(driver, "ScreenShotName");
                    test.Log(Status.Info, "Snapshot below: " + test.AddScreenCaptureFromPath(screenShotPath));
                }
                test.Log(Status.Info, stackTrace);
            }
            else if (status == "Passed")
            {
                test.Log(Status.Pass, "Test case passed");
            }
            else
            {
                test.Log(Status.Info, "Test case Skipped");
            }
        }
Example #28
0
 public void AfterTest()
 {
     try
     {
         var status = TestContext.CurrentContext.Result.Outcome.Status;
         var stacktrace = “” +TestContext.CurrentContext.Result.StackTrace + “”;
         var errorMessage = TestContext.CurrentContext.Result.Message;
         Status logstatus;
         switch (status)
         {
             case TestStatus.Failed:
                 logstatus = Status.Fail;
                 string screenShotPath = Capture(driver, TestContext.CurrentContext.Test.Name);
                 _test.Log(logstatus, “Test ended with ” +logstatus + ” – ” +errorMessage);
                 _test.Log(logstatus, “Snapshot below: ” +_test.AddScreenCaptureFromPath(screenShotPath));
                 break;
             case TestStatus.Skipped:
                 logstatus = Status.Skip;
                 _test.Log(logstatus, “Test ended with ” +logstatus);
                 break;
             default:
                 logstatus = Status.Pass;
                 _test.Log(logstatus, “Test ended with ” +logstatus);
                 break;
         }
     }
     catch (Exception e)
     {
         throw (e);
     }
 }
Example #29
0
        public void ExtentClose()
        {
            var    status     = TestContext.CurrentContext.Result.Outcome.Status;
            var    stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace) ? "" : string.Format("{0}", TestContext.CurrentContext.Result.StackTrace);
            Status logstatus;

            switch (status)
            {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                DateTime time           = DateTime.Now;
                string   fileName       = "Screenshot_" + DateTime.Now.ToString("_MMddyyyy_hhmmtt") + ".png";
                string   screenShotPath = Capture(TestBase.GetDriver(), fileName);
                Console.WriteLine($"Screenshot has been captured at {screenShotPath}");
                test.Log(Status.Fail, "Fail");
                test.Log(Status.Fail, "Snapshot below: " + test.AddScreenCaptureFromPath(System.AppDomain.CurrentDomain.BaseDirectory + "../../TestReport" + fileName));
                break;

            case TestStatus.Inconclusive:
                logstatus = Status.Warning;
                break;

            case TestStatus.Skipped:
                logstatus = Status.Skip;
                break;

            default:
                logstatus = Status.Pass;
                break;
            }
            test.Log(logstatus, "Test ended with " + logstatus + stacktrace);
            extent.Flush();
        }
        public void afterTest()
        {
            var status     = TestContext.CurrentContext.Result.Outcome.Status;
            var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace)
                    ? ""
                    : string.Format("{0}", TestContext.CurrentContext.Result.StackTrace);
            Status logstatus;
            string screenShotPath = Capture(TestContext.CurrentContext.Test.Name);

            switch (status)
            {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                test.Log(Status.Fail, "Fail");
                break;

            case TestStatus.Inconclusive:
                logstatus = Status.Warning;
                break;

            case TestStatus.Skipped:
                logstatus = Status.Skip;
                break;

            default:
                logstatus = Status.Pass;
                break;
            }
            //seleDriver.Quit();
            test.Log(logstatus, "Test ended with " + logstatus + stacktrace);
            test.Log(logstatus, "Snapshot below: " + test.AddScreenCaptureFromPath(screenShotPath));
            extent.Flush();
        }