public void ClearCompleted() { AddToDo("ToDoToBeCleared"); AddToDo("SecondToDoToNotBeCleared"); NgWebElement toDoList = ngDriver.FindElement(By.Id("todo-list")); Assert.AreEqual(2, toDoList.FindElements(By.CssSelector("li")).Count, "to-do's weren't created"); NgWebElement item = toDoList.FindElement(By.CssSelector("li")); WebDriverWait wait = new WebDriverWait(ngDriver, new TimeSpan(0, 0, 15)); wait.Until(ExpectedConditions.ElementToBeClickable(item.FindElement(NgBy.Model("todo.completed")))); Assert.True(!item.GetAttribute("class").Contains("completed"), "item was already set to completed without being clicked"); item.FindElement(NgBy.Model("todo.completed")).Click(); Assert.True(item.GetAttribute("class").Contains("completed"), "item is still not to completed after it has been clicked"); wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("clear-completed"))); ngDriver.FindElement(By.Id("clear-completed")).Click(); Assert.AreEqual(1, toDoList.FindElements(By.CssSelector("li")).Count, "to-do wasn't deleted"); }
public void ShouldDeposit() { ngDriver.FindElement(NgBy.ButtonText("Customer Login")).Click(); ReadOnlyCollection <NgWebElement> ng_customers = ngDriver.FindElement(NgBy.Model("custId")).FindElements(NgBy.Repeater("cust in Customers")); // select customer to log in ng_customers.First(cust => Regex.IsMatch(cust.Text, "Harry Potter")).Click(); ngDriver.FindElement(NgBy.ButtonText("Login")).Click(); ngDriver.FindElement(NgBy.Options("account for account in Accounts")).Click(); // inspect the account NgWebElement ng_account_number = ngDriver.FindElement(NgBy.Binding("accountNo")); int account_id = 0; int.TryParse(ng_account_number.Text.FindMatch(@"(?<account_number>\d+)$"), out account_id); Assert.AreNotEqual(0, account_id); int account_balance = -1; int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out account_balance); Assert.AreNotEqual(-1, account_balance); NgWebElement ng_deposit_button = ngDriver.FindElement(NgBy.PartialButtonText("Deposit")); Assert.IsTrue(ng_deposit_button.Displayed); actions.MoveToElement(ng_deposit_button.WrappedElement).Build().Perform(); Thread.Sleep(500); ng_deposit_button.Click(); // core Selenium wait.Until(ExpectedConditions.ElementExists(By.CssSelector("form[name='myForm']"))); NgWebElement ng_form_element = new NgWebElement(ngDriver, driver.FindElement(By.CssSelector("form[name='myForm']"))); // deposit amount NgWebElement ng_deposit_amount = ng_form_element.FindElement(NgBy.Model("amount")); ng_deposit_amount.SendKeys("100"); wait.Until(ExpectedConditions.ElementIsVisible(NgBy.ButtonText("Deposit"))); ng_deposit_button = ng_form_element.FindElement(NgBy.ButtonText("Deposit")); actions.MoveToElement(ng_deposit_button.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_deposit_button); ng_deposit_button.Click(); // http://www.way2automation.com/angularjs-protractor/banking/depositTx.html // inspect message var ng_message = ngDriver.FindElement(NgBy.Binding("message")); StringAssert.Contains("Deposit Successful", ng_message.Text); ngDriver.Highlight(ng_message); // re-read the amount int updated_account_balance = -1; int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out updated_account_balance); Assert.AreEqual(updated_account_balance, account_balance + 100); }
/// <summary> /// Method to get the value of a particular row cell. /// </summary> /// <param name="rowElement"> /// The element of the row being targeted. /// </param> /// <param name="cellIndex"> /// The index of the cell being targeted. Not zero based. Start at 1. /// </param> /// <param name="asHtml"> /// Determines if the value should be returned in its HTML source. /// </param> /// <returns> /// Returns the value of the cell. /// </returns> public string GetCellValue(NgWebElement rowElement, int cellIndex, bool asHtml = false) { if (asHtml) { // Get the HTML source value of the row cell. return(rowElement.FindElement(By.XPath(string.Format("td[{0}]", cellIndex))).GetAttribute("innerHTML")); } // Get the text value of the row cell. return(rowElement.FindElement(By.XPath(string.Format("td[{0}]", cellIndex))).Text); }
public void ShouldWithdraw() { ShouldDeposit(); int account_balance = -1; int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out account_balance); Assert.AreNotEqual(-1, account_balance); ngDriver.FindElement(NgBy.PartialButtonText("Withdrawl")).Click(); // core Selenium Thread.Sleep(1000); wait.Until(ExpectedConditions.ElementExists(By.CssSelector("form[name='myForm']"))); NgWebElement ng_form_element = new NgWebElement(ngDriver, driver.FindElement(By.CssSelector("form[name='myForm']"))); NgWebElement ng_withdrawl_amount = ng_form_element.FindElement(NgBy.Model("amount")); ng_withdrawl_amount.SendKeys((account_balance + 100).ToString()); NgWebElement ng_withdrawl_button = ng_form_element.FindElement(NgBy.ButtonText("Withdraw")); ngDriver.Highlight(ng_withdrawl_button, highlight_timeout); ng_withdrawl_button.Click(); // inspect message var ng_message = ngDriver.FindElement(NgBy.Binding("message")); StringAssert.Contains("Transaction Failed. You can not withdraw amount more than the balance.", ng_message.Text); ngDriver.Highlight(ng_message); // re-read the amount int updated_account_balance = -1; int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out updated_account_balance); Assert.AreEqual(account_balance, updated_account_balance); // core Selenium Thread.Sleep(1000); wait.Until(ExpectedConditions.ElementExists(By.CssSelector("form[name='myForm']"))); ng_form_element = new NgWebElement(ngDriver, driver.FindElement(By.CssSelector("form[name='myForm']"))); ng_form_element.FindElement(NgBy.Model("amount")).SendKeys((account_balance - 10).ToString()); ng_form_element.FindElement(NgBy.ButtonText("Withdraw")).Click(); // inspect message ng_message = ngDriver.FindElement(NgBy.Binding("message")); StringAssert.Contains("Transaction successful", ng_message.Text); ngDriver.Highlight(ng_message, highlight_timeout); // re-read the amount int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out updated_account_balance); Assert.AreEqual(10, updated_account_balance); }
public void ShouldHandleDeselectAngularUISelect() { Common.GetLocalHostPageContent("ng_ui_select_example1.htm"); ReadOnlyCollection <NgWebElement> ng_selected_colors = ngDriver.FindElements(NgBy.Repeater("$item in $select.selected")); while (true) { ng_selected_colors = ngDriver.FindElements(NgBy.Repeater("$item in $select.selected")); if (ng_selected_colors.Count == 0) { break; } NgWebElement ng_deselect_color = ng_selected_colors.Last(); Object itemColor = ng_deselect_color.Evaluate("$item"); Console.Error.WriteLine(String.Format("Deselecting color: {0}", itemColor.ToString())); IWebElement ng_close = ng_deselect_color.FindElement(By.CssSelector("span[class *='close']")); Assert.IsNotNull(ng_close); Assert.IsNotNull(ng_close.GetAttribute("ng-click")); StringAssert.IsMatch(@"removeChoice", ng_close.GetAttribute("ng-click")); ngDriver.Highlight(ng_close); ng_close.Click(); // ngDriver.waitForAngular(); } Console.Error.WriteLine("Nothing is selected"); }
public void FilterByCompleted() { AddToDo("ToDoToBeFiltered"); AddToDo("SecondToDoToNotBeFiltered"); NgWebElement toDoList = ngDriver.FindElement(By.Id("todo-list")); Assert.AreEqual(2, toDoList.FindElements(By.CssSelector("li")).Count, "to-do's weren't created"); NgWebElement item = toDoList.FindElement(By.CssSelector("li")); Assert.True(!item.GetAttribute("class").Contains("completed"), "item was already set to completed without being clicked"); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(ExpectedConditions.ElementToBeClickable(item.FindElement(NgBy.Model("todo.completed")))); item.FindElement(NgBy.Model("todo.completed")).Click(); Assert.True(item.GetAttribute("class").Contains("completed"), "item is still not to completed after it has been clicked"); NgWebElement filters = ngDriver.FindElement(By.Id("filters")); filters.FindElement(By.CssSelector("a[href='#/completed']")).Click(); //changing the filter reloaded the todo list from scratch causing a stale todo list element Assert.AreEqual(1, ngDriver.FindElement(By.Id("todo-list")).FindElements(By.CssSelector("li")).Count, "to-do wasn't filtered"); }
public void UncompleteToDo() { AddToDo("ToDoToBeSetBackToACtive"); NgWebElement toDoList = ngDriver.FindElement(By.Id("todo-list")); Assert.AreEqual(1, toDoList.FindElements(By.CssSelector("li")).Count, "to-do wasn't created"); NgWebElement item = toDoList.FindElement(By.CssSelector("li")); WebDriverWait wait = new WebDriverWait(ngDriver, new TimeSpan(0, 0, 15)); wait.Until(ExpectedConditions.ElementToBeClickable(item.FindElement(NgBy.Model("todo.completed")))); item.FindElement(NgBy.Model("todo.completed")).Click(); //issue was caused in edge attemted to fix with commented out code but basically the clicks whould happen too fast and the seond wouldnt be recognised Thread.Sleep(1000); Assert.True(item.GetAttribute("class").Contains("completed"), "to-do wasn't set to completed"); wait.Until(ExpectedConditions.ElementToBeClickable(item.FindElement(NgBy.Model("todo.completed")))); item.FindElement(NgBy.Model("todo.completed")).Click(); //ngDriver.WaitForAngular(); Assert.True(!item.GetAttribute("class").Contains("completed"), "to-do wasn't set to active"); }
protected void CloseTinyMce(NgWebElement tinyMce) { var parent = tinyMce.FindElement(By.XPath("../..")); var close = parent.FindElement(By.LinkText("Close")); close.Click(); }
public void ShouldNavigateDatesInDatePicker() { Common.GetLocalHostPageContent("ng_datepicker.htm"); 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(); IWebElement dropdown = driver.FindElement(By.CssSelector("div.dropdown.open ul.dropdown-menu")); NgWebElement ng_dropdown = new NgWebElement(ngDriver, dropdown); Assert.IsNotNull(ng_dropdown); NgWebElement ng_display = ngDriver.FindElement(NgBy.Binding("data.previousViewDate.display")); Assert.IsNotNull(ng_display); String dateDattern = @"\d{4}\-(?<month>\w{3})"; Regex dateDatternReg = new Regex(dateDattern); Assert.IsTrue(dateDatternReg.IsMatch(ng_display.Text)); ngDriver.Highlight(ng_display); String display_month = ng_display.Text.FindMatch(dateDattern); // Console.Error.WriteLine("Current month: " + ng_display.Text); String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Dec", "Jan" }; String next_month = months[Array.IndexOf(months, display_month) + 1]; Console.Error.WriteLine("Current month: " + display_month); Console.Error.WriteLine("Next month: " + next_month); IWebElement ng_right = ng_display.FindElement(By.XPath("..")).FindElement(By.ClassName("right")); Assert.IsNotNull(ng_right); ngDriver.Highlight(ng_right, 100); ng_right.Click(); Assert.IsTrue(ng_display.Text.Contains(next_month)); ngDriver.Highlight(ng_display); Console.Error.WriteLine("Next month: " + ng_display.Text); }
public void ShouldSelectAll() { // Given multuselect directive NgWebElement ng_directive = ngDriver.FindElement(NgBy.Model("selectedCar")); Assert.IsNotNull(ng_directive.WrappedElement); Assert.That(ng_directive.TagName, Is.EqualTo("am-multiselect")); // open am-multiselect IWebElement toggleSelect = ng_directive.FindElement(NgBy.ButtonText("Select Some Cars")); Assert.IsNotNull(toggleSelect); Assert.IsTrue(toggleSelect.Displayed); toggleSelect.Click(); // When using 'check all' link wait.Until(o => (o.FindElements(By.CssSelector("button[ng-click='checkAll()']")).Count != 0)); IWebElement check_all = ng_directive.FindElement(By.CssSelector("button[ng-click='checkAll()']")); Assert.IsTrue(check_all.Displayed); ngDriver.Highlight(check_all, highlight_timeout, 5, "blue"); check_all.Click(); // Then every car is selected // validatate the count ReadOnlyCollection <NgWebElement> cars = ng_directive.FindElements(NgBy.Repeater("i in items")); Assert.AreEqual(cars.Count(), cars.Count(car => (Boolean)car.Evaluate("i.checked"))); // walk over foreach (NgWebElement ng_item in ng_directive.FindElements(NgBy.RepeaterColumn("i in items", "i.label"))) { if (Boolean.Parse(ng_item.Evaluate("i.checked").ToString())) { IWebElement icon = ng_item.FindElement(By.ClassName("glyphicon")); // NOTE: the icon attributes // <i class="glyphicon glyphicon-ok" ng-class="{'glyphicon-ok': i.checked, 'empty': !i.checked}"></i> StringAssert.Contains("{'glyphicon-ok': i.checked, 'empty': !i.checked}", icon.GetAttribute("ng-class")); Console.Error.WriteLine("Icon: " + icon.GetAttribute("class")); ngDriver.Highlight(ng_item, highlight_timeout); } } Thread.Sleep(1000); }
public void EditToDo() { AddToDo("ToDoToBeEdited"); NgWebElement toDoList = ngDriver.FindElement(By.Id("todo-list")); Actions act = new Actions(ngDriver); NgWebElement item = toDoList.FindElement(By.CssSelector("li")); NgWebElement label = item.FindElement(By.CssSelector("label")); act.MoveToElement(label).DoubleClick().Perform(); NgWebElement editInput = item.FindElement(NgBy.Model("todo.title")); editInput.SendKeys(Keys.Control + "a"); editInput.SendKeys("ToDoThatHasBeenEdited"); ngDriver.FindElement(By.Id("new-todo")).Click(); Assert.AreEqual("ToDoThatHasBeenEdited", label.Text, "the todo wasn't modified"); }
public void CompleteToDo() { AddToDo("ToDoToBeCompleted"); NgWebElement toDoList = ngDriver.FindElement(By.Id("todo-list")); Actions act = new Actions(ngDriver); NgWebElement item = toDoList.FindElement(By.CssSelector("li")); Assert.True(!item.GetAttribute("class").Contains("completed"), "item was already set to completed without being clicked"); item.FindElement(NgBy.Model("todo.completed")).Click(); Assert.True(item.GetAttribute("class").Contains("completed"), "item is still not to completed after it has been clicked"); }
public void ClearCache() { this.ngDriver.Navigate().GoToUrl("chrome://settings/clearBrowserData"); Thread.Sleep(3000); var element = new NgWebElement(this.ngDriver, this.ngDriver.FindElement(By.ClassName("body-container")), By.ClassName("body-container")); var checkboxes = element.FindElements(By.Id("checkbox")); checkboxes[1].Click(); Thread.Sleep(500); checkboxes[2].Click(); Thread.Sleep(500); element.FindElement(By.Id("clearBrowsingDataConfirm")).Click(); Thread.Sleep(5000); }
public void SelectCountry(string Text) { log.Info(String.Format("Selecting '{0}' on Explore page", Text)); NgWebElement geoOptions = driver.FindElement(By.CssSelector("hierarchy-picker[data='ctrl.geoOptions']")); wait.Until(driver => geoOptions.Enabled); geoOptions.Click(); NgWebElement geoOptionsInput = geoOptions.FindElement(By.CssSelector("input")); wait.Until(driver => geoOptions.Displayed); geoOptionsInput.SendKeys(Text); geoOptionsInput.SendKeys(Keys.ArrowDown); geoOptionsInput.SendKeys(Keys.Enter); }
/// <summary> /// Method to click a hyperlink or button in a particular row cell. /// </summary> /// <param name="rowElement"> /// The element of the row being targeted. /// </param> /// <param name="cellIndex"> /// The index of the cell being targeted. Not zero based. Start at 1. /// </param> public void ClickRowCell(NgWebElement rowElement, int cellIndex) { // Attempt to find a hyperlink or button to click within the supplied row and cell. try { // Search for a hyperlink to click. rowElement.FindElement(By.XPath(string.Format("td[{0}]//a", cellIndex))).Click(); return; } catch (NoSuchElementException) { // No hyperlinks found. } try { // Search for a button to click. rowElement.FindElement(By.XPath(string.Format("td[{0}]//button", cellIndex))).Click(); } catch (NoSuchElementException) { // No buttons found. } }
public void ShouldDeleteCustomer() { // switch to "Add Customer" screen ngDriver.FindElement(NgBy.ButtonText("Bank Manager Login")).Click(); ngDriver.FindElement(NgBy.PartialButtonText("Add Customer")).Click(); // fill new Customer data ngDriver.FindElement(NgBy.Model("fName")).SendKeys("John"); ngDriver.FindElement(NgBy.Model("lName")).SendKeys("Doe"); ngDriver.FindElement(NgBy.Model("postCd")).SendKeys("11011"); // NOTE: there are two 'Add Customer' buttons on this form NgWebElement ng_add_customer_button = ngDriver.FindElements(NgBy.PartialButtonText("Add Customer"))[1]; actions.MoveToElement(ng_add_customer_button.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_add_customer_button); ng_add_customer_button.Submit(); // confirm ngDriver.WrappedDriver.SwitchTo().Alert().Accept(); // switch to "Home" screen ngDriver.FindElement(NgBy.ButtonText("Home")).Click(); ngDriver.FindElement(NgBy.ButtonText("Bank Manager Login")).Click(); ngDriver.FindElement(NgBy.PartialButtonText("Customers")).Click(); // found new customer ReadOnlyCollection <NgWebElement> ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); // collect all customers ReadOnlyCollection <NgWebElement> ng_users = ngDriver.FindElements(NgBy.RepeaterColumn("cust in Customers", "user")); NgWebElement new_customer = ng_customers.Single(cust => Regex.IsMatch(cust.Text, "John Doe")); Assert.IsNotNull(new_customer); // remove button NgWebElement ng_delete_customer_button = new_customer.FindElement(NgBy.ButtonText("Delete")); StringAssert.IsMatch("Delete", ng_delete_customer_button.Text); actions.MoveToElement(ng_delete_customer_button.WrappedElement).Build().Perform(); ng_delete_customer_button.Click(); // confirm the cusomer is no loger present ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); IEnumerable <NgWebElement> removed_customer = ng_customers.TakeWhile(cust => Regex.IsMatch(cust.Text, "John Doe.*")); Assert.IsEmpty(removed_customer); }
public void ShouldPrintOrderByFieldColumn() { GetPageContent("ng_headers_sort_example2.htm"); String[] headers = new String[] { "First Name", "Last Name", "Age" }; foreach (String header in headers) { for (int cnt = 0; cnt != 2; cnt++) { IWebElement headerElement = ngDriver.FindElement(By.XPath("//th/a[contains(text(),'" + header + "')]")); Console.Error.WriteLine("Clicking on header: " + header); headerElement.Click(); // triggers ngDriver.WaitForAngular() Assert.IsNotEmpty(ngDriver.Url); ReadOnlyCollection <NgWebElement> ng_emps = ngDriver.FindElements(NgBy.Repeater("emp in data.employees")); NgWebElement ng_emp = ng_emps[0]; String field = ng_emp.GetAttribute("ng-order-by"); Console.Error.WriteLine(field + ": " + ng_emp.Evaluate(field).ToString()); String empField = "emp." + ng_emp.Evaluate(field); Console.Error.WriteLine(empField + ":"); var ng_emp_enumerator = ng_emps.GetEnumerator(); ng_emp_enumerator.Reset(); while (ng_emp_enumerator.MoveNext()) { ng_emp = (NgWebElement)ng_emp_enumerator.Current; if (ng_emp.Text == null) { break; } Assert.IsNotNull(ng_emp.WrappedElement); // Console.Error.WriteLine(ngEmp.getAttribute("innerHTML")); try { NgWebElement ng_column = ng_emp.FindElement(NgBy.Binding(empField)); Assert.IsNotNull(ng_column); Console.Error.WriteLine(ng_column.Text); } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); } } } } }
public void DeleteToDo() { AddToDo("ToDoToBeDeleted"); NgWebElement toDoList = ngDriver.FindElement(By.Id("todo-list")); Assert.AreEqual(1, toDoList.FindElements(By.CssSelector("li")).Count, "to-do item didn't add"); NgWebElement item = toDoList.FindElement(By.CssSelector("li")); Actions act = new Actions(ngDriver); act.MoveToElement(item).Perform(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("button.destroy"))); item.FindElement(By.CssSelector("button.destroy")).Click(); Assert.Zero(toDoList.FindElements(By.CssSelector("li")).Count, "to-do item wasn't deleted"); }
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 ShouldFindOrderByField() { GetPageContent("ng_headers_sort_example1.htm"); String[] headers = new String[] { "First Name", "Last Name", "Age" }; foreach (String header in headers) { IWebElement headerelement = ngDriver.FindElement(By.XPath(String.Format("//th/a[contains(text(),'{0}')]", header))); Console.Error.WriteLine(header); headerelement.Click(); // to trigger WaitForAngular Assert.IsNotEmpty(ngDriver.Url); IWebElement emp = ngDriver.FindElement(NgBy.Repeater("emp in data.employees")); NgWebElement ngRow = new NgWebElement(ngDriver, emp); String orderByField = emp.GetAttribute("ng-order-by"); Console.Error.WriteLine(orderByField + ": " + ngRow.Evaluate(orderByField).ToString()); } ReadOnlyCollection <NgWebElement> ng_people = ngDriver.FindElements(NgBy.Repeater("person in people")); var ng_people_enumerator = ng_people.GetEnumerator(); ng_people_enumerator.Reset(); while (ng_people_enumerator.MoveNext()) { NgWebElement ng_person = (NgWebElement)ng_people_enumerator.Current; if (ng_person.Text == null) { break; } NgWebElement ng_name = ng_person.FindElement(NgBy.Binding("person.Name")); Assert.IsNotNull(ng_name.WrappedElement); Object obj_country = ng_person.Evaluate("person.Country"); Assert.IsNotNull(obj_country); if (String.Compare("Around the Horn", ng_name.Text) == 0) { StringAssert.IsMatch("UK", obj_country.ToString()); } } }
public string GetValueAfterClick() { //клик по селекту, ждем когда расскроется список selectElement.Click(); var arrTagLi = selectElement.FindElement(By.CssSelector("select-dropdown>div>div.options")).FindElements(By.TagName("li")); foreach (var i in arrTagLi) { if (i.GetAttribute("class") == "highlighted selected") { return(i.Text); } } return(null); }
public void ShouldAddCustomer() { // When I proceed to "Bank Manager Login" ngDriver.FindElement(NgBy.ButtonText("Bank Manager Login")).Click(); // And I proceed to "Add Customer" ngDriver.FindElement(NgBy.PartialButtonText("Add Customer")).Click(); // And I fill new Customer data IWebElement ng_first_name = ngDriver.FindElement(NgBy.Model("fName")); ngDriver.Highlight(ng_first_name, highlight_timeout); StringAssert.IsMatch("First Name", ng_first_name.GetAttribute("placeholder")); ng_first_name.SendKeys("John"); IWebElement ng_last_name = ngDriver.FindElement(NgBy.Model("lName")); ngDriver.Highlight(ng_last_name, highlight_timeout); StringAssert.IsMatch("Last Name", ng_last_name.GetAttribute("placeholder")); ng_last_name.SendKeys("Doe"); IWebElement ng_post_code = ngDriver.FindElement(NgBy.Model("postCd")); ngDriver.Highlight(ng_post_code, highlight_timeout); StringAssert.IsMatch("Post Code", ng_post_code.GetAttribute("placeholder")); ng_post_code.SendKeys("11011"); // NOTE: there are two 'Add Customer' buttons on this form NgWebElement ng_add_customer_button = ngDriver.FindElements(NgBy.PartialButtonText("Add Customer"))[1]; actions.MoveToElement(ng_add_customer_button.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_add_customer_button, highlight_timeout); ng_add_customer_button.Submit(); // confirm string alert_text = null; try { alert = ngDriver.WrappedDriver.SwitchTo().Alert(); alert_text = alert.Text; StringAssert.StartsWith("Customer added successfully with customer id :", alert_text); alert.Accept(); } catch (NoAlertPresentException ex) { // Alert not present verificationErrors.Append(ex.StackTrace); } catch (WebDriverException ex) { // Alert not handled by PhantomJS verificationErrors.Append(ex.StackTrace); } int customer_id = 0; int.TryParse(alert_text.FindMatch(@"(?<customer_id>\d+)$"), out customer_id); Assert.AreNotEqual(0, customer_id); // And I switch to "Customers" screen ngDriver.FindElement(NgBy.PartialButtonText("Customers")).Click(); // discover newly added customer ReadOnlyCollection <NgWebElement> ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); int customer_count = ng_customers.Count; NgWebElement ng_new_customer = ng_customers.First(cust => Regex.IsMatch(cust.Text, "John Doe")); Assert.IsNotNull(ng_new_customer); actions.MoveToElement(ng_new_customer.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_new_customer, highlight_timeout); // confirm searching for the customer name ngDriver.FindElement(NgBy.Model("searchCustomer")).SendKeys("John"); ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); Assert.AreEqual(1, ng_customers.Count); // show all customers again ngDriver.FindElement(NgBy.Model("searchCustomer")).Clear(); Thread.Sleep(500); wait.Until(ExpectedConditions.ElementIsVisible(NgBy.Repeater("cust in Customers"))); // discover newly added customer again ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); ng_new_customer = ng_customers.First(cust => Regex.IsMatch(cust.Text, "John Doe")); // delete new customer NgWebElement ng_delete_button = ng_new_customer.FindElement(NgBy.ButtonText("Delete")); Assert.IsNotNull(ng_delete_button); actions.MoveToElement(ng_delete_button.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_delete_button, highlight_timeout); // in slow motion actions.MoveToElement(ng_delete_button.WrappedElement).ClickAndHold().Build().Perform(); Thread.Sleep(1000); actions.Release(); // sometimes actions do not work - for example in this test ng_delete_button.Click(); // wait for customer list to reload Thread.Sleep(1000); wait.Until(ExpectedConditions.ElementIsVisible(NgBy.Repeater("cust in Customers"))); // count the remaining customers ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); int new_customer_count = ng_customers.Count; // conrirm the customer count changed Assert.IsTrue(customer_count - 1 == new_customer_count); }
public void ShouldDeposit() { ngDriver.FindElement(NgBy.ButtonText("Customer Login")).Click(); ReadOnlyCollection <NgWebElement> ng_customers = ngDriver.FindElement(NgBy.Model("custId")).FindElements(NgBy.Repeater("cust in Customers")); // select customer to log in ng_customers.First(cust => Regex.IsMatch(cust.Text, "Harry Potter")).Click(); ngDriver.FindElement(NgBy.ButtonText("Login")).Click(); ngDriver.FindElement(NgBy.Options("account for account in Accounts")).Click(); // inspect the account NgWebElement ng_account_number = ngDriver.FindElement(NgBy.Binding("accountNo")); int account_id = 0; int.TryParse(ng_account_number.Text.FindMatch(@"(?<account_number>\d+)$"), out account_id); Assert.AreNotEqual(0, account_id); /* * IEnumerable<IWebElement>elements = driver.FindElements(By.CssSelector("[data-id]")); * int[] results = elements.TakeWhile(e => Regex.IsMatch(e.GetAttribute("data-id") , "[0-9]+" )).Select(x => Int32.Parse(x.GetAttribute("data-id"))).ToArray<int>(); */ int account_balance = -1; int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out account_balance); Assert.AreNotEqual(-1, account_balance); NgWebElement ng_deposit_button = ngDriver.FindElement(NgBy.PartialButtonText("Deposit")); Assert.IsTrue(ng_deposit_button.Displayed); actions.MoveToElement(ng_deposit_button.WrappedElement).Build().Perform(); Thread.Sleep(500); ng_deposit_button.Click(); // core Selenium wait.Until(ExpectedConditions.ElementExists(By.CssSelector("form[name='myForm']"))); NgWebElement ng_form_element = new NgWebElement(ngDriver, driver.FindElement(By.CssSelector("form[name='myForm']"))); // deposit amount NgWebElement ng_deposit_amount = ng_form_element.FindElement(NgBy.Model("amount")); ng_deposit_amount.SendKeys("100"); // Confirm to perform deposit NgWebElement ng_submit_deposit_button = ng_form_element.FindElements(NgBy.ButtonText("Deposit")).First(o => o.GetAttribute("class").IndexOf("btn-default", StringComparison.InvariantCultureIgnoreCase) > -1); actions.MoveToElement(ng_submit_deposit_button.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_submit_deposit_button, highlight_timeout); ng_submit_deposit_button.Click(); // http://www.way2automation.com/angularjs-protractor/banking/depositTx.html // inspect message var ng_message = ngDriver.FindElement(NgBy.Binding("message")); StringAssert.Contains("Deposit Successful", ng_message.Text); ngDriver.Highlight(ng_message, highlight_timeout); // re-read the amount int updated_account_balance = -1; int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out updated_account_balance); Assert.AreEqual(updated_account_balance, account_balance + 100); }
public void VerifyAccountDeposit() { driver.Navigate().GoToUrl(base_url); By elem = By.XPath(".//button[contains(text(),'Customer Login')]"); NgDriver.FindElement(elem).Click(); //NgDriver.FindElement(By.XPath(".//button[contains(text(),'Customer Login')]")).Click(); ReadOnlyCollection <NgWebElement> ng_customers = NgDriver.FindElement(NgBy.Model("custId")).FindElements(NgBy.Repeater("cust in Customers")); // select customer to log in ng_customers.First(cust => Regex.IsMatch(cust.Text, "Harry Potter")).Click(); By elemBut = By.XPath(".//button[contains(text(),'Login')]"); NgDriver.FindElement(elemBut).Click(); //wait until document has fully loaded (new BasePage(NgDriver)).WaitUntilDocumentIsReady(TimeSpan.FromSeconds(10)); //wait for angularjs to load (new BasePage(NgDriver)).waitForAngular(NgDriver); By Selectelem = By.XPath(".//select[contains(@id,'accountSelect')]"); //driver.FindElement(By.Id("ps_ck$0")) SelectElement SelectAccount = new SelectElement(NgDriver.FindElement(Selectelem)); //To count elements IList <IWebElement> ElementCount = SelectAccount.Options; int NumberOfItems = ElementCount.Count; Console.WriteLine("Size of SelectAccount Dropdown options: " + NumberOfItems); //click selected option string SelectedOption = SelectAccount.SelectedOption.Text; Console.WriteLine("SelectedOption: " + SelectedOption); SelectAccount.SelectedOption.Click(); NgWebElement ng_account_number_element = NgDriver.FindElement(NgBy.Binding("accountNo")); Console.WriteLine("ng_account_number_element: " + ng_account_number_element.Text); int account_id = 0; string pattern = @"(?<result>\d+)$"; string input = ng_account_number_element.Text; Match match = Regex.Match(input, pattern); Console.WriteLine("match: " + match.Value); //int.TryParse(ng_account_number_element.Text.FindMatch(@"(?<result>\d+)$"), out account_id); int.TryParse(match.Value, out account_id); Assert.AreNotEqual(0, account_id); int account_amount = -1; int.TryParse(Regex.Match(NgDriver.FindElement(NgBy.Binding("amount")).Text, pattern).Value, out account_amount); Console.WriteLine("account_amount: " + account_amount); Assert.AreNotEqual(-1, account_amount); NgDriver.FindElement(By.XPath(".//button[contains(text(),'Deposit')]")).Click(); // core Selenium wait.Until(ExpectedConditions.ElementExists(By.CssSelector("form[name='myForm']"))); NgWebElement ng_form_element = new NgWebElement(NgDriver, driver.FindElement(By.CssSelector("form[name='myForm']"))); NgWebElement ng_deposit_amount_element = ng_form_element.FindElement(NgBy.Model("amount")); ng_deposit_amount_element.SendKeys("100"); //Highlight UI Element NgWebElement ng_deposit_button_element = ng_form_element.FindElement(By.XPath(".//button[contains(text(),'Deposit')]")); //NgDriver.Highlight(ng_deposit_button_element); var jsDriver = (IJavaScriptExecutor)NgDriver; var element = ng_deposit_button_element; string highlightJavascript = @"arguments[0].style.cssText = ""border-width: 2px; border-style: solid; border-color: red"";"; jsDriver.ExecuteScript(highlightJavascript, new object[] { element }); ng_deposit_button_element.Click(); // inspect status message var ng_message_element = NgDriver.FindElement(NgBy.Binding("message")); StringAssert.Contains("Deposit Successful", ng_message_element.Text); //NgDriver.Highlight(ng_message_element); jsDriver.ExecuteScript(highlightJavascript, new object[] { ng_message_element }); // re-read the amount int updated_account_amount = -1; //int.TryParse(NgDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<result>\d+)$"), out updated_account_amount); int.TryParse(Regex.Match(NgDriver.FindElement(NgBy.Binding("amount")).Text, pattern).Value, out updated_account_amount); Console.WriteLine("updated_account_amount: " + updated_account_amount); Assert.AreEqual(updated_account_amount, account_amount + 100); }
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")); }
public void ShouldBrowse() { // Open datepicker directive String searchText = "Drop-down Datetime with input box"; IWebElement contaiter = null; try { contaiter = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(String.Format("//div[@class='col-sm-6']//*[contains(text(),'{0}')]", searchText)))); ngDriver.Highlight(contaiter); } catch (Exception e) { Console.Error.WriteLine("Exception: " + e.ToString()); } try { contaiter = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(String.Format("//*[text()[contains(.,'{0}')]]", searchText)))); ngDriver.Highlight(contaiter); } catch (Exception e) { Console.Error.WriteLine("Exception: " + e.ToString()); } 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")); 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); NgWebElement ng_display = ngDriver.FindElement(NgBy.Binding("data.previousViewDate.display", true, "[data-ng-app]")); Assert.IsNotNull(ng_display); String datePattern = @"\d{4}\-(?<month>\w{3})"; Regex datePatternReg = new Regex(datePattern); Assert.IsTrue(datePatternReg.IsMatch(ng_display.Text)); ngDriver.Highlight(ng_display); String display_month = ng_display.Text.FindMatch(datePattern); String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Dec", "Jan" }; String next_month = months[Array.IndexOf(months, display_month) + 1]; Console.Error.WriteLine("Current month: " + display_month); Console.Error.WriteLine("Expect to find next month: " + next_month); IWebElement ng_next_month = ng_display.FindElement(By.XPath("..")).FindElement(By.ClassName("right")); Assert.IsNotNull(ng_next_month); ngDriver.Highlight(ng_next_month, 100); ng_next_month.Click(); Assert.IsTrue(ng_display.Text.Contains(next_month)); ngDriver.Highlight(ng_display); Console.Error.WriteLine("Next month: " + ng_display.Text); }
public void ShouldDirectSelectFromDatePicker() { GetPageContent("ng_datepicker.htm"); 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 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 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 ShouldSelectOneByOne() { // Given multuselect directive NgWebElement ng_directive = ngDriver.FindElement(NgBy.Model("selectedCar")); Assert.IsNotNull(ng_directive.WrappedElement); Assert.That(ng_directive.TagName, Is.EqualTo("am-multiselect")); // open am-multiselect IWebElement toggleSelect = ng_directive.FindElement(By.CssSelector("button[ng-click='toggleSelect()']")); Assert.IsNotNull(toggleSelect); Assert.IsTrue(toggleSelect.Displayed); toggleSelect.Click(); // When I want to select every "Audi", "Honda" or "Toyota" car String makeMatcher = "(?i:" + String.Join("|", new String[] { "audi", "honda", "toyota" }) + ")"; ReadOnlyCollection <NgWebElement> cars = ng_directive.FindElements(NgBy.Repeater("i in items")); Assert.Greater(cars.Count(car => Regex.IsMatch(car.Text, makeMatcher)), 0); // And I pick every matching car one item at a time int selected_cars_count = 0; for (int num_row = 0; num_row < cars.Count(); num_row++) { NgWebElement ng_item = ng_directive.FindElement(NgBy.Repeaterelement("i in items", num_row, "i.label")); if (Regex.IsMatch(ng_item.Text, makeMatcher, RegexOptions.IgnoreCase)) { Console.Error.WriteLine("Selecting: " + ng_item.Text); ng_item.Click(); selected_cars_count++; ngDriver.Highlight(ng_item, highlight_timeout); } } // Then button text shows the total number of cars I have selected IWebElement button = driver.FindElement(By.CssSelector("am-multiselect > div > button")); ngDriver.Highlight(button, highlight_timeout); StringAssert.IsMatch(@"There are (\d+) car\(s\) selected", button.Text); int displayed_count = 0; int.TryParse(button.Text.FindMatch(@"(?<count>\d+)"), out displayed_count); Assert.AreEqual(displayed_count, selected_cars_count); Console.Error.WriteLine("Button text: " + button.Text); try { // NOTE: the following does not work: // ms-selected = "There are {{selectedCar.length}} NgWebElement ng_button = new NgWebElement(ngDriver, button); Console.Error.WriteLine(ng_button.GetAttribute("innerHTML")); NgWebElement ng_length = ng_button.FindElement(NgBy.Binding("selectedCar.length")); ng_length = ngDriver.FindElement(NgBy.Binding("selectedCar.length")); Console.Error.WriteLine(ng_length.Text); } catch (NullReferenceException) { } }
public void ShouldInviteToOpenAccount() { // When I proceed to "Bank Manager Login" ngDriver.FindElement(NgBy.ButtonText("Bank Manager Login")).Click(); // And I proceed to "Add Customer" ngDriver.FindElement(NgBy.PartialButtonText("Add Customer")).Click(); // And I fill new Customer data IWebElement ng_first_name = ngDriver.FindElement(NgBy.Model("fName")); ngDriver.Highlight(ng_first_name, highlight_timeout); StringAssert.IsMatch("First Name", ng_first_name.GetAttribute("placeholder")); ng_first_name.SendKeys("John"); IWebElement ng_last_name = ngDriver.FindElement(NgBy.Model("lName")); ngDriver.Highlight(ng_last_name, highlight_timeout); StringAssert.IsMatch("Last Name", ng_last_name.GetAttribute("placeholder")); ng_last_name.SendKeys("Doe"); IWebElement ng_post_code = ngDriver.FindElement(NgBy.Model("postCd")); ngDriver.Highlight(ng_post_code, highlight_timeout); StringAssert.IsMatch("Post Code", ng_post_code.GetAttribute("placeholder")); ng_post_code.SendKeys("11011"); // NOTE: there are two 'Add Customer' buttons on this form NgWebElement ng_add_customer_button = ngDriver.FindElements(NgBy.PartialButtonText("Add Customer"))[1]; actions.MoveToElement(ng_add_customer_button.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_add_customer_button, highlight_timeout); ng_add_customer_button.Submit(); // confirm string alert_text = null; try { alert = ngDriver.WrappedDriver.SwitchTo().Alert(); alert_text = alert.Text; StringAssert.StartsWith("Customer added successfully with customer id :", alert_text); alert.Accept(); } catch (NoAlertPresentException ex) { // Alert not present verificationErrors.Append(ex.StackTrace); } catch (WebDriverException ex) { // Alert not handled by PhantomJS verificationErrors.Append(ex.StackTrace); } int customer_id = 0; int.TryParse(alert_text.FindMatch(@"(?<customer_id>\d+)$"), out customer_id); Assert.AreNotEqual(0, customer_id); // And I switch to "Home" screen ngDriver.FindElement(NgBy.ButtonText("Home")).Click(); // And I proceed to "Customer Login" ngDriver.FindElement(NgBy.ButtonText("Customer Login")).Click(); // And I login as new customer "John Doe" ReadOnlyCollection <NgWebElement> ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); int customer_count = ng_customers.Count; NgWebElement ng_new_customer = ng_customers.First(cust => Regex.IsMatch(cust.Text, "John Doe")); Assert.IsNotNull(ng_new_customer); actions.MoveToElement(ng_new_customer.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_new_customer, highlight_timeout); ng_new_customer.Click(); NgWebElement ng_login_button = ngDriver.FindElement(NgBy.ButtonText("Login")); Assert.IsTrue(ng_login_button.Displayed && ng_login_button.Enabled); ngDriver.Highlight(ng_login_button, highlight_timeout); ng_login_button.Click(); // Then I am greeted as "John Doe" NgWebElement ng_user = ngDriver.FindElement(NgBy.Binding("user")); StringAssert.Contains("John", ng_user.Text); StringAssert.Contains("Doe", ng_user.Text); // And I am invited to open an account Object noAccount = ng_user.Evaluate("noAccount"); Assert.IsTrue(Boolean.Parse(noAccount.ToString())); Boolean hasAccounts = !(Boolean.Parse(noAccount.ToString())); Console.Error.WriteLine("Has accounts: " + hasAccounts); // IWebElement invitationMessage = driver.FindElement(By.CssSelector("span[ng-show='noAccount']")); IWebElement invitationMessage = ng_user.FindElement(By.XPath("..")).FindElement(By.XPath("..")).FindElement(By.CssSelector("span[ng-show='noAccount']")); Assert.IsTrue(invitationMessage.Displayed); ngDriver.Highlight(invitationMessage); StringAssert.Contains("Please open an account with us", invitationMessage.Text); Console.Error.WriteLine(invitationMessage.Text); // And I have no accounts NgWebElement accountNo = ngDriver.FindElement(NgBy.Binding("accountNo")); Assert.IsFalse(accountNo.Displayed); ReadOnlyCollection <NgWebElement> ng_accounts = ngDriver.FindElements(NgBy.Repeater("account for account in Accounts")); Assert.AreEqual(0, ng_accounts.Count); }
public void ShouldWithdraw() { ShouldDeposit(); int account_balance = -1; int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out account_balance); Assert.AreNotEqual(-1, account_balance); ngDriver.FindElement(NgBy.PartialButtonText("Withdrawl")).Click(); // core Selenium Thread.Sleep(1000); wait.Until(ExpectedConditions.ElementExists(By.CssSelector("form[name='myForm']"))); NgWebElement ng_form_element = new NgWebElement(ngDriver, driver.FindElement(By.CssSelector("form[name='myForm']"))); NgWebElement ng_withdrawl_amount = ng_form_element.FindElement(NgBy.Model("amount")); ng_withdrawl_amount.SendKeys((account_balance + 100).ToString()); NgWebElement ng_withdrawl_button = ng_form_element.FindElement(NgBy.ButtonText("Withdraw")); ngDriver.Highlight(ng_withdrawl_button); ng_withdrawl_button.Click(); // inspect message var ng_message = ngDriver.FindElement(NgBy.Binding("message")); StringAssert.Contains("Transaction Failed. You can not withdraw amount more than the balance.", ng_message.Text); ngDriver.Highlight(ng_message); // re-read the amount int updated_account_balance = -1; int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out updated_account_balance); Assert.AreEqual(account_balance, updated_account_balance); // core Selenium Thread.Sleep(1000); wait.Until(ExpectedConditions.ElementExists(By.CssSelector("form[name='myForm']"))); ng_form_element = new NgWebElement(ngDriver, driver.FindElement(By.CssSelector("form[name='myForm']"))); ng_form_element.FindElement(NgBy.Model("amount")).SendKeys((account_balance - 10).ToString()); ng_form_element.FindElement(NgBy.ButtonText("Withdraw")).Click(); // inspect message ng_message = ngDriver.FindElement(NgBy.Binding("message")); StringAssert.Contains("Transaction successful", ng_message.Text); ngDriver.Highlight(ng_message); // re-read the amount int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out updated_account_balance); Assert.AreEqual(10, updated_account_balance); }
public void ShouldDeleteCustomer() { // switch to "Add Customer" screen ngDriver.FindElement(NgBy.ButtonText("Bank Manager Login")).Click(); ngDriver.FindElement(NgBy.PartialButtonText("Add Customer")).Click(); // fill new Customer data ngDriver.FindElement(NgBy.Model("fName")).SendKeys("John"); ngDriver.FindElement(NgBy.Model("lName")).SendKeys("Doe"); ngDriver.FindElement(NgBy.Model("postCd")).SendKeys("11011"); // NOTE: there are two 'Add Customer' buttons on this form NgWebElement ng_add_customer_button = ngDriver.FindElements(NgBy.PartialButtonText("Add Customer"))[1]; actions.MoveToElement(ng_add_customer_button.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_add_customer_button, highlight_timeout); ng_add_customer_button.Submit(); // confirm ngDriver.WrappedDriver.SwitchTo().Alert().Accept(); // switch to "Home" screen ngDriver.FindElement(NgBy.ButtonText("Home")).Click(); ngDriver.FindElement(NgBy.ButtonText("Bank Manager Login")).Click(); ngDriver.FindElement(NgBy.PartialButtonText("Customers")).Click(); // found new customer ReadOnlyCollection <NgWebElement> ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); // collect all customers ReadOnlyCollection <NgWebElement> ng_custfNames = ngDriver.FindElements(NgBy.RepeaterColumn("cust in Customers", "cust.fName")); // In the application there is always 5 customers preloaded: // http://www.way2automation.com/angularjs-protractor/banking/mockDataLoadService.js Assert.Greater(ng_custfNames.Count, 3); NgWebElement new_customer = ng_customers.Single(cust => Regex.IsMatch(cust.Text, "Harry Potter")); Assert.IsNotNull(new_customer); ReadOnlyCollection <Object> accounts = (ReadOnlyCollection <Object>)new_customer.Evaluate("cust.accountNo"); foreach (Object account in accounts) { Console.Error.WriteLine("AccountNo: {0}", account.ToString()); } // highlight individual accounts of an existing customer ReadOnlyCollection <NgWebElement> ng_accounts = ng_customers.First().FindElements(NgBy.Repeater("account in cust.accountNo")); foreach (NgWebElement ng_account in ng_accounts) { ngDriver.Highlight(ng_account, highlight_timeout); } // remove customer that was just added NgWebElement ng_delete_customer = ng_customers.Single(cust => Regex.IsMatch(cust.Text, "John Doe")); Assert.IsNotNull(ng_delete_customer); actions.MoveToElement(ng_delete_customer.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_delete_customer, highlight_timeout); Thread.Sleep(1000); // locate the remove button NgWebElement ng_delete_customer_button = ng_delete_customer.FindElement(NgBy.ButtonText("Delete")); StringAssert.IsMatch("Delete", ng_delete_customer_button.Text); ngDriver.Highlight(ng_delete_customer_button, highlight_timeout); actions.MoveToElement(ng_delete_customer_button.WrappedElement).ClickAndHold().Build().Perform(); Thread.Sleep(1000); actions.Release().Build().Perform(); // confirm the customer is gone ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers")); IEnumerable <NgWebElement> removed_customer = ng_customers.TakeWhile(cust => Regex.IsMatch(cust.Text, "John Doe.*")); Assert.IsEmpty(removed_customer); }
public void ShouldDeposit() { ngDriver.FindElement(NgBy.ButtonText("Customer Login")).Click(); ReadOnlyCollection<NgWebElement> ng_customers = ngDriver.FindElement(NgBy.Model("custId")).FindElements(NgBy.Repeater("cust in Customers")); // select customer to log in ng_customers.First(cust => Regex.IsMatch(cust.Text, "Harry Potter")).Click(); ngDriver.FindElement(NgBy.ButtonText("Login")).Click(); ngDriver.FindElement(NgBy.Options("account for account in Accounts")).Click(); // inspect the account NgWebElement ng_account_number = ngDriver.FindElement(NgBy.Binding("accountNo")); int account_id = 0; int.TryParse(ng_account_number.Text.FindMatch(@"(?<account_number>\d+)$"), out account_id); Assert.AreNotEqual(0, account_id); int account_balance = -1; int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out account_balance); Assert.AreNotEqual(-1, account_balance); NgWebElement ng_deposit_button = ngDriver.FindElement(NgBy.PartialButtonText("Deposit")); Assert.IsTrue(ng_deposit_button.Displayed); actions.MoveToElement(ng_deposit_button.WrappedElement).Build().Perform(); Thread.Sleep(500); ng_deposit_button.Click(); // core Selenium wait.Until(ExpectedConditions.ElementExists(By.CssSelector("form[name='myForm']"))); NgWebElement ng_form_element = new NgWebElement(ngDriver, driver.FindElement(By.CssSelector("form[name='myForm']"))); // deposit amount NgWebElement ng_deposit_amount = ng_form_element.FindElement(NgBy.Model("amount")); ng_deposit_amount.SendKeys("100"); wait.Until(ExpectedConditions.ElementIsVisible(NgBy.ButtonText("Deposit"))); ng_deposit_button = ng_form_element.FindElement(NgBy.ButtonText("Deposit")); actions.MoveToElement(ng_deposit_button.WrappedElement).Build().Perform(); ngDriver.Highlight(ng_deposit_button); ng_deposit_button.Click(); // http://www.way2automation.com/angularjs-protractor/banking/depositTx.html // inspect message var ng_message = ngDriver.FindElement(NgBy.Binding("message")); StringAssert.Contains("Deposit Successful", ng_message.Text); ngDriver.Highlight(ng_message); // re-read the amount int updated_account_balance = -1; int.TryParse(ngDriver.FindElement(NgBy.Binding("amount")).Text.FindMatch(@"(?<account_balance>\d+)$"), out updated_account_balance); Assert.AreEqual(updated_account_balance, account_balance + 100); }