public void RecordEnd() { if (TestStopwatch == null) { throw new InvalidOperationException("TestReporter.RecordStart() must be called prior to calling TestReporter.RecordEnd()."); } TestStopwatch.Stop(); }
public void AfterTest() { string zaleniumTestStatusCookieValue = string.Empty; try { ResultAdapter result = CurrentContext.Result; List <object> testResults = result.CheckForTestStatusInjection(); testStatus = (TestStatus)testResults[0]; switch (testStatus) { case TestStatus.Failed: string injMsg = (string)testResults[1]; string stacktrace = result.StackTrace.HasValue() ? (injMsg = injMsg.HasValue() ? "" : $"{injMsg}<br> ") : $"<pre>{result.StackTrace}</pre>"; string screenshotName = BaseUtil.CaptureScreenshot(); if (reporter == ReporterType.Klov) { /*Use when Klov Reporter bug is fixed * //Upload screenshot to MongoDB server * var screenshotPath = $"\\\\10.1.1.207\\errorscreenshots\\{screenshotName}"; * testInstance.Fail($"Test Failed: <br> {stacktrace}").AddScreenCaptureFromPath(screenshotPath, screenshotName); */ //Workaround due to bug in Klov Reporter var screenshotRemotePath = $"http://{GridVmIP}/errorscreenshots/{screenshotName}"; var detailsWithScreenshot = $"Test Failed:<br> {stacktrace}<br> <img data-featherlight=\"{screenshotRemotePath}\" class=\"step-img\" src=\"{screenshotRemotePath}\" data-src=\"{screenshotRemotePath}\" width=\"200\">"; testInstance.Fail(MarkupHelper.CreateLabel(detailsWithScreenshot, ExtentColor.Red)); } else { //Attach screenshot to log var screenshotPath = $"errorscreenshots/{screenshotName}"; testInstance.Fail($"Test Failed: <br> {stacktrace}", MediaEntityBuilder.CreateScreenCaptureFromPath(screenshotPath, screenshotName).Build()); } zaleniumTestStatusCookieValue = "false"; break; case TestStatus.Passed: testInstance.Pass(MarkupHelper.CreateLabel("Test Passed", ExtentColor.Green)); zaleniumTestStatusCookieValue = "true"; break; case TestStatus.Skipped: testInstance.Skip(MarkupHelper.CreateLabel("Test Skipped", ExtentColor.Yellow)); break; default: testInstance.Debug(MarkupHelper.CreateLabel("Inconclusive Test Result", ExtentColor.Orange)); break; } TestStopwatch.Stop(); if (hiptest) { var resultDesc = new KeyValuePair <TestStatus, string>(testStatus, testDescription); var tcResultPair = new KeyValuePair <int, KeyValuePair <TestStatus, string> >(int.Parse(testCaseNumber), resultDesc); hipTestResults.Add(tcResultPair); } } catch (Exception e) { log.Error($"Exception occured for Failed TC in AfterTest method {e.Message}"); } finally { try { if (driver != null) { Report.Info($"TOTAL TEST TIME: {TestStopwatch.Elapsed.ToString()}"); reportInstance.Flush(); if (cookie != null) { AddCookieToCurrentPage("zaleniumTestPassed", zaleniumTestStatusCookieValue); } if (!driver.Title.Equals("Home Page")) { driver.FindElement(By.XPath("//a[text()=' Log out']")).Click(); } DismissDriverInstance(driver); } } catch (UnableToSetCookieException e) { log.Debug(e.Message); } catch (NoSuchElementException e) { log.Debug(e.Message); } catch (Exception e) { log.Error($"{e.Message}\n{e.StackTrace}"); } } }