Beispiel #1
0
        // [Ignore("Ignore test to prevent exception crashing later tests")]
        public void ShouldFindElementByModel()
        {
            //  NOTE: works with Angular 1.2.13, fails with Angular 1.4.9
            Common.GetLocalHostPageContent("ng_pattern_validate.htm");
            NgWebElement ng_input = ngDriver.FindElement(NgBy.Model("myVal"));

            ng_input.Clear();
            NgWebElement ng_valid = ngDriver.FindElement(NgBy.Binding("form.value.$valid"));

            StringAssert.IsMatch("false", ng_valid.Text);

            NgWebElement ng_pattern = ngDriver.FindElement(NgBy.Binding("form.value.$error.pattern"));

            StringAssert.IsMatch("false", ng_pattern.Text);

            NgWebElement ng_required = ngDriver.FindElement(NgBy.Binding("!!form.value.$error.required"));

            StringAssert.IsMatch("true", ng_required.Text);

            ng_input.SendKeys("42");
            Assert.IsTrue(ng_input.Displayed);
            ng_valid = ngDriver.FindElement(NgBy.Binding("form.value.$valid"));
            StringAssert.IsMatch("true", ng_valid.Text);

            ng_pattern = ngDriver.FindElement(NgBy.Binding("form.value.$error.pattern"));
            StringAssert.IsMatch("false", ng_pattern.Text);

            ng_required = ngDriver.FindElement(NgBy.Binding("!!form.value.$error.required"));
            StringAssert.IsMatch("false", ng_required.Text);
        }
        public void ShouldDropDown()
        {
            GetPageContent("ng_dropdown.htm");
            string optionsCountry = "country for (country, states) in countries";
            ReadOnlyCollection <NgWebElement> ng_countries = ngDriver.FindElements(NgBy.Options(optionsCountry));

            Assert.IsTrue(4 == ng_countries.Count);
            Assert.IsTrue(ng_countries[0].Enabled);
            string       optionsState = "state for (state,city) in states";
            NgWebElement ng_state     = ngDriver.FindElement(NgBy.Options(optionsState));

            Assert.IsFalse(ng_state.Enabled);
            SelectElement countries = new SelectElement(ngDriver.FindElement(NgBy.Model("states")).WrappedElement);

            countries.SelectByText("Australia");
            Thread.Sleep(1000);
            Assert.IsTrue(ng_state.Enabled);
            NgWebElement ng_selected_country = ngDriver.FindElement(NgBy.SelectedOption(optionsCountry));
            // TODO:debug (works in Java client)
            // Assert.IsNotNull(ng_selected_country.WrappedElement);
            // ng_countries = ngDriver.FindElements(NgBy.Options(optionsCountry));
            NgWebElement ng_country = ng_countries.First(o => o.Selected);

            StringAssert.IsMatch("Australia", ng_country.Text);
        }
Beispiel #3
0
        public void HelloNgDriver()
        {
            NgWebElement ngElement = _ngWebDriver.FindElement(NgBy.Model("q"));

            ngElement.Clear();
            ngElement.SendKeys("Hello NgWebDriver");
        }
Beispiel #4
0
        public void AddButtonWithoutAddAnotherToggle_ClosesForm()
        {
            _driver.Navigate().GoToUrl(PollUrl);

            IWebElement addChoiceButton = _driver.FindElement(By.PartialLinkText("New Choice"));

            addChoiceButton.Click();

            Thread.Sleep(DialogClearWaitTime);

            IWebElement formName = _driver.FindElement(NgBy.Model("addChoiceForm.name"));

            formName.SendKeys("Test");

            IWebElement addAnotherCheckbox = _driver.FindElement(By.Id("add-another-checkbox"));

            addAnotherCheckbox.Click();

            IWebElement addButton = _driver.FindElement(By.Id("add-button"));

            addButton.Click();

            Thread.Sleep(DialogClearWaitTime);

            formName = _driver.FindElement(NgBy.Model("addChoiceForm.name"));

            Assert.IsFalse(formName.IsVisible());
        }
