/// <summary> /// Checks for screenshot. /// </summary> public void CheckForScreenshot() { var scenarioHelper = this.objectContainer.Resolve <IScenarioContextHelper>(); var ex = scenarioHelper.GetError(); if (ex == null) { return; } LogDebug(() => ex.GetType().Name + ": " + ex.Message); var fileName = scenarioHelper.GetStepFileName(); var basePath = Directory.GetCurrentDirectory(); var fullPath = browser.TakeScreenshot(basePath, fileName); browser.SaveHtml(basePath, fileName); var traceListener = this.objectContainer.Resolve <ITraceListener>(); if (fullPath != null && traceListener != null) { traceListener.WriteTestOutput("Created Error Screenshot: {0}", fullPath); } try { browser.Close(dispose: true); } finally { browser = null; } }
void InitializeScreenshotMessagesSubscription() { MemoryMappedFile rScreenshotMMF = null; r_Messages.Subscribe(CommunicatorMessages.TakeScreenshot, r => { try { var rScreenshotData = r_Browser.TakeScreenshot(); if (rScreenshotData == null || rScreenshotData.BitmapData == null) { r_Communicator.Write(CommunicatorMessages.ScreenshotFail + ":" + StringResources.Instance.Main.Log_Screenshot_Failed_NoData); rScreenshotMMF = null; return; } var rMapName = "HeavenlyWind/ScreenshotTransmission/" + r.ToString(); var rMemoryMappedFile = MemoryMappedFile.CreateNew(rMapName, rScreenshotData.BitmapData.Length, MemoryMappedFileAccess.ReadWrite); using (var rStream = rMemoryMappedFile.CreateViewStream()) rStream.Write(rScreenshotData.BitmapData, 0, rScreenshotData.BitmapData.Length); r_Communicator.Write(CommunicatorMessages.StartScreenshotTransmission + $":{rMapName};{rScreenshotData.Width};{rScreenshotData.Height};{rScreenshotData.BitCount}"); rScreenshotMMF = rMemoryMappedFile; } catch (Exception e) { r_Communicator.Write($"{CommunicatorMessages.ScreenshotFail}:{r};{e.Message}"); rScreenshotMMF = null; try { using (var rStreamWriter = new StreamWriter(Logger.GetNewExceptionLogFilename(), false, new UTF8Encoding(true))) { rStreamWriter.WriteLine("Screenshot error"); rStreamWriter.WriteLine(); rStreamWriter.WriteLine(e.ToString()); } } catch { } } }); r_Messages.Subscribe(CommunicatorMessages.FinishScreenshotTransmission, delegate { if (rScreenshotMMF != null) { rScreenshotMMF.Dispose(); rScreenshotMMF = null; } }); }
/// <summary> /// Checks for screenshot. /// </summary> public void CheckForScreenshot() { if ((browser == null) || (!browser.IsCreated)) { return; } var scenarioHelper = this.objectContainer.Resolve <IScenarioContextHelper>(); var ex = scenarioHelper.GetError(); var isError = false; if (ex == null) { if (!browserFactory.Configuration.CreateScreenshotOnExit) { return; } } else { isError = true; LogDebug(() => $"{ex.GetType().Name}: {ex.Message}"); } var fileName = scenarioHelper.GetStepFileName(isError); var basePath = Directory.GetCurrentDirectory(); browser.SaveHtml(basePath, fileName); string fullPath = browser.TakeScreenshot(basePath, fileName); if (fullPath != null) { var traceListener = this.objectContainer.Resolve <ITraceListener>(); if (traceListener != null) { traceListener.WriteTestOutput("Created Screenshot: {0}", fullPath); } } try { browser.Close(dispose: true); } finally { browser = null; } }
/// <summary> /// Checks for screenshot. /// </summary> /// <param name="browser">The browser.</param> private void CheckForScreenshot(IBrowser browser) { var scenarioHelper = this.objectContainer.Resolve <IScenarioContextHelper>(); if (scenarioHelper.GetError() == null) { return; } var fileName = scenarioHelper.GetStepFileName(); var basePath = Directory.GetCurrentDirectory(); var fullPath = browser.TakeScreenshot(basePath, fileName); browser.SaveHtml(basePath, fileName); var traceListener = this.objectContainer.Resolve <ITraceListener>(); if (fullPath != null && traceListener != null) { traceListener.WriteTestOutput("Created Error Screenshot: {0}", fullPath); } }
/// <summary> /// Checks for screenshot. /// </summary> /// <param name="browser">The browser.</param> private void CheckForScreenshot(IBrowser browser) { var scenarioHelper = this.objectContainer.Resolve<IScenarioContextHelper>(); if (scenarioHelper.GetError() == null) { return; } var fileName = scenarioHelper.GetStepFileName(); var basePath = Directory.GetCurrentDirectory(); var fullPath = browser.TakeScreenshot(basePath, fileName); var traceListener = this.objectContainer.Resolve<ITraceListener>(); if (fullPath != null && traceListener != null) { traceListener.WriteTestOutput("Created Error Screenshot: {0}", fullPath); } }
public string TakeScreenshot(string imageFolder, string fileNameBase) { return(browser.TakeScreenshot(imageFolder, fileNameBase)); }