예제 #1
0
        public void TestExecuteWhenPageIsFoundAndUrlMatchesReturnsSuccess()
        {
            var page = new Mock <IPage>(MockBehavior.Strict);

            var pageMapper = new Mock <IPageMapper>(MockBehavior.Strict);

            pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage));

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

            browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object);
            browser.Setup(b => b.EnsureOnPage(page.Object));

            var logger = new Mock <ILogger>();

            var action  = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object);
            var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1));

            var result = action.Execute(context);

            Assert.AreEqual(true, result.Success);
            Assert.AreSame(page.Object, result.Result);

            pageMapper.VerifyAll();
            browser.VerifyAll();
            page.VerifyAll();
        }
예제 #2
0
        public void TestExecuteWhenPageIsFoundAndUrlMatchesReturnsSuccess()
        {
            var page = new Mock<IPage>(MockBehavior.Strict);

            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage));

            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object);
            browser.Setup(b => b.EnsureOnPage(page.Object));

            var logger = new Mock<ILogger>();

            var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object);
            var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1));

            var result = action.Execute(context);

            Assert.AreEqual(true, result.Success);
            Assert.AreSame(page.Object, result.Result);

            pageMapper.VerifyAll();
            browser.VerifyAll();
            page.VerifyAll();
        }
예제 #3
0
        public void TestExecuteWhenPageIsFoundAndUrlDoesntMatchAfterTimeoutReturnsFailure()
        {
            var page = new Mock <IPage>(MockBehavior.Strict);

            var pageMapper = new Mock <IPageMapper>(MockBehavior.Strict);

            pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage));

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

            browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object);
            browser.Setup(b => b.EnsureOnPage(page.Object)).Throws(new PageNavigationException("Cannot find URL"));

            var logger = new Mock <ILogger>();

            var action  = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object);
            var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1));

            var result = action.Execute(context);

            Assert.AreEqual(false, result.Success);
            Assert.IsNotNull(result.Exception);
            Assert.AreEqual("Browser did not resolve to the 'SamplePage' page in 00:00:01", result.Exception.Message);

            pageMapper.VerifyAll();
            browser.VerifyAll();
            page.VerifyAll();
        }
예제 #4
0
        public void TestExecuteWhenPageIsFoundAndUrlMatchesAfterInitialFailureReturnsSuccess()
        {
            var page = new Mock <IPage>(MockBehavior.Strict);

            var pageMapper = new Mock <IPageMapper>(MockBehavior.Strict);

            pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage));

            var count   = 0;
            var browser = new Mock <IBrowser>(MockBehavior.Strict);

            browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object);
            browser.Setup(b => b.EnsureOnPage(page.Object))
            .Callback(() =>
            {
                count++;
                if (count == 1)
                {
                    throw new PageNavigationException("Cannot find URL");
                }
            });

            var logger = new Mock <ILogger>(MockBehavior.Strict);

            logger.Setup(l => l.Debug("Browser is not on page. Details: {0}", "Cannot find URL"));

            var action  = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object);
            var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1));

            var result = action.Execute(context);

            Assert.AreEqual(true, result.Success);
            Assert.AreSame(page.Object, result.Result);

            pageMapper.VerifyAll();
            browser.Verify(b => b.EnsureOnPage(page.Object), Times.Exactly(2));
            browser.Verify(b => b.Page(typeof(SamplePage)), Times.Exactly(2));
            browser.Verify(b => b.IsCreated, Times.Never());
            browser.VerifyAll();
            page.VerifyAll();
            logger.VerifyAll();
        }
예제 #5
0
        public void TestExecuteWhenPageDoesNotExistReturnsAFailure()
        {
            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("MyPage")).Returns((Type)null);

            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            var logger = new Mock<ILogger>();

            var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object);
            var context = new WaitForPageAction.WaitForPageActionContext("MyPage", null);

            var result = action.Execute(context);

            Assert.AreEqual(false, result.Success);
            Assert.IsNotNull(result.Exception);
            Assert.AreEqual("Cannot locate a page for name: MyPage. Check page aliases in the test assembly.", result.Exception.Message);

            pageMapper.VerifyAll();
            browser.VerifyAll();
        }
예제 #6
0
        public void TestExecuteWhenPageDoesNotExistReturnsAFailure()
        {
            var pageMapper = new Mock <IPageMapper>(MockBehavior.Strict);

            pageMapper.Setup(p => p.GetTypeFromName("MyPage")).Returns((Type)null);

            var browser = new Mock <IBrowser>(MockBehavior.Strict);
            var logger  = new Mock <ILogger>();

            var action  = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object);
            var context = new WaitForPageAction.WaitForPageActionContext("MyPage", null);

            var result = action.Execute(context);

            Assert.AreEqual(false, result.Success);
            Assert.IsNotNull(result.Exception);
            Assert.AreEqual("Cannot locate a page for name: MyPage. Check page aliases in the test assembly.", result.Exception.Message);

            pageMapper.VerifyAll();
            browser.VerifyAll();
        }
예제 #7
0
        public void TestExecuteWhenPageIsFoundAndUrlMatchesAfterInitialFailureReturnsSuccess()
        {
            var page = new Mock<IPage>(MockBehavior.Strict);

            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage));

            var count = 0;
            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object);
            browser.Setup(b => b.EnsureOnPage(page.Object))
                   .Callback(() =>
                        {
                            count++;
                            if (count == 1)
                            {
                                throw new PageNavigationException("Cannot find URL");
                            }
                        });

            var logger = new Mock<ILogger>(MockBehavior.Strict);
            logger.Setup(l => l.Debug("Browser is not on page. Details: {0}", "Cannot find URL"));

            var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object);
            var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1));

            var result = action.Execute(context);

            Assert.AreEqual(true, result.Success);
            Assert.AreSame(page.Object, result.Result);

            pageMapper.VerifyAll();
            browser.Verify(b => b.EnsureOnPage(page.Object), Times.Exactly(2));
            browser.Verify(b => b.Page(typeof(SamplePage)), Times.Once());
            browser.VerifyAll();
            page.VerifyAll();
            logger.VerifyAll();
        }
예제 #8
0
        public void TestExecuteWhenPageIsFoundAndUrlDoesntMatchAfterTimeoutReturnsFailure()
        {
            var page = new Mock<IPage>(MockBehavior.Strict);

            var pageMapper = new Mock<IPageMapper>(MockBehavior.Strict);
            pageMapper.Setup(p => p.GetTypeFromName("SamplePage")).Returns(typeof(SamplePage));

            var browser = new Mock<IBrowser>(MockBehavior.Strict);
            browser.Setup(b => b.Page(typeof(SamplePage))).Returns(page.Object);
            browser.Setup(b => b.EnsureOnPage(page.Object)).Throws(new PageNavigationException("Cannot find URL"));

            var logger = new Mock<ILogger>();

            var action = new WaitForPageAction(pageMapper.Object, browser.Object, logger.Object);
            var context = new WaitForPageAction.WaitForPageActionContext("SamplePage", TimeSpan.FromSeconds(1));

            var result = action.Execute(context);

            Assert.AreEqual(false, result.Success);
            Assert.IsNotNull(result.Exception);
            Assert.AreEqual("Browser did not resolve to the 'SamplePage' page in 00:00:01", result.Exception.Message);

            pageMapper.VerifyAll();
            browser.VerifyAll();
            page.VerifyAll();
        }