Example usage for org.openqa.selenium WebDriverException WebDriverException

List of usage examples for org.openqa.selenium WebDriverException WebDriverException

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriverException WebDriverException.

Prototype

public WebDriverException(Throwable cause) 

Source Link

Usage

From source file:com.google.android.testing.nativedriver.server.AndroidNativeDriver.java

License:Apache License

@Override
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
    if (target != OutputType.BASE64)
        throw new WebDriverException("You must use getScreenShotAsBase64");

    //Credit: This screenshot stuff is 99% from the people at
    //http://stackoverflow.com/questions/2661536/how-to-programatically-take-a-screenshot-on-android
    //http://stackoverflow.com/questions/2339429/android-view-getdrawingcache-returns-null-only-null
    Runnable myrunner = new Runnable() {
        @Override//  w w w. j  av a2 s  . c  o m
        public void run() {
            Bitmap bitmap;
            View rootview = context.getActivities().current().getWindow().getDecorView().getRootView();
            rootview.setDrawingCacheEnabled(true);
            rootview.buildDrawingCache(true);
            rootview.layout(0, 0, rootview.getWidth(), rootview.getHeight());
            bitmap = Bitmap.createBitmap(rootview.getDrawingCache());
            rootview.buildDrawingCache(false);
            rootview.setDrawingCacheEnabled(false);
            try {
                baostream = new ByteArrayOutputStream(bitmap.getRowBytes() * bitmap.getHeight());
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, baostream);
            } catch (Exception e) {
                Log.i("appdriver", e.toString());
                throw new WebDriverException(e.toString());
            }
            try {
                synchronized (this) {
                    this.notify();
                }
            } catch (Exception e) {
                Log.i("appdriver", e.toString());
                throw new WebDriverException(e.toString());
            }
        }
    };
    context.getActivities().current().runOnUiThread(myrunner);
    try {
        synchronized (myrunner) {
            myrunner.wait();
        }
    } catch (Exception e) {
        Log.i("appdriver", e.toString());
        throw new WebDriverException(e.toString());
    }
    try {
        byte[] imagebytes = baostream.toByteArray();
        baostream.close();
        return (X) Base64.encodeToString(imagebytes, 0);
    } catch (Exception e) {
        Log.i("appdriver", e.toString());
        throw new WebDriverException(e.toString());
    }
}

From source file:com.google.android.testing.nativedriver.server.AndroidNativeTouch.java

License:Apache License

protected void sleep(long millis) {
    try {/*from w w  w  . jav a2  s. c o  m*/
        Thread.sleep(millis);
    } catch (InterruptedException exception) {
        Thread.currentThread().interrupt();
        throw new WebDriverException(exception);
    }
}

From source file:com.google.android.testing.nativedriver.server.AndroidWait.java

License:Apache License

/**
 * Sleeps for a few milliseconds./*from  w  w w  .j  a  v a 2s.c  om*/
 */
protected void sleep() {
    try {
        Thread.sleep(sleepIntervalInMillis);
    } catch (InterruptedException exception) {
        Thread.currentThread().interrupt();
        throw new WebDriverException(exception);
    }
}

From source file:com.google.android.testing.nativedriver.server.KeySender.java

License:Apache License

/**
 * Sends a single key event to the {@code Instrumentation} for a given 
 * character./*from w  ww  .j  ava2 s. co  m*/
 * 
 * @param action {@code KeyEvent.ACTION_*} code representing key action
 * @param keyCode character representing key to press, release, etc.
 */
public void sendKeyEvent(int action, char keyCode) {
    instrumentation.waitForIdleSync();
    try {
        instrumentation.sendKeySync(new KeyEvent(action, AndroidKeys.keyCodeFor(keyCode)));
    } catch (SecurityException exception) {
        throw new WebDriverException(exception);
    }
}

From source file:com.jaliansystems.customiSE.driver.CustomiSEDriver.java

License:Apache License

