Ejemplo n.º 1
0
        public void SetAllCompleted()
        {
            AddToDo("FirstToDoToBeSetToComplete");
            AddToDo("SecondToDoToBeSetToComplete");

            NgWebElement toDoList = ngDriver.FindElement(By.Id("todo-list"));

            int countAll = toDoList.FindElements(By.CssSelector("li")).Count;

            Assert.AreEqual(2, countAll, "the 2 test to-do's weren't added");

            int countAllCompletedPreClick = toDoList.FindElements(By.CssSelector("li.completed")).Count;

            Assert.AreEqual(0, countAllCompletedPreClick, "the to-do's began as completed");

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

            wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("toggle-all")));

            ngDriver.FindElement(By.Id("toggle-all")).Click();

            int countAllCompletedAfterClick = toDoList.FindElements(By.CssSelector("li.completed")).Count;

            Assert.AreEqual(2, countAllCompletedAfterClick, "the to-do's did not become completed");
        }
Ejemplo n.º 2
0
        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");
        }
Ejemplo n.º 3
0
        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");
        }
Ejemplo n.º 4
0
        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");
        }
Ejemplo n.º 5
0
        public void AddSecondToDoTest()
        {
            AddToDo("FirstToDo");

            NgWebElement toDoList = ngDriver.FindElement(By.Id("todo-list"));
            bool         result   = toDoList.FindElements(By.CssSelector("li")).Count == 1;

            Assert.True(result, "First to-do was not added");

            AddToDo("SecondToDo");

            //toDoList = ngDriver.FindElement(By.Id("todo-list"));
            result = toDoList.FindElements(By.CssSelector("li")).Count == 2;

            Assert.True(result, "Second to-do was not added");
        }
Ejemplo n.º 6
0
        public void ShouldDragAndDrop()
        {
            Common.GetLocalHostPageContent("ng_drag_and_drop1.htm");
            ReadOnlyCollection <NgWebElement> ng_cars = ngDriver.FindElements(NgBy.Repeater("car in models.cars"));

            Assert.AreEqual(5, ng_cars.Count);
            foreach (NgWebElement ng_car in ng_cars)
            {
                try {
                    ngDriver.Highlight(ng_car);
                    actions.MoveToElement(ng_car).Build().Perform();
                    IWebElement basket = driver.FindElement(By.XPath("//*[@id='my-basket']"));
                    // works in Java, desktop browser
                    actions.ClickAndHold(ng_car).MoveToElement(basket).Release().Build()
                    .Perform();
                    Thread.Sleep(1000);
                    NgWebElement ng_basket = new NgWebElement(ngDriver, basket);
                    ReadOnlyCollection <NgWebElement> ng_cars_basket = ng_basket.FindElements(NgBy.Repeater("car in models.basket"));
                    NgWebElement ng_car_basket = ng_cars_basket.Last();

                    Assert.IsTrue(ng_car_basket.Displayed);
                    // {{ car.name }} - {{ car.modelYear }} ( {{ car.price | currency }} )
                    Console.Error.WriteLine("%s - %s ( %s )", ng_car_basket.Evaluate("car.name"), ng_car_basket.Evaluate("car.modelYear"), ng_car_basket.Evaluate("car.price | currency"));
                } catch (Exception e) {
                    // System.InvalidOperationException: Sequence contains no elements
                    // TODO
                    Console.Error.WriteLine(e.ToString());
                }
            }
        }
        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);
        }
Ejemplo n.º 8
0
        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");
        }
