Example #1
0
        //Method For Returning Combobox Values
        public List <string> return_combobox_values(string locator, string list_locator, string locator_type)
        {
            try
            {
                List <string> elements = new List <string>();
                if (locator_type == "id")
                {
                    AndroidElement Combobox = (AndroidElement)waitDriver.Until(ExpectedConditions.ElementToBeClickable(By.Id(locator)));
                    Thread.Sleep(1000);
                    Combobox.Click();
                    Thread.Sleep(2000);
                    var temp = driver.FindElementsById(list_locator);
                    for (int i = 0; i < temp.Count; i++)
                    {
                        if (temp[i].Text.ToString().ToLower().Contains("select"))
                        {
                            continue;
                        }
                        else
                        {
                            elements.Add(temp[i].Text.ToString());
                        }
                    }
                }
                else if (locator_type == "xpath")
                {
                    AndroidElement Combobox = (AndroidElement)waitDriver.Until(ExpectedConditions.ElementToBeClickable(By.XPath(locator)));
                    Thread.Sleep(1000);
                    Combobox.Click();
                    Thread.Sleep(2000);
                    var temp = driver.FindElementsById(list_locator);
                    for (int i = 0; i < elements.Count; i++)
                    {
                        elements.Add(temp.ToString());
                    }
                }
                driver.FindElementByXPath("//*").Click();
                return(elements);
            }

            catch (ElementNotVisibleException)
            {
                throw new AssertFailedException(string.Format("The element provided {0} is not on screen", locator));
            }
            catch (StaleElementReferenceException)
            {
                throw new AssertFailedException(string.Format("The element provided {0} is Stale", locator));
            }
            catch (Exception ex)
            {
                throw new Exception("ex message: " + ex.Message);
            }
        }
Example #2
0
        // Get a list of elements from selector and return based on index
        public static AndroidElement GetElementFromList(AndroidDriver <AndroidElement> driver, SelectBy by, string selector, int index)
        {
            AndroidElement e = null;

            switch (by)
            {
            case SelectBy.ID:
                e = driver.FindElementsById(selector)[index];
                break;

            case SelectBy.Class:
                e = driver.FindElementsByClassName(selector)[index];
                break;

            case SelectBy.XPath:
                e = driver.FindElementsByXPath(selector)[index];
                break;

            case SelectBy.ExactText:
                e = driver.FindElementsByAndroidUIAutomator(String.Format("new UiSelector().text(\"{0}\")", selector)).ElementAt(index);
                break;

            case SelectBy.ContainsText:
                e = driver.FindElementsByAndroidUIAutomator(String.Format("new UiSelector().textContains(\"{0}\")", selector)).ElementAt(index);
                break;

            case SelectBy.RegexText:
                e = driver.FindElementsByAndroidUIAutomator(String.Format("new UiSelector().textMatches(\"{0}\")", selector)).ElementAt(index);
                break;
            }
            return(e ?? throw new NotFoundException("Element with selector " + selector + " not found."));
        }
Example #3
0
        public void TestShouldFindElementsById()
        {
            ICollection <AndroidElement> elements = driver.FindElementsById("android:id/action_bar_container");

            Assert.AreEqual(1, elements.Count);
        }
