Ejemplo n.º 1
0
        public void ExecuteCommand_ShouldSendsTracesOnlyForNextCommand()
        {
            //arrange
            MockCommandExecutor commandExec = new MockCommandExecutor();

            commandExec.SetBrowserInfo(new BrowserInfo()
            {
                Data = "<html><body>Hello</body></html>"
            });
            _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec);

            ServiceLocator.ApplicationPathFinder = new ApplicationPathFinder("http://test");
            var testPage = new HtmlPage();

            //act
            WebTestConsole.Clear();
            WebTestConsole.Write("foo");
            WebTestConsole.Write("bar");

            testPage.Elements.Refresh();

            //assert
            UnitTestAssert.AreEqual("GetPageDom", commandExec.ExecutedCommands[0].Handler.ClientFunctionName);
            UnitTestAssert.AreEqual(2, commandExec.ExecutedCommands[0].Traces.Length);
            UnitTestAssert.AreEqual("foo", commandExec.ExecutedCommands[0].Traces[0]);
            UnitTestAssert.AreEqual("bar", commandExec.ExecutedCommands[0].Traces[1]);

            //act
            testPage.Elements.Refresh();

            //assert
            UnitTestAssert.AreEqual(0, commandExec.ExecutedCommands[1].Traces.Length);
        }
Ejemplo n.º 2
0
        public void CanAccessElementsOnThePage()
        {
            ServiceLocator.ApplicationPathFinder = new ApplicationPathFinder("/test");
            MockCommandExecutor commandExecutor = new MockCommandExecutor();

            _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExecutor);

            string html = @"
                <html id='control1'>
                    <foo id='control2'> 
                        <bar id='control3' />
                    </foo>
                </html>
                ";

            BrowserInfo browserInfo = new BrowserInfo();

            browserInfo.Data = html;
            commandExecutor.SetBrowserInfo(browserInfo);

            HtmlPage page = new HtmlPage();

            page.Elements.Refresh();
            UnitTestAssert.AreEqual("html", page.RootElement.TagName);
            UnitTestAssert.AreEqual("foo", page.Elements.Find("control2").TagName);
        }
Ejemplo n.º 3
0
        public void GetPopupWindow_ThrowsIfFailsToRefresh()
        {
            MockCommandExecutor commandExec = new MockCommandExecutor();

            _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec);
            _newWindowRefreshCount        = 0;
            commandExec.ExecutingCommand += new EventHandler(commandExec_ExecutingCommandThrows);

            ServiceLocator.ApplicationPathFinder = new ApplicationPathFinder("http://test");
            var testPage = new HtmlPage();

            testPage.GetPopupPage(1, 0);
        }
Ejemplo n.º 4
0
        public void GetPopupWindow_SendsARefreshCommandWithTheCorrectIndex()
        {
            MockCommandExecutor commandExec = new MockCommandExecutor();

            _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec);
            commandExec.SetBrowserInfo(new BrowserInfo()
            {
                Data = "<html><body>Hello</body></html>"
            });
            ServiceLocator.ApplicationPathFinder = new ApplicationPathFinder("http://test");
            var testPage = new HtmlPage();

            HtmlPage popupPage = testPage.GetPopupPage(1);

            UnitTestAssert.IsNotNull(popupPage);
            UnitTestAssert.AreEqual("GetPageDom", commandExec.ExecutedCommands[0].Handler.ClientFunctionName);
            UnitTestAssert.AreEqual("GetPageDom (Popup window: 1)", commandExec.ExecutedCommands[0].Description);
            UnitTestAssert.AreEqual(1, commandExec.ExecutedCommands[0].Target.WindowIndex);
        }
Ejemplo n.º 5
0
        public void GetFrame_NestedFrames()
        {
            MockCommandExecutor commandExec = new MockCommandExecutor();

            _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec);
            commandExec.SetBrowserInfo(new BrowserInfo()
            {
                Data = "<html><body><input id='Button1' /></body></html>"
            });
            ServiceLocator.ApplicationPathFinder = new ApplicationPathFinder("http://test");
            var testPage = new HtmlPage();

            HtmlPage framePage = testPage.GetFramePage("frame1", "frame2", "frame3");

            framePage.Elements.Find("Button1").Click();
            UnitTestAssert.AreEqual("Click (Frame: frame1-frame2-frame3)", commandExec.ExecutedCommands[1].Description);
            UnitTestAssert.AreEqual("frame1", (string)commandExec.ExecutedCommands[1].Target.FrameHierarchy[0]);
            UnitTestAssert.AreEqual("frame2", (string)commandExec.ExecutedCommands[1].Target.FrameHierarchy[1]);
            UnitTestAssert.AreEqual("frame3", (string)commandExec.ExecutedCommands[1].Target.FrameHierarchy[2]);
        }
Ejemplo n.º 6
0
        public void GetFrame_ActionsFromFrameGetSentWithCorrectFrameHierarchy()
        {
            MockCommandExecutor commandExec = new MockCommandExecutor();

            _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec);
            commandExec.SetBrowserInfo(new BrowserInfo()
            {
                Data = "<html><body><input id='Button1' /></body></html>"
            });
            ServiceLocator.ApplicationPathFinder = new ApplicationPathFinder("http://test");
            var testPage = new HtmlPage();

            HtmlPage framePage = testPage.GetFramePage("FrameName");

            framePage.Elements.Find("Button1").Click();

            UnitTestAssert.AreEqual("ClickElement", commandExec.ExecutedCommands[1].Handler.ClientFunctionName);
            UnitTestAssert.AreEqual("Click (Frame: FrameName)", commandExec.ExecutedCommands[1].Description);
            UnitTestAssert.AreEqual("FrameName", (string)commandExec.ExecutedCommands[1].Target.FrameHierarchy[0]);
        }
Ejemplo n.º 7
0
        public void GetPopupWindow_ActionsFromPopupGetSentWithCorrectWindowIndex()
        {
            MockCommandExecutor commandExec = new MockCommandExecutor();

            _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec);
            commandExec.SetBrowserInfo(new BrowserInfo()
            {
                Data = "<html><body><input id='Button1' /></body></html>"
            });
            ServiceLocator.ApplicationPathFinder = new ApplicationPathFinder("http://test");
            var testPage = new HtmlPage();

            HtmlPage popupPage = testPage.GetPopupPage(1);

            popupPage.Elements.Find("Button1").Click();

            UnitTestAssert.AreEqual("ClickElement", commandExec.ExecutedCommands[1].Handler.ClientFunctionName);
            UnitTestAssert.AreEqual("Click (Popup window: 1)", commandExec.ExecutedCommands[1].Description);
            UnitTestAssert.AreEqual(1, commandExec.ExecutedCommands[1].Target.WindowIndex);
        }
Ejemplo n.º 8
0
        public void GetPopupWindow_KeepsTryingUntilRefreshSucceeds()
        {
            MockCommandExecutor commandExec = new MockCommandExecutor();

            _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec);
            commandExec.SetBrowserInfo(new BrowserInfo()
            {
                Data = "<html><body>Hello</body></html>"
            });
            _newWindowRefreshCount        = 0;
            commandExec.ExecutingCommand += new EventHandler(commandExec_ExecutingCommandThrows);

            ServiceLocator.ApplicationPathFinder = new ApplicationPathFinder("http://test");
            var testPage = new HtmlPage();

            HtmlPage popupPage = testPage.GetPopupPage(1, timeoutInSeconds: 1, waitBetweenAttemptsInMilliseconds: 0);

            UnitTestAssert.IsNotNull(popupPage);
            Assert.AreEqual(_newWindowRefreshCount, 2);
        }