public void WhenRefreshing_ShouldNotGetGetAttributes() { MockCommandExecutor commandExecutor = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExecutor); var testPage = new HtmlPage(); string html = @" <html id='control1'> <span id='MySpan' randomAttribute='foo'> Span text </span> </html> "; commandExecutor.SetBrowserInfo(new LTAF.Engine.BrowserInfo() { Data = @"<span id='MySpan' randomAttribute='bar'> Span text </span>" }); var element = HtmlElement.Create(html, testPage, false); var span = element.ChildElements.Find("MySpan"); span.ChildElements.Refresh(); Assert.IsNull(commandExecutor.ExecutedCommands[0].Handler.Arguments); }
public void WhenRefreshing_IfPassingTwoAttribute_ShouldRefreshDomIncludingThoseAttributes() { MockCommandExecutor commandExecutor = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExecutor); var testPage = new HtmlPage(); string html = @" <html id='control1'> <span id='MySpan' randomAttribute='foo'> Span text </span> </html> "; commandExecutor.SetBrowserInfo(new LTAF.Engine.BrowserInfo() { Data = @"<span id='MySpan' randomAttribute='bar'> Span text </span>" }); var element = HtmlElement.Create(html, testPage, false); var span = element.ChildElements.Find("MySpan"); span.ChildElements.Refresh(new string[] { "randomAttribute", "anotherAttribute" }); Assert.AreEqual("randomattribute-anotherattribute", commandExecutor.ExecutedCommands[0].Handler.Arguments[0]); }
public void ClickPopupActionGetTextBack() { MockCommandExecutor commandExecutor = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExecutor); var testPage = new HtmlPage(); HtmlElement element = new HtmlElement("input", new Dictionary <string, string>() { { "id", "button1" }, { "type", "button" } }, null, testPage); CommandParameters commandParameters = new CommandParameters(WaitFor.None, PopupAction.ConfirmOK); commandExecutor.SetBrowserInfo(new BrowserInfo() { Data = "This is the text from confirm" }); element.Click(commandParameters); UnitTestAssert.AreEqual(PopupAction.ConfirmOK, commandExecutor.ExecutedCommands[0].Handler.PopupAction); UnitTestAssert.AreEqual("This is the text from confirm", commandParameters.PopupText); }
public void RowsAreRefreshedWhenTBodyIsRefreshed() { MockCommandExecutor commandExecutor = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExecutor); var testPage = new HtmlPage(); string html = @" <html id='control1'> <table id='MyTable'> <tbody> <tr>First</tr> <tr>Second</tr> </tbody> </table> </html> "; commandExecutor.SetBrowserInfo(new LTAF.Engine.BrowserInfo() { Data = @"<tbody> <tr>First Refreshed</tr> <tr>Second Refreshed</tr> </tbody>" }); HtmlElement element = HtmlElement.Create(html, testPage, false); HtmlTableElement table = (HtmlTableElement)element.ChildElements.Find("MyTable"); table.TBody.ChildElements.Refresh(); UnitTestAssert.AreEqual(2, table.Rows.Count); UnitTestAssert.AreEqual("First Refreshed", table.Rows[0].CachedInnerText); UnitTestAssert.AreEqual("Second Refreshed", table.Rows[1].CachedInnerText); }
public void ClickPopupActionNone() { MockCommandExecutor commandExecutor = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExecutor); HtmlPage testPage = new HtmlPage(); HtmlElement element = new HtmlElement("input", new Dictionary <string, string>() { { "id", "button1" }, { "type", "button" } }, null, testPage); CommandParameters parameters = new CommandParameters(); parameters.WaitFor = WaitFor.None; parameters.PopupAction = PopupAction.None; element.Click(parameters); UnitTestAssert.AreEqual("Click", commandExecutor.ExecutedCommands[0].Description); UnitTestAssert.AreEqual(2, commandExecutor.ExecutedCommands[0].Handler.Arguments.Length); UnitTestAssert.AreEqual(false, (bool)(commandExecutor.ExecutedCommands[0].Handler.Arguments[0])); UnitTestAssert.AreEqual(1, commandExecutor.ExecutedCommands.Length); UnitTestAssert.AreEqual(PopupAction.None, commandExecutor.ExecutedCommands[0].Handler.PopupAction); }
public void WhenSubmit_ShouldSendSubmitCommand() { //arrange var html = @" <html> <body> <form id='form1'> <input type='hidden' id='input1' value='thevalue' /> </form> </body> </html>"; MockCommandExecutor commandExecutor = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExecutor); var testPage = new HtmlPage(); var document = HtmlElement.Create(html, testPage, false); //act var form = (HtmlFormElement)document.ChildElements.Find("form1"); form.Submit(); //assert MSAssert.AreEqual("FormSubmit", commandExecutor.ExecutedCommands[0].Handler.ClientFunctionName); MSAssert.AreEqual("FormSubmit", commandExecutor.ExecutedCommands[0].Description); MSAssert.IsTrue(commandExecutor.ExecutedCommands[0].Handler.RequiresElementFound); MSAssert.AreEqual("form1", commandExecutor.ExecutedCommands[0].Target.Id); MSAssert.IsNull(commandExecutor.ExecutedCommands[0].Handler.Arguments); }
public void SetText_NonInputElement() { MockCommandExecutor commandExec = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec); var testPage = new HtmlPage(); HtmlElement element = HtmlElement.Create("<image id='textbox1' type='textbox' />", testPage, false); element.SetText("foo"); }
public void GetOuterHtml() { MockCommandExecutor commandExec = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec); var testPage = new HtmlPage(); HtmlElement element = HtmlElement.Create("<input id='textbox1' type='textbox' />", testPage, false); element.GetOuterHtml(); UnitTestAssert.AreEqual("GetElementDom", commandExec.ExecutedCommands[0].Handler.ClientFunctionName); }
public void GetMappedPathReplacesShortestPrefixThatExistsWithDrive() { var fs = new Mock<IFileSystem>(); var directory = new Mock<DirectoryBase>(); directory.Setup(m => m.Exists(@"\\foo")).Returns(true); directory.Setup(m => m.Exists(@"\\foo\bar")).Returns(true); fs.Setup(m => m.Directory).Returns(directory.Object); var commandRunner = new MockCommandExecutor(fs.Object, @"\\foo\bar\baz"); string path = commandRunner.GetMappedPath(@"\\foo\bar\baz"); Assert.Equal(@"A:\bar\baz", path); }
public void MouseOver() { MockCommandExecutor commandExec = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec); var testPage = new HtmlPage(); HtmlElement element = HtmlElement.Create("<input id='textbox1' type='textbox' />", testPage, false); element.MouseOver(); UnitTestAssert.AreEqual("DispatchMouseEvent", commandExec.ExecutedCommands[0].Handler.ClientFunctionName); UnitTestAssert.AreEqual("mouseover", (string)commandExec.ExecutedCommands[0].Handler.Arguments[0]); }
public void WaitUntilNotFound() { MockCommandExecutor commandExec = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec); var testPage = new HtmlPage(); HtmlElement element = HtmlElement.Create("<foo id='foo'><bar>baz</bar></foo>", testPage, false); element.WaitUntilNotFound(10); UnitTestAssert.AreEqual("WaitUntilDissapears", commandExec.ExecutedCommands[0].Handler.ClientFunctionName); UnitTestAssert.AreEqual(10000, (int)commandExec.ExecutedCommands[0].Handler.Arguments[0]); }
public void GetMappedPathReplacesShortestPrefixThatExistsWithDrive() { var fs = new Mock <IFileSystem>(); var directory = new Mock <DirectoryBase>(); directory.Setup(m => m.Exists(@"\\foo")).Returns(true); directory.Setup(m => m.Exists(@"\\foo\bar")).Returns(true); fs.Setup(m => m.Directory).Returns(directory.Object); var commandRunner = new MockCommandExecutor(fs.Object, @"\\foo\bar\baz"); string path = commandRunner.GetMappedPath(@"\\foo\bar\baz"); Assert.Equal(@"A:\bar\baz", path); }
public void GetMappedPathUsesMappedDriveIfPrefixIsTheSame() { var fs = new Mock<IFileSystem>(); var directory = new Mock<DirectoryBase>(); directory.Setup(m => m.Exists(@"\\foo\bar")).Returns(true); fs.Setup(m => m.Directory).Returns(directory.Object); var commandRunner = new MockCommandExecutor(fs.Object, @"\\foo\bar\baz"); string path1 = commandRunner.GetMappedPath(@"\\foo\bar\a"); string path2 = commandRunner.GetMappedPath(@"\\foo\bar\z\emr"); string path3 = commandRunner.GetMappedPath(@"\\foo\bar\b\d\f"); Assert.Equal(@"A:\a", path1); Assert.Equal(@"A:\z\emr", path2); Assert.Equal(@"A:\b\d\f", path3); }
public void WaitForInnerText() { MockCommandExecutor commandExec = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec); var testPage = new HtmlPage(); HtmlElement element = HtmlElement.Create("<input id='textbox1' type='textbox' />", testPage, false); element.WaitForInnerText("foo", 10); UnitTestAssert.AreEqual("WaitForDomChange", commandExec.ExecutedCommands[0].Handler.ClientFunctionName); UnitTestAssert.AreEqual("innerHTML", (string)commandExec.ExecutedCommands[0].Handler.Arguments[0]); UnitTestAssert.AreEqual("foo", (string)commandExec.ExecutedCommands[0].Handler.Arguments[1]); UnitTestAssert.AreEqual(10000, (int)commandExec.ExecutedCommands[0].Handler.Arguments[2]); }
public void GetMappedPathUsesMappedDriveIfPrefixIsTheSame() { var fs = new Mock <IFileSystem>(); var directory = new Mock <DirectoryBase>(); directory.Setup(m => m.Exists(@"\\foo\bar")).Returns(true); fs.Setup(m => m.Directory).Returns(directory.Object); var commandRunner = new MockCommandExecutor(fs.Object, @"\\foo\bar\baz"); string path1 = commandRunner.GetMappedPath(@"\\foo\bar\a"); string path2 = commandRunner.GetMappedPath(@"\\foo\bar\z\emr"); string path3 = commandRunner.GetMappedPath(@"\\foo\bar\b\d\f"); Assert.Equal(@"A:\a", path1); Assert.Equal(@"A:\z\emr", path2); Assert.Equal(@"A:\b\d\f", path3); }
public void IsVisible_False() { MockCommandExecutor commandExec = new MockCommandExecutor(); commandExec.SetBrowserInfo(new BrowserInfo() { Data = "<input id='button1' type='button' style='visibility:hidden;' />" }); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec); var testPage = new HtmlPage(); HtmlElement element = HtmlElement.Create("<input id='textbox1' type='textbox' />", testPage, false); UnitTestAssert.IsFalse(element.IsVisible()); UnitTestAssert.AreEqual("GetElementAttributes", commandExec.ExecutedCommands[0].Handler.ClientFunctionName); }
public void ClickSendsBrowserCommand() { MockCommandExecutor commandExecutor = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExecutor); var testPage = new HtmlPage(); HtmlElement element = new HtmlElement("input", new Dictionary <string, string>() { { "id", "button1" }, { "type", "button" } }, null, testPage); element.Click(); UnitTestAssert.AreEqual("Click", commandExecutor.ExecutedCommands[0].Description); UnitTestAssert.AreEqual(2, commandExecutor.ExecutedCommands[0].Handler.Arguments.Length); UnitTestAssert.AreEqual(false, (bool)(commandExecutor.ExecutedCommands[0].Handler.Arguments[0])); }
public void SetText() { MockCommandExecutor commandExec = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec); var testPage = new HtmlPage(); HtmlInputElement element = new HtmlInputElement( new Dictionary <string, string>() { { "id", "button1" }, { "type", "textbox" } }, null, testPage); element.SetText("foo"); UnitTestAssert.AreEqual("SetTextBox", commandExec.ExecutedCommands[0].Handler.ClientFunctionName); UnitTestAssert.AreEqual("foo", (string)commandExec.ExecutedCommands[0].Handler.Arguments[0]); }