public void TearDown() { try { if (TestContextInfo.Result.Outcome.Status != TestStatus.Passed) { var screenshotPath = Utils.GeScreenshotFile(TestContextInfo.CurrentContext); DriverUtils.TakeScreenshot(screenshotPath); AddTestAttachment(screenshotPath); Log.GetBrowserLog(); //Add screenshot for extents report extentTest.Fail(MarkupHelper.CreateCodeBlock(TestContextInfo.Result.Message)); extentTest.AddScreenCaptureFromPath(screenshotPath); } AddTestAttachment(Log.LogPath); ExtentTestManager.EndTest(); DriverUtils.CloseDrivers(); } catch (Exception e) { Log.Error(e); extentTest.Error(e); } Log.EndTest(); }
public static void markupCodeblock(string text, Status status) { String code = "\n\t\n\t\t" + text + "\n\t\n"; IMarkup m = MarkupHelper.CreateCodeBlock(code); test.Log(status, m); }
public static void InfoTestMarkup(string text) { String code = " \n\t \n\t\t" + text + "\n\t \n "; IMarkup p = MarkupHelper.CreateCodeBlock(code); scenario.Log(Status.Info, p); }
public void LogExceptionAndFail(Exception e) { // Formats the exception details to look nice var message = e.Message + Environment.NewLine + e.StackTrace.Trim(); var markup = MarkupHelper.CreateCodeBlock(message); Test.Error(markup); throw e; }
protected void TestError(Exception ex) { if (this.CurrentTest != null) { var markup = MarkupHelper.CreateLabel(ex.Message, ExtentColor.Red); var stack = MarkupHelper.CreateCodeBlock(ex.StackTrace); this.CurrentTest.Error(markup); this.CurrentTest.Fatal(stack); } }
public void ParseTestRunnerOutput(string resultsFile) { var doc = XDocument.Load(resultsFile); if (doc.Root == null) { throw new NullReferenceException("Root element not found for " + resultsFile); } AddSystemInformation(doc); var suites = doc .Descendants("test-suite") .Where(x => x.Attribute("type").Value.Equals("TestFixture", StringComparison.CurrentCultureIgnoreCase)); foreach (var ts in suites.ToList()) { var test = _extent.CreateTest(ts.Attribute("name").Value); // any error messages and/or stack-trace var failure = ts.Element("failure"); if (failure != null) { var message = failure.Element("message"); if (message != null) { test.Fail(message.Value); } var stacktrace = failure.Element("stack-trace"); if (stacktrace != null && !string.IsNullOrWhiteSpace(stacktrace.Value)) { test.Fail(MarkupHelper.CreateCodeBlock(stacktrace.Value)); } } var output = ts.Element("output")?.Value; if (!string.IsNullOrWhiteSpace(output)) { test.Info(output); } // get test suite level categories var suiteCategories = ParseTags(ts, false); test.AssignCategory(suiteCategories.ToArray()); // Test Cases foreach (var tc in ts.Descendants("test-case").ToList()) { var node = CreateNode(tc, test); AssignStatusAndMessage(tc, node); AssignTags(tc, node); } } }
public void LogUrlRequest(ExtentTest currentTest, string request, CodeLanguage codeFormat) { //Adds a label for visual purposes var formattedLabel = MarkupHelper.CreateLabel("Request:", ExtentColor.Lime); currentTest.Log(Status.Info, formattedLabel); //Logs the response in the codeFormat var formattedMessage = MarkupHelper.CreateCodeBlock(request, codeFormat); currentTest.Log(Status.Info, formattedMessage); Core.ExtentReport.Flush(); }
private static void AssignStatusAndMessage(XElement tc, ExtentTest test) { var status = StatusExtensions.ToStatus(tc.Attribute("result").Value); // error and other status messages var statusMessage = tc.Element("failure") != null?tc.Element("failure").Element("message").Value.Trim() : string.Empty; statusMessage += tc.Element("failure") != null && tc.Element("failure").Element("stack-trace") != null?tc.Element("failure").Element("stack-trace").Value.Trim() : string.Empty; statusMessage += tc.Element("reason") != null && tc.Element("reason").Element("message") != null?tc.Element("reason").Element("message").Value.Trim() : string.Empty; statusMessage += tc.Element("output") != null?tc.Element("output").Value.Trim() : string.Empty; statusMessage = (status == Status.Fail || status == Status.Error) ? MarkupHelper.CreateCodeBlock(statusMessage).GetMarkup() : statusMessage; statusMessage = string.IsNullOrEmpty(statusMessage) ? status.ToString() : statusMessage; test.Log(status, statusMessage); }
/// <summary> /// Get browser logs and print /// </summary> public void GetBrowserLog() { var logs = DriverUtils.GetBrowserLog(); if (logs != null) { foreach (var log in logs) { if (log.Level != LogLevel.Severe) { continue; } Info($"[URL]: {DriverUtils.CurrentUrl()}", false); Info($"[BROWSER LOG]: {log.Message}", false); ExtentTest?.Info(MarkupHelper.CreateCodeBlock(log.Message)); } } }
public void LogException(Exception ex, [CallerMemberName] string memberName = "") { if (this.CurrentTest != null) { var errorMessage = MarkupHelper.CreateLabel($"Test case for {memberName} is failed. Actual Error : {ex.Message}", ExtentColor.Red); var errorStack = MarkupHelper.CreateCodeBlock(ex.StackTrace); if (ex is AssertFailedException) { this.CurrentTest.Fail(errorMessage); this.CurrentTest.Fatal(errorStack); } else { this.CurrentTest.Error(errorMessage); this.CurrentTest.Fatal(errorStack); } } }
public static void StepInfo(string msg, CodeLanguage formatType) { var formattedMessage = MarkupHelper.CreateCodeBlock(msg, formatType); CurrentTest.Info(formattedMessage); }
private static void Log(LogEventInfo eventInfo) { var logger = Reporter.reporters[0]; string message = ((eventInfo.Message != null) ? eventInfo.Message : eventInfo.Exception.Message); if (eventInfo.CodeBlockType != CodeBlockType.None) { if (logger.CurrentScenarioBlock == logger.CurrentScenario.Given) { if (eventInfo.CodeBlockType == CodeBlockType.Json) { logger.MethodStepGiven.Log(eventInfo.Status, MarkupHelper.CreateCodeBlock(message, CodeLanguage.Json)); } if (eventInfo.CodeBlockType == CodeBlockType.Xml) { logger.MethodStepGiven.Log(eventInfo.Status, MarkupHelper.CreateCodeBlock(message, CodeLanguage.Xml)); } if (eventInfo.CodeBlockType == CodeBlockType.Label) { ExtentColor color = ((eventInfo.Status == Status.Pass) ? ExtentColor.Green : ExtentColor.Grey); logger.MethodStepGiven.Log(eventInfo.Status, MarkupHelper.CreateLabel(message, color)); } } else if (logger.CurrentScenarioBlock == logger.CurrentScenario.When) { if (eventInfo.CodeBlockType == CodeBlockType.Json) { logger.MethodStepWhen.Log(eventInfo.Status, MarkupHelper.CreateCodeBlock(message, CodeLanguage.Json)); } if (eventInfo.CodeBlockType == CodeBlockType.Xml) { logger.MethodStepWhen.Log(eventInfo.Status, MarkupHelper.CreateCodeBlock(message, CodeLanguage.Xml)); } if (eventInfo.CodeBlockType == CodeBlockType.Label) { ExtentColor color = ((eventInfo.Status == Status.Pass) ? ExtentColor.Green : ExtentColor.Grey); logger.MethodStepWhen.Log(eventInfo.Status, MarkupHelper.CreateLabel(message, color)); } } else if (logger.CurrentScenarioBlock == logger.CurrentScenario.Then) { if (eventInfo.CodeBlockType == CodeBlockType.Json) { logger.MethodStepThen.Log(eventInfo.Status, MarkupHelper.CreateCodeBlock(message, CodeLanguage.Json)); } if (eventInfo.CodeBlockType == CodeBlockType.Xml) { logger.MethodStepThen.Log(eventInfo.Status, MarkupHelper.CreateCodeBlock(message, CodeLanguage.Xml)); } if (eventInfo.CodeBlockType == CodeBlockType.Label) { ExtentColor color = ((eventInfo.Status == Status.Pass) ? ExtentColor.Green : ExtentColor.Grey); logger.MethodStepThen.Log(eventInfo.Status, MarkupHelper.CreateLabel(message, color)); } } } else { if (logger.CurrentScenarioBlock == logger.CurrentScenario.Given) { logger.MethodStepGiven.Log(eventInfo.Status, message); } else if (logger.CurrentScenarioBlock == logger.CurrentScenario.When) { logger.MethodStepWhen.Log(eventInfo.Status, message); } else if (logger.CurrentScenarioBlock == logger.CurrentScenario.Then) { logger.MethodStepThen.Log(eventInfo.Status, message); } } }
public static void LogCodeBlock(ExtentTest test, string message, CodeLanguage language = CodeLanguage.Json) { test.Log(Status.Debug, MarkupHelper.CreateCodeBlock(message, language)); }
public static IMarkup MarkupJsonString(this string data) { return(MarkupHelper.CreateCodeBlock(data, CodeLanguage.Json)); }