Search in sources :

Example 6 with ExtendedWebElement

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

the class DriverHelper method dragAndDrop.

/**
 * Drags and drops element to specified place.
 *
 * @param from
 *            - element to drag.
 * @param to
 *            - element to drop to.
 */
public void dragAndDrop(final ExtendedWebElement from, final ExtendedWebElement to) {
    if (from.isElementPresent() && to.isElementPresent()) {
        WebDriver drv = getDriver();
        if (!drv.toString().contains("safari")) {
            Actions builder = new Actions(drv);
            Action dragAndDrop = builder.clickAndHold(from.getElement()).moveToElement(to.getElement()).release(to.getElement()).build();
            dragAndDrop.perform();
        } else {
            WebElement LocatorFrom = from.getElement();
            WebElement LocatorTo = to.getElement();
            String xto = Integer.toString(LocatorTo.getLocation().x);
            String yto = Integer.toString(LocatorTo.getLocation().y);
            ((JavascriptExecutor) driver).executeScript("function simulate(f,c,d,e){var b,a=null;for(b in eventMatchers)if(eventMatchers[b].test(c)){a=b;break}if(!a)return!1;document.createEvent?(b=document.createEvent(a),a==\"HTMLEvents\"?b.initEvent(c,!0,!0):b.initMouseEvent(c,!0,!0,document.defaultView,0,d,e,d,e,!1,!1,!1,!1,0,null),f.dispatchEvent(b)):(a=document.createEventObject(),a.detail=0,a.screenX=d,a.screenY=e,a.clientX=d,a.clientY=e,a.ctrlKey=!1,a.altKey=!1,a.shiftKey=!1,a.metaKey=!1,a.button=1,f.fireEvent(\"on\"+c,a));return!0} var eventMatchers={HTMLEvents:/^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,MouseEvents:/^(?:click|dblclick|mouse(?:down|up|over|move|out))$/}; " + "simulate(arguments[0],\"mousedown\",0,0); simulate(arguments[0],\"mousemove\",arguments[1],arguments[2]); simulate(arguments[0],\"mouseup\",arguments[1],arguments[2]); ", LocatorFrom, xto, yto);
        }
        Messager.ELEMENTS_DRAGGED_AND_DROPPED.info(from.getName(), to.getName());
    } else {
        Messager.ELEMENTS_NOT_DRAGGED_AND_DROPPED.error(from.getNameWithLocator(), to.getNameWithLocator());
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Action(org.openqa.selenium.interactions.Action) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Actions(org.openqa.selenium.interactions.Actions) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement)

Example 7 with ExtendedWebElement

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

the class DriverHelper method findExtendedWebElements.

/**
 * Find List of Extended Web Elements on page using By.
 *
 * @param by
 *            Selenium By locator
 * @param timeout
 *            Timeout to find
 * @return List of ExtendedWebElement.
 */
public List<ExtendedWebElement> findExtendedWebElements(final By by, long timeout) {
    List<ExtendedWebElement> extendedWebElements = new ArrayList<ExtendedWebElement>();
    List<WebElement> webElements = new ArrayList<WebElement>();
    String name = "undefined";
    if (!waitUntil(ExpectedConditions.presenceOfElementLocated(by), timeout)) {
        Messager.ELEMENT_NOT_FOUND.info(name);
        return extendedWebElements;
    }
    webElements = getDriver().findElements(by);
    int i = 1;
    for (WebElement element : webElements) {
        try {
            name = element.getText();
        } catch (Exception e) {
        /* do nothing and keep 'undefined' for control name */
        }
        ExtendedWebElement tempElement = new ExtendedWebElement(element, name);
        tempElement.setBy(tempElement.generateByForList(by, i));
        extendedWebElements.add(tempElement);
        i++;
    }
    return extendedWebElements;
}
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) TimeoutException(org.openqa.selenium.TimeoutException) JavascriptException(org.openqa.selenium.JavascriptException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) ScriptTimeoutException(org.openqa.selenium.ScriptTimeoutException) WebDriverException(org.openqa.selenium.WebDriverException) UnhandledAlertException(org.openqa.selenium.UnhandledAlertException) JsonException(org.openqa.selenium.json.JsonException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException)

Example 8 with ExtendedWebElement

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

the class LocatingListHandler method invoke.

public Object invoke(Object object, Method method, Object[] objects) throws Throwable {
    // Hotfix for huge and expected regression in carina: we lost managed
    // time delays with lists manipulations
    // Temporary we are going to restore explicit waiter here with hardcoded
    // timeout before we find better solution
    // Pros: super fast regression issue which block UI execution
    // Cons: there is no way to manage timeouts in this places
    // if (!waitUntil(ExpectedConditions.or(ExpectedConditions.presenceOfElementLocated(by),
    // ExpectedConditions.visibilityOfElementLocated(by)))) {
    // LOGGER.error("List is not present: " + by);
    // }
    List<WebElement> elements = null;
    try {
        elements = locator.findElements();
    } catch (StaleElementReferenceException | InvalidElementStateException e) {
        LOGGER.debug("catched StaleElementReferenceException: ", e);
        elements = driver.findElements(by);
    }
    List<ExtendedWebElement> extendedWebElements = null;
    int i = 0;
    if (elements != null) {
        extendedWebElements = new ArrayList<ExtendedWebElement>();
        for (WebElement element : elements) {
            InvocationHandler handler = new LocatingListsElementHandler(element, locator);
            WebElement proxy = (WebElement) Proxy.newProxyInstance(loader, new Class[] { WebElement.class, WrapsElement.class, Locatable.class }, handler);
            ExtendedWebElement webElement = new ExtendedWebElement(proxy, name + i, by);
            Field searchContextField = locator.getClass().getDeclaredField("searchContext");
            searchContextField.setAccessible(true);
            webElement.setSearchContext((SearchContext) searchContextField.get(locator));
            extendedWebElements.add(webElement);
            i++;
        }
    }
    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) InvalidElementStateException(org.openqa.selenium.InvalidElementStateException) WrapsElement(org.openqa.selenium.internal.WrapsElement) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) Locatable(org.openqa.selenium.interactions.internal.Locatable)

Example 9 with ExtendedWebElement

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

the class DivisionElementExtractor 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);
    WebElement tempElement;
    int index = 0;
    int isLower;
    Rectangle tempRect;
    while (elements.size() != 1) {
        index = (int) (Math.round(elements.size() / 2f));
        tempElement = elements.get(index);
        tempRect = getRect(tempElement);
        isLower = isLower(tempRect, y);
        LOGGER.debug("Is Lower: " + isLower);
        if (isInside(tempRect, x, y) || isLower == 0) {
            break;
        }
        if (isLower == 1) {
            elements = elements.subList(index, elements.size());
        } else {
            elements = elements.subList(0, index);
        }
    }
    LOGGER.debug("Index: " + index);
    if (elements.size() == 1) {
        return generateExtenedElement(elements, elementName);
    }
    return generateExtenedElement(checkBoundaryElements(elements, x, y, index), elementName);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Rectangle(org.openqa.selenium.Rectangle) WebElement(org.openqa.selenium.WebElement) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement)

Example 10 with ExtendedWebElement

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

the class L10Nparser method checkMultipleLocalization.

/**
 * check MultipleLocalization
 *
 * @param localizationCheckList
 *            - ExtendedWebElement[] should be set on required page with all
 *            needed public elements
 * @param timeout - timeout for element presence waiting.
 * @param skipPunctuationAndNumbers - if true - there will be no numbers and tricky punctuation in l10n values
 * @return boolean
 */
public static boolean checkMultipleLocalization(ExtendedWebElement[] localizationCheckList, int timeout, boolean skipPunctuationAndNumbers) {
    boolean ret = true;
    String returnAssertErrorMsg = "";
    assertErrorMsg = "";
    for (ExtendedWebElement elem : localizationCheckList) {
        if (!checkLocalizationText(elem, true, timeout, skipPunctuationAndNumbers)) {
            ret = false;
            returnAssertErrorMsg = returnAssertErrorMsg + " \n" + assertErrorMsg;
        }
    }
    assertErrorMsg = returnAssertErrorMsg;
    return ret;
}
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