public void GetHtmlDiv_ByClass_Succeeds() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <div class=""button""><a href=""/main"">main text</a></div> <div class=""button""><a href=""/about"">about text</a></div> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); // Act HtmlDiv div = window.Find <HtmlDiv>(By.Class("button")); HtmlHyperlink about = window.Find <HtmlHyperlink>(By.SearchProperties("InnerText=about text;href~about")); HtmlDiv div2 = about.Parent as HtmlDiv; // Assert Assert.IsTrue(div.Exists); Assert.AreEqual("main text", div.SourceControl.InnerText); Assert.IsTrue(about.Exists); Assert.IsTrue(div2.Exists); Assert.AreEqual("about text", div2.SourceControl.InnerText); window.Close(); } }
public void GenericGet_WithHtmlControls_GetsControlsDynamically() { // Arrange BrowserWindowUnderTest browserWindow = BrowserWindowUnderTest.Launch("http://mail.google.com"); // Act browserWindow.Find <HtmlEdit>(By.Id("Email")).Text = "*****@*****.**"; browserWindow.Find <HtmlPassword>(By.Id("Password")).Text = "MyPa$$Word"; browserWindow.Find <HtmlInputButton>(By.Id("signIn")).Click(); browserWindow.Close(); }
public void HtmlHyperlink_OnSharePoint2010_Succeeds() { BrowserWindow.Launch("http://myasia/sites/sureba/Default.aspx"); BrowserWindowUnderTest.Authenticate("username", "passwd"); var bWin = new BrowserWindowUnderTest("Suresh Balasubramanian"); bWin.Find <HtmlHyperlink>(By.Id("idHomePageNewDocument")).Click(); var closeLink = bWin.Find <HtmlHyperlink>(By.SearchProperties("Title=Close;class=ms-dlgCloseBtn")); //clicking closeLink directly doesn't work as the maximizeLink is clicked due to the controls being placed too close to each other Mouse.Click(closeLink.SourceControl.GetChildren()[0].GetChildren()[0]); bWin.RunScript(@"STSNavigate2(event,'/sites/sureba/_layouts/SignOut.aspx');"); }
public void SlButtonAndEditAndDTP_ClickAndSetTextAndSelectedDateAsString_Succeeds() { BrowserWindowUnderTest b = BrowserWindowUnderTest.Launch(silverlightApplicationHtmlPageUrl); b.SetFocus(); b.Find <SilverlightButton>(By.AutomationId("button1")).Click(); SilverlightEdit oEdit = b.Find <SilverlightEdit>(By.AutomationId("textBox1")); oEdit.Text = "asddasdasdasdadasdadasdadadadasd"; SilverlightDatePicker dp = b.Find <SilverlightDatePicker>(By.AutomationId("datePicker1")); dp.SourceControl.SelectedDate = new DateTime(2011, 5, 11); b.Close(); }
public void Launch_UsingNewInstanceOfABrowserWindow_CanUsePartialWindowTitle() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test 1 2 3</title> </head> <body> <button id=""buttonId"" >Button</button> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); //Act HtmlButton button = window.Find <HtmlButton>(By.Id("buttonId")); //Assert Assert.AreEqual(button.InnerText, "Button"); Trace.WriteLine(window.Uri.ToString()); window.Close(); } }
[Ignore] // this test currently fails public void HtmlButton_HiddenByStyle_ControlExistsAndCanAssertOnStyle() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <button id=""buttonId"" style=""display: none;"" >Hidden</button> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); //Act HtmlButton button = window.Find <HtmlButton>(By.Id("buttonId")); //Assert Assert.IsTrue(button.Exists); Assert.IsTrue(button.SourceControl.ControlDefinition.Contains("style=\"display: none;\"")); window.Close(); } }
public void GetHtmlRow_ById_Succeeds() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <table class=""cart"" cellspacing=""0""> <tbody> <tr id=""555002_gp2""> <td> banana </td> </tr> </tbody> </table> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); // Act HtmlRow row = window.Find <HtmlRow>(By.Id("555002_gp2")); // Assert Assert.IsTrue(row.Exists); window.Close(); } }
public void SetText_OnHtmlEdit_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <div id=""div1""> <input type=""text""/> </div> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlDiv div = window.Find <HtmlDiv>(By.Id("div1")); HtmlEdit inputTextBox = div.Find <HtmlEdit>(); //Act inputTextBox.Text = "text"; //Assert Assert.AreEqual("text", inputTextBox.Text); window.Close(); } }
public void HtmlCheckBox_DisabledByStyle_ControlExistsAndCanGetCheckedState() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input type=""checkbox"" id=""checkBoxId"" disabled=""disabled"" name=""checkBoxName"" checked=""checked"" /> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); //Act HtmlCheckBox checkBox = window.Find <HtmlCheckBox>(By.Id("checkBoxId")); //Assert Assert.IsTrue(checkBox.Exists); Assert.IsTrue(checkBox.Checked); window.Close(); } }
public void Click_OnHtmlInputButtonWithEqualsSignInSearchPropertyValue_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input type=""submit"" value=""="" onclick=""alert('onclick');""/> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlInputButton button = window.Find <HtmlInputButton>(By.ValueAttribute("=")); //Act button.Click(); window.PerformDialogAction(BrowserDialogAction.Ok); window.Close(); } }
public void SelectedItems_OnHtmlList_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <select id=""selectId"" multiple=""multiple""> <option value=""1"">1</option> <option value=""2"">2</option> <option value=""3"">3</option> </select> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var bWin = new BrowserWindowUnderTest("test"); HtmlList list = bWin.Find <HtmlList>(By.Id("selectId")); string[] itemsToSelect = { "1", "2" }; //Act list.SelectedItems = itemsToSelect; //Assert CollectionAssert.AreEqual(itemsToSelect, list.SelectedItems); bWin.Close(); } }
public void InnerText_OnHtmlComboBoxWithDisabledItems_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <select id=""selectId""> <option value=""1"">1</option> <option value=""2"" disabled=""disabled"">2</option> <option value=""3"" disabled=""disabled"">3</option> </select> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlComboBox comboBox = window.Find <HtmlComboBox>(By.Id("selectId")); //Assert Assert.AreEqual(3, comboBox.ItemCount); CollectionAssert.AreEqual(new[] { "1", "2", "3" }, comboBox.Items); Assert.AreEqual("1 2 3", comboBox.InnerText.Trim()); window.Close(); } }
public void LabelFor_OnHtmlLabel_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <form> <label for=""male"">Male</label> <input type=""radio"" name=""sex"" id=""male"" value=""male""><br> <label for=""female"">Female</label> <input type=""radio"" name=""sex"" id=""female"" value=""female""><br> <label id=""other"" for=""other"">Other</label> <input type=""radio"" name=""sex"" id=""other"" value=""other""><br> <input type=""submit"" value=""Submit""> </form> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlLabel label = window.Find <HtmlLabel>(By.Id("other")); //Assert Assert.AreEqual("other", label.LabelFor); window.Close(); } }
public void ClickAllControlsOnPage_UsingReflection_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <a href=""#"">test</a> <button>test</button> <input type=""text"" value=""test""/> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); ControlBase a = window.Find <HtmlHyperlink>(By.SearchProperties("InnerText=test")); a.Click(); List <Type> list = new List <Type>(); list.Add(typeof(HtmlHyperlink)); list.Add(typeof(HtmlButton)); list.Add(typeof(HtmlEdit)); MethodInfo getMethodInfo = typeof(BrowserWindowUnderTest).GetMethod("Find", new[] { typeof(By) }); foreach (Type t in list) { MethodInfo test = getMethodInfo.MakeGenericMethod(t); ControlBase control; if ((t == typeof(HtmlEdit)) || (t == typeof(HtmlTextArea))) { control = (ControlBase)test.Invoke(window, new object[] { By.ValueAttribute("test") }); } else { //window.Find<t>("InnerText=test"); control = (ControlBase)test.Invoke(window, new object[] { By.SearchProperties("InnerText=test") }); } //Act control.Click(); if (control is HtmlEdit) { (control as HtmlEdit).Text = "text"; } else if (control is HtmlTextArea) { (control as HtmlTextArea).Text = "text"; } } window.Close(); } }
public void Launch_TempHtmlFile_CanFindHyperlinkByHref() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <div class=""login"" style=""border: none;""> <div class=""member_box""> <span>APPLY FOR MEMBERSHIP</span> <a href=""/registration""> </a> </div> </body> </html>")) { // Act BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); // Assert HtmlHyperlink SignUpHyperLink = window.Find <HtmlHyperlink>(By.SearchProperties("href~registration")); Assert.IsTrue(SignUpHyperLink.Exists, "SignUp not found"); window.Close(); } }
public void SelectItem_ByIndexOnHtmlComboBox_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <select id=""selectId""> <option>Cricket</option> <option>Football</option> <option>Tennis</option> </select> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); //Act HtmlComboBox comboBox = window.Find <HtmlComboBox>(By.Id("selectId")); comboBox.SelectIndex(1); //Assert Assert.AreEqual("Football", comboBox.SelectedItem); window.Close(); } }
public void Launch_TempHtmlFileWithInputWithMaxLength_CanSetTextWhichExceedsMaxLength() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input id=""input"" type=""text"" maxlength=10 /> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlEdit input = window.Find <HtmlEdit>(By.Id("input")); // Act string inputText = "12345678901"; string outputText = "1234567890"; Keyboard.SendKeys(input.SourceControl, inputText); // Assert Assert.AreEqual(input.Text, outputText); window.Close(); } }
public void Get_UsingMultipleValuesOfClassAttributeWithContainsOperatorOfHtmlSpan_ReturnsTheSpecificElementWithAllSpecifiedClassValues() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <span name=""span1"" class=""class1"" /> <span name=""span2"" class=""class1 class4"" /> <span name=""span3"" class=""class1 class2 class3"" /> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlSpan span3 = window.Find <HtmlSpan>(By .Class("class1", PropertyExpressionOperator.Contains) .AndClass("class2", PropertyExpressionOperator.Contains)); // Act and Assert Assert.AreEqual("span3", span3.SourceControl.Name); window.Close(); } }
public void SetText_OnHtmlPassword_Succeeds() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <div class=""row textbox"" id=""idDiv_PWD_PasswordTb""> <div style=""width: 100%; position: relative;""> <input name=""passwd"" id=""i0118"" aria-labelledby=""idDiv_PWD_PasswordExample"" type=""password"" autocomplete=""off""> <div class=""phholder"" style=""left: 0px; top: 0px; width: 100%; position: absolute; z-index: 5;""> <div class=""placeholder"" id=""idDiv_PWD_PasswordExample"" aria-hidden=""true"" style=""cursor: text;"">Password</div> </div> </div> </div> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlPassword txtPwd = window.Find <HtmlPassword>(By.Id("i0118")); // Act txtPwd.Text = "hello"; // TODO: Assert window.Close(); } }
public void GetSelectedValue_OfRadioButton_Succeeds() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input type=""radio"" name=""radio:tab1:gender.type.male"" value=""male"" checked=checked>Male</input><br/> <input type=""radio"" name=""radio:tab1:gender.type.female"" value=""female"">Female</input><br/> <input type=""radio"" name=""radio:tab1:gender.type.other"" value=""other"">Other</input><br/> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); // Act HtmlRadioButton genderTypeMale = window.Find <HtmlRadioButton>(By.Name("radio:tab1:gender.type.male")); // Assert Assert.IsTrue(genderTypeMale.Selected); Assert.AreEqual("male", genderTypeMale.ValueAttribute); window.Close(); } }
public void ClickAllControlsOnPage_UsingReflection_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <a href=""#"">test</a> <button>test</button> <input type=""text"" value=""test""/> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); ControlBase a = window.Find<HtmlHyperlink>(By.SearchProperties("InnerText=test")); a.Click(); List<Type> list = new List<Type>(); list.Add(typeof(HtmlHyperlink)); list.Add(typeof(HtmlButton)); list.Add(typeof(HtmlEdit)); MethodInfo getMethodInfo = typeof(BrowserWindowUnderTest).GetMethod("Find", new[] { typeof(By) }); foreach(Type t in list) { MethodInfo test = getMethodInfo.MakeGenericMethod(t); ControlBase control; if ((t == typeof(HtmlEdit)) || (t == typeof(HtmlTextArea))) { control = (ControlBase)test.Invoke(window, new object[] { By.ValueAttribute("test") }); } else { //window.Find<t>("InnerText=test"); control = (ControlBase)test.Invoke(window, new object[] { By.SearchProperties("InnerText=test") }); } //Act control.Click(); if (control is HtmlEdit) { (control as HtmlEdit).Text = "text"; } else if (control is HtmlTextArea) { (control as HtmlTextArea).Text = "text"; } } window.Close(); } }
public void Click_OnHtmlHyperlink_InTableWithEmptyCell_Succeeds() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <table id=""tableId""> <tr id=""row""> <td></td> <td><a href=""#"">Details</a></td> </tr> </table> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); var table = window.Find <HtmlTable>(By.Id("tableId")); HtmlCell cell = table.GetCell(0, 1); HtmlHyperlink hyperlink = cell.Find <HtmlHyperlink>(); // Act hyperlink.Click(); // TODO: Assert window.Close(); } }
public void HtmlFileInput_SetFile_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input name=""inputName"" type=""file"" id=""inputId"" /> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlFileInput fileInput = window.Find <HtmlFileInput>(By.Id("inputId")); string tempInputFilePath = Path.GetTempFileName(); //Act fileInput.FileName = tempInputFilePath; window.Close(); File.Delete(tempInputFilePath); } }
public void HtmlTable_ColumnCount_Succeeds() { BrowserWindow.Launch(currentDirectory + "/TestHtmlPage.html"); var bWin = new BrowserWindowUnderTest("A Test"); var tbl = bWin.Find <HtmlTable>(By.Id("calcWithHeaders")); Assert.AreEqual(3, tbl.ColumnCount); bWin.Close(); }
public void HtmlTable_ClickOnColumnHeader_Succeeds() { BrowserWindow.Launch(currentDirectory + "/TestHtmlPage.html"); var bWin = new BrowserWindowUnderTest("A Test"); var tbl = bWin.Find <HtmlTable>(By.Id("tableWithAlertOnHeaderClick")); tbl.FindHeaderCellAndClick(0, 0); bWin.PerformDialogAction(BrowserDialogAction.Ok); bWin.Close(); }
public void SlList_DynamicObjectRecognition_Succeeds() { BrowserWindowUnderTest b = BrowserWindowUnderTest.Launch(silverlightApplicationHtmlPageUrl); b.SetFocus(); SilverlightList oList = b.Find <SilverlightList>(By.AutomationId("listBox1")); oList.SelectedIndices = new[] { 2 }; Assert.IsTrue(oList.SelectedItemsAsString == "Coded UI Test"); b.Close(); }
public void HtmlTable_GetCellValueUsingTableWithTHInTBODY_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <table id=""tableId"" border=""1""> <tbody> <tr> <th>Lun</th> <th>Used Space</th> <th>Free Space</th> <th>Usage %</th> <th> </th> </tr> <tr> <td>LUN_04</td> <td>26534605227</td> <td>15405750418</td> <td> <dl> <dd> <dl> <dd> <span>64.27%</span> </dd> </dl> </dd> </dl> </td> <td></td> </tr> </tbody> </table> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); var table = window.Find <HtmlTable>(By.Id("tableId")); //Act table.FindRowAndClick("LUN_04", 0, HtmlTableSearchOptions.NormalTight); //Assert Assert.AreEqual("LUN_04", table.GetCellValue(1, 0).Trim()); window.Close(); } }
public void SlTab_SelectedIndex_Succeeds() { BrowserWindowUnderTest b = BrowserWindowUnderTest.Launch(silverlightApplicationHtmlPageUrl); b.SetFocus(); SilverlightTab oTab = b.Find <SilverlightTab>(By.AutomationId("tabControl1")); oTab.SelectedIndex = 1; Assert.IsTrue(oTab.SourceControl.Items[0].Name == "tabItem1"); b.Close(); }
public void SlComboBox_SelectItem_Succeeds() { BrowserWindowUnderTest.Launch(silverlightApplicationHtmlPageUrl); BrowserWindowUnderTest b = new BrowserWindowUnderTest("Home"); b.SetFocus(); SilverlightComboBox oCombo = b.Find<SilverlightComboBox>(By.AutomationId("comboBox1")); oCombo.SelectIndex(3); foreach (UITestControl temp in oCombo.Items) { Console.WriteLine(temp.Name); } b.Close(); }
public void HtmlTable_GetColumnHeaders_Succeeds() { BrowserWindow.Launch(currentDirectory + "/TestHtmlPage.html"); var bWin = new BrowserWindowUnderTest("A Test"); var tbl = bWin.Find <HtmlTable>(By.Id("calcWithHeaders")); string[] saExpectedValues = { "Header1", "Header2", "Header3" }; string[] saHeaders = tbl.GetColumnHeaders(); Assert.AreEqual(saExpectedValues[0], saHeaders[0]); Assert.AreEqual(saExpectedValues[1], saHeaders[1]); Assert.AreEqual(saExpectedValues[2], saHeaders[2]); bWin.Close(); }
public void SlTab_TraverseSiblingsAndChildren_Succeeds() { BrowserWindowUnderTest b = BrowserWindowUnderTest.Launch(silverlightApplicationHtmlPageUrl); b.SetFocus(); SilverlightTab oTab = b.Find <SilverlightTab>(By.AutomationId("tabControl1")); oTab.SelectedIndex = 0; var btnOK = b.Find <SilverlightButton>(By.AutomationId("OKButtonInTabItem1")); ((SilverlightEdit)(btnOK.PreviousSibling)).Text = "blah blah hurray"; foreach (ControlBase control in oTab.GetChildren()) { if (control.GetType() == typeof(SilverlightEdit)) { ((SilverlightEdit)control).Text = "Text Changed"; break; } } Assert.IsTrue(((SilverlightTab)btnOK.Parent).SelectedItem == "tabItem1"); b.Close(); }
public void SlComboBox_SelectItem_Succeeds() { BrowserWindowUnderTest.Launch(silverlightApplicationHtmlPageUrl); BrowserWindowUnderTest b = new BrowserWindowUnderTest("Home"); b.SetFocus(); SilverlightComboBox oCombo = b.Find <SilverlightComboBox>(By.AutomationId("comboBox1")); oCombo.SelectIndex(3); foreach (UITestControl temp in oCombo.Items) { Console.WriteLine(temp.Name); } b.Close(); }
public void HtmlCheckBox_DisabledByStyle_ControlExistsAndCanGetCheckedState() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input type=""checkbox"" id=""checkBoxId"" disabled=""disabled"" name=""checkBoxName"" checked=""checked"" /> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); //Act HtmlCheckBox checkBox = window.Find<HtmlCheckBox>(By.Id("checkBoxId")); //Assert Assert.IsTrue(checkBox.Exists); Assert.IsTrue(checkBox.Checked); window.Close(); } }
public void LabelFor_OnHtmlLabel_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <form> <label for=""male"">Male</label> <input type=""radio"" name=""sex"" id=""male"" value=""male""><br> <label for=""female"">Female</label> <input type=""radio"" name=""sex"" id=""female"" value=""female""><br> <label id=""other"" for=""other"">Other</label> <input type=""radio"" name=""sex"" id=""other"" value=""other""><br> <input type=""submit"" value=""Submit""> </form> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlLabel label = window.Find<HtmlLabel>(By.Id("other")); //Assert Assert.AreEqual("other", label.LabelFor); window.Close(); } }
public void Launch_TempHtmlFileWithInputWithMaxLength_CanSetTextWhichExceedsMaxLength() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input id=""input"" type=""text"" maxlength=10 /> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlEdit input = window.Find<HtmlEdit>(By.Id("input")); // Act string inputText = "12345678901"; string outputText = "1234567890"; Keyboard.SendKeys(input.SourceControl, inputText); // Assert Assert.AreEqual(input.Text, outputText); window.Close(); } }
public void SelectedItems_OnHtmlList_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <select id=""selectId"" multiple=""multiple""> <option value=""1"">1</option> <option value=""2"">2</option> <option value=""3"">3</option> </select> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var bWin = new BrowserWindowUnderTest("test"); HtmlList list = bWin.Find<HtmlList>(By.Id("selectId")); string[] itemsToSelect = { "1", "2" }; //Act list.SelectedItems = itemsToSelect; //Assert CollectionAssert.AreEqual(itemsToSelect, list.SelectedItems); bWin.Close(); } }
public void SetText_OnHtmlPassword_Succeeds() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <div class=""row textbox"" id=""idDiv_PWD_PasswordTb""> <div style=""width: 100%; position: relative;""> <input name=""passwd"" id=""i0118"" aria-labelledby=""idDiv_PWD_PasswordExample"" type=""password"" autocomplete=""off""> <div class=""phholder"" style=""left: 0px; top: 0px; width: 100%; position: absolute; z-index: 5;""> <div class=""placeholder"" id=""idDiv_PWD_PasswordExample"" aria-hidden=""true"" style=""cursor: text;"">Password</div> </div> </div> </div> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlPassword txtPwd = window.Find<HtmlPassword>(By.Id("i0118")); // Act txtPwd.Text = "hello"; // TODO: Assert window.Close(); } }
public void HtmlInputButton_GetWithValueContainingWhitespace_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input name=""inputName"" type=""submit"" value="" Search "" /> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlInputButton button = window.Find<HtmlInputButton>(By.ValueAttribute(" Search ")); //Act button.Click(); window.Close(); } }
public void GetSelectedValue_OfRadioButton_Succeeds() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input type=""radio"" name=""radio:tab1:gender.type.male"" value=""male"" checked=checked>Male</input><br/> <input type=""radio"" name=""radio:tab1:gender.type.female"" value=""female"">Female</input><br/> <input type=""radio"" name=""radio:tab1:gender.type.other"" value=""other"">Other</input><br/> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); // Act HtmlRadioButton genderTypeMale = window.Find<HtmlRadioButton>(By.Name("radio:tab1:gender.type.male")); // Assert Assert.IsTrue(genderTypeMale.Selected); Assert.AreEqual("male", genderTypeMale.ValueAttribute); window.Close(); } }
public void HtmlTable_ClickOnColumnHeader_Succeeds() { BrowserWindow.Launch(currentDirectory + "/TestHtmlPage.html"); var bWin = new BrowserWindowUnderTest("A Test"); var tbl = bWin.Find<HtmlTable>(By.Id("tableWithAlertOnHeaderClick")); tbl.FindHeaderCellAndClick(0, 0); bWin.PerformDialogAction(BrowserDialogAction.Ok); bWin.Close(); }
public void HtmlInputButton_UsingSearchPropertyWithValueAsKey_Succeeds() { //Internet Explorer may display the message: Internet Explorer restricted this webpage from running scripts or ActiveX controls. //This security restriction prevents the alert message to appear. //To enable running scripts on the local computer, go to Tools > Internet options > Advanced > Security > [checkmark] Allow active content to run in files on My Computer //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input type=""submit"" value=""Log In"" onclick=""alert('onclick');""/> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlInputButton button = window.Find<HtmlInputButton>(By.ValueAttribute("Log In")); //Act button.Click(); if (BrowserWindowUnderTest.GetCurrentBrowser() is InternetExplorer) { //read JavaScript alert text WinWindow popup = new WinWindow(By.Name("Message from webpage").AndSearchProperties("ClassName=#32770")); WinText text = popup.Find<WinText>(); Assert.AreEqual("onclick", text.DisplayText); } window.PerformDialogAction(BrowserDialogAction.Ok); window.Close(); } }
public void HtmlTable_ColumnCount_Succeeds() { BrowserWindow.Launch(currentDirectory + "/TestHtmlPage.html"); var bWin = new BrowserWindowUnderTest("A Test"); var tbl = bWin.Find<HtmlTable>(By.Id("calcWithHeaders")); Assert.AreEqual(3, tbl.ColumnCount); bWin.Close(); }
public void HtmlTable_FindHeaderAndClick_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <table style=""width: 100%;"" id=""tableId""> <tbody> <tr> <td>Commitment</td> <th>September</th> <th>October</th> <th>November</th> <td>Total</td> </tr> <tr> <td>Beginning Balance</td> <td>¥21,570,253</td> <td>¥21,375,491</td> <td>¥21,200,873</td> <td></td> </tr> <tr> <td>New Purchases</td> <td>¥0</td> <td>¥0</td> <td>¥0</td> <td></td> </tr> <tr> <td>Utilized</td> <td>¥194,762</td> <td>¥174,618</td> <td>¥0</td> <td>¥369,380</td> </tr> <tr> <td>Ending Balance</td> <td>¥21,375,491</td> <td>¥21,200,873</td> <td>¥21,200,873</td> <td></td> </tr> <tr> <td><b>Overage</b></td> <td>¥0</td> <td>¥0</td> <td>¥0</td> <td>¥0</td> <td></td> </tr> <tr> <td><b>Total Usage</b></td> <td>¥194,762</td> <td>¥174,618</td> <td>¥0</td> <td>¥369,380</td> </tr> </tbody> </table> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); var table = window.Find<HtmlTable>(By.Id("tableId")); //Act table.FindHeaderCellAndClick(0, 2); window.Close(); } }
public void Click_OnHtmlHyperlink_InTableWithEmptyCell_Succeeds() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <table id=""tableId""> <tr id=""row""> <td></td> <td><a href=""#"">Details</a></td> </tr> </table> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); var table = window.Find<HtmlTable>(By.Id("tableId")); HtmlCell cell = table.GetCell(0, 1); HtmlHyperlink hyperlink = cell.Find<HtmlHyperlink>(); // Act hyperlink.Click(); // TODO: Assert window.Close(); } }
public void HtmlButton_HiddenByStyle_ControlExistsAndCanAssertOnStyle() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <button id=""buttonId"" style=""display: none;"" >Hidden</button> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); //Act HtmlButton button = window.Find<HtmlButton>(By.Id("buttonId")); //Assert Assert.IsTrue(button.Exists); Assert.IsTrue(button.SourceControl.ControlDefinition.Contains("style=\"display: none;\"")); window.Close(); } }
public void GetHtmlDiv_ByClass_Succeeds() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <div class=""button""><a href=""/main"">main text</a></div> <div class=""button""><a href=""/about"">about text</a></div> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); // Act HtmlDiv div = window.Find<HtmlDiv>(By.Class("button")); HtmlHyperlink about = window.Find<HtmlHyperlink>(By.SearchProperties("InnerText=about text;href~about")); HtmlDiv div2 = about.Parent as HtmlDiv; // Assert Assert.IsTrue(div.Exists); Assert.AreEqual("main text", div.SourceControl.InnerText); Assert.IsTrue(about.Exists); Assert.IsTrue(div2.Exists); Assert.AreEqual("about text", div2.SourceControl.InnerText); window.Close(); } }
public void Get_UsingMultipleValuesOfClassAttributeWithContainsOperatorOfHtmlSpan_ReturnsTheSpecificElementWithAllSpecifiedClassValues() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <span name=""span1"" class=""class1"" /> <span name=""span2"" class=""class1 class4"" /> <span name=""span3"" class=""class1 class2 class3"" /> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlSpan span3 = window.Find<HtmlSpan>(By .Class("class1", PropertyExpressionOperator.Contains) .AndClass("class2", PropertyExpressionOperator.Contains)); // Act and Assert Assert.AreEqual("span3", span3.SourceControl.Name); window.Close(); } }
public void Enabled_OnDisabledHtmlInputButton_ReturnsFalse() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input name=""inputName"" type=""submit"" value=""Click here"" disabled=""disabled"" /> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlInputButton button = window.Find<HtmlInputButton>(By.ValueAttribute("Click here")); // Act and Assert Assert.IsFalse(button.Enabled); window.Close(); } }
public void GetHtmlRow_ById_Succeeds() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <table class=""cart"" cellspacing=""0""> <tbody> <tr id=""555002_gp2""> <td> banana </td> </tr> </tbody> </table> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); // Act HtmlRow row = window.Find<HtmlRow>(By.Id("555002_gp2")); // Assert Assert.IsTrue(row.Exists); window.Close(); } }
public void HtmlTable_GetCellValueUsingTableWithTHInTBODY_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <table id=""tableId"" border=""1""> <tbody> <tr> <th>Lun</th> <th>Used Space</th> <th>Free Space</th> <th>Usage %</th> <th> </th> </tr> <tr> <td>LUN_04</td> <td>26534605227</td> <td>15405750418</td> <td> <dl> <dd> <dl> <dd> <span>64.27%</span> </dd> </dl> </dd> </dl> </td> <td></td> </tr> </tbody> </table> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); var table = window.Find<HtmlTable>(By.Id("tableId")); //Act table.FindRowAndClick("LUN_04", 0, HtmlTableSearchOptions.NormalTight); //Assert Assert.AreEqual("LUN_04", table.GetCellValue(1, 0).Trim()); window.Close(); } }
public void GetChildren_UsingHyperlinks_CanFindHyperlinkByInnerText() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <div id=""div1""> <a href=""#"">A - B - C</a> <a href=""#"">A - F - E</a> <a href=""#"">A - D - E</a> <a href=""#"">Z - B - C</a> <a href=""#"">Z - D - E</a> </div> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); //Act IEnumerable<ControlBase> collection = window.Find<HtmlDiv>(By.Id("div1")).GetChildren(); foreach (ControlBase control in collection) { if (control is HtmlHyperlink) { HtmlHyperlink link = (HtmlHyperlink)control; if (link.InnerText.StartsWith("A")) { Trace.WriteLine(string.Format("found: {0}", link.InnerText)); } } } window.Close(); } }
public void HtmlHyperlink_OnSharePoint2010_Succeeds() { BrowserWindow.Launch("http://myasia/sites/sureba/Default.aspx"); BrowserWindowUnderTest.Authenticate("username", "passwd"); var bWin = new BrowserWindowUnderTest("Suresh Balasubramanian"); bWin.Find<HtmlHyperlink>(By.Id("idHomePageNewDocument")).Click(); var closeLink = bWin.Find<HtmlHyperlink>(By.SearchProperties("Title=Close;class=ms-dlgCloseBtn")); //clicking closeLink directly doesn't work as the maximizeLink is clicked due to the controls being placed too close to each other Mouse.Click(closeLink.SourceControl.GetChildren()[0].GetChildren()[0]); bWin.RunScript(@"STSNavigate2(event,'/sites/sureba/_layouts/SignOut.aspx');"); }
public void Click_OnHtmlInputButtonWithEqualsSignInSearchPropertyValue_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input type=""submit"" value=""="" onclick=""alert('onclick');""/> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlInputButton button = window.Find<HtmlInputButton>(By.ValueAttribute("=")); //Act button.Click(); window.PerformDialogAction(BrowserDialogAction.Ok); window.Close(); } }
public void HtmlFileInput_SetFile_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <input name=""inputName"" type=""file"" id=""inputId"" /> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlFileInput fileInput = window.Find<HtmlFileInput>(By.Id("inputId")); string tempInputFilePath = Path.GetTempFileName(); //Act fileInput.FileName = tempInputFilePath; window.Close(); File.Delete(tempInputFilePath); } }
public void HtmlControl_NonExistent_DoesNotExist() { //Arrange SmartMatchOptions smartMatchOptions = SmartMatchOptions.Control; try { //set SmartMatchOptions to None because we are using .Exists on an invalid control //remember previous setting so that it can be reset smartMatchOptions = Playback.PlaybackSettings.SmartMatchOptions; Playback.PlaybackSettings.SmartMatchOptions = SmartMatchOptions.None; using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); //Act HtmlDiv div = window.Find<HtmlDiv>(By.Id("invalid")); //Assert Assert.IsFalse(div.Exists); window.Close(); } } finally { //reset default setting Playback.PlaybackSettings.SmartMatchOptions = smartMatchOptions; } }
public void HtmlComboBox_Items_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <select id=""selectId""> <option>Cricket</option> <option>Football</option> <option>Tennis</option> </select> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); //Act HtmlComboBox comboBox = window.Find<HtmlComboBox>(By.Id("selectId")); //Assert Assert.AreEqual("Football", comboBox.Items[1]); Assert.IsTrue(comboBox.Items.Contains("Cricket")); window.Close(); } }
public void SetText_OnHtmlEdit_Succeeds() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <div id=""div1""> <input type=""text""/> </div> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); HtmlDiv div = window.Find<HtmlDiv>(By.Id("div1")); HtmlEdit inputTextBox = div.Find<HtmlEdit>(); //Act inputTextBox.Text = "text"; //Assert Assert.AreEqual("text", inputTextBox.Text); window.Close(); } }
public void Launch_TempHtmlFile_CanFindHyperlinkByHref() { // Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test</title> </head> <body> <div class=""login"" style=""border: none;""> <div class=""member_box""> <span>APPLY FOR MEMBERSHIP</span> <a href=""/registration""> </a> </div> </body> </html>")) { // Act BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); // Assert HtmlHyperlink SignUpHyperLink = window.Find<HtmlHyperlink>(By.SearchProperties("href~registration")); Assert.IsTrue(SignUpHyperLink.Exists, "SignUp not found"); window.Close(); } }
public void Launch_UsingNewInstanceOfABrowserWindow_CanUsePartialWindowTitle() { //Arrange using (TempFile tempFile = new TempFile( @"<html> <head> <title>test 1 2 3</title> </head> <body> <button id=""buttonId"" >Button</button> </body> </html>")) { BrowserWindow.Launch(tempFile.FilePath); var window = new BrowserWindowUnderTest("test"); //Act HtmlButton button = window.Find<HtmlButton>(By.Id("buttonId")); //Assert Assert.AreEqual(button.InnerText, "Button"); Trace.WriteLine(window.Uri.ToString()); window.Close(); } }
public void HtmlTable_GetColumnHeaders_Succeeds() { BrowserWindow.Launch(currentDirectory + "/TestHtmlPage.html"); var bWin = new BrowserWindowUnderTest("A Test"); var tbl = bWin.Find<HtmlTable>(By.Id("calcWithHeaders")); string[] saExpectedValues = { "Header1", "Header2", "Header3" }; string[] saHeaders = tbl.GetColumnHeaders(); Assert.AreEqual(saExpectedValues[0], saHeaders[0]); Assert.AreEqual(saExpectedValues[1], saHeaders[1]); Assert.AreEqual(saExpectedValues[2], saHeaders[2]); bWin.Close(); }