Ejemplo n.º 1
0
        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.SetCurrentBrowser(browser.Object);
            var driverSupport = new WebDriverSupport(container.Object);

            driverSupport.CheckForScreenshot();

            container.VerifyAll();
            browser.VerifyAll();
            scenarioContext.VerifyAll();
            listener.VerifyAll();
        }
Ejemplo n.º 2
0
        public void TestTearDownAfterTest()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(b => b.Close(true));
            WebDriverSupport.SetCurrentBrowser(browser.Object);

            WebDriverSupport.TearDownAfterTest();

            browser.VerifyAll();
        }
Ejemplo n.º 3
0
        public void WaitForjQuery_WhenCanGetUrlReturnsFalse_DoesNotTryToGetUrl()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(s => s.IsClosed).Returns(false);
            browser.Setup(s => s.IsDisposed).Returns(false);
            browser.Setup(s => s.CanGetUrl()).Returns(false);
            WebDriverSupport.SetCurrentBrowser(browser.Object);

            WebDriverSupport.WaitForjQuery();

            browser.VerifyAll();
        }
Ejemplo n.º 4
0
        public void WaitForjQuery_WhenCanGetUrlReturnsTrue_GetsUrl()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(s => s.IsClosed).Returns(false);
            browser.Setup(s => s.IsDisposed).Returns(false);
            browser.Setup(s => s.CanGetUrl()).Returns(true);
            browser.Setup(s => s.Url).Returns("http://www.specbind.org");
            browser.Setup(s => s.ExecuteScript(It.IsAny <string>())).Returns("0");
            WebDriverSupport.SetCurrentBrowser(browser.Object);

            WebDriverSupport.WaitForjQuery();

            browser.VerifyAll();
        }
Ejemplo n.º 5
0
        public void TestWaitForAngularWithNothingPending()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(s => s.IsClosed).Returns(false);
            browser.Setup(s => s.IsDisposed).Returns(false);
            browser.Setup(s => s.CanGetUrl()).Returns(true);
            browser.Setup(s => s.Url).Returns("http://www.specbind.org");
            browser.Setup(s => s.ExecuteScript(It.IsAny <string>())).Returns("0");
            WebDriverSupport.SetCurrentBrowser(browser.Object);

            WebDriverSupport.WaitForAngular();

            browser.VerifyAll();
        }
Ejemplo n.º 6
0
        public void IWaitForjQueryAjaxCallsToCompleteStep_WhenCanGetUrlReturnsFalse_DoesNotTryToGetUrl()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(s => s.IsClosed).Returns(false);
            browser.Setup(s => s.IsDisposed).Returns(false);
            browser.Setup(s => s.CanGetUrl()).Returns(false);
            WebDriverSupport.SetCurrentBrowser(browser.Object);

            var pipelineService = new Mock <IActionPipelineService>(MockBehavior.Strict);
            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);
            var steps           = new WaitingSteps(pipelineService.Object, scenarioContext.Object);

            steps.WaitForjQuery();

            browser.VerifyAll();
        }
Ejemplo n.º 7
0
        public void IWaitForjQueryAjaxCallsToCompleteStep_WhenCanGetUrlReturnsTrue_GetsUrl()
        {
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(s => s.IsClosed).Returns(false);
            browser.Setup(s => s.IsDisposed).Returns(false);
            browser.Setup(s => s.CanGetUrl()).Returns(true);
            browser.Setup(s => s.Url).Returns("http://www.specbind.org");
            browser.Setup(s => s.ExecuteScript(It.IsAny <string>())).Returns("0");
            WebDriverSupport.SetCurrentBrowser(browser.Object);

            var pipelineService = new Mock <IActionPipelineService>(MockBehavior.Strict);
            var scenarioContext = new Mock <IScenarioContextHelper>(MockBehavior.Strict);
            var steps           = new WaitingSteps(pipelineService.Object, scenarioContext.Object);

            steps.WaitForjQuery();

            browser.VerifyAll();
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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());
        }
Ejemplo n.º 10
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();
        }