Exemplo n.º 1
0
        public void Test1()
        {
            var xp2 = "//*[@text='Log in']";
            var xp  = "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[3]/android.widget.TextView";
            //AndroidElement confirmAndContinue = _driver.FindElementByXPath("//*[@resource-id='com.example.android.apis:id/button']");
            AndroidElement button = _driver.FindElementByXPath(xp);

            button.Click();
            AndroidElement button2 = _driver.FindElementByXPath(xp2);

            button2.Click();
            AndroidElement el3 = _driver.FindElementByAccessibilityId("Yes");

            el3.Click();
            AndroidElement el4 = _driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.ImageView");

            el4.Click();


            var            journey = "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[3]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[16]/android.view.ViewGroup[2]/android.widget.TextView";
            AndroidElement el5     = _driver.FindElementByXPath(journey);

            el5.Click();
            System.Threading.Thread.Sleep(20000);
            Assert.Pass();
        }
        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);
        }
Exemplo n.º 3
0
        //Method For Link Visibility
        public void links_visibility(string locator, string locator_type)
        {
            try
            {
                Thread.Sleep(3000);

                if (locator_type == "id")
                {
                    AndroidElement link = driver.FindElementById(locator);
                }
                else if (locator_type == "xpath")
                {
                    AndroidElement link = driver.FindElementByXPath(locator);
                }
            }
            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);
            }
        }
Exemplo n.º 4
0
 public void LogIn()
 {
     driver = Init(MainActivity);
     Thread.Sleep(5000);
     driver.FindElementByXPath(LoginInput).SendKeys(Login);
     driver.FindElementByXPath(PasswordInput).SendKeys(Password);
     driver.FindElementByXPath(LoginButton).Click();
 }
Exemplo n.º 5
0
    public void DetailTest()
    {
        AppiumWebElement el1 = (AppiumWebElement)driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v4.view.ViewPager/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.ListView/android.widget.LinearLayout[1]/android.view.ViewGroup/android.view.ViewGroup");

        el1.Click();
        AppiumWebElement el2 = (AppiumWebElement)driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v4.view.ViewPager/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.TextView");
        AppiumWebElement el3 = (AppiumWebElement)driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.view.ViewGroup/android.support.v4.view.ViewPager/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[1]/android.widget.ImageButton");

        el3.Click();
        Assert.IsTrue(el2.Text.Equals("First item"));
    }
Exemplo n.º 6
0
        public static void ClearTextElement(AndroidDriver <AppiumWebElement> webDriver, string by, string elementName, int timeInSeconds)
        {
            switch (by)
            {
            case "id":
                webDriver.FindElementById(elementName).Clear();
                break;

            case "xPath":
                webDriver.FindElementByXPath(elementName).Clear();
                break;

            case "cssSelector":
                webDriver.FindElementByCssSelector(elementName).Clear();
                break;

            case "name":
                webDriver.FindElementByName(elementName).Clear();
                break;

            case "className":
                webDriver.FindElementByClassName(elementName).Clear();
                break;
            }

            Thread.Sleep(timeInSeconds * 1000);
        }
Exemplo n.º 7
0
        public static string GetValueFromElement(AndroidDriver <AppiumWebElement> webDriver, string by, string elementName, int timeInseconds)
        {
            string elementText = "";

            switch (by)
            {
            case "id":
                elementText = webDriver.FindElementById(elementName).GetAttribute("value");
                break;

            case "xPath":
                elementText = webDriver.FindElementByXPath(elementName).GetAttribute("value");
                break;

            case "cssSelector":
                elementText = webDriver.FindElementByCssSelector(elementName).GetAttribute("value");
                break;

            case "name":
                elementText = webDriver.FindElementByName(elementName).GetAttribute("value");
                break;

            case "className":
                elementText = webDriver.FindElementByClassName(elementName).GetAttribute("value");
                break;

            case "linkText":
                elementText = webDriver.FindElementByLinkText(elementName).GetAttribute("value");
                break;
            }

            Thread.Sleep(timeInseconds * 1000);

            return(elementText);
        }
Exemplo n.º 8
0
        public void FindByXPathTest()
        {
            var byXPath = "//android.widget.TextView[contains(@text, 'Animat')]";

            Assert.IsNotNull(_driver.FindElementByXPath(byXPath).Text);
            Assert.AreEqual(_driver.FindElementsByXPath(byXPath).Count, 1);
        }
Exemplo n.º 9
0
        public void FindElementTestCase()
        {
            By byAccessibilityId = new ByAccessibilityId("Graphics");

            Assert.AreNotEqual(driver.FindElement(byAccessibilityId).Text, null);
            Assert.GreaterOrEqual(driver.FindElements(byAccessibilityId).Count, 1);

            driver.FindElementByAccessibilityId("Graphics").Click();
            Assert.IsNotNull(driver.FindElementByAccessibilityId("Arcs"));
            driver.Navigate().Back();

            Assert.IsNotNull(driver.FindElementByName("App"));

            Assert.IsNotNull(driver.FindElement(new ByAndroidUIAutomator("new UiSelector().clickable(true)")).Text);
            var els = driver.FindElementsByAndroidUIAutomator("new UiSelector().clickable(true)");

            Assert.GreaterOrEqual(els.Count, 12);

            var els2 = driver.FindElements(new ByAndroidUIAutomator("new UiSelector().enabled(true)"));

            Assert.GreaterOrEqual(els2.Count, 20);

            els = driver.FindElementsByAndroidUIAutomator("new UiSelector().enabled(true)");
            Assert.GreaterOrEqual(els.Count, 20);
            Assert.IsNotNull(driver.FindElementByXPath("//android.widget.TextView[@text='API Demos']"));
        }
Exemplo n.º 10
0
        public string searchQuestion(AndroidDriver <IWebElement> driver, string question)
        {
            driver.FindElementByXPath("//*[@resource-id='com.dozuki.ifixit:id/topic_title' and @index=1]").Click();
            WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 60));

            wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//android.widget.FrameLayout")));
            wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@resource-id='com.dozuki.ifixit:id/topic_info_image']")));
            Thread.Sleep(3000);
            swipe();
            driver.FindElementByXPath("//*[@resource-id='answersSearch']").SendKeys(question);
            driver.FindElementByXPath("//*[@resource-id='searchIcon']").Click();
            Thread.Sleep(2000);

            return(driver.FindElementByXPath("//android.view.View[contains(@content-desc,'questions') and @index=1]")
                   .GetAttribute("name"));
        }
Exemplo n.º 11
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."));
        }
Exemplo n.º 12
0
        public void APIDemo()
        {
            AppiumDriver <AppiumWebElement> driver;

            var cap = new AppiumOptions();

            cap.AddAdditionalCapability("deviceName", "Appium_emulator");
            cap.AddAdditionalCapability("platformVersion", "9.0.0");
            cap.AddAdditionalCapability("platformName", "Android");
            cap.AddAdditionalCapability("appPackage", "io.appium.android.apis");
            cap.AddAdditionalCapability("appActivity", "io.appium.android.apis.ApiDemos");


            driver = new AndroidDriver <AppiumWebElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap);
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));

            //click Preference
            driver.FindElementByXPath("//android.widget.TextView[@content-desc='Preference']").Click();

            //click PreferenceDependencies
            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//android.widget.TextView[@content-desc='3. Preference dependencies']"))).Click();

            //click wifi checkbox
            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("android:id/checkbox"))).Click();

            //click WIFI Settings
            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("(//android.widget.RelativeLayout)[2]"))).Click();

            //send keys
            driver.FindElementByClassName("android.widget.EditText").SendKeys("hello");

            //use findelements if the xpath is same for many elements and choose the index and click the element
            //click ok button which is in second position with the index 1
            driver.FindElementsByClassName("android.widget.Button")[1].Click();
        }
Exemplo n.º 13
0
        public void TestMethod1()
        {
            driver.LaunchApp();
            var         el1 = driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.support.v4.widget.DrawerLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.view.ViewGroup/android.support.v4.view.ViewPager/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.support.v7.widget.RecyclerView/android.view.ViewGroup[4]/android.view.ViewGroup/android.widget.FrameLayout");
            TouchAction a   = new TouchAction(driver);

            a.Tap(el1);

            el1.Click();
            var el2 = driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.support.v4.widget.DrawerLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup/android.widget.FrameLayout[2]");


            Assert.IsTrue(el2.Text.Contains("will"));

            driver.CloseApp();
        }
Exemplo n.º 14
0
        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();
        }
        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);
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        public String GetCategoryTitle()
        {
            /*
             * Steps:
             * 1. Click on "Car and Truck" Categories on Homepage
             * 2. Click on "Acura" Categories
             *
             * Expected:
             * General Information is "Acura".
             */
            Helpers.Pause(5);
            if (driver_.FindElementsByXPath(browseDevicesXpath).Count > 0)
            {
                driver_.FindElementByXPath(browseDevicesXpath).Click();
            }
            Helpers.Pause(2);
            driver_.FindElementByXPath(carTruckXpath).Click();
            driver_.FindElementByXPath(acuraXpath).Click();
            Helpers.Pause(2);
            string acuraText = driver_.FindElementByXPath("//*[@resource-id='com.dozuki.ifixit:id/topic_title' and @index=1]").Text;

            return(acuraText);
        }
        public void FindElementTestCase()
        {
            driver.FindElementByXPath("//android.widget.TextView[@text='Animation']");
            Assert.AreEqual(driver.FindElementByXPath("//android.widget.TextView").Text,
                            "API Demos");
            IList <AppiumWebElement> els = driver.FindElementsByXPath("//android.widget.TextView[contains(@text, 'Animat')]");
            var elsres = Filters.FilterDisplayed <AppiumWebElement>(els);

            if (!Env.isSauce())
            {
                Assert.AreEqual(elsres [0].Text, "Animation");
            }
            driver.FindElementByName("App").Click();
            Thread.Sleep(3000);
            els = driver.FindElementsByAndroidUIAutomator("new UiSelector().clickable(true)");
            Assert.GreaterOrEqual(els.Count, 10);
            Assert.IsNotNull(
                driver.FindElementByXPath("//android.widget.TextView[@text='Action Bar']"));
            els    = driver.FindElementsByXPath("//android.widget.TextView");
            elsres = Filters.FilterDisplayed <AppiumWebElement>(els);
            Assert.AreEqual(elsres[0].Text, "API Demos");
            driver.Navigate().Back();
        }
Exemplo n.º 19
0
        public void CrearAppMemoryTest()
        {
            AndroidElement menuButton = driver.FindElementById("com.alibaba.aliexpresshd:id/left_action");

            menuButton.Click();
            wait.Until(ExpectedConditions.ElementExists(By.Id("com.alibaba.aliexpresshd:id/navdrawer_items_list")));
            AndroidElement settingsMenuButton = driver.FindElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/" +
                                                                          "android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/" +
                                                                          "android.support.v4.widget.DrawerLayout/android.widget.ScrollView/android.widget.LinearLayout/" +
                                                                          "android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[9]/" +
                                                                          "android.widget.TextView");

            wait.Until(ExpectedConditions.ElementToBeClickable(settingsMenuButton));
            settingsMenuButton.Click();

            wait.Until(ExpectedConditions.ElementExists(By.Id("com.alibaba.aliexpresshd:id/rl_clear_memory_settings")));
            AndroidElement clearMemoryButton = driver.FindElementById("com.alibaba.aliexpresshd:id/rl_clear_memory_settings");

            clearMemoryButton.Click();

            string popupText = driver.FindElementByXPath("/hierarchy/android.widget.Toast").Text;

            Assert.IsTrue(popupText == "Память приложения очищена.", "Текст сообщения - '" + popupText + "' отличается от ожидаемого");
        }
        // return mapping for menu item "Widget + Feed (Scroll View)"
        public static AppiumWebElement WidgetFeedScrollView(AndroidDriver <AppiumWebElement> driver)
        {
            String           locator = "//android.widget.Button[@text = 'Widget + Feed (ScrollView)']";
            AppiumWebElement widgetFeedScrollViewButton = null;

            try
            {
                widgetFeedScrollViewButton = driver.FindElementByXPath(locator);
            }
            catch (Exception e)
            {
                throw new Exception("widgetFeedScrollViewButton not found, please check locator:"
                                    + Environment.NewLine + locator
                                    + Environment.NewLine + "original exception: " + e.Message);
            }

            return(widgetFeedScrollViewButton);
        }
        // holds logic to locate elements

        // return mapping for home screen title
        public static AppiumWebElement HomeScreenTitle(AndroidDriver <AppiumWebElement> driver)
        {
            String           locator         = "//android.widget.TextView[@text='Taboola Sample App']";
            AppiumWebElement homeScreenTitle = null;

            try
            {
                homeScreenTitle = driver.FindElementByXPath(locator);
            }
            catch (Exception e)
            {
                throw new Exception("homeScreenTitle not found, please check locator:"
                                    + Environment.NewLine + locator
                                    + Environment.NewLine + "original exception: " + e.Message);
            }

            return(homeScreenTitle);
        }
        // return mapping for "taboola feed" below the article
        public static AppiumWebElement TaboolaFeedLogo(AndroidDriver <AppiumWebElement> driver)
        {
            String           locator           = "//android.view.View[@resource-id = 'taboola']";
            AppiumWebElement taboolaFeedButton = null;

            try
            {
                taboolaFeedButton = driver.FindElementByXPath(locator);
            }
            catch (Exception e)
            {
                // no need to throw an exception here

                /*throw new Exception("taboolaFeedButton not found, please check locator:"
                 + Environment.NewLine + locator
                 + Environment.NewLine + "original exception: " + e.Message);*/
            }

            return(taboolaFeedButton);
        }
        // return mapping for close adchoice
        public static AppiumWebElement CloseAdchoiceButton(AndroidDriver <AppiumWebElement> driver)
        {
            String           locator           = "//android.widget.ImageButton[contains(@resource-id , 'dismiss_button')]";
            AppiumWebElement closeChoiceButton = null;

            try
            {
                // allow time for the content to be available
                Thread.Sleep(5000);
                closeChoiceButton = driver.FindElementByXPath(locator);
            }
            catch (Exception e)
            {
                throw new Exception("closeItemButton not found, please check locator:"
                                    + Environment.NewLine + locator
                                    + Environment.NewLine + "original exception: " + e.Message);
            }

            return(closeChoiceButton);
        }
        // return mapping for second part of the article
        public static AppiumWebElement ArticleSecondPart(AndroidDriver <AppiumWebElement> driver)
        {
            String           locator           = "//android.widget.TextView[@index = 2]";
            AppiumWebElement taboolaFeedButton = null;

            try
            {
                taboolaFeedButton = driver.FindElementByXPath(locator);
            }
            catch (Exception e)
            {
                // no need to throw an exception here

                /*throw new Exception("taboolaFeedButton not found, please check locator:"
                 + Environment.NewLine + locator
                 + Environment.NewLine + "original exception: " + e.Message);*/
            }

            return(taboolaFeedButton);
        }
        // return mapping of items in taboola feed
        public static AppiumWebElement ItemInTaboolaFeed(AndroidDriver <AppiumWebElement> driver, int index)
        {
            String locator = "//android.view.View[@resource-id = 'taboola-pl" + index +
                             "' and @index = " + index + "]";
            AppiumWebElement itemInTaboolaFeed = null;

            try
            {
                itemInTaboolaFeed = driver.FindElementByXPath(locator);
            }
            catch (Exception e)
            {
                // no need to throw an exception here

                /*throw new Exception("itemsInTaboolaFeed not found, please check locator:"
                 + Environment.NewLine + locator
                 + Environment.NewLine + "original exception: " + e.Message);*/
            }

            return(itemInTaboolaFeed);
        }
        // return mapping of "sponsored" element
        public static AppiumWebElement AdchoiceButton(AndroidDriver <AppiumWebElement> driver, int index)
        {
            String locator = "//android.view.View[@resource-id = 'taboola-pl" + index +
                             "' and @index = " + index + "]//android.view.View[@text = 'Sponsored']";
            AppiumWebElement adchoiceButton = null;

            try
            {
                adchoiceButton = driver.FindElementByXPath(locator);
            }
            catch (Exception e)
            {
                // no need to throw an exception here

                /*throw new Exception("adchoiceButton not found, please check locator:"
                 + Environment.NewLine + locator
                 + Environment.NewLine + "original exception: " + e.Message);*/
            }

            return(adchoiceButton);
        }
Exemplo n.º 27
0
 public void LogIn()
 {
     driver = Init(MainActivity);
     Thread.Sleep(2000);
     try
     {
         driver.FindElementByXPath(TapOnProfile).Click();
     }
     catch (Exception e)
     {
         driver.FindElementByXPath(LoginInput).SendKeys(Login);
         Thread.Sleep(500);
         driver.FindElementByXPath(LoginInput).Tap(1, 1);
         driver.FindElementByXPath(PasswordInput).SendKeys(Password);
         Thread.Sleep(500);
         driver.FindElementByXPath(LoginButton).Click();
         Thread.Sleep(3000);
         driver.FindElementByXPath(RememberPswdButton).Click();
     }
 }
Exemplo n.º 28
0
 public override AndroidElement FindElement(AndroidDriver <AndroidElement> searchContext)
 {
     return(searchContext.FindElementByXPath(Value));
 }
Exemplo n.º 29
0
        public void AppiumTestMethod()
        {
            //Write your test here
            // Notify Reporting Server that test is starting
            reportClient.testStart("Wikipedia assignment", new TestContextTags("assignment1", "apple entry"));

            Dictionary <String, Object> pars = new Dictionary <String, Object>();

            try
            {
                reportClient.stepStart("Open YouTube");
                try
                {
                    // close the calendar if open to verify that starting from fresh app
                    pars.Add("name", "YouTube");
                    driver.ExecuteScript("mobile:application:close", pars);
                }
                catch (Exception e)
                {
                    Trace.Write(e.StackTrace);
                    Trace.WriteLine(" ");
                }
                pars.Clear();
                pars.Add("name", "YouTube");
                driver.ExecuteScript("mobile:application:open", pars);
                driver.Context = "NATIVE_APP";

                reportClient.stepEnd();

                reportClient.stepStart("Adjust Volume");
                MaxVolume(driver);
                reportClient.stepEnd();

                reportClient.stepStart("Activate the audio search");
                driver.FindElementByXPath("//*[@content-desc=\"Search\"]").Click();
                driver.FindElementByXPath("//*[@resource-id=\"com.google.android.youtube:id/voice_search\"]").Click();
                reportClient.stepEnd();

                reportClient.stepStart("Play name for audio search");
                // Create audio file from String
                String key = "PRIVATE:mysong.wav";
                pars.Clear();
                pars.Add("text", "Metallica Master of Puppets");
                pars.Add("repositoryFile", key);
                driver.ExecuteScript("mobile:text:audio", pars);
                // inject Audio to device
                pars.Clear();
                pars.Add("key", key);
                pars.Add("wait", "wait");
                driver.ExecuteScript("mobile:audio:inject", pars);
                reportClient.stepEnd();

                reportClient.stepStart("Play the music clip and validate");
                driver.FindElementByXPath("//*[@content-desc=\"Play album\"]").Click();

                pars.Clear();
                pars.Add("timeout", 30);
                pars.Add("duration", 1);
                String audioR = (String)driver.ExecuteScript("mobile:checkpoint:audio", pars);
                reportClient.stepEnd();

                reportClient.stepStart("Close the app");
                // inject Audio to device
                pars.Clear();
                pars.Add("name", "YouTube");
                driver.ExecuteScript("mobile:application:close", pars);
                reportClient.stepEnd();

                if (audioR.ToLower().Equals("true"))
                {
                    reportClient.reportiumAssert("Audio is playing", true);
                    reportClient.testStop(TestResultFactory.createSuccess());
                }
                else
                {
                    reportClient.reportiumAssert("Audio failed", false);
                    reportClient.testStop(TestResultFactory.createFailure("Audio failed", null));
                }
            }
            catch (Exception e)
            {
                reportClient.testStop(TestResultFactory.createFailure(e.Message, e));
                Trace.Write(e.StackTrace);
                Trace.WriteLine(" ");
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// This method will select "Great Western Pilsner" from the beverage select,
        /// and send you to the status screen.
        /// </summary>
        private void SelectBeverage()
        {
            TouchAction touchAction = new TouchAction(driver);

            Thread.Sleep(500);

            //AndroidElement element = driver.FindElementByAndroidUIAutomator("new UiSelector().textContains(\"Please enter a beverage, type or brand!!\");");
            AndroidElement element = driver.FindElementByClassName("android.widget.EditText");

            element.SendKeys("Great");

            Thread.Sleep(500);

            //element = driver.FindElementByAndroidUIAutomator("new UiSelector().textContains(\"Great Western Pilsner\");");
            element = driver.FindElementByXPath("//android.widget.TextView[@text='Great Western Pilsner']");

            Thread.Sleep(500);

            var action = touchAction.Tap(element);

            action.Perform();
            action.Cancel();

            Thread.Sleep(500);
        }