Ejemplo n.º 9
0
        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 ShouldHighlightCurrentMonthDays()
        {
            // Arrange
            try {
                wait.Until(e => e.FindElements(
                               By.ClassName("col-sm-6")).Any(element => element.Text.Contains("Embedded calendar")));
            } catch (Exception e) {
                verificationErrors.Append(e.Message);
            }
            NgWebElement ng_datepicker = ngDriver.FindElement(NgBy.Model("data.embeddedDate", "*[data-ng-app]"));

            Assert.IsNotNull(ng_datepicker);
            // NOTE: cannot highlight calendar, only individual days
            actions.MoveToElement(ng_datepicker).Build().Perform();
            ngDriver.Highlight(ng_datepicker);

            NgWebElement[] ng_dates = ng_datepicker.FindElements(NgBy.Repeater("dateObject in week.dates")).ToArray();
            Assert.IsTrue(28 <= ng_dates.Length);
            // Act
            // Highlight every day in the month
            int start = 0, end = ng_dates.Length;

            for (int cnt = 0; cnt != ng_dates.Length; cnt++)
            {
                if (start == 0 && Convert.ToInt32(ng_dates[cnt].Text) == 1)
                {
                    start = cnt;
                }
                if (cnt > start && Convert.ToInt32(ng_dates[cnt].Text) == 1)
                {
                    end = cnt;
                }
            }
            for (int cnt = start; cnt != end; cnt++)
            {
                NgWebElement ng_date = ng_dates[cnt];
                ngDriver.Highlight(ng_date, highlight_timeout, 3, (ng_date.GetAttribute("class").Contains("current")) ? "blue" : "green");
            }
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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 static void TrySelectOption(this NgWebElement selectionPanel, int index)
        {
            ReadOnlyCollection <NgWebElement> options = selectionPanel.FindElements(By.TagName("mat-option"));

            options[index].Click();
        }
        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) {
            }
        }
Ejemplo n.º 15
0
        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"));
        }
Ejemplo n.º 17
0
        public void ShouldLoginCustomer()
        {
            NgWebElement ng_customer_button = ngDriver.FindElement(NgBy.ButtonText("Customer Login"));

            StringAssert.IsMatch("Customer Login", ng_customer_button.Text);
            ngDriver.Highlight(ng_customer_button, highlight_timeout);
            // core Selenium
            IWebElement customer_button = driver.FindElement(By.XPath("//button[contains(.,'Customer Login')]"));

            StringAssert.IsMatch("Customer Login", customer_button.Text);
            ngDriver.Highlight(customer_button, highlight_timeout);

            ng_customer_button.Click();

                        #pragma warning disable 618
            NgWebElement ng_customer_select = ngDriver.FindElement(NgBy.Input("custId"));
                        #pragma warning restore 618

            StringAssert.IsMatch("userSelect", ng_customer_select.GetAttribute("id"));
            ReadOnlyCollection <NgWebElement> ng_customers = ng_customer_select.FindElements(NgBy.Repeater("cust in Customers"));
            Assert.AreNotEqual(0, ng_customers.Count);
            // won't move to or highlight select options
            foreach (NgWebElement ng_customer in ng_customers)
            {
                actions.MoveToElement(ng_customer);
                ngDriver.Highlight(ng_customer);
            }
            // pick first customer
            NgWebElement first_customer = ng_customers.First();
            Assert.IsTrue(first_customer.Displayed);

            // the {{user}} is composed from first and last name
            StringAssert.IsMatch("(?:[^ ]+) +(?:[^ ]+)", first_customer.Text);
            string user = first_customer.Text;
            first_customer.Click();

            // login button
            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();

            NgWebElement ng_greeting = ngDriver.FindElement(NgBy.Binding("user"));
            Assert.IsNotNull(ng_greeting);
            StringAssert.IsMatch(user, ng_greeting.Text);
            ngDriver.Highlight(ng_greeting, highlight_timeout);

            NgWebElement ng_account_number = ngDriver.FindElement(NgBy.Binding("accountNo"));
            Assert.IsNotNull(ng_account_number);
            theReg = new Regex(@"(?<account_id>\d+)$");
            Assert.IsTrue(theReg.IsMatch(ng_account_number.Text));
            ngDriver.Highlight(ng_account_number, highlight_timeout);

            NgWebElement ng_account_balance = ngDriver.FindElement(NgBy.Binding("amount"));
            Assert.IsNotNull(ng_account_balance);
            theReg = new Regex(@"(?<account_balance>\d+)$");
            Assert.IsTrue(theReg.IsMatch(ng_account_balance.Text));
            ngDriver.Highlight(ng_account_balance, highlight_timeout);

            NgWebElement ng_account_currency = ngDriver.FindElement(NgBy.Binding("currency"));
            Assert.IsNotNull(ng_account_currency);
            theReg = new Regex(@"(?<account_currency>(?:Dollar|Pound|Rupee))$");
            Assert.IsTrue(theReg.IsMatch(ng_account_currency.Text));
            ngDriver.Highlight(ng_account_currency, highlight_timeout);
            NgWebElement ng_logout_botton = ngDriver.FindElement(NgBy.ButtonText("Logout"));
            ngDriver.Highlight(ng_logout_botton, highlight_timeout);
            ng_logout_botton.Click();
        }