Beispiel #5
0
        public void EditSubmit_ChangesChoiceDetails()
        {
            _driver.Navigate().GoToUrl(PollUrl);

            IReadOnlyCollection <IWebElement> editButtons = _driver.FindElements(By.ClassName("fa-pencil"));

            editButtons.First().Click();

            IWebElement form = _driver.FindElement(By.Name("editChoiceForm"));

            IWebElement formName        = _driver.FindElement(NgBy.Model("editChoiceForm.name"));
            IWebElement formDescription = _driver.FindElement(NgBy.Model("editChoiceForm.description"));

            string newName        = "Changed Name";
            string newDescription = "Changed Description";

            formName.Clear();
            formDescription.Clear();

            formName.SendKeys(newName);
            formDescription.SendKeys(newDescription);

            IWebElement saveButton = _driver.FindElement(By.Id("dialog-save-button"));

            saveButton.Click();

            Thread.Sleep(DialogClearWaitTime);

            IReadOnlyCollection <IWebElement> choiceNames        = _driver.FindElements(NgBy.Binding("choice.Name"));
            IReadOnlyCollection <IWebElement> choiceDescriptions = _driver.FindElements(NgBy.Binding("choice.Description"));

            Assert.AreEqual(newName, choiceNames.First().Text);
            Assert.AreEqual(newDescription, choiceDescriptions.First().Text);
        }
Beispiel #6
0
        public void CancelButton_DoesNotSaveChanges()
        {
            _driver.Navigate().GoToUrl(PollUrl);

            IWebElement addChoiceButton = _driver.FindElement(By.PartialLinkText("New Choice"));

            addChoiceButton.Click();

            IWebElement formName = _driver.FindElement(NgBy.Model("addChoiceForm.name"));

            formName.SendKeys("Test");

            IWebElement addAnotherCheckbox = _driver.FindElement(By.Id("add-another-checkbox"));

            addAnotherCheckbox.Click();

            IWebElement addButton = _driver.FindElement(By.Id("add-button"));

            addButton.Click();

            Thread.Sleep(DialogClearWaitTime);

            IWebElement cancelButton = _driver.FindElement(By.Id("cancel-button"));

            cancelButton.Click();

            Poll dbPoll = _context.Polls.Where(p => p.ManageId == _defaultPoll.ManageId).Single();

            Thread.Sleep(WaitTime);
            _context.ReloadEntity(dbPoll);

            Assert.AreEqual(_defaultPoll.Choices.Count, dbPoll.Choices.Count);
        }
Beispiel #7
0
 public void Calculate(decimal firstNumber, decimal secondNumber, string selectedOperator)
 {
     DriverContext.NgDriver.FindElement(NgBy.Model("first")).SendKeys(firstNumber.ToString());
     DriverContext.NgDriver.FindElement(NgBy.Model("second")).SendKeys(secondNumber.ToString());
     DriverContext.NgDriver.FindElement(NgBy.Model("operator")).SendKeys(selectedOperator);
     DriverContext.NgDriver.FindElement(By.Id("gobutton")).Click();
 }
        public void TestAjApps()
        {
            ngWebDriver.Navigate().GoToUrl("https://hello-angularjs.appspot.com/sorttablecolumn");
            NgWebElement element = ngWebDriver.FindElement(NgBy.Model("searchKeyword"));

            element.SendKeys("Angular");
        }
Beispiel #9
0
        // appears to be broken in PahtomJS / working in desktop browsers
        public void ShouldHandleMultiSelect()
        {
            Actions actions = new Actions(ngDriver.WrappedDriver);

            Common.GetLocalHostPageContent("ng_multi_select.htm");
            IWebElement element = ngDriver.FindElement(NgBy.Model("selectedValues"));
            // use core Selenium
            IList <IWebElement>       options = new SelectElement(element).Options;
            IEnumerator <IWebElement> etr     = options.Where(o => Convert.ToBoolean(o.GetAttribute("selected"))).GetEnumerator();

            while (etr.MoveNext())
            {
                Console.Error.WriteLine(etr.Current.Text);
            }
            foreach (IWebElement option in options)
            {
                // http://selenium.googlecode.com/svn/trunk/docs/api/dotnet/html/AllMembers_T_OpenQA_Selenium_Keys.htm
                actions.KeyDown(Keys.Control).Click(option).KeyUp(Keys.Control).Build().Perform();
                // triggers ngDriver.WaitForAngular()
                Assert.IsNotEmpty(ngDriver.Url);
            }
            // re-read select options
            element = ngDriver.FindElement(NgBy.Model("selectedValues"));
            options = new SelectElement(element).Options;
            etr     = options.Where(o => Convert.ToBoolean(o.GetAttribute("selected"))).GetEnumerator();
            while (etr.MoveNext())
            {
                Console.Error.WriteLine(etr.Current.Text);
            }
        }
        public void ShouldFilter()
        {
            // Fake backend with 2 phones
            NgMockE2EModule mockModule = new NgMockE2EModule(@"
$httpBackend.whenGET('phones/phones.json').respond(
[
    {
        age: 12, 
        carrier: 'AT&amp;T', 
        id: 'motorola-bravo-with-motoblur', 
        imageUrl: 'img/phones/motorola-bravo-with-motoblur.0.jpg', 
        name: 'MOTOROLA BRAVO\u2122 with MOTOBLUR\u2122', 
        snippet: 'An experience to cheer about.'
    }, 
    {
        age: 13, 
        carrier: 'T-Mobile', 
        id: 'motorola-defy-with-motoblur', 
        imageUrl: 'img/phones/motorola-defy-with-motoblur.0.jpg', 
        name: 'Motorola DEFY\u2122 with MOTOBLUR\u2122', 
        snippet: 'Are you ready for everything life throws your way?'
    }, 
]
);
");
            IWebDriver      ngDriver   = new NgWebDriver(driver, mockModule);

            ngDriver.Navigate().GoToUrl("http://angular.github.io/angular-phonecat/step-5/app/");
            Assert.AreEqual(2, ngDriver.FindElements(NgBy.Repeater("phone in phones")).Count);
            ngDriver.FindElement(NgBy.Model("query")).SendKeys("bravo");
            Assert.AreEqual(1, ngDriver.FindElements(NgBy.Repeater("phone in phones")).Count);
            ngDriver.FindElement(NgBy.Model("query")).SendKeys("!");
            Assert.AreEqual(0, ngDriver.FindElements(NgBy.Repeater("phone in phones")).Count);
        }
Beispiel #11
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");
            }
        }
