Пример #1
0
        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);

            // Setup Configuration
            BrowserFactoryConfiguration config = new BrowserFactoryConfiguration
            {
                CreateScreenshotOnExit = true
            };

            var browserFactory = new Mock <BrowserFactory>(config);

            WebDriverSupport.SetBrowserFactory(browserFactory.Object);
            WebDriverSupport.SetCurrentBrowser(browser.Object);
            var driverSupport = new WebDriverSupport(container.Object);

            driverSupport.CheckForScreenshot();

            config.CreateScreenshotOnExit = false;
            container.VerifyAll();
            browser.VerifyAll();
            scenarioContext.VerifyAll();
            listener.VerifyAll();
        }
Пример #2
0
        public void TestTearDownAfterScenarioWhenReuseBrowserIsTrue()
        {
            // arrange
            BrowserFactoryConfiguration config = new BrowserFactoryConfiguration
            {
                ReuseBrowser = true
            };

            var browserFactory = new Mock <BrowserFactory>(config);

            WebDriverSupport.SetBrowserFactory(browserFactory.Object);

            var browser = new Mock <IBrowser>(MockBehavior.Loose);

            WebDriverSupport.SetCurrentBrowser(browser.Object);

            // act
            WebDriverSupport.TearDownAfterScenario();

            // assert
            browser.Verify(b => b.Close(true), Times.Never());
        }
Пример #3
0
        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();
        }