public void LightTheme()
        {
            //var viewButton = _driver.FindElementByXPath("//android.widget.View[@content-desc='View']");

            //https://qavalidation.com/2016/07/scrolling-in-appium.html/ -- Utils
            var winSize     = _driver.Manage().Window.Size;
            int scrollStart = (int)(winSize.Height * 0.5);
            int scrollEnd   = (int)(winSize.Height * 0.2);

            //Message=The IWebDriver object must implement or wrap a driver that implements IHasTouchScreen. (Parameter 'driver')
            ITouchAction touchActions = new OpenQA.Selenium.Appium.MultiTouch.TouchAction(_driver);
            ////touchActions.
            ////touchActions.Perform();


            By byScrollLocator = new ByAndroidUIAutomator("new UiSelector().text(\"Views\");");
            //Message = An element could not be located on the page using the given search parameters.
            var viewsButton = _driver.FindElement(byScrollLocator);

            viewsButton.Click();


            var demoTitle = _driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.view.ViewGroup");

            Assert.AreEqual <string>("API Demos", demoTitle.Text, "Not on Controls page");

            var lightThemeButton = _driver.FindElementByXPath("//android.widget.TextView[@content-desc='1. Light Theme']");

            lightThemeButton.Click();

            var themeTitle = _driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.widget.TextView");

            Assert.AreEqual <string>("Views/Controls/1. Light Theme", themeTitle.Text, "Not on Light Theme page");
        }
Esempio n. 2
0
        public void FindByAndroidUiAutomatorTest()
        {
            By byAndroidUiAutomator = new ByAndroidUIAutomator("new UiSelector().clickable(true)");

            Assert.IsNotNull(_driver.FindElement(byAndroidUiAutomator).Text);
            Assert.GreaterOrEqual(_driver.FindElements(byAndroidUiAutomator).Count, 1);
        }
        public void PerformActionsButtons()
        {
            By  byScrollLocator = new ByAndroidUIAutomator("new UiSelector().text(\"Views\");");
            var viewsButton     = _driver.FindElement(byScrollLocator);

            viewsButton.Click();

            var controlsViewButton = _driver.FindElementByXPath("//*[@text='Controls']");

            controlsViewButton.Click();

            var lightThemeButton = _driver.FindElementByXPath("//*[@text='1. Light Theme']");

            lightThemeButton.Click();
            _driver.HideKeyboard();

            // rotate the device
            ////var rotatable = (IRotatable)_driver;
            ////rotatable.Orientation = ScreenOrientation.Landscape;
            ////_driver.ToggleWifi();

            var saveButton = _driver.FindElementByXPath("//*[@text='Save']");

            Assert.IsTrue(saveButton.Enabled);
        }
        public IWebElement ScrollDownToText(string text)
        {
            var locator = new ByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
                                                   + $"new UiSelector().text(\"{text}\"));");

            return(ListView.FindElement(locator));
        }
Esempio n. 5
0
        public void CanFindByDescriptionUsingBuilderWhenDoubleQuoteCharacterIncluded()
        {
            _driver.StartActivity("io.appium.android.apis", ".text.Link");
            By byAndroidUiAutomator = new ByAndroidUIAutomator(new AndroidUiSelector()
                                                               .DescriptionContains("Use a \"tel:\" URL"));

            Assert.IsNotNull(_driver.FindElementById("android:id/content").FindElement(byAndroidUiAutomator).Text);
            Assert.GreaterOrEqual(_driver.FindElementById("android:id/content").FindElements(byAndroidUiAutomator).Count, 1);
        }
Esempio n. 6
0
        public void FindByAndroidUiAutomatorBuilderTest()
        {
            By byAndroidUiAutomator = new ByAndroidUIAutomator(new AndroidUiSelector().IsClickable(true));

            Assert.IsNotNull(_driver.FindElementById("android:id/content").FindElement(byAndroidUiAutomator).Text);
            Assert.GreaterOrEqual(
                _driver.FindElementById("android:id/content").FindElements(byAndroidUiAutomator).Count,
                1);
        }
Esempio n. 7
0
        public void ScrollingToSubElementUsingBuilder()
        {
            _driver.FindElementByAccessibilityId("Views").Click();
            var list    = _driver.FindElement(By.Id("android:id/list"));
            var locator = new ByAndroidUIAutomator(new AndroidUiScrollable()
                                                   .ScrollIntoView(new AndroidUiSelector().TextEquals("Radio Group")));
            var radioGroup = list.FindElement(locator);

            Assert.NotNull(radioGroup.Location);
        }