@Override
public void setFileDetector(FileDetector detector) {
    throw new WebDriverException("Setting the file detector only works on remote webdriver instances obtained "
            + "via RemoteWebDriver");
}

From source file:com.jobaline.uiautomation.framework.selenium.phantomJsThreeHourTimeoutFix.HttpCommandExecutor.java

License:Apache License

public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addressOfRemoteServer) {
    try {/*from  ww  w  .j ava2 s  .c  om*/
        remoteServer = addressOfRemoteServer == null
                ? new URL(System.getProperty("webdriver.remote.server", "http://localhost:4444/wd/hub"))
                : addressOfRemoteServer;
    } catch (MalformedURLException e) {
        throw new WebDriverException(e);
    }

    HttpParams params = new BasicHttpParams();
    // Use the JRE default for the socket linger timeout.
    params.setParameter(CoreConnectionPNames.SO_LINGER, -1);
    HttpClientParams.setRedirecting(params, false);

    synchronized (HttpCommandExecutor.class) {
        if (httpClientFactory == null) {
            httpClientFactory = new HttpClientFactory();
        }
    }
    client = httpClientFactory.getHttpClient();

    // PATCH start
    // HttpClientFactory has a hardcoded timeout of three hours.
    // This class is intended to be used only for phantomjs which runs locally so the timeouts will be set to a low value

    BasicHttpParams paramsPatched = (BasicHttpParams) client.getParams();
    paramsPatched.setIntParameter("http.connection.timeout", 90000); //  1 minute an a half
    paramsPatched.setIntParameter("http.socket.timeout", 90000); // 1 minute an a half
    ((DefaultHttpClient) client).setParams(params);

    // PATCH end

    if (addressOfRemoteServer != null && addressOfRemoteServer.getUserInfo() != null) {
        // Use HTTP Basic auth
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
                addressOfRemoteServer.getUserInfo());
        ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
    }

    // Some machines claim "localhost.localdomain" is the same as "localhost".
    // This assumption is not always true.

    String host = remoteServer.getHost().replace(".localdomain", "");

    targetHost = new HttpHost(host, remoteServer.getPort(), remoteServer.getProtocol());

    ImmutableMap.Builder<String, CommandInfo> builder = ImmutableMap.builder();
    for (Map.Entry<String, CommandInfo> entry : additionalCommands.entrySet()) {
        builder.put(entry.getKey(), entry.getValue());
    }

    builder.put(GET_ALL_SESSIONS, get("/sessions")).put(NEW_SESSION, post("/session"))
            .put(GET_CAPABILITIES, get("/session/:sessionId")).put(QUIT, delete("/session/:sessionId"))
            .put(GET_CURRENT_WINDOW_HANDLE, get("/session/:sessionId/window_handle"))
            .put(GET_WINDOW_HANDLES, get("/session/:sessionId/window_handles"))
            .put(GET, post("/session/:sessionId/url"))

            // The Alert API is still experimental and should not be used.
            .put(GET_ALERT, get("/session/:sessionId/alert"))
            .put(DISMISS_ALERT, post("/session/:sessionId/dismiss_alert"))
            .put(ACCEPT_ALERT, post("/session/:sessionId/accept_alert"))
            .put(GET_ALERT_TEXT, get("/session/:sessionId/alert_text"))
            .put(SET_ALERT_VALUE, post("/session/:sessionId/alert_text"))

            .put(GO_FORWARD, post("/session/:sessionId/forward")).put(GO_BACK, post("/session/:sessionId/back"))
            .put(REFRESH, post("/session/:sessionId/refresh"))
            .put(EXECUTE_SCRIPT, post("/session/:sessionId/execute"))
            .put(EXECUTE_ASYNC_SCRIPT, post("/session/:sessionId/execute_async"))
            .put(GET_CURRENT_URL, get("/session/:sessionId/url"))
            .put(GET_TITLE, get("/session/:sessionId/title"))
            .put(GET_PAGE_SOURCE, get("/session/:sessionId/source"))
            .put(SCREENSHOT, get("/session/:sessionId/screenshot"))
            .put(FIND_ELEMENT, post("/session/:sessionId/element"))
            .put(FIND_ELEMENTS, post("/session/:sessionId/elements"))
            .put(GET_ACTIVE_ELEMENT, post("/session/:sessionId/element/active"))
            .put(FIND_CHILD_ELEMENT, post("/session/:sessionId/element/:id/element"))
            .put(FIND_CHILD_ELEMENTS, post("/session/:sessionId/element/:id/elements"))
            .put(CLICK_ELEMENT, post("/session/:sessionId/element/:id/click"))
            .put(CLEAR_ELEMENT, post("/session/:sessionId/element/:id/clear"))
            .put(SUBMIT_ELEMENT, post("/session/:sessionId/element/:id/submit"))
            .put(GET_ELEMENT_TEXT, get("/session/:sessionId/element/:id/text"))
            .put(SEND_KEYS_TO_ELEMENT, post("/session/:sessionId/element/:id/value"))
            .put(UPLOAD_FILE, post("/session/:sessionId/file"))
            .put(GET_ELEMENT_VALUE, get("/session/:sessionId/element/:id/value"))
            .put(GET_ELEMENT_TAG_NAME, get("/session/:sessionId/element/:id/name"))
            .put(IS_ELEMENT_SELECTED, get("/session/:sessionId/element/:id/selected"))
            .put(IS_ELEMENT_ENABLED, get("/session/:sessionId/element/:id/enabled"))
            .put(IS_ELEMENT_DISPLAYED, get("/session/:sessionId/element/:id/displayed"))
            .put(HOVER_OVER_ELEMENT, post("/session/:sessionId/element/:id/hover"))
            .put(GET_ELEMENT_LOCATION, get("/session/:sessionId/element/:id/location"))
            .put(GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW,
                    get("/session/:sessionId/element/:id/location_in_view"))
            .put(GET_ELEMENT_SIZE, get("/session/:sessionId/element/:id/size"))
            .put(GET_ELEMENT_ATTRIBUTE, get("/session/:sessionId/element/:id/attribute/:name"))
            .put(ELEMENT_EQUALS, get("/session/:sessionId/element/:id/equals/:other"))
            .put(GET_ALL_COOKIES, get("/session/:sessionId/cookie"))
            .put(ADD_COOKIE, post("/session/:sessionId/cookie"))
            .put(DELETE_ALL_COOKIES, delete("/session/:sessionId/cookie"))
            .put(DELETE_COOKIE, delete("/session/:sessionId/cookie/:name"))
            .put(SWITCH_TO_FRAME, post("/session/:sessionId/frame"))
            .put(SWITCH_TO_PARENT_FRAME, post("/session/:sessionId/frame/parent"))
            .put(SWITCH_TO_WINDOW, post("/session/:sessionId/window"))
            .put(GET_WINDOW_SIZE, get("/session/:sessionId/window/:windowHandle/size"))
            .put(GET_WINDOW_POSITION, get("/session/:sessionId/window/:windowHandle/position"))
            .put(SET_WINDOW_SIZE, post("/session/:sessionId/window/:windowHandle/size"))
            .put(SET_WINDOW_POSITION, post("/session/:sessionId/window/:windowHandle/position"))
            .put(MAXIMIZE_WINDOW, post("/session/:sessionId/window/:windowHandle/maximize"))
            .put(CLOSE, delete("/session/:sessionId/window"))
            .put(DRAG_ELEMENT, post("/session/:sessionId/element/:id/drag"))
            .put(GET_ELEMENT_VALUE_OF_CSS_PROPERTY, get("/session/:sessionId/element/:id/css/:propertyName"))
            .put(IMPLICITLY_WAIT, post("/session/:sessionId/timeouts/implicit_wait"))
            .put(SET_SCRIPT_TIMEOUT, post("/session/:sessionId/timeouts/async_script"))
            .put(SET_TIMEOUT, post("/session/:sessionId/timeouts"))
            .put(EXECUTE_SQL, post("/session/:sessionId/execute_sql"))
            .put(GET_LOCATION, get("/session/:sessionId/location"))
            .put(SET_LOCATION, post("/session/:sessionId/location"))
            .put(GET_APP_CACHE_STATUS, get("/session/:sessionId/application_cache/status"))
            .put(IS_BROWSER_ONLINE, get("/session/:sessionId/browser_connection"))
            .put(SET_BROWSER_ONLINE, post("/session/:sessionId/browser_connection"))

            .put(SWITCH_TO_CONTEXT, post("/session/:sessionId/context"))
            .put(GET_CURRENT_CONTEXT_HANDLE, get("/session/:sessionId/context"))
            .put(GET_CONTEXT_HANDLES, get("/session/:sessionId/contexts"))

            // TODO (user): Would it be better to combine this command with
            // GET_LOCAL_STORAGE_SIZE?
            .put(GET_LOCAL_STORAGE_ITEM, get("/session/:sessionId/local_storage/key/:key"))
            .put(REMOVE_LOCAL_STORAGE_ITEM, delete("/session/:sessionId/local_storage/key/:key"))
            .put(GET_LOCAL_STORAGE_KEYS, get("/session/:sessionId/local_storage"))
            .put(SET_LOCAL_STORAGE_ITEM, post("/session/:sessionId/local_storage"))
            .put(CLEAR_LOCAL_STORAGE, delete("/session/:sessionId/local_storage"))
            .put(GET_LOCAL_STORAGE_SIZE, get("/session/:sessionId/local_storage/size"))

            // TODO (user): Would it be better to combine this command with
            // GET_SESSION_STORAGE_SIZE?
            .put(GET_SESSION_STORAGE_ITEM, get("/session/:sessionId/session_storage/key/:key"))
            .put(REMOVE_SESSION_STORAGE_ITEM, delete("/session/:sessionId/session_storage/key/:key"))
            .put(GET_SESSION_STORAGE_KEYS, get("/session/:sessionId/session_storage"))
            .put(SET_SESSION_STORAGE_ITEM, post("/session/:sessionId/session_storage"))
            .put(CLEAR_SESSION_STORAGE, delete("/session/:sessionId/session_storage"))
            .put(GET_SESSION_STORAGE_SIZE, get("/session/:sessionId/session_storage/size"))

            .put(GET_SCREEN_ORIENTATION, get("/session/:sessionId/orientation"))
            .put(SET_SCREEN_ORIENTATION, post("/session/:sessionId/orientation"))

            // Interactions-related commands.
            .put(CLICK, post("/session/:sessionId/click"))
            .put(DOUBLE_CLICK, post("/session/:sessionId/doubleclick"))
            .put(MOUSE_DOWN, post("/session/:sessionId/buttondown"))
            .put(MOUSE_UP, post("/session/:sessionId/buttonup"))
            .put(MOVE_TO, post("/session/:sessionId/moveto"))
            .put(SEND_KEYS_TO_ACTIVE_ELEMENT, post("/session/:sessionId/keys"))

            // IME related commands.
            .put(IME_GET_AVAILABLE_ENGINES, get("/session/:sessionId/ime/available_engines"))
            .put(IME_GET_ACTIVE_ENGINE, get("/session/:sessionId/ime/active_engine"))
            .put(IME_IS_ACTIVATED, get("/session/:sessionId/ime/activated"))
            .put(IME_DEACTIVATE, post("/session/:sessionId/ime/deactivate"))
            .put(IME_ACTIVATE_ENGINE, post("/session/:sessionId/ime/activate"))

            // Advanced Touch API commands
            // TODO(berrada): Refactor single tap with mouse click.
            .put(TOUCH_SINGLE_TAP, post("/session/:sessionId/touch/click"))
            .put(TOUCH_DOWN, post("/session/:sessionId/touch/down"))
            .put(TOUCH_UP, post("/session/:sessionId/touch/up"))
            .put(TOUCH_MOVE, post("/session/:sessionId/touch/move"))
            .put(TOUCH_SCROLL, post("/session/:sessionId/touch/scroll"))
            .put(TOUCH_DOUBLE_TAP, post("/session/:sessionId/touch/doubleclick"))
            .put(TOUCH_LONG_PRESS, post("/session/:sessionId/touch/longclick"))
            .put(TOUCH_FLICK, post("/session/:sessionId/touch/flick"))

            .put(GET_LOG, post("/session/:sessionId/log"))
            .put(GET_AVAILABLE_LOG_TYPES, get("/session/:sessionId/log/types"))

            .put(STATUS, get("/status"));

    nameToUrl = builder.build();
}