Example #4
0
        /// <summary>
        /// 根据好友微信号判断自己是否被删
        /// </summary>
        /// <param name="friend"></param>
        /// <returns></returns>
        static bool IsDeleteWeiChatFriends(string friend)
        {
            Console.WriteLine("点击微信搜索框");
            driver.FindElementsById("com.tencent.mm:id/f8y")[0].Click();
            Console.WriteLine("在搜索框输入搜索信息");
            driver.FindElementsById("com.tencent.mm:id/bhn")[0].SendKeys(friend);
            Console.WriteLine("点击搜索到的好友");
            driver.FindElementsById("com.tencent.mm:id/tm")[0].Click();
            Console.WriteLine("# 转账");
            driver.FindElementsById("com.tencent.mm:id/aks")[0].Click();
            driver.FindElementsById("com.tencent.mm:id/pa")[5].Click();
            driver.FindElementsById("com.tencent.mm:id/cx_")[0].Click();
            driver.FindElementsById("com.tencent.mm:id/cxi")[0].Click();
            Thread.Sleep(1000);
            Console.WriteLine("# 判断是否被删");
            var isExist = IsElementExist("com.tencent.mm:id/jh");

            return(isExist);
        }
        public void MakeMobileChargePayment()
        {
            AppiumDriver <AppiumWebElement> driver;

            DesiredCapabilities capabilities = new DesiredCapabilities();

            capabilities.SetCapability("deviceName", "Test");
            //capabilities.SetCapability("platformVersion", "4.4.4");
            capabilities.SetCapability("PlatformName", "Android");

            capabilities.SetCapability("appPackage", "com.alibaba.aliexpresshd");
            capabilities.SetCapability("appActivity", ".home.ui.MainActivity");

            capabilities.SetCapability("noReset", "true");

            driver = new AndroidDriver <AppiumWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities);
            driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 10));
            WebDriverWait waiter = new WebDriverWait(driver, new TimeSpan(0, 0, 20));

            //click Profile
            driver.FindElement(By.Id("com.alibaba.aliexpresshd:id/navigation_my_ae")).Click();
            //click Following
            driver.FindElement(By.Id("com.alibaba.aliexpresshd:id/rl_following")).Click();

            //get all favourite shop, find element with text, then click
            var favouriteShops = waiter.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("com.alibaba.aliexpresshd:id/follow_item")));

            var ruChargeShop = favouriteShops.Where(shop => ((AppiumWebElement)shop).FindElementByClassName("android.widget.TextView").Text == "RU recharge Store").Single();

            ruChargeShop.Click();

            //click on picture in shop
            driver.FindElementById("com.alibaba.aliexpresshd:id/iv_photo").Click();

            for (int i = 0; i < this.repeat; i++) //repeat
            {
                Console.WriteLine($"\r\nIteration {i + 1} from {this.repeat}");
                //get all available charge value
                var chargeValues = driver.FindElementsById("com.alibaba.aliexpresshd:id/ll_phone_recharge_product_item_container");

                AppiumWebElement chargeValForPay = null;
                //show their in console
                foreach (var chargeVal in chargeValues)
                {
                    var textCharge = chargeVal.FindElementByClassName("android.widget.TextView").Text;
                    if (textCharge.Contains(this.valueForCharge.ToString()))
                    {
                        textCharge     += " <- select this value";
                        chargeValForPay = chargeVal;
                    }

                    Console.WriteLine("Find charge value - " + textCharge);
                }

                //select last value
                chargeValForPay
                .ShouldNotBeNull($"Not found needed value for charge - {this.valueForCharge}")
                .Click();

                //find input field and send telephone number
                var inputField = driver.FindElementById("com.alibaba.aliexpresshd:id/pniv_phone_number");
                var telNumber  = inputField.Text;

                //check - if input not needed number
                if (Regex.Replace(telNumber, @"\(|\)|-| ", "") != this.telephoneNumber)
                {
                    inputField.Click();
                    inputField.SendKeys(this.telephoneNumber);

                    telNumber = inputField.Text;// driver.FindElementById("com.alibaba.aliexpresshd:id/pniv_phone_number").Text;
                    Console.WriteLine("Input telephone number - " + telNumber);
                    Regex.Replace(telNumber, @"\(|\)|-| ", "").ShouldBeEqualTo(this.telephoneNumber);
                }

                Console.WriteLine("Input telephone number - " + telNumber);

                //click on Recharge button
                driver.FindElementById("com.alibaba.aliexpresshd:id/bt_place_order").Click();

                //verify payment method and amount
                var selectedPaymentMethon = driver.FindElementById("com.alibaba.aliexpresshd:id/tv_selected_payment_method_text").Text;
                selectedPaymentMethon.ShouldContain("4167");
                Console.WriteLine("select payment method - " + selectedPaymentMethon);

                var paymentAmount = driver.FindElementById("com.alibaba.aliexpresshd:id/tv_payment_order_total_amount").Text;

                double.Parse(paymentAmount.Replace("руб.", ""))
                .ShouldBeLessThanOrEqualTo(this.valueForCharge, $"Ammount for pay great than set value for charge - {this.valueForCharge}");
                Console.WriteLine("Amount for payment - " + paymentAmount);

                if (this.makePayment)
                {
                    //click Confirm and Pay
                    driver.FindElementById("com.alibaba.aliexpresshd:id/bt_confirm_and_pay").Click();

                    //find result of payment
                    waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("com.alibaba.aliexpresshd:id/tv_payment_result_success_message")));
                }

                //return to back for next iteration
                ((AndroidDriver <AppiumWebElement>)driver).PressKeyCode(AndroidKeyCode.Back);
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            //  AppiumOptions opt = new AppiumOptions();


            //  opt.AddAdditionalCapability("deviceName", "emulator-5554");
            //  opt.AddAdditionalCapability("platformName", "Android");
            // // opt.AddAdditionalCapability("browserName", "chrome");
            //  opt.AddAdditionalCapability("udid", "emulator-5554");
            //  opt.AddAdditionalCapability("app", @"E:\DHLe-MobileV0.1.6.apk");
            ////  opt.AddAdditionalCapability("automationName", "UIAutomator2");


            //  AndroidDriver<IWebElement> driver =
            //      new AndroidDriver<IWebElement>(new Uri("http://*****:*****@"E:\DHLe-MobileV0.1.6.apk");
                opt.AddAdditionalCapability("automationName", "UIAutomator2");

                opt.AddAdditionalCapability("appPackage", "org.khanacademy.android");
                opt.AddAdditionalCapability("appActivity", "org.khanacademy.android.ui.library.MainActivity");

                opt.AddAdditionalCapability("noReset", true);

                driver =
                    new AndroidDriver <IWebElement>(new Uri("http://localhost:4723/wd/hub"), opt);
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);

                if (driver.FindElementsByAndroidUIAutomator("UiSelector().text(\"Dismiss\")").Count > 0)
                {
                    driver.FindElementByAndroidUIAutomator("UiSelector().text(\"Dismiss\")").Click();
                }

                driver.FindElementById("org.khanacademy.android:id/tab_bar_button_profile").Click();


                driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"Sign up\")").Click();

                driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"Birth\")").Click();

                ReadOnlyCollection <IWebElement> dateEle = driver.FindElementsById("android:id/numberpicker_input");

                //foreach(IWebElement ele in dateEle)
                //{
                //    Console.WriteLine(ele.Text);
                //}

                dateEle[0].Click();

                dateEle[0].Clear();

                dateEle[0].SendKeys("Aug");

                driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"OK\")").Click();

                driver.FindElementByAndroidUIAutomator("UiSelector().text(\"Home\")").Click();

                Size size  = driver.Manage().Window.Size;
                int  width = size.Width;

                int height = size.Height;

                while (driver.FindElementsByAndroidUIAutomator("UiSelector().textContains(\"College\")").Count == 0)
                {
                    //scroll
                    TouchAction action = new TouchAction(driver);
                    //action.Tap(100, 500, 6).Perform();
                    //action.Press(width / 2, 3 * height / 4).MoveTo(width / 2, height / 4).Release().Perform();

                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    dic.Add("command", "input touchscreen swipe 250 800 250 400");


                    driver.ExecuteScript("mobile:shell", dic);
                }

                driver.FindElementByAndroidUIAutomator("UiSelector().textContains(\"College\")").Click();


                //IWebDriver d = new ChromeDriver();
                //ITakesScreenshot ts = (ITakesScreenshot)d;
                //ts.GetScreenshot().SaveAsFile("Error.png"); ;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

                //  string path = Directory.GetParent(Directory.GetCurrentDirectory()).Name;



                driver.GetScreenshot().SaveAsFile("Error.png");
            }
        }