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.opera.core.systems.scope.services.ums.EcmaScriptDebugger.java

License:Apache License

protected Response eval(String using, int runtimeId, Variable... variables) {
    /*//from  w w w .j  a v  a  2 s .co m
    if (windowManager.getActiveWindowId() != activeWindowId) {
      recover();
    }
    */

    EvalData.Builder builder = buildEval(using, runtimeId);
    builder.addAllVariableList(Arrays.asList(variables));

    Response response = executeCommand(ESDebuggerCommand.EVAL, builder,
            OperaIntervals.SCRIPT_TIMEOUT.getValue());

    if (response == null && retries < OperaIntervals.SCRIPT_RETRY.getValue()) {
        retries++;
        sleepDuration += sleepDuration;
        sleep(sleepDuration);
        recover();
        return eval(using, variables);
    } else if (retries >= OperaIntervals.SCRIPT_RETRY.getValue()) {
        resetCounters();
        throw new WebDriverException("No response on executing JS command");
    }

    resetCounters();

    return response;
}

From source file:com.opera.core.systems.scope.services.ums.EcmaScriptDebugger.java

License:Apache License

/**
 * Parses a reply and returns the following types String presentation of number, boolean or
 * string.//from  ww  w  .j a v a  2 s. com
 */
protected Object parseEvalReply(EvalResult result) {
    String status = result.getStatus();

    if (!status.equals("completed")) {
        if (status.equals("unhandled-exception")) {
            // Would be great give the JS error here, but it appears that by the
            // time we callFunctionOnObject the error object has gone...
            throw new WebDriverException("Ecmascript exception");
        }
        // FIXME what is the best approach here?
        else if (status.equals("cancelled-by-scheduler")) {
            return null;
        } else if (status.equals("aborted")) {

        }

    }

    String dataType = result.getType();

    if (dataType.equals("object")) {
        return result.getObjectValue();
    } else {
        return parseValue(dataType, result.getValue());
    }
}

From source file:com.opera.core.systems.scope.services.ums.EcmaScriptDebugger6.java

License:Apache License

@Override
public Object scriptExecutor(String script, Object... params) {
    List<WebElement> elements = new ArrayList<WebElement>();
    String toSend;/*from   w  w  w. j  av  a  2  s  .  co m*/
    if (params != null && params.length > 0) {
        StringBuilder builder = new StringBuilder();
        for (Object object : params) {
            if (builder.toString().length() > 0) {
                builder.append(",");
            }

            if (object instanceof Collection<?>) {
                builder.append("[");
                Collection<?> collection = (Collection<?>) object;
                for (Object argument : collection) {
                    processArgument(argument, builder, elements);
                    builder.append(",");
                }
                int lastCharIndex = builder.length() - 1;
                if (builder.charAt(lastCharIndex) != '[') {
                    builder.deleteCharAt(lastCharIndex);
                }

                builder.append("]");
            } else {
                processArgument(object, builder, elements);
            }
        }

        String arguments = builder.toString();
        toSend = "(function(){" + script + "})(" + arguments + ")";
    } else {
        toSend = script;
    }

    EvalData.Builder evalBuilder = buildEval(toSend, getRuntimeId());

    for (WebElement webElement : elements) {
        Variable variable = buildVariable(webElement.toString(), ((OperaWebElement) webElement).getObjectId());
        evalBuilder.addVariableList(variable);
    }

    Response response = executeCommand(ESDebuggerCommand.EVAL, evalBuilder);

    if (response == null) {
        throw new WebDriverException("Internal error while executing script");
    }

    EvalResult result = parseEvalData(response);

    Object parsed = parseEvalReply(result);
    if (parsed instanceof ObjectValue) {
        ObjectValue data = (ObjectValue) parsed;
        return new ScriptResult(data.getObjectID(), data.getClassName());
    } else {
        return parsed;
    }
}

From source file:com.opera.core.systems.scope.services.ums.EcmaScriptDebugger6.java

License:Apache License

protected Object parseEvalReply(EvalResult result) {

    String status = result.getStatus();

    if (!status.equals("completed")) {
        if (status.equals("unhandled-exception")) {
            String message;//from ww  w  . j  a v  a 2  s . c o  m
            try {
                message = (String) callFunctionOnObject("return locator.name+': '+locator.message;",
                        result.getObjectValue().getObjectID(), true);
            } catch (Exception e) {
                // If we get an exception while trying to get the message just throw
                // a generic Ecmascript exception.
                throw new WebDriverException("Ecmascript exception");
            }
            // Throw the ecmascript exception
            throw new WebDriverException("Ecmascript exception:\n" + message);
        }
        // FIXME what is the best approach here?
        else if (status.equals("cancelled-by-scheduler")) {
            return null;
        } else if (status.equals("aborted")) {

        }

    }

    String dataType = result.getType();

    if ("string".equals(dataType)) {
        return result.getValue();
    } else if ("number".equals(dataType)) {
        return parseNumber(result.getValue());
    } else if ("boolean".equals(dataType)) {
        return Boolean.valueOf(result.getValue());
    } else if ("undefined".equals(dataType)) {
        return null;
    } else if ("object".equals(dataType)) {
        return result.getObjectValue();
    }
    // return null if none
    return null;
}

From source file:com.opera.core.systems.scope.services.ums.EcmascriptService.java

License:Apache License