Beispiel #12
0
        public static string Geettextfromtextbox(string webelementvalue, propertytype elementtype)
        {
            if (elementtype == propertytype.Model)
            {
                return(PropertiesCollection.ngdriver.FindElement(NgBy.Model(webelementvalue)).GetAttribute("value"));
            }

            else
            if (elementtype == propertytype.Name)
            {
                return(PropertiesCollection.ngdriver.FindElement(By.Name(webelementvalue)).GetAttribute("value"));
            }
            else
            if (elementtype == propertytype.XPath)
            {
                return(PropertiesCollection.ngdriver.FindElement(By.XPath(webelementvalue)).GetAttribute("value"));
            }

            else

            if (elementtype == propertytype.CssSelector)
            {
                return(PropertiesCollection.ngdriver.FindElement(By.CssSelector(webelementvalue)).GetAttribute("value"));
            }
            else
            {
                return(string.Empty);
            }
        }
Beispiel #13
0
        public void FirstTest()
        {
            driver.Navigate().GoToUrl(URL);
            ngDriver.WaitForAngular();

            //Find product price text box using the ng-model
            NgWebElement ProductPrice = ngDriver.FindElement(NgBy.Model("productPrice"));

            ProductPrice.SendKeys(TestContext.DataRow["ProductPrice"].ToString());
            Thread.Sleep(2000);

            //Find discount text box using the ng-model
            NgWebElement DiscountOnProduct = ngDriver.FindElement(NgBy.Model("discountPercent"));

            DiscountOnProduct.SendKeys(TestContext.DataRow["DiscountOnProduct"].ToString());
            Thread.Sleep(2000);

            //Find button using selenium locator XPath
            NgWebElement BtnPriceAfterDiscount = ngDriver.FindElement(By.XPath("//*[@id='f1']/fieldset[2]/input[1]"));

            BtnPriceAfterDiscount.Click();
            Thread.Sleep(2000);

            //Find discounted product text box using the ng-model
            NgWebElement afterDiscountValue = ngDriver.FindElement(NgBy.Model("afterDiscount"));
            string       value = afterDiscountValue.GetAttribute("value");

            Thread.Sleep(2000);

            //Assert for corect value
            Assert.AreEqual <string>(TestContext.DataRow["AfterDiscountPrice"].ToString(), value);
        }
Beispiel #14
0
        public static string GettextfromLabel(string webelementvalue, propertytype elementtype)
        {
            if (elementtype == propertytype.Model)
            {
                return(PropertiesCollection.ngdriver.FindElement(NgBy.Model(webelementvalue)).Text);
            }

            else
            if (elementtype == propertytype.Name)
            {
                return(PropertiesCollection.ngdriver.FindElement(By.Name(webelementvalue)).Text);
            }

            else
            if (elementtype == propertytype.XPath)
            {
                return(PropertiesCollection.ngdriver.FindElement(By.XPath(webelementvalue)).Text);
            }

            else

            if (elementtype == propertytype.CssSelector)
            {
                return(PropertiesCollection.ngdriver.FindElement(By.CssSelector(webelementvalue)).Text);
            }
            else
            if (elementtype == propertytype.LinkText)
            {
                return(PropertiesCollection.ngdriver.FindElement(By.CssSelector(webelementvalue)).Text);
            }


            return(string.Empty);
        }
