public void TestTeardownNoError() { var scenarioContext = new Mock<IScenarioContextHelper>(MockBehavior.Strict); scenarioContext.Setup(s => s.GetError()).Returns((Exception)null); var browser = new Mock<IBrowser>(MockBehavior.Strict); browser.Setup(b => b.Close()); var container = new Mock<IObjectContainer>(MockBehavior.Strict); container.Setup(c => c.Resolve<IBrowser>()).Returns(browser.Object); container.Setup(c => c.Resolve<IScenarioContextHelper>()).Returns(scenarioContext.Object); var driverSupport = new WebDriverSupport(container.Object); driverSupport.TearDownWebDriver(); container.VerifyAll(); browser.VerifyAll(); scenarioContext.VerifyAll(); }
public void TestTeardownWithErrorAttemptsScreenshotButListenerIsUnavailable() { 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.Close()); browser.Setup(b => b.TakeScreenshot(It.IsAny<string>(), "TestFileName")).Returns((string)null); browser.Setup(b => b.SaveHtml(It.IsAny<string>(), "TestFileName")).Returns((string)null); var container = new Mock<IObjectContainer>(MockBehavior.Strict); container.Setup(c => c.Resolve<IBrowser>()).Returns(browser.Object); container.Setup(c => c.Resolve<IScenarioContextHelper>()).Returns(scenarioContext.Object); container.Setup(c => c.Resolve<ITraceListener>()).Returns((ITraceListener)null); var driverSupport = new WebDriverSupport(container.Object); driverSupport.TearDownWebDriver(); container.VerifyAll(); browser.VerifyAll(); scenarioContext.VerifyAll(); }
public void TestTeardownWithErrorTakesSueccessfulScreenshot() { 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()).Returns("TestFileName"); var browser = new Mock<IBrowser>(MockBehavior.Strict); browser.Setup(b => b.Close()); browser.Setup(b => b.TakeScreenshot(It.IsAny<string>(), "TestFileName")).Returns("TestFileName.jpg"); browser.Setup(b => b.SaveHtml(It.IsAny<string>(), "TestFileName")).Returns((string)null); var container = new Mock<IObjectContainer>(MockBehavior.Strict); container.Setup(c => c.Resolve<IBrowser>()).Returns(browser.Object); container.Setup(c => c.Resolve<IScenarioContextHelper>()).Returns(scenarioContext.Object); container.Setup(c => c.Resolve<ITraceListener>()).Returns(listener.Object); var driverSupport = new WebDriverSupport(container.Object); driverSupport.TearDownWebDriver(); container.VerifyAll(); browser.VerifyAll(); scenarioContext.VerifyAll(); listener.VerifyAll(); }