public void TestCheckForScreenshotWithErrorTakesSueccessfulScreenshot() { var listener = new Mock <ITraceListener>(MockBehavior.Strict); listener.Setup(l => l.WriteTestOutput(It.Is <string>(s => s.Contains("TestFileName.jpg")))); var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict); scenarioContext.Setup(s => s.GetError()).Returns(new InvalidOperationException()); scenarioContext.Setup(s => s.GetStepFileName(true)).Returns("TestFileName"); var browser = new Mock <IBrowser>(MockBehavior.Strict); browser.Setup(b => b.TakeScreenshot(It.IsAny <string>(), "TestFileName")).Returns("TestFileName.jpg"); browser.Setup(b => b.SaveHtml(It.IsAny <string>(), "TestFileName")).Returns((string)null); browser.Setup(b => b.Close(true)); browser.Setup(b => b.IsCreated).Returns(true); var container = new Mock <IObjectContainer>(MockBehavior.Strict); container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object); container.Setup(c => c.Resolve <ITraceListener>()).Returns(listener.Object); WebDriverSupport.Browser = browser.Object; var driverSupport = new WebDriverSupport(container.Object); driverSupport.CheckForScreenshot(); container.VerifyAll(); browser.VerifyAll(); scenarioContext.VerifyAll(); listener.VerifyAll(); }
public void TestCheckForScreenshotWithErrorAttemptsScreenshotButListenerIsUnavailable() { var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict); scenarioContext.Setup(s => s.GetError()).Returns(new InvalidOperationException()); scenarioContext.Setup(s => s.GetStepFileName()).Returns("TestFileName"); var browser = new Mock <IBrowser>(MockBehavior.Strict); browser.Setup(b => b.TakeScreenshot(It.IsAny <string>(), "TestFileName")).Returns((string)null); browser.Setup(b => b.SaveHtml(It.IsAny <string>(), "TestFileName")).Returns((string)null); browser.Setup(b => b.Close(true)); var container = new Mock <IObjectContainer>(MockBehavior.Strict); container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object); container.Setup(c => c.Resolve <ITraceListener>()).Returns((ITraceListener)null); WebDriverSupport.Browser = browser.Object; var driverSupport = new WebDriverSupport(container.Object); driverSupport.CheckForScreenshot(); container.VerifyAll(); browser.VerifyAll(); scenarioContext.VerifyAll(); }
public void TestCheckForScreenshotWithNoErrorButSettingEnabledTakesSuccessfulScreenshot() { var listener = new Mock <ITraceListener>(MockBehavior.Strict); listener.Setup(l => l.WriteTestOutput(It.Is <string>(s => s.Contains("TestFileName.jpg")))); var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict); scenarioContext.Setup(s => s.GetError()).Returns((Exception)null); scenarioContext.Setup(s => s.GetStepFileName(false)).Returns("TestFileName"); var browser = new Mock <IBrowser>(MockBehavior.Strict); browser.Setup(b => b.TakeScreenshot(It.IsAny <string>(), "TestFileName")).Returns("TestFileName.jpg"); browser.Setup(b => b.SaveHtml(It.IsAny <string>(), "TestFileName")).Returns((string)null); browser.Setup(b => b.Close(true)); browser.Setup(b => b.IsCreated).Returns(true); var container = new Mock <IObjectContainer>(MockBehavior.Strict); container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object); container.Setup(c => c.Resolve <ITraceListener>()).Returns(listener.Object); WebDriverSupport.Browser = browser.Object; var driverSupport = new WebDriverSupport(container.Object); // Setup Configuration var config = new ConfigurationSectionHandler { BrowserFactory = new BrowserFactoryConfigurationElement { CreateScreenshotOnExit = true } }; WebDriverSupport.ConfigurationMethod = new Lazy <ConfigurationSectionHandler>(() => config); driverSupport.CheckForScreenshot(); config.BrowserFactory.CreateScreenshotOnExit = false; WebDriverSupport.ConfigurationMethod = new Lazy <ConfigurationSectionHandler>(() => config); container.VerifyAll(); browser.VerifyAll(); scenarioContext.VerifyAll(); listener.VerifyAll(); }
public void TestCheckForScreenShotNoError() { var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict); scenarioContext.Setup(s => s.GetError()).Returns((Exception)null); var container = new Mock <IObjectContainer>(MockBehavior.Strict); container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object); var driverSupport = new WebDriverSupport(container.Object); driverSupport.CheckForScreenshot(); container.VerifyAll(); scenarioContext.VerifyAll(); }
public void TestCheckForScreenShotNoError() { var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict); scenarioContext.Setup(s => s.GetError()).Returns((Exception)null); var container = new Mock <IObjectContainer>(MockBehavior.Strict); container.Setup(c => c.Resolve <IScenarioContextHelper>()).Returns(scenarioContext.Object); WebDriverSupport.SetBrowserFactory(new MockBrowserFactory()); var browser = new Mock <IBrowser>(MockBehavior.Strict); browser.Setup(b => b.IsCreated).Returns(true); WebDriverSupport.SetCurrentBrowser(browser.Object); var driverSupport = new WebDriverSupport(container.Object); driverSupport.CheckForScreenshot(); container.VerifyAll(); scenarioContext.VerifyAll(); }