Search in sources :

Example 1 with WebDriverException

use of org.openqa.selenium.WebDriverException in project zeppelin by apache.

the class ScreenCaptureHtmlUnitDriver method getScreenshotAs.

@Override
@SuppressWarnings("unchecked")
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
    byte[] archive = new byte[0];
    try {
        archive = downloadCssAndImages(getWebClient(), (HtmlPage) getCurrentWindow().getEnclosedPage());
    } catch (Exception e) {
        LOGGER.error("Exception in ScreenCaptureHtmlUnitDriver while getScreenshotAs ", e);
    }
    if (target.equals(OutputType.BASE64)) {
        return target.convertFromBase64Png(new Base64Encoder().encode(archive));
    }
    if (target.equals(OutputType.FILE)) {
        File f = new File("screen.tmp");
        try {
            FileOutputStream scr = new FileOutputStream(f);
            scr.write(archive);
            scr.close();
        } catch (IOException e) {
            throw new WebDriverException(e);
        }
        return (X) f;
    }
    return (X) archive;
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException) IOException(java.io.IOException) Base64Encoder(org.openqa.selenium.internal.Base64Encoder) WebDriverException(org.openqa.selenium.WebDriverException)

Example 2 with WebDriverException

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

the class Retry method execute.

<T> void execute(Supplier<Optional<T>> target, Consumer<T> action) {
    WebDriverException lastError = null;
    boolean retried = false;
    long start = System.currentTimeMillis();
    while ((System.currentTimeMillis() - start) < timeoutInMs) {
        try {
            Optional<T> targetElement = target.get();
            if (targetElement.isPresent()) {
                action.accept(targetElement.get());
                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 3 with WebDriverException

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

the class GraphApi method createFacebookTestUser.

public HashMap<String, String> createFacebookTestUser(String appId) {
    try {
        HttpResponse response = createTestUser(appId);
        String entity = EntityUtils.toString(response.getEntity());
        return new Gson().fromJson(entity, new TypeToken<HashMap<String, String>>() {
        }.getType());
    } catch (IOException e) {
        PageObjectLogging.log(URI_SYNTAX_EXCEPTION, ExceptionUtils.getStackTrace(e), false);
        throw new WebDriverException(ERROR_MESSAGE);
    } catch (URISyntaxException e) {
        PageObjectLogging.log(URI_SYNTAX_EXCEPTION, ExceptionUtils.getStackTrace(e), false);
        throw new WebDriverException(ERROR_MESSAGE);
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) HttpResponse(org.apache.http.HttpResponse) Gson(com.google.gson.Gson) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 4 with WebDriverException

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

the class PageObjectLogging method afterNavigateTo.

@Override
public void afterNavigateTo(String url, WebDriver driver) {
    StringBuilder builder = new StringBuilder();
    if (!AlertHandler.isAlertPresent(driver)) {
        if (url.equals(driver.getCurrentUrl())) {
            builder.append("<tr class=\"success\"><td>Url after navigation</td><td>" + "<a href='" + driver.getCurrentUrl() + "'>" + driver.getCurrentUrl() + "</a></td><td> <br/> &nbsp;</td></tr>");
            CommonUtils.appendTextToFile(logPath, builder.toString());
        } else {
            if (driver.getCurrentUrl().contains("data:text/html,chromewebdata ")) {
                driver.get(url);
            }
            logWarning("Url after navigation", driver.getCurrentUrl());
        }
    } else {
        logWarning("Url after navigation", "Unable to check URL after navigation - alert present");
    }
    if (driver.getCurrentUrl().contains(Configuration.getWikiaDomain())) {
        // HACK FOR DISABLING NOTIFICATIONS
        try {
            new JavascriptActions(driver).execute("$(\".sprite.close-notification\")[0].click()");
        } catch (WebDriverException e) {
        }
        /**
       * We want to disable sales pitch dialog for new potential contributors to avoid hiding other
       * UI elements. see https://wikia-inc.atlassian.net/browse/CE-3768
       */
        if ("true".equals(Configuration.getDisableCommunityPageSalesPitchDialog())) {
            driver.manage().addCookie(new Cookie("cpBenefitsModalShown", "1", Configuration.getWikiaDomain(), null, null));
        }
        if (TestContext.isFirstLoad() && "true".equals(Configuration.getMockAds())) {
            driver.manage().addCookie(new Cookie("mock-ads", XMLReader.getValue("mock.ads_token"), String.format(".%s", Configuration.getEnvType().getWikiaDomain()), null, null));
        }
    }
    Method method = TestContext.getCurrentTestMethod();
    Class<?> declaringClass = method.getDeclaringClass();
    if (TestContext.isFirstLoad()) {
        User user = null;
        TestContext.setFirstLoad(false);
        if (declaringClass.isAnnotationPresent(Execute.class)) {
            user = declaringClass.getAnnotation(Execute.class).asUser();
        }
        if (method.isAnnotationPresent(Execute.class)) {
            user = method.getAnnotation(Execute.class).asUser();
        }
        if (user != null && user != User.ANONYMOUS) {
            // log in, make sure user is logged in and flow is on the requested url
            new WikiBasePageObject().loginAs(user);
        }
    }
    logJSError(driver);
}
Also used : Cookie(org.openqa.selenium.Cookie) JavascriptActions(com.wikia.webdriver.common.core.elemnt.JavascriptActions) User(com.wikia.webdriver.common.core.helpers.User) WikiBasePageObject(com.wikia.webdriver.pageobjectsfactory.pageobject.WikiBasePageObject) Method(java.lang.reflect.Method) WebDriverException(org.openqa.selenium.WebDriverException)

Example 5 with WebDriverException

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

the class ImageComparison method areFilesTheSame.

/**
   * Compare two images after converting them into byte arrays
   *
   * @param file1 - file containing first image
   * @param file2 - file containing second image
   * @return boolean   - if images are the same
   */
public boolean areFilesTheSame(File file1, File file2) {
    byte[] fileInBytes1;
    byte[] fileInBytes2;
    try {
        fileInBytes1 = FileUtils.readFileToByteArray(file1);
        fileInBytes2 = FileUtils.readFileToByteArray(file2);
    } catch (IOException e) {
        throw new WebDriverException(e);
    }
    return Arrays.equals(fileInBytes1, fileInBytes2);
}
Also used : IOException(java.io.IOException) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

WebDriverException (org.openqa.selenium.WebDriverException)27 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