From source file:com.jobaline.uiautomation.framework.selenium.phantomJsThreeHourTimeoutFix.HttpCommandExecutor.java

License:Apache License

private HttpResponse followRedirects(HttpClient client, HttpContext context, HttpResponse response,
        int redirectCount) {
    if (!isRedirect(response)) {
        return response;
    }//from  w w w. ja  v a 2 s  .  co  m

    try {
        // Make sure that the previous connection is freed.
        HttpEntity httpEntity = response.getEntity();
        if (httpEntity != null) {
            EntityUtils.consume(httpEntity);
        }
    } catch (IOException e) {
        throw new WebDriverException(e);
    }

    if (redirectCount > MAX_REDIRECTS) {
        throw new WebDriverException("Maximum number of redirects exceeded. Aborting");
    }

    String location = response.getFirstHeader("location").getValue();
    URI uri;
    try {
        uri = buildUri(context, location);

        HttpGet get = new HttpGet(uri);
        setAcceptHeader(get);
        HttpResponse newResponse = client.execute(targetHost, get, context);
        return followRedirects(client, context, newResponse, redirectCount + 1);
    } catch (URISyntaxException e) {
        throw new WebDriverException(e);
    } catch (ClientProtocolException e) {
        throw new WebDriverException(e);
    } catch (IOException e) {
        throw new WebDriverException(e);
    }
}

