Ejemplo n.º 1
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");
            }
        }
        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());
            }
        }
Ejemplo n.º 3
0
        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 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);
        }
        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);
        }
        public void ShouldFindOptions()
        {
            // base_url = "http://www.java2s.com/Tutorials/AngularJSDemo/n/ng_options_with_object_example.htm";
            GetPageContent("ng_options_with_object.htm");
            ReadOnlyCollection <NgWebElement> elements = ngDriver.FindElements(NgBy.Options("c.name for c in colors"));

            Assert.AreEqual(5, elements.Count);
            try {
                List <Dictionary <String, String> > result = elements[0].ScopeOf();
            } catch (InvalidOperationException) {
                // Maximum call stack size exceeded.
                // TODO
            }
            StringAssert.IsMatch("black", elements[0].Text);
            StringAssert.IsMatch("white", elements[1].Text);
        }
Ejemplo n.º 7
0
        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, highlight_timeout);
            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());
                // NOTE: need to evaluate full expression - Evaluate("tx.date") returns an empty Dictionary
                string   transaction_datetime = ng_current_transaction.Evaluate(" tx.date | date:'medium'").ToString();
                DateTime dt;
                try {
                    CultureInfo    culture = CultureInfo.CreateSpecificCulture("en-US");
                    DateTimeStyles styles  = DateTimeStyles.AllowWhiteSpaces;
                    dt = DateTime.Parse(transaction_datetime, culture, styles);
                } catch (FormatException) {
                    Console.WriteLine("Unable to parse datetime '{0}'.", transaction_datetime);
                    throw;
                }
            }
        }
Ejemplo n.º 8
0
        public void ShouldDropDownWatch()
        {
            Common.GetLocalHostPageContent("ng_dropdown_watch.htm");
            string optionsCountry = "country for country in countries";
            ReadOnlyCollection <NgWebElement> ng_countries = ngDriver.FindElements(NgBy.Options(optionsCountry));

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

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

            countries.SelectByText("china");
            Thread.Sleep(1000);
            Assert.IsTrue(ng_state.Enabled);
            NgWebElement ng_selected_country = ngDriver.FindElement(NgBy.SelectedOption("country"));

            Assert.IsNotNull(ng_selected_country.WrappedElement);
            NgWebElement ng_country = ng_countries.First(o => o.Selected);

            StringAssert.IsMatch("china", ng_country.Text);
        }
Ejemplo n.º 9
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.º 10
0
        public void ShouldSubstract()
        {
            var first = ngDriver.FindElement(NgBy.Input("first"));

            first.SendKeys("10");

            var second = ngDriver.FindElement(NgBy.Input("second"));

            second.SendKeys("2");

            ReadOnlyCollection <NgWebElement> ng_math_operators = ngDriver.FindElements(NgBy.Options("value for (key, value) in operators"));
            NgWebElement ng_substract_math_operator             = ng_math_operators.First(op => op.Text.Equals("-", StringComparison.Ordinal));

            Assert.IsNotNull(ng_substract_math_operator);
            ng_substract_math_operator.Click();

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

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

            Assert.AreEqual("8", result_element.Text);
            highlight(result_element, 1000);
        }