public void init() {
    // We no longer need the configuration
    if (!updateRuntime()) {
        throw new WebDriverException("Could not find a runtime for script injection");
    }/*from w ww  .  ja  va2  s  . co m*/
    // Nor the dialogue hack
}

From source file:com.opera.core.systems.scope.services.ums.EcmascriptService.java

License:Apache License

public Object scriptExecutor(String script, Object... params) {
    processQueues();//from ww  w. java 2s  . com

    List<WebElement> elements = new ArrayList<WebElement>();

    String toSend = buildEvalString(elements, script, params);
    EvalArg.Builder evalBuilder = buildEval(toSend, getRuntimeId());

    for (WebElement webElement : elements) {
        Variable variable = buildVariable(webElement.toString(), ((OperaWebElement) webElement).getObjectId());
        evalBuilder.addVariableList(variable);
    }

    Response response = executeCommand(ESCommand.EVAL, evalBuilder);

    if (response == null) {
        throw new WebDriverException("Internal error while executing script");
    }

    EvalResult result = parseEvalData(response);

    Object parsed = parseEvalReply(result);
    if (parsed instanceof EcmascriptProtos.Object) {
        EcmascriptProtos.Object data = (EcmascriptProtos.Object) parsed;
        return new ScriptResult(data.getObjectID(), data.getClassName());
    } else {
        return parsed;
    }
}

From source file:com.opera.core.systems.scope.services.ums.EcmascriptService.java

License:Apache License

private Response eval(String using, int runtimeId, Variable... variables) {
    // This call causes us to release objects, which allows them to be garbage collected, and
    // sometimes causes this method to fail. So I've commented it out. But I reckon it might cause
    // high memory usage in Opera, so the method might need to be updated in the future.
    // processQueues();

    EvalArg.Builder builder = buildEval(using, runtimeId);
    builder.addAllVariableList(Arrays.asList(variables));

    Response response = executeCommand(ESCommand.EVAL, builder, OperaIntervals.SCRIPT_TIMEOUT.getValue());

    if (response == null && retries < OperaIntervals.SCRIPT_RETRY.getValue()) {
        retries++;/*from  w ww  .j a  va 2  s  .c  o m*/
        sleepDuration += sleepDuration;
        sleep(sleepDuration);
        recover();
        return eval(using, variables);
    } else if (retries >= OperaIntervals.SCRIPT_RETRY.getValue()) {
        resetCounters();
        throw new WebDriverException("No response on executing JS command");
    }

    resetCounters();

    return response;
}

From source file:com.opera.core.systems.scope.services.ums.EcmascriptService.java

License:Apache License

private Object parseEvalReply(EvalResult result) {
    Status status = result.getStatus();/*  www . ja  v a  2  s .c o m*/

    switch (status) {
    case CANCELLED:
        return null;
    case EXCEPTION:
        throw new WebDriverException("EcmaScript exception");
    case NO_MEMORY:
        // releaseObjects();
        throw new WebDriverException("Out of memory");
    case FAILURE:
        throw new WebDriverException("Could not execute script");
    default:
        break;
    }

    Value value = result.getValue();
    Type type = value.getType();

    switch (type) {
    case STRING:
        return value.getStr();
    case FALSE:
        return false;
    case TRUE:
        return true;
    case OBJECT:
        return value.getObject();
    case NUMBER:
        return parseNumber(String.valueOf(value.getNumber()));
    case NAN:
        return Float.NaN;
    case MINUS_INFINITY:
        return Float.NEGATIVE_INFINITY;
    case PLUS_INFINITY:
        return Float.POSITIVE_INFINITY;
    case UNDEFINED:
    case NULL:
    default:
        return null;
    }
}

From source file:com.opera.core.systems.scope.services.ums.OperaExec.java

License:Apache License

public void action(String using, int windowID, String... params) {
    using = using.toLowerCase();//from   w w  w  .  j a  v a 2s .  co m

    if (!actions.contains(using)) {
        throw new WebDriverException("The requested action is not supported: " + using);
    }

    ActionList.Builder builder = ActionList.newBuilder();
    Action.Builder actionBuilder = Action.newBuilder();
    actionBuilder.setName(using);
    if (params != null && params.length > 0) {
        actionBuilder.setValue(params[0]);
    }

    if (!excludedActions.contains(using)) {
        try {
            actionBuilder.setWindowID(windowID);
        } catch (WindowNotFoundException e) {
            logger.warning("Exception from setWindowID: " + e);
            e.printStackTrace();
        }
    }

    // type.setSpace("preserve");
    builder.addActionList(actionBuilder);
    if (executeCommand(ExecCommand.EXEC, builder) == null) {
        throw new WebDriverException("Unexpected error while calling action: " + using);
    }
}

From source file:com.opera.core.systems.scope.services.ums.OperaExec.java

License:Apache License

public void action(String using, int data, String dataString, String dataStringParam) {
    if (!actions.contains(using)) {
        throw new UnsupportedCommandException("The requested action is not supported: " + using);
    }//from  w  w  w  .ja  va 2  s.com

    ActionList.Builder builder = ActionList.newBuilder();
    Action.Builder actionBuilder = Action.newBuilder();
    actionBuilder.setName(using);
    actionBuilder.setValue(dataString);
    actionBuilder.setData(data);
    actionBuilder.setStringParam(dataStringParam);

    // type.setSpace("preserve");
    builder.addActionList(actionBuilder);
    if (executeCommand(ExecCommand.EXEC, builder) == null) {
        throw new WebDriverException("Unexpected error while calling action: " + using);
    }
}