Exemplo n.º 1
0
        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;
                DateTime time           = DateTime.Now;
                string   fileName       = "Screenshot_" + time.ToString("h_mm_ss") + ".png";
                string   screenShotPath = ExtentReport.Capture(_driver, fileName);
                ExtentReport.test.Log(Status.Fail, "Fail");
                ExtentReport.test.Log(Status.Fail, "Snapshot below: " + ExtentReport.test.AddScreenCaptureFromPath("Screenshots\\" + fileName));
                break;

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

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

            default:
                logstatus = Status.Pass;
                break;
            }

            ExtentReport.test.Log(logstatus, "Test ended with " + logstatus + stacktrace);
            _driver.Quit();
        }
        public void GetResult()
        {
            var status       = TestContext.CurrentContext.Result.Outcome.Status;
            var stackTrace   = "<pre>" + TestContext.CurrentContext.Result.StackTrace + "</pre>";
            var errorMessage = TestContext.CurrentContext.Result.Message;

            if (status == TestStatus.Failed)
            {
                string screenShotPath = ExtentReport.Capture(_driver);
                ExtentReport.test.Log(LogStatus.Fail, stackTrace + errorMessage);
                ExtentReport.test.Log(LogStatus.Fail, "Please find the Screenshot below: " + ExtentReport.test.AddScreenCapture(screenShotPath));
            }
            ExtentReport.extent.EndTest(ExtentReport.test);
        }