Esempio n. 8
0
        public void ScrollingToSubElement()
        {
            _driver.FindElementByAccessibilityId("Views").Click();
            var list    = _driver.FindElement(By.Id("android:id/list"));
            var locator = new ByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
                                                   + "new UiSelector().text(\"Radio Group\"));");
            var radioGroup = list.FindElement(locator);

            Assert.NotNull(radioGroup.Location);
        }
Esempio n. 9
0
        public void CanFindByDescriptionUsingBuilderWhenNewlineCharacterIncluded()
        {
            _driver.StartActivity("io.appium.android.apis", ".accessibility.TaskListActivity");
            By byAndroidUiAutomator = new ByAndroidUIAutomator(new AndroidUiSelector().DescriptionEquals(
                                                                   "1. Enable QueryBack (Settings -> Accessibility -> QueryBack). \n\n" +
                                                                   "2. Enable Explore-by-Touch (Settings -> Accessibility -> Explore by Touch). \n\n" +
                                                                   "3. Touch explore the list."));

            Assert.IsNotNull(_driver.FindElementById("android:id/content").FindElement(byAndroidUiAutomator).Text);
            Assert.GreaterOrEqual(_driver.FindElementById("android:id/content").FindElements(byAndroidUiAutomator).Count, 1);
        }
Esempio n. 10
0
 static bool HasProgressBar()
 {
     try
     {
         var locator = new ByAndroidUIAutomator(Const.ProgressBarLocator);
         return(_driver.FindElement(locator) != null);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 11
0
 static bool IsLoadingMsg()
 {
     try
     {
         var locator = new ByAndroidUIAutomator(Const.MsgLoadingLocator);
         return(_driver.FindElement(locator) != null);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 12
0
 static bool HasMoreMsg()
 {
     try
     {
         var locator = new ByAndroidUIAutomator(Const.NoMoreMsgLocator);
         return(_driver.FindElement(locator) == null);
     }
     catch (Exception)
     {
         return(true);
     }
 }
Esempio n. 13
0
        static void OperateHistoryMsgItem()
        {
            var isLastTime = false;

            while (true)
            {
                var locator  = new ByAndroidUIAutomator(Const.HistoryMsgsLocator);
                var elements = _driver.FindElements(locator);


                foreach (var element in elements)
                {
                    var rectangle = element.Rect;

                    var needScroll = rectangle.Bottom > _screenSize.Height - 50;
                    Console.WriteLine($"rectangle.Bottom -> {rectangle.Bottom}");
                    if (needScroll)
                    {
                        Console.WriteLine("Scroll");
                        Swipe(new Point(_x, rectangle.Top), new Point(_x, 180), TimeSpan.FromSeconds(1));
                    }

                    element.Click();
                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    // 可能需要更久

                    // 返回至消息列表
                    _driver.PressKeyCode(AndroidKeyCode.Back);
                    Thread.Sleep(TimeSpan.FromSeconds(3));
                }

                while (!IsLoadingMsg())
                {
                    if (!HasMoreMsg())
                    {
                        if (isLastTime)
                        {
                            return;
                        }

                        isLastTime = true;
                    }
                    else
                    {
                        Swipe(new Point(_x, _fromY), new Point(_x, _toY), TimeSpan.FromSeconds(1));
                    }
                }
            }
        }
        public void PerformActionsButtons()
        {
            By  byScrollLocator = new ByAndroidUIAutomator("new UiSelector().text(\"Views\");");
            var viewsButton     = _driver.FindElement(byScrollLocator);

            viewsButton.Click();

            var controlsViewButton = _driver.FindElementByXPath("//*[@text='Controls']");

            controlsViewButton.Click();

            var lightThemeButton = _driver.FindElementByXPath("//*[@text='1. Light Theme']");

            lightThemeButton.Click();
            var saveButton = _driver.FindElementByXPath("//*[@text='Save']");

            Assert.IsTrue(saveButton.Enabled);
        }
Esempio n. 15
0
        static IReadOnlyCollection <AppiumWebElement> FetchPublicItems(AppiumWebElement ele)
        {
            var locator = new ByAndroidUIAutomator($"new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().resourceId(\"{Const.PublicLvItemId}\"));");

            return(ele.FindElements(locator));
        }