public void ShouldAddFriend() { StringAssert.AreEqualIgnoringCase(ngDriver.Title, "Angular JS Demo"); String friendName = "John Doe"; int friendCount = ngDriver.FindElements(NgBy.Repeater("row in rows")).Count; NgWebElement addnameBox = ngDriver.FindElement(NgBy.Model("addName")); Assert.IsNotNull(addnameBox); ngDriver.Highlight(addnameBox, highlight_timeout); addnameBox.SendKeys(friendName); // add the friend NgWebElement addButton = ngDriver.FindElement(NgBy.ButtonText("+ add")); Assert.IsNotNull(addButton); ngDriver.Highlight(addButton, highlight_timeout); addButton.Click(); // confirm the number of friends Assert.AreEqual(1, ngDriver.FindElements(NgBy.Repeater("row in rows")).Count - friendCount); // find friend NgWebElement addedFriendElement = ngDriver.FindElements(NgBy.CssContainingText("td.ng-binding", friendName)).First(); Assert.IsNotNull(addedFriendElement); ngDriver.Highlight(addedFriendElement, highlight_timeout); Console.Error.WriteLine("Added friend name: " + addedFriendElement.Text); }
public void ShouldSearchAndDeleteFriend() { ReadOnlyCollection <NgWebElement> names = ngDriver.FindElements(NgBy.RepeaterColumn("row in rows", "row")); // pick random friend to remove Random random = new Random(); int index = random.Next(0, names.Count - 1); String friendName = names.ElementAt(index).Text; ReadOnlyCollection <NgWebElement> friendRows = ngDriver.FindElements(NgBy.Repeater("row in rows")); // remove all friends with that name foreach (NgWebElement friendRow in friendRows.Where(op => op.Text.Contains(friendName))) { IWebElement deleteButton = friendRow.FindElement(By.CssSelector("i.icon-trash")); ngDriver.Highlight(deleteButton, highlight_timeout); deleteButton.Click(); } // confirm search no longer finds any NgWebElement searchBox = ngDriver.FindElement(NgBy.Model("search")); Assert.IsNotNull(searchBox); ngDriver.Highlight(searchBox, highlight_timeout); searchBox.SendKeys(friendName); Action a = () => { var displayed = ngDriver.FindElement(NgBy.CssContainingText("td.ng-binding", friendName)).Displayed; }; a.ShouldThrow <NullReferenceException>(); // clear search inpout IWebElement clearSearchBox = searchBox.FindElement(By.XPath("..")).FindElement(By.CssSelector("i.icon-remove")); Assert.IsNotNull(clearSearchBox); ngDriver.Highlight(clearSearchBox, highlight_timeout); clearSearchBox.Click(); // confirm name of remaining friends are different foreach (NgWebElement friendRow in ngDriver.FindElements(NgBy.Repeater("row in rows"))) { String otherFriendName = new NgWebElement(ngDriver, friendRow).Evaluate("row").ToString(); Console.Error.WriteLine("Found name: " + otherFriendName); StringAssert.DoesNotMatch(otherFriendName, friendName); } }
public void ShouldDirectSelectFromDatePicker() { Common.GetLocalHostPageContent("ng_datepicker.htm"); // http://dalelotts.github.io/angular-bootstrap-datetimepicker/ NgWebElement ng_result = ngDriver.FindElement(NgBy.Model("data.inputOnTimeSet")); ng_result.Clear(); ngDriver.Highlight(ng_result); IWebElement calendar = ngDriver.FindElement(By.CssSelector(".input-group-addon")); ngDriver.Highlight(calendar); Actions actions = new Actions(ngDriver.WrappedDriver); actions.MoveToElement(calendar).Click().Build().Perform(); int datepicker_width = 900; int datepicker_heght = 800; driver.Manage().Window.Size = new System.Drawing.Size(datepicker_width, datepicker_heght); IWebElement dropdown = driver.FindElement(By.CssSelector("div.dropdown.open ul.dropdown-menu")); NgWebElement ng_dropdown = new NgWebElement(ngDriver, dropdown); Assert.IsNotNull(ng_dropdown); ReadOnlyCollection <NgWebElement> elements = ng_dropdown.FindElements(NgBy.Repeater("dateObject in week.dates")); Assert.IsTrue(28 <= elements.Count); String monthDate = "12"; IWebElement dateElement = ng_dropdown.FindElements(NgBy.CssContainingText("td.ng-binding", monthDate)).First(); Console.Error.WriteLine("Mondh Date: " + dateElement.Text); dateElement.Click(); NgWebElement ng_element = ng_dropdown.FindElement(NgBy.Model("data.inputOnTimeSet")); Assert.IsNotNull(ng_element); ngDriver.Highlight(ng_element); ReadOnlyCollection <NgWebElement> ng_dataDates = ng_element.FindElements(NgBy.Repeater("dateObject in data.dates")); Assert.AreEqual(24, ng_dataDates.Count); String timeOfDay = "6:00 PM"; NgWebElement ng_hour = ng_element.FindElements(NgBy.CssContainingText("span.hour", timeOfDay)).First(); Assert.IsNotNull(ng_hour); ngDriver.Highlight(ng_hour); Console.Error.WriteLine("Hour of the day: " + ng_hour.Text); ng_hour.Click(); String specificMinute = "6:35 PM"; // reload // dropdown = driver.FindElement(By.CssSelector("div.dropdown.open ul.dropdown-menu")); // ng_dropdown = new NgWebElement(ngDriver, dropdown); ng_element = ng_dropdown.FindElement(NgBy.Model("data.inputOnTimeSet")); Assert.IsNotNull(ng_element); ngDriver.Highlight(ng_element); NgWebElement ng_minute = ng_element.FindElements(NgBy.CssContainingText("span.minute", specificMinute)).First(); Assert.IsNotNull(ng_minute); ngDriver.Highlight(ng_minute); Console.Error.WriteLine("Time of the day: " + ng_minute.Text); ng_minute.Click(); ng_result = ngDriver.FindElement(NgBy.Model("data.inputOnTimeSet")); ngDriver.Highlight(ng_result, 100); Console.Error.WriteLine("Selected Date/time: " + ng_result.GetAttribute("value")); }
public void ShouldDirectSelect() { // Arrange try { wait.Until(e => e.FindElements( By.ClassName("col-sm-6")).Any(element => element.Text.IndexOf("Drop-down Datetime with input box", StringComparison.InvariantCultureIgnoreCase) > -1)); } catch (Exception e) { verificationErrors.Append(e.Message); } NgWebElement ng_datepicker = ngDriver.FindElement(NgBy.Model("data.dateDropDownInput", "*[data-ng-app]")); Assert.IsNotNull(ng_datepicker); // ng_datepicker.Clear(); ngDriver.Highlight(ng_datepicker); IWebElement calendar = ngDriver.FindElement(By.CssSelector(".input-group-addon")); Assert.IsNotNull(calendar); ngDriver.Highlight(calendar); Actions actions = new Actions(ngDriver.WrappedDriver); actions.MoveToElement(calendar).Click().Build().Perform(); IWebElement dropdown = driver.FindElement(By.CssSelector("div.dropdown.open ul.dropdown-menu")); NgWebElement ng_dropdown = new NgWebElement(ngDriver, dropdown); Assert.IsNotNull(ng_dropdown); ReadOnlyCollection <NgWebElement> elements = ng_dropdown.FindElements(NgBy.Repeater("dateObject in week.dates")); Assert.IsTrue(28 <= elements.Count); String monthDate = "12"; IWebElement dateElement = ng_dropdown.FindElements(NgBy.CssContainingText("td.ng-binding", monthDate)).First(); Console.Error.WriteLine("Mondh Date: " + dateElement.Text); dateElement.Click(); NgWebElement ng_element = ng_dropdown.FindElement(NgBy.Model("data.dateDropDownInput", "[data-ng-app]")); Assert.IsNotNull(ng_element); ngDriver.Highlight(ng_element); ReadOnlyCollection <NgWebElement> ng_dataDates = ng_element.FindElements(NgBy.Repeater("dateObject in data.dates")); Assert.AreEqual(24, ng_dataDates.Count); String timeOfDay = "6:00 PM"; NgWebElement ng_hour = ng_element.FindElements(NgBy.CssContainingText("span.hour", timeOfDay)).First(); Assert.IsNotNull(ng_hour); ngDriver.Highlight(ng_hour); Console.Error.WriteLine("Hour of the day: " + ng_hour.Text); ng_hour.Click(); String specificMinute = "6:35 PM"; // no need to reload ng_element = ng_dropdown.FindElement(NgBy.Model("data.dateDropDownInput", "*[data-ng-app]")); Assert.IsNotNull(ng_element); ngDriver.Highlight(ng_element); NgWebElement ng_minute = ng_element.FindElements(NgBy.CssContainingText("span.minute", specificMinute)).First(); Assert.IsNotNull(ng_minute); ngDriver.Highlight(ng_minute); Console.Error.WriteLine("Time of the day: " + ng_minute.Text); ng_minute.Click(); ng_datepicker = ngDriver.FindElement(NgBy.Model("data.dateDropDownInput", "[data-ng-app]")); ngDriver.Highlight(ng_datepicker, 100); Console.Error.WriteLine("Selected Date/time: " + ng_datepicker.GetAttribute("value")); }