Пример #1
0
        public void ShouldFindElementByRepeaterColumn()
        {
            GetPageContent("ng_service.htm");
            ReadOnlyCollection <NgWebElement> ng_countries = ngDriver.FindElements(NgBy.RepeaterColumn("person in people", "person.Country"));

            Assert.AreEqual(3, ng_countries.Count(o => String.Compare("Mexico", o.Text,
                                                                      StringComparison.InvariantCulture) == 0));
        }
Пример #2
0
        public void ShouldFindCells()
        {
            //  NOTE: works with Angular 1.2.13, fails with Angular 1.4.9
            Common.GetLocalHostPageContent("ng_repeat_start_end.htm");
            ReadOnlyCollection <NgWebElement> elements = ngDriver.FindElements(NgBy.RepeaterColumn("definition in definitions", "definition.text"));

            Assert.AreEqual(2, elements.Count);
            StringAssert.IsMatch("Lorem ipsum", elements[0].Text);
        }
        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 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 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);
            }
        }
Пример #6
0
        public void ShouldListTransactions()
        {
            ngDriver.FindElement(NgBy.ButtonText("Customer Login")).Click();
            // select customer/account with transactions
            ngDriver.FindElement(NgBy.Model("custId")).FindElements(NgBy.Repeater("cust in Customers")).First(cust => Regex.IsMatch(cust.Text, "Hermoine Granger")).Click();
            ngDriver.FindElement(NgBy.ButtonText("Login")).Click();
            ngDriver.FindElements(NgBy.Options("account for account in Accounts")).First(account => Regex.IsMatch(account.Text, "1001")).Click();

            // switch to transactions
            NgWebElement ng_transaction_button = ngDriver.FindElement(NgBy.PartialButtonText("Transactions"));

            StringAssert.Contains("Transactions", ng_transaction_button.Text);
            ngDriver.Highlight(ng_transaction_button, highlight_timeout);
            ng_transaction_button.Click();
            // http://www.way2automation.com/angularjs-protractor/banking/listTx.html

            // wait for transaction information to be loaded and rendered
            wait.Until(ExpectedConditions.ElementExists(NgBy.Repeater("tx in transactions")));

            // highlight transaction type cells in the page differently for Credit or Debit using RepeaterColumn
            ReadOnlyCollection <NgWebElement> ng_transaction_type_columns = ngDriver.FindElements(NgBy.RepeaterColumn("tx in transactions", "tx.type"));

            Assert.IsNotEmpty(ng_transaction_type_columns);

            foreach (NgWebElement ng_current_transaction_type in ng_transaction_type_columns)
            {
                if (String.IsNullOrEmpty(ng_current_transaction_type.Text))
                {
                    break;
                }
                ngDriver.Highlight(ng_current_transaction_type, highlight_timeout, 3, ng_current_transaction_type.Text.Equals("Credit") ? "green" : "blue");
            }
        }
Пример #7
0
        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);
        }
Пример #8
0
        public void ShouldFindElementByRepeaterColumn()
        {
            Common.GetLocalHostPageContent("ng_service.htm");
            // TODO: properly wait for Angular service to complete
            Thread.Sleep(3000);
            // wait.Until(ExpectedConditions.ElementIsVisible(NgBy.Repeater("person in people")));
            ReadOnlyCollection <NgWebElement> ng_people = ngDriver.FindElements(NgBy.Repeater("person in people"));

            if (ng_people.Count > 0)
            {
                ng_people = ngDriver.FindElements(NgBy.Repeater("person in people"));
                var check = ng_people.Select(o => o.FindElement(NgBy.Binding("person.Country")));
                Assert.AreEqual(ng_people.Count, check.Count());
                ReadOnlyCollection <NgWebElement> ng_countries = ngDriver.FindElements(NgBy.RepeaterColumn("person in people", "person.Country"));

                Assert.AreEqual(3, ng_countries.Count(o => String.Compare("Mexico", o.Text,
                                                                          StringComparison.InvariantCulture) == 0));
            }
        }