Search in sources :

Example 16 with WebDriverException

use of org.openqa.selenium.WebDriverException in project blueocean-plugin by jenkinsci.

the class SmartWebElement method click.

@Override
public void click() {
    for (int i = 0; i < RETRY_COUNT; i++) {
        try {
            WebElement e = getElement();
            e.click();
            if (i > 0) {
                logger.info(String.format("retry click successful for %s", by.toString()));
            }
            return;
        } catch (WebDriverException ex) {
            if (ex.getMessage().contains("is not clickable at point")) {
                logger.warn(String.format("%s not clickable: will retry click", by.toString()));
                logger.debug("exception: " + ex.getMessage());
                try {
                    // typically this is during an animation, which should not take long
                    Thread.sleep(500);
                } catch (InterruptedException ie) {
                // ignore
                }
            } else {
                throw ex;
            }
        }
    }
}
Also used : WebElement(org.openqa.selenium.WebElement) Point(org.openqa.selenium.Point) WebDriverException(org.openqa.selenium.WebDriverException)

Example 17 with WebDriverException

use of org.openqa.selenium.WebDriverException in project sonarqube by SonarSource.

the class Retry method execute.

<T> void execute(Runnable action) {
    WebDriverException lastError = null;
    boolean retried = false;
    long start = System.currentTimeMillis();
    while ((System.currentTimeMillis() - start) < timeoutInMs) {
        try {
            action.run();
            if (retried) {
                System.out.println();
            }
            return;
        } catch (StaleElementReferenceException e) {
        // ignore
        } catch (WebDriverException e) {
            lastError = e;
        }
        retried = true;
        System.out.print(".");
    }
    if (retried) {
        System.out.println();
    }
    if (lastError != null) {
        throw lastError;
    }
    throw new NoSuchElementException("Not found");
}
Also used : StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) NoSuchElementException(java.util.NoSuchElementException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 18 with WebDriverException

use of org.openqa.selenium.WebDriverException in project ats-framework by Axway.

the class HiddenHtmlElementUtils method mouseClick.

@PublicAtsApi
public static void mouseClick(HtmlUnitWebElement webElement) {
    Method getElementForOperationMethod = null;
    boolean getElementForOperationMethodAccessible = false;
    Method moveOutIfNeededMethod = null;
    boolean moveOutIfNeededMethodAccessible = false;
    Method updateActiveElementMethod = null;
    boolean updateActiveElementMethodAccessible = false;
    try {
        // change access modifiers of some methods
        getElementForOperationMethod = HtmlUnitMouse.class.getDeclaredMethod("getElementForOperation", Coordinates.class);
        getElementForOperationMethodAccessible = getElementForOperationMethod.isAccessible();
        getElementForOperationMethod.setAccessible(true);
        moveOutIfNeededMethod = HtmlUnitMouse.class.getDeclaredMethod("moveOutIfNeeded", DomElement.class);
        moveOutIfNeededMethodAccessible = moveOutIfNeededMethod.isAccessible();
        moveOutIfNeededMethod.setAccessible(true);
        updateActiveElementMethod = HtmlUnitMouse.class.getDeclaredMethod("updateActiveElement", DomElement.class);
        updateActiveElementMethodAccessible = updateActiveElementMethod.isAccessible();
        updateActiveElementMethod.setAccessible(true);
        // get the target element
        HtmlUnitDriver htmlUnitDriver = (HtmlUnitDriver) webElement.getWrappedDriver();
        HtmlUnitMouse mouse = (HtmlUnitMouse) htmlUnitDriver.getMouse();
        HtmlElement element = (HtmlElement) getElementForOperationMethod.invoke(mouse, webElement.getCoordinates());
        moveOutIfNeededMethod.invoke(mouse, element);
        if (htmlUnitDriver.isJavascriptEnabled()) {
            if (!(element instanceof HtmlInput)) {
                element.focus();
            }
            element.mouseOver();
            element.mouseMove();
        }
        HtmlUnitKeyboard keyboard = (HtmlUnitKeyboard) htmlUnitDriver.getKeyboard();
        element.click(keyboard.isShiftPressed(), keyboard.isCtrlPressed(), keyboard.isAltPressed());
        updateActiveElementMethod.invoke(mouse, element);
    } catch (IOException ioe) {
        throw new WebDriverException(ioe);
    } catch (ScriptException e) {
        // we need only our exception if such exists
        Throwable uiEngineException = e.getCause();
        while (uiEngineException != null && !uiEngineException.getClass().getName().toLowerCase().contains("com.axway.ats")) {
            uiEngineException = uiEngineException.getCause();
        }
        if (uiEngineException != null) {
            throw (RuntimeException) uiEngineException;
        }
        // Log the exception with level WARN, because in the main Selenium implementation
        // (HtmlUnitMouse.click(coordinates)) the exception is even skipped
        log.warn("Script error while clicking web element. " + webElement.toString(), e);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (getElementForOperationMethod != null) {
            getElementForOperationMethod.setAccessible(getElementForOperationMethodAccessible);
        }
        if (moveOutIfNeededMethod != null) {
            moveOutIfNeededMethod.setAccessible(moveOutIfNeededMethodAccessible);
        }
        if (updateActiveElementMethod != null) {
            updateActiveElementMethod.setAccessible(updateActiveElementMethodAccessible);
        }
    }
}
Also used : HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) Coordinates(org.openqa.selenium.interactions.internal.Coordinates) Method(java.lang.reflect.Method) IOException(java.io.IOException) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) WebDriverException(org.openqa.selenium.WebDriverException) IOException(java.io.IOException) ScriptException(com.gargoylesoftware.htmlunit.ScriptException) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) ScriptException(com.gargoylesoftware.htmlunit.ScriptException) DomElement(com.gargoylesoftware.htmlunit.html.DomElement) HtmlUnitMouse(org.openqa.selenium.htmlunit.HtmlUnitMouse) HtmlUnitKeyboard(org.openqa.selenium.htmlunit.HtmlUnitKeyboard) WebDriverException(org.openqa.selenium.WebDriverException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 19 with WebDriverException

use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.

the class FirefoxBrowser method setOptions.

@Override
public void setOptions() {
    // to path where executive file of FF is placed
    if ("WINDOWS 8".equalsIgnoreCase(System.getProperty("os.name"))) {
        System.setProperty("webdriver.firefox.bin", "c:" + File.separator + "Program Files (x86)" + File.separator + "Mozilla Firefox" + File.separator + "Firefox.exe");
    }
    // Check if user who is running tests have write access in ~/.mozilla dir and home dir
    if ("LINUX".equalsIgnoreCase(System.getProperty("os.name"))) {
        File homePath = new File(System.getenv("HOME") + File.separator);
        File mozillaPath = new File(homePath + File.separator + ".mozilla");
        File tmpFile;
        if (mozillaPath.exists()) {
            try {
                tmpFile = File.createTempFile("webdriver", null, mozillaPath);
            } catch (IOException ex) {
                PageObjectLogging.log("Can't create file", ex, false);
                throw new WebDriverException("Can't create file in path: %s".replace("%s", mozillaPath.getAbsolutePath()));
            }
        } else {
            try {
                tmpFile = File.createTempFile("webdriver", null, homePath);
            } catch (IOException ex) {
                PageObjectLogging.log("Can't create file", ex, false);
                throw new WebDriverException("Can't create file in path: %s".replace("%s", homePath.getAbsolutePath()));
            }
        }
        tmpFile.delete();
    }
    firefoxProfile = new FirefoxProfile(new File(ClassLoader.getSystemResource("FirefoxProfiles/Default").getPath()));
    if ("true".equals(Configuration.getPageLoadStrategy())) {
        firefoxProfile.setPreference("webdriver.load.strategy", "unstable");
    }
    if ("true".equals(Configuration.getDisableFlash())) {
        firefoxProfile.setPreference("plugin.state.flash", 0);
    }
}
Also used : IOException(java.io.IOException) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException)

Example 20 with WebDriverException

use of org.openqa.selenium.WebDriverException in project selenium-tests by Wikia.

the class ImageEditor method cropImage.

public File cropImage(org.openqa.selenium.Point start, org.openqa.selenium.Dimension size, BufferedImage image) {
    int width = size.width;
    int height = size.height;
    File subImg;
    try {
        subImg = File.createTempFile("screenshot", ".png");
    } catch (IOException e) {
        throw new WebDriverException(e);
    }
    if (width < 1) {
        width = 1;
    }
    if (height < 1) {
        height = 1;
    }
    // https://github.com/Wikia/selenium-tests/blob/9d00f02ba24391534a80520908c2973d9e6bed86/src/test/java/com/wikia/webdriver/common/core/imageutilities/Shooter.java#L46
    if (start.getX() < 0) {
        start.move(0, start.getY());
    }
    if (start.getY() < 0) {
        start.move(start.getX(), 0);
    }
    BufferedImage dest = image.getSubimage(start.getX(), start.getY(), width, height);
    try {
        ImageIO.write(dest, "png", subImg);
    } catch (IOException e) {
        throw new WebDriverException(e);
    }
    return subImg;
}
Also used : IOException(java.io.IOException) File(java.io.File) Point(org.openqa.selenium.Point) BufferedImage(java.awt.image.BufferedImage) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

WebDriverException (org.openqa.selenium.WebDriverException)28 IOException (java.io.IOException)16 File (java.io.File)8 Matcher (java.util.regex.Matcher)4 URISyntaxException (java.net.URISyntaxException)3 Pattern (java.util.regex.Pattern)3 ClientProtocolException (org.apache.http.client.ClientProtocolException)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 Gson (com.google.gson.Gson)2 TypeToken (com.google.gson.reflect.TypeToken)2 User (com.wikia.webdriver.common.core.helpers.User)2 AdsComparison (com.wikia.webdriver.pageobjectsfactory.pageobject.adsbase.helpers.AdsComparison)2 BufferedImage (java.awt.image.BufferedImage)2 Method (java.lang.reflect.Method)2 URL (java.net.URL)2 NoSuchElementException (java.util.NoSuchElementException)2 HttpResponse (org.apache.http.HttpResponse)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpPost (org.apache.http.client.methods.HttpPost)2