Ejemplo n.º 18
0
        public void ShouldOpenAccount()
        {
            // switch to "Add Customer" screen
            ngDriver.FindElement(NgBy.ButtonText("Bank Manager Login")).Click();
            ngDriver.FindElement(NgBy.PartialButtonText("Open Account")).Click();

            // fill new Account data
            NgWebElement ng_customer_select = ngDriver.FindElement(NgBy.Model("custId"));

            StringAssert.IsMatch("userSelect", ng_customer_select.GetAttribute("id"));
            ReadOnlyCollection <NgWebElement> ng_customers = ng_customer_select.FindElements(NgBy.Repeater("cust in Customers"));

            // select customer to log in
            NgWebElement account_customer = ng_customers.First(cust => Regex.IsMatch(cust.Text, "Harry Potter*"));

            Assert.IsNotNull(account_customer);
            account_customer.Click();

            NgWebElement ng_currencies_select = ngDriver.FindElement(NgBy.Model("currency"));
            // use core Selenium
            SelectElement       currencies_select  = new SelectElement(ng_currencies_select.WrappedElement);
            IList <IWebElement> account_currencies = currencies_select.Options;
            IWebElement         account_currency   = account_currencies.First(cust => Regex.IsMatch(cust.Text, "Dollar"));

            Assert.IsNotNull(account_currency);
            currencies_select.SelectByText("Dollar");

            // add the account
            var submit_button = ngDriver.FindElement(By.XPath("/html/body//form/button[@type='submit']"));

            StringAssert.IsMatch("Process", submit_button.Text);
            submit_button.Click();

            try {
                alert      = driver.SwitchTo().Alert();
                alert_text = alert.Text;
                StringAssert.StartsWith("Account created successfully with account Number", 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);
            }

            // Confirm account added for customer
            Assert.IsEmpty(verificationErrors.ToString());

            // switch to "Customers" screen
            ngDriver.FindElement(NgBy.PartialButtonText("Customers")).Click();

            // get customers
            ng_customers = ngDriver.FindElements(NgBy.Repeater("cust in Customers"));
            // discover customer
            NgWebElement ng_customer = ng_customers.First(cust => Regex.IsMatch(cust.Text, "Harry Potter"));

            Assert.IsNotNull(ng_customer);

            // extract the account id from the alert message
            string account_id = alert_text.FindMatch(@"(?<account_id>\d+)$");

            Assert.IsNotNullOrEmpty(account_id);
            // search accounts of specific customer
            ReadOnlyCollection <NgWebElement> ng_customer_accounts = ng_customer.FindElements(NgBy.Repeater("account in cust.accountNo"));

            NgWebElement account_matching = ng_customer_accounts.First(acc => String.Equals(acc.Text, account_id));

            Assert.IsNotNull(account_matching);
            ngDriver.Highlight(account_matching, highlight_timeout);
        }
Ejemplo n.º 19
0
 public void Click()
 {
     checkboxElement.FindElements(By.TagName("span"))[0].Click();
 }