Esempio n. 1
0
 public void market()
 {
     Thread.Sleep(10000);
     // driver.FindElementByXPath("//*[@text='Market']").Click();
     // driver.FindElementById("com.fsresidential.connect:id/marketLabel").Click();
     driver.FindElementByAndroidUIAutomator("new UiSelector().text(\"Market\")").Click();
 }
Esempio n. 2
0
        // Get element from selector
        public static AndroidElement GetElement(AndroidDriver <AndroidElement> driver, SelectBy by, string selector)
        {
            AndroidElement e = null;

            switch (by)
            {
            case SelectBy.ID:
                e = driver.FindElementById(selector);
                break;

            case SelectBy.Class:
                e = driver.FindElementByClassName(selector);
                break;

            case SelectBy.XPath:
                e = driver.FindElementByXPath(selector);
                break;

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

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

            case SelectBy.RegexText:
                e = driver.FindElementByAndroidUIAutomator(String.Format("new UiSelector().textMatches(\"{0}\")", selector));
                break;
            }
            return(e ?? throw new NotFoundException("Element with selector " + selector + " not found."));
        }
Esempio n. 3
0
 public static AndroidElement ScrollToElement(string element)
 {
     return(driver.FindElementByAndroidUIAutomator(
                "new UiScrollable(new UiSelector().scrollable(true))" +
                ".scrollIntoView(new UiSelector().resourceIdMatches(" +
                "\"" + element + "\"))"));
 }
        public void ClickBookFlightButton()
        {
            //IWebElement bookFlightBtn = driver.FindElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text(\"Book a flight\").instance(0)");
            IWebElement bookFlightBtn = driver.FindElementByAndroidUIAutomator("new UiSelector().text(\"Book a flight\")");

            bookFlightBtn.Click();
        }
        public void TestVivinoAndroidApp()
        {
            // Login in VivinoApp using existing user
            var getStartedButton = driver.FindElementById("vivino.web.app:id/getstarted_layout");

            getStartedButton.Click();
            var emailTextBox = driver.FindElementById("vivino.web.app:id/edtEmail");

            emailTextBox.SendKeys(VivinoTestEmail);
            var passwordTextBox = driver.FindElementById("vivino.web.app:id/edtPassword");

            passwordTextBox.SendKeys(VivinoTestPass);
            var signInButton = driver.FindElementById("vivino.web.app:id/action_next");

            signInButton.Click();

            // Search "Katarzyna Reserve Red 2006" and open the top result
            var searchTab = driver.FindElementById("vivino.web.app:id/wine_explorer_tab");

            searchTab.Click();
            var findWineTextBox = driver.FindElementById("vivino.web.app:id/search_vivino");

            findWineTextBox.Click();
            var searchForWineTextBox = driver.FindElementById("vivino.web.app:id/editText_input");

            searchForWineTextBox.SendKeys("Katarzyna Reserve Red 2006");
            var firstSearchResult = driver.FindElementById("vivino.web.app:id/wineimage");

            firstSearchResult.Click();
            // Assert wine name is "Reserve Red 2006"
            var expectedWineName = driver.FindElementById("vivino.web.app:id/wine_name").Text;

            Assert.AreEqual("Reserve Red 2006", expectedWineName);

            // Assert wine rating is a number in the range [1.00 ... 5.00]
            string ratingText   = driver.FindElementById("vivino.web.app:id/rating").Text;
            double ratingNumber = double.Parse(ratingText);
            var    rating       = (ratingNumber > 1.00 && ratingNumber <= 5.00);

            Assert.IsTrue(rating);

            // Assert wine highlights contain "Among top 1% of all wines in the world"(SCROLLING needed!)
            // we need to use scrolable selector to scroll down!
            var summaryBox = driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.HorizontalScrollView/android.widget.LinearLayout/android.widget.TextView[1]");
            var highlightsTabScrollable = driver.FindElementByAndroidUIAutomator
                                              ("new UiScrollable(new UiSelector().scrollable(true))" +
                                              ".scrollIntoView(new UiSelector().resourceIdMatches(" +
                                              "\"vivino.web.app:id/highlight_description\"));");

            Assert.AreEqual("Among top 1% of all wines in the world", highlightsTabScrollable.Text);

            // Assert the wine facts hold "Grapes: Cabernet Sauvignon, Merlot"
            var factsTab = driver.FindElementByXPath
                               ("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.HorizontalScrollView/android.widget.LinearLayout/android.widget.TextView[2]");

            factsTab.Click();
            string factText = driver.FindElementById("vivino.web.app:id/wine_fact_text").Text;

            Assert.AreEqual("Cabernet Sauvignon,Merlot", factText);
        }