Beispiel #15
0
        public void ShouldWaitForAngular()
        {
            ngDriver.Navigate().GoToUrl(base_url);
            IWebElement element = ngDriver.FindElement(NgBy.Model("yourName"));

            Assert.IsTrue(((NgWebElement)element).Displayed);
        }
        public void GivenUserFillesTheFieldsWithForRegistration()
        {
            ngDriver = new NgWebDriver(driver);
            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);

            /*ReadOnlyCollection<NgWebElement>*/
            var firstName = ngDriver.FindElement(NgBy.Model("FirstName"));

            //NgWebElement firstName = ngDriver.FindElement(By.TagName("FirstName"));
            firstName.SendKeys("hello");
            //input = wd.findElement(By.tagName("input"));
            //System.out.println("fieldValue=" + input.getAttribute("value"));
            _driver.Quit();

            //wd.get("http://jsfiddle.net/SAWsA/11/show/");
            //NgWebElement input = ngDriver.FindElement(By.Name("name='FirstName'"));

            //input = wd.findElement(By.tagName("input"));
            //System.out.println("fieldValue=" + input.getAttribute("value"));
            ngDriver.Quit();



            //_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            //var  firstName = _driver.FindElement(By.CssSelector("input[ng-model='FirstName']"));
            firstName.SendKeys("GenRandomString()");
        }
        public void ShouldAddFriend()
        {
            StringAssert.AreEqualIgnoringCase(ngDriver.Title, "Angular JS Demo");
            String       friendName  = "John Doe";
            int          friendCount = ngDriver.FindElements(NgBy.Repeater("row in rows")).Count;
            NgWebElement addnameBox  = ngDriver.FindElement(NgBy.Model("addName"));

            Assert.IsNotNull(addnameBox);
            ngDriver.Highlight(addnameBox, highlight_timeout);
            addnameBox.SendKeys(friendName);
            // add the friend
            NgWebElement addButton = ngDriver.FindElement(NgBy.ButtonText("+ add"));

            Assert.IsNotNull(addButton);
            ngDriver.Highlight(addButton, highlight_timeout);
            addButton.Click();
            // confirm the number of friends
            Assert.AreEqual(1, ngDriver.FindElements(NgBy.Repeater("row in rows")).Count - friendCount);
            // find friend
            NgWebElement addedFriendElement = ngDriver.FindElements(NgBy.CssContainingText("td.ng-binding", friendName)).First();

            Assert.IsNotNull(addedFriendElement);
            ngDriver.Highlight(addedFriendElement, highlight_timeout);
            Console.Error.WriteLine("Added friend name: " + addedFriendElement.Text);
        }
        public void 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");
        }
Beispiel #20
0
        // click button, checkbox,radio buttion,check boxal

        public static void click(string webelementvalue, propertytype elementtype)

        {
            switch (elementtype)
            {
            case propertytype.Model:

                PropertiesCollection.ngdriver.FindElement(NgBy.Model(webelementvalue)).Click();
                break;

            case propertytype.Name:
                PropertiesCollection.ngdriver.FindElement(By.Name(webelementvalue)).Click();
                break;

            case propertytype.XPath:

                PropertiesCollection.ngdriver.FindElement(By.XPath(webelementvalue)).Click();
                break;

            case propertytype.CssSelector:

                PropertiesCollection.ngdriver.FindElement(By.CssSelector(webelementvalue)).Click();
                break;

            case propertytype.Class:

                PropertiesCollection.ngdriver.FindElement(By.ClassName(webelementvalue)).Click();
                break;

            case propertytype.LinkText:

                PropertiesCollection.ngdriver.FindElement(By.LinkText(webelementvalue)).Click();
                break;
            }
        }
        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");
        }
Beispiel #22
0
 public static void clickable(string webelementvalue, propertytype elementtype)
 {
     if (elementtype == propertytype.Model)
     {
         PropertiesCollection.ngdriver.FindElement(NgBy.Model(webelementvalue)).Click();
     }
     else
     if (elementtype == propertytype.Name)
     {
         PropertiesCollection.ngdriver.FindElement(By.Name(webelementvalue)).Click();
     }
     else
     if (elementtype == propertytype.XPath)
     {
         PropertiesCollection.ngdriver.FindElement(By.XPath(webelementvalue)).Click();
     }
     else
     if (elementtype == propertytype.CssSelector)
     {
         PropertiesCollection.ngdriver.FindElement(By.CssSelector(webelementvalue)).Click();
     }
     else
     if (elementtype == propertytype.Class)
     {
         PropertiesCollection.ngdriver.FindElement(By.ClassName(webelementvalue)).Click();
     }
     else
     if (elementtype == propertytype.LinkText)
     {
         PropertiesCollection.ngdriver.FindElement(By.LinkText(webelementvalue)).Click();
     }
 }
Beispiel #23
0
        // EnterText

        public static void Entertext(string webelementvalue, string value, propertytype elementtype)

        {
            switch (elementtype)
            {
            case propertytype.Model:
                PropertiesCollection.ngdriver.FindElement(NgBy.Model(webelementvalue)).SendKeys(value);
                break;

            case propertytype.Name:
                PropertiesCollection.ngdriver.FindElement(By.Name(webelementvalue)).SendKeys(value);
                break;

            case propertytype.XPath:
                PropertiesCollection.ngdriver.FindElement(By.XPath(webelementvalue)).SendKeys(value);
                break;

            case propertytype.CssSelector:
                PropertiesCollection.ngdriver.FindElement(By.CssSelector(webelementvalue)).SendKeys(value);
                break;

            case propertytype.Id:
                PropertiesCollection.ngdriver.FindElement(By.Id(webelementvalue)).SendKeys(value);
                break;
            }
        }
        public void ShouldAdd()
        {
            StringAssert.AreEqualIgnoringCase(ngDriver.Title, "Super Calculator");

            var ng_first_operand = ngDriver.FindElement(NgBy.Model("first"));

            ng_first_operand.SendKeys("1");

            NgWebElement ng_second_operand = ngDriver.FindElement(NgBy.Input("second"));

            ng_second_operand.SendKeys("2");

            NgWebElement ng_math_operator_element = ngDriver.FindElement(NgBy.Options("value for (key, value) in operators"));

            Assert.AreEqual(ng_math_operator_element.Text, "+");

            IWebElement math_operator_element = ngDriver.FindElement(NgBy.SelectedOption("operator"));

            Assert.AreEqual(math_operator_element.Text, "+");

            IWebElement go_button_element = ngDriver.FindElement(NgBy.PartialButtonText("Go"));

            Assert.IsTrue(go_button_element.Displayed);

            var ng_go_button_element = ngDriver.FindElement(By.Id("gobutton"));

            ng_go_button_element.Click();

            NgWebElement result_element = ngDriver.FindElement(NgBy.Binding("latest"));

            Assert.AreEqual("3", result_element.Text);
            highlight(result_element, 1000);
        }
        public void ShouldEvaluateTransactionDetails()
        {
            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);
            ng_transaction_button.Click();

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

            // examine first few transactions using Evaluate
            ReadOnlyCollection <NgWebElement> ng_transactions = ngDriver.FindElements(NgBy.Repeater("tx in transactions"));
            int cnt = 0;

            foreach (NgWebElement ng_current_transaction in ng_transactions)
            {
                if (cnt++ > 5)
                {
                    break;
                }
                StringAssert.IsMatch("(?i:credit|debit)", ng_current_transaction.Evaluate("tx.type").ToString());
                StringAssert.IsMatch(@"(?:\d+)", ng_current_transaction.Evaluate("tx.amount").ToString());
                // 'tx.date' is in Javascript UTC format similar to UniversalSorta­bleDateTimePat­tern in C#
                var transaction_date = ng_current_transaction.Evaluate("tx.date");
                StringAssert.IsMatch(@"(?:\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z)", transaction_date.ToString());
            }
        }
Beispiel #26
0
        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 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);
        }
Beispiel #28
0
        public void ShouldGreetUsingBinding()
        {
            IWebDriver ngDriver = new NgWebDriver(_driver);

            ngDriver.Navigate().GoToUrl("http://www.angularjs.org");
            ngDriver.FindElement(NgBy.Model("yourName")).SendKeys("Julie");
            Assert.AreEqual("Hello Julie!", ngDriver.FindElement(NgBy.Binding("yourName")).Text);
        }
Beispiel #29
0
        public void ShouldGreetUsingBinding()
        {
            var ngDriver = new NgWebDriver(driver);

            ngDriver.Navigate().GoToUrl(base_url);
            ngDriver.FindElement(NgBy.Model("yourName")).SendKeys("Julie");
            Assert.AreEqual("Hello Julie!", ngDriver.FindElement(NgBy.Binding("yourName")).Text);
        }
Beispiel #30
0
        public TutorialStep5Page SearchFor(string query)
        {
            var q = ngDriver.FindElement(NgBy.Model("query"));

            q.Clear();
            q.SendKeys(query);
            return(this);
        }