Search in sources :

Example 11 with ExtendedWebElement

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

the class NotificationPage method clearNotifications.

/*
     * public MessagesPage tapLastItemsContent(int num) {
     * tapElement(lastItemsContainer.get(num));
     * return new MessagesPage(driver);
     * }
     * 
     * public MessagesPage tapItemTitle(int num) {
     * tapElement(lastItemsContent.get(num));
     * return new MessagesPage(driver);
     * }
     */
/**
 * clearNotifications
 */
public void clearNotifications() {
    if (!isOpened(1)) {
        notificationService.expandStatusBar();
    }
    if (dismissBtn.isElementPresent(SHORT_TIMEOUT)) {
        LOGGER.info("Dismiss all notifications btn is present.");
        dismissBtn.click();
    } else {
        LOGGER.info("Dismiss all notifications btn isn't present. Attempt to clear all notifications manually");
        LOGGER.debug("Notifications page source: ".concat(getDriver().getPageSource()));
        int x1, x2, y1, y2;
        Point point;
        Dimension dim;
        List<ExtendedWebElement> notificationList;
        if (notifications.size() > 0) {
            notificationList = notifications;
        } else {
            notificationList = notificationsOtherDevices;
        }
        LOGGER.info("Visible Notifications size:" + notificationList.size());
        for (ExtendedWebElement notification : notificationList) {
            point = notification.getElement().getLocation();
            dim = notification.getElement().getSize();
            x1 = point.x + dim.width / 6;
            x2 = point.x + dim.width * 5 / 6;
            y1 = y2 = point.y + dim.height / 2;
            MobileUtils.swipe(x1, y1, x2, y2, SWIPE_DURATION);
        }
    }
}
Also used : ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) Point(org.openqa.selenium.Point)

Example 12 with ExtendedWebElement

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

the class ScreenElementExtractor method getElementsByCoordinates.

@Override
public ExtendedWebElement getElementsByCoordinates(int x, int y) {
    String elementName = String.format("Element founded by x:%d - y:%d", x, y);
    WebDriver driver = getDriver();
    List<WebElement> elements = getEndLevelElements(driver);
    List<WebElement> result = new ArrayList<WebElement>();
    Rectangle rect;
    for (WebElement webElement : elements) {
        try {
            rect = getRect(webElement);
        } catch (Exception e) {
            continue;
        }
        if (isInside(rect, x, y)) {
            result.add(webElement);
        }
    }
    return generateExtenedElement(result, elementName);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) ArrayList(java.util.ArrayList) Rectangle(org.openqa.selenium.Rectangle) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement)

Example 13 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
 *            - 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 default ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, SelectorType eleSelectorType) {
    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) + ")" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ")");
            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) + ").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)

Example 14 with ExtendedWebElement

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

the class IAndroidUtils method toggleAppNotificationsFromDeviceSettings.

/**
 * Toggles a specified app's ability to recieve Push Notifications on the system level
 *
 * @param appName - The app name as it appears within device System Settings
 * @param setValue - The value you wish to set the toggle to
 */
default void toggleAppNotificationsFromDeviceSettings(String appName, boolean setValue) {
    openAppMenuFromDeviceSettings(appName);
    WebDriver driver = getDriver();
    ExtendedWebElement element = new ExtendedWebElement(By.xpath("//*[contains(@text, 'Notifications') or contains(@text, 'notifications')]"), "notifications", driver);
    element.click();
    element = new ExtendedWebElement(By.xpath("//*[@resource-id='com.android.settings:id/switch_text']/following-sibling::android.widget.Switch"), "toggle", driver);
    if (Boolean.valueOf(element.getAttribute("checked")) != setValue) {
        element.click();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement)

Example 15 with ExtendedWebElement

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

the class IAndroidUtils method openAppMenuFromDeviceSettings.

/**
 * Method enters an App's menu within device System Settings
 *
 * @param appName - Name of the app as it appears in the device's Apps list (Language specific)
 */
default void openAppMenuFromDeviceSettings(String appName) {
    AndroidService androidService = AndroidService.getInstance();
    androidService.executeAdbCommand("shell am start -a android.settings.APPLICATION_SETTINGS");
    ExtendedWebElement appItem = new ExtendedWebElement(By.xpath(String.format("//*[contains(@text, '%s')]", appName)), "notifications", getDriver());
    swipe(appItem);
    appItem.click();
}
Also used : ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement)

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