Esempio n. 6
0
        public void FromElementTestCase()
        {
            AndroidDriver <IWebElement> driver = new AndroidDriver <IWebElement>(defaultUri, capabilities);

            server.respondTo("POST", "/element", new Dictionary <string, object>  {
                
                             {
                    "ELEMENT", '5'
                } 

            });
            AndroidElement element = (AndroidElement)driver.FindElementByAndroidUIAutomator(".elements()");

            server.clear();
            server.respondTo("POST", "/element/5/element", new Dictionary <string, object>  {
                
                           {
                    "ELEMENT", '6'
                } 

            });
            element.FindElementByAndroidUIAutomator(".elements()");
            server.clear();
            List <object> results = new List <object>();

            results.Add(new Dictionary <string, object> {
                { "ELEMENT", "4" }
            });
            server.respondTo("POST", "/element/5/elements", results);
            element.FindElementsByAndroidUIAutomator(".elements()");
        }
        public void ReplaceValueTest()
        {
            string originalValue = "original value";
            string replacedValue = "replaced value";

            driver.StartActivity("io.appium.android.apis", ".view.Controls1");

            AndroidElement editElement = driver.FindElementByAndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")");

            editElement.SendKeys(originalValue);

            Assert.AreEqual(originalValue, editElement.Text);

            editElement.ReplaceValue(replacedValue);

            Assert.AreEqual(replacedValue, editElement.Text);
        }
Esempio n. 8
0
        public void FindScrollable()
        {
            _driver.FindElementByAccessibilityId("Views").Click();
            var radioGroup = _driver
                             .FindElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"
                                                              + ".resourceId(\"android:id/list\")).scrollIntoView("
                                                              + "new UiSelector().text(\"Radio Group\"));");

            Assert.NotNull(radioGroup.Location);
        }
        public void FindElementByAndroidUIAutomatorTestCase()
        {
            AndroidDriver driver = new AndroidDriver(defaultUri, capabilities);

            server.respondTo("POST", "/element", new Dictionary <string, object>  {
                { "ELEMENT", '5' }
            });
            IWebElement element = driver.FindElementByAndroidUIAutomator(".elements()");

            server.clear();
            server.respondTo("GET", "/element/5/attribute/id", "1234");
            element.GetAttribute("id");
        }
        public static void Main()
        {
            appiumLocalService = new AppiumServiceBuilder().UsingAnyFreePort().Build();
            appiumLocalService.Start();
            var appiumOptions = new AppiumOptions();

            appiumOptions.AddAdditionalCapability(MobileCapabilityType.DeviceName, "device");
            appiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
            appiumOptions.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, "9.0");
            appiumOptions.AddAdditionalCapability(AndroidMobileCapabilityType.AppPackage, "com.draeger.connect.cse");
            appiumOptions.AddAdditionalCapability(AndroidMobileCapabilityType.AppActivity, "com.draeger.connect.cse.MainActivity");
            appiumOptions.AddAdditionalCapability(MobileCapabilityType.NoReset, true);
            //new Uri("http://127.0.0.1:4723/wd/hub")
            driver = new AndroidDriver <AppiumWebElement>(appiumLocalService, appiumOptions);

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
            AppiumWebElement approveBox             = driver.FindElementByAndroidUIAutomator("new UiSelector().textContains(\"Approve\");");

            approveBox.Click();
            AppiumWebElement background = driver.FindElementByAndroidUIAutomator("new UiSelector().textContains(\"Dräger CSE Mobile\");");

            background.Click();
        }
        public void LocatingElementsTest()
        {
            AndroidElement button = _driver.FindElementById("button");

            button.Click();

            AndroidElement checkBox = _driver.FindElementByClassName("android.widget.CheckBox");

            checkBox.Click();

            AndroidElement secondButton = _driver.FindElementByAndroidUIAutomator("new UiSelector().textContains(\"BUTTO\");");

            secondButton.Click();

            AndroidElement thirdButton = _driver.FindElementByXPath("//*[@resource-id='com.example.android.apis:id/button']");

            thirdButton.Click();
        }
Esempio n. 12
0
 private AndroidElement FindByText(string searchText)
 {
     return(driver.FindElementByAndroidUIAutomator($"new UiSelector().text(\"{searchText}\")"));
 }
Esempio n. 13
0
 public override AndroidElement FindElement(AndroidDriver <AndroidElement> searchContext)
 {
     return(searchContext.FindElementByAndroidUIAutomator(_locatorValue));
 }
Esempio n. 14
0
 public static void Goto(string page)
 {
     _driver.FindElementByAndroidUIAutomator("UiSelector().text(" + "\"" + page + "\")").Tap(1, 2);
 }
Esempio n. 15
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");
            }
        }