Search in sources :

Example 1 with ExtendedWebElement

use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.

the class AndroidUtils method scroll.

/**
 * Scrolls into view in a container specified by it's instance (index)
 * @param scrollToEle - has to be id, text, contentDesc or className
 * @param scrollableContainer - ExtendedWebElement type
 * @param containerSelectorType - has to be id, text, textContains, textStartsWith, Description, DescriptionContains
 *                             or className
 * @param containerInstance - has to an instance number of desired container
 * @param eleSelectorType -  has to be id, text, textContains, textStartsWith, Description, DescriptionContains
 *                             or className
 * @return ExtendedWebElement
 * <p>
 * example of usage:
 * ExtendedWebElement res = AndroidUtils.scroll("News", newsListContainer, AndroidUtils.SelectorType.CLASS_NAME, 1,
 *                          AndroidUtils.SelectorType.TEXT);
 */
public static ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, int containerInstance, SelectorType eleSelectorType) {
    ExtendedWebElement el = null;
    long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
    for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {
        try {
            WebElement ele = DriverPool.getDriver().findElement(MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ".instance(" + containerInstance + "))" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ")"));
            if (ele.isDisplayed()) {
                LOGGER.info("Element found!!!");
                el = new ExtendedWebElement(ele, scrollToEle, DriverPool.getDriver());
                break;
            }
        } catch (NoSuchElementException noSuchElement) {
            LOGGER.error(String.format("Element %s:%s was NOT found.", eleSelectorType, scrollToEle), noSuchElement);
        }
        for (int j = 0; j < i; j++) {
            checkTimeout(startTime);
            MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ".instance(" + containerInstance + ")).scrollForward()");
            LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
        }
    }
    return el;
}
Also used : ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 2 with ExtendedWebElement

use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.

the class AndroidUtils method scroll.

/**
 * Scrolls into view in specified container
 * @param scrollToEle - has to be id, text, contentDesc or className
 * @param scrollableContainer - ExtendedWebElement type
 * @param containerSelectorType - container Selector type: has to be id, text, textContains, textStartsWith, Description, DescriptionContains
 *                             or className
 * @param eleSelectorType -  scrollToEle Selector type: has to be id, text, textContains, textStartsWith, Description, DescriptionContains
 *                             or className
 * @return ExtendedWebElement
 * <p>
 * example of usage:
 * ExtendedWebElement res = AndroidUtils.scroll("News", newsListContainer, AndroidUtils.SelectorType.CLASS_NAME,
 *                          AndroidUtils.SelectorType.TEXT);
 */
public static ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, SelectorType eleSelectorType) {
    ExtendedWebElement el = null;
    long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
    for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {
        try {
            WebElement ele = DriverPool.getDriver().findElement(MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ")" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ")"));
            if (ele.isDisplayed()) {
                LOGGER.info("Element found!!!");
                el = new ExtendedWebElement(ele, scrollToEle, DriverPool.getDriver());
                break;
            }
        } catch (NoSuchElementException noSuchElement) {
            LOGGER.error(String.format("Element %s:%s was NOT found.", eleSelectorType, scrollToEle), noSuchElement);
        }
        for (int j = 0; j < i; j++) {
            checkTimeout(startTime);
            MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ").scrollForward()");
            LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
        }
    }
    return el;
}
Also used : ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 3 with ExtendedWebElement

use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.

the class DriverHelper method findExtendedWebElement.

/**
 * Find Extended Web Element on page using By.
 *
 * @param by
 *            Selenium By locator
 * @param name
 *            Element name
 * @param timeout
 *            Timeout to find
 * @return ExtendedWebElement if exists otherwise null.
 */
public ExtendedWebElement findExtendedWebElement(final By by, String name, long timeout) {
    ExtendedWebElement element;
    final WebDriver drv = getDriver();
    wait = new WebDriverWait(drv, timeout, RETRY_TIME);
    try {
        setImplicitTimeout(0);
        wait.until((Function<WebDriver, Object>) dr -> !drv.findElements(by).isEmpty());
        element = new ExtendedWebElement(driver.findElement(by), name, by, driver);
        Messager.ELEMENT_FOUND.info(name);
    } catch (Exception e) {
        element = null;
        Messager.ELEMENT_NOT_FOUND.error(name);
        throw new RuntimeException(e);
    } finally {
        setImplicitTimeout(IMPLICIT_TIMEOUT);
    }
    return element;
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Wait(org.openqa.selenium.support.ui.Wait) SpecialKeywords(com.qaprosoft.carina.core.foundation.commons.SpecialKeywords) Parameter(com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter) Messager(com.qaprosoft.carina.core.foundation.utils.Messager) Set(java.util.Set) Configuration(com.qaprosoft.carina.core.foundation.utils.Configuration) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) Action(org.openqa.selenium.interactions.Action) Function(java.util.function.Function) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) Logger(org.apache.log4j.Logger) BaseMatcher(org.hamcrest.BaseMatcher) List(java.util.List) CommonUtils(com.qaprosoft.carina.core.foundation.utils.common.CommonUtils) Matcher(java.util.regex.Matcher) CryptoTool(com.qaprosoft.carina.core.foundation.crypto.CryptoTool) AbstractPage(com.qaprosoft.carina.core.gui.AbstractPage) DevicePool(com.qaprosoft.carina.core.foundation.webdriver.device.DevicePool) Pattern(java.util.regex.Pattern) org.openqa.selenium(org.openqa.selenium) Actions(org.openqa.selenium.interactions.Actions) LogicUtils(com.qaprosoft.carina.core.foundation.utils.LogicUtils) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 4 with ExtendedWebElement

use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.

the class LocatingElementListHandler method invoke.

public Object invoke(Object object, Method method, Object[] objects) throws Throwable {
    List<WebElement> elements = locator.findElements();
    List<ExtendedWebElement> extendedWebElements = null;
    if (elements != null) {
        extendedWebElements = new ArrayList<ExtendedWebElement>();
        for (WebElement element : elements) {
            extendedWebElements.add(new ExtendedWebElement(element, name, by, webDriver));
        }
    }
    try {
        return method.invoke(extendedWebElements, objects);
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
}
Also used : ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with ExtendedWebElement

use of com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement in project carina by qaprosoft.

the class IAndroidUtils method scroll.

/**
 * Scrolls into view in specified container
 *
 * @param scrollToEle
 *            - has to be id, text, contentDesc or className
 * @param scrollableContainer
 *            - ExtendedWebElement type
 * @param containerSelectorType
 *            - has to be id, text, textContains, textStartsWith, Description,
 *            DescriptionContains or className
 * @param containerInstance
 *            - has to an instance number of desired container
 * @param eleSelectorType
 *            - has to be id, text, textContains, textStartsWith, Description,
 *            DescriptionContains or className
 * @param eleSelectorInstance
 *            - has to an instance number of desired container
 * @return ExtendedWebElement
 *         <p>
 *         example of usage: ExtendedWebElement res =
 *         AndroidUtils.scroll("News", newsListContainer,
 *         AndroidUtils.SelectorType.CLASS_NAME, 1,
 *         AndroidUtils.SelectorType.TEXT, 2);
 */
public default ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, int containerInstance, SelectorType eleSelectorType, int eleSelectorInstance) {
    ExtendedWebElement extendedWebElement = null;
    long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
    // TODO: support multi threaded WebDriver's removing DriverPool usage
    WebDriver drv = castDriver();
    // workaorund for appium issue: https://github.com/appium/appium/issues/10159
    if (scrollToEle.contains(",")) {
        scrollToEle = StringUtils.join(StringUtils.split(scrollToEle, ","), ",", 0, 2);
        if (eleSelectorType.equals(SelectorType.TEXT)) {
            eleSelectorType = SelectorType.TEXT_CONTAINS;
        }
    }
    for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {
        try {
            By scrollBy = MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ".instance(" + containerInstance + "))" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ".instance(" + eleSelectorInstance + "))");
            WebElement ele = drv.findElement(scrollBy);
            if (ele.isDisplayed()) {
                UTILS_LOGGER.info("Element found!!!");
                extendedWebElement = new ExtendedWebElement(scrollBy, scrollToEle, drv);
                break;
            }
        } catch (NoSuchElementException noSuchElement) {
            UTILS_LOGGER.error(String.format("Element %s:%s was NOT found.", eleSelectorType, scrollToEle), noSuchElement);
        }
        for (int j = 0; j < i; j++) {
            checkTimeout(startTime);
            MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ".instance(" + containerInstance + ")).scrollForward()");
            UTILS_LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
        }
    }
    return extendedWebElement;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) MobileBy(io.appium.java_client.MobileBy) By(org.openqa.selenium.By) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Aggregations

ExtendedWebElement (com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement)15 WebElement (org.openqa.selenium.WebElement)10 WebDriver (org.openqa.selenium.WebDriver)6 NoSuchElementException (org.openqa.selenium.NoSuchElementException)5 MobileBy (io.appium.java_client.MobileBy)2 ArrayList (java.util.ArrayList)2 By (org.openqa.selenium.By)2 Rectangle (org.openqa.selenium.Rectangle)2 Action (org.openqa.selenium.interactions.Action)2 Actions (org.openqa.selenium.interactions.Actions)2 SpecialKeywords (com.qaprosoft.carina.core.foundation.commons.SpecialKeywords)1 CryptoTool (com.qaprosoft.carina.core.foundation.crypto.CryptoTool)1 Configuration (com.qaprosoft.carina.core.foundation.utils.Configuration)1 Parameter (com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter)1 LogicUtils (com.qaprosoft.carina.core.foundation.utils.LogicUtils)1 Messager (com.qaprosoft.carina.core.foundation.utils.Messager)1 CommonUtils (com.qaprosoft.carina.core.foundation.utils.common.CommonUtils)1 DevicePool (com.qaprosoft.carina.core.foundation.webdriver.device.DevicePool)1 AbstractPage (com.qaprosoft.carina.core.gui.AbstractPage)1 IOException (java.io.IOException)1