From source file:com.mengge.android.AndroidDriver.java

License:Apache License

@Override
public Connection getConnection() {
    long bitMask = CommandExecutionHelper.execute(this,
            AndroidMobileCommandHelper.getNetworkConnectionCommand());
    Connection[] types = Connection.values();

    for (Connection connection : types) {
        if (connection.bitMask == bitMask) {
            return connection;
        }//from   w w w  . j av a 2s  .c  o m
    }
    throw new WebDriverException(
            "The unknown network connection " + "type has been returned. The bitmask is " + bitMask);
}

From source file:com.mengge.AppiumDriver.java

License:Apache License

@Override
public ScreenOrientation getOrientation() {
    Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION);
    String orientation = response.getValue().toString().toLowerCase();
    if (orientation.equals(ScreenOrientation.LANDSCAPE.value())) {
        return ScreenOrientation.LANDSCAPE;
    } else if (orientation.equals(ScreenOrientation.PORTRAIT.value())) {
        return ScreenOrientation.PORTRAIT;
    } else {/*from   w  ww .  j  ava2s.c o m*/
        throw new WebDriverException("Unexpected orientation returned: " + orientation);
    }
}

From source file:com.opera.core.systems.common.io.ProcessManager.java

License:Apache License

public static boolean isPidRunning(int processID) {
    String output;/*from   w w  w. j  ava 2s .  c o m*/

    if (currentPlatform.is(WINDOWS)) {
        output = executeCommand("tasklist", "/FI", String.format("\"PID eq %d\"", processID));
    } else if (currentPlatform.is(UNIX) || currentPlatform.is(MAC)) {
        output = executeCommand("ps", "-p", String.valueOf(processID));
    } else {
        throw new WebDriverException("Unknown platform: " + currentPlatform);
    }

    return output != null && output.contains(String.format("%d ", processID));
}