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:org.uiautomation.ios.client.uiamodels.impl.augmenter.AddIOSTouchScreen.java

License:Apache License

@Override
public InterfaceImplementation getImplementation(Object value) {
    return new InterfaceImplementation() {

        public Object invoke(ExecuteMethod exec, Object self, Method method, Object... args) {
            RemoteWebDriver driver = (RemoteWebDriver) self;
            WebDriverLikeCommandExecutor executor = new WebDriverLikeCommandExecutor(driver);

            if ("dragFromToForDuration".equals(method.getName())) {
                Point from = (Point) args[0];
                Point to = (Point) args[1];
                int duration = (Integer) args[2];
                RemoteIOSDriver.dragFromToForDuration(executor, from, to, duration);
                return null;
            } else if ("pinchCloseFromToForDuration".equals(method.getName())) {
                Point from = (Point) args[0];
                Point to = (Point) args[1];
                int duration = (Integer) args[2];
                RemoteIOSDriver.pinchCloseFromToForDuration(executor, from, to, duration);
                return null;
            } else if ("pinchOpenFromToForDuration".equals(method.getName())) {
                Point from = (Point) args[0];
                Point to = (Point) args[1];
                int duration = (Integer) args[2];
                RemoteIOSDriver.pinchOpenFromToForDuration(executor, from, to, duration);
                return null;
            } else {
                throw new WebDriverException(method.getName() + " isn't recognized for IOSTouchScreen");
            }//from   w ww. j a va2  s.  c om
        }
    };
}

From source file:org.uiautomation.ios.client.uiamodels.impl.RemoteUIADriver.java

License:Apache License

/**
 * send the request to the remote server for execution.
 *///from w w  w  . jav a  2s.co  m
public <T> T execute(WebDriverLikeRequest request) {
    Response response = null;
    long total = 0;
    try {
        HttpClient client = HttpClientFactory.getClient();
        String url = remoteURL + request.getPath();
        BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest(request.getMethod(), url);
        if (request.hasPayload()) {
            r.setEntity(new StringEntity(request.getPayload().toString(), "UTF-8"));
        }

        HttpHost h = new HttpHost(host, port);
        long start = System.currentTimeMillis();
        HttpResponse res = client.execute(h, r);
        total = System.currentTimeMillis() - start;

        response = Helper.exctractResponse(res);
    } catch (Exception e) {
        throw new WebDriverException(e);
    }
    response = errorHandler.throwIfResponseFailed(response, total);
    return cast(response.getValue());
}

From source file:org.uiautomation.ios.client.uiamodels.impl.RemoteUIADriver.java

License:Apache License

private <T> T cast(Object o) {
    if (o == null) {
        return null;
    }/*w  w w.j av a  2s.  co m*/
    if (o instanceof Map) {
        Map<String, Object> map = (Map<String, Object>) o;
        if (map.containsKey("ELEMENT")) {
            return (T) RemoteIOSObject.createObject(this, map);
        } else if (map.containsKey("tree")) {
            String serialized = new BeanToJsonConverter().convert(o);
            try {
                return (T) new JSONObject(serialized);
            } catch (JSONException e) {
                throw new WebDriverException("cannot cast");
            }
        } else {
            return (T) map;
        }
    }
    if (o instanceof Collection) {
        List<Object> res = new ArrayList<Object>();
        Collection c = (Collection<Object>) o;
        for (Object ob : c) {
            res.add(cast(ob));
        }
        return (T) res;
    }
    return (T) o;
}

From source file:org.uiautomation.ios.client.uiamodels.impl.RemoteUIAElement.java

License:Apache License

public static void createFileFrom64EncodedString(File f, String encoded64) {
    try {//  w w  w  .  jav a2  s .  co  m
        byte[] img64 = Base64.decodeBase64(encoded64);
        FileOutputStream os = new FileOutputStream(f);
        os.write(img64);
        os.close();
    } catch (Exception e) {
        throw new WebDriverException("cannot extract screenshot" + e.getMessage());
    }
}

From source file:org.uiautomation.ios.client.uiamodels.impl.RemoteUIAScrollView.java

License:Apache License

@Override
public void scroll(ScrollDirection scrollDirection) {

    switch (scrollDirection) {

    case UP:/*from www  .  j  a v  a2  s.co m*/
        createScrollRequest("up");
        break;
    case DOWN:
        createScrollRequest("down");
        break;
    case LEFT:
        createScrollRequest("left");
        break;
    case RIGHT:
        createScrollRequest("right");
        break;
    default:
        throw new WebDriverException("Scrolling direction : " + scrollDirection + " not recognised");

    }

}

From source file:org.uiautomation.ios.communication.Helper.java

License:Apache License

public static Response exctractResponse(HttpResponse resp) {
    String s = extractString(resp);
    try {/*from ww w.j a  v a  2s . c  o  m*/
        Response response = new JsonToBeanConverter().convert(Response.class, s);
        return response;
    } catch (ClassCastException cce) {
        throw new WebDriverException("not a valid response " + s);
    }

}

From source file:org.uiautomation.ios.communication.WebDriverLikeCommand.java

License:Apache License

public static WebDriverLikeCommand getCommand(String method, String path) {
    for (WebDriverLikeCommand command : values()) {
        if (command.isGenericFormOf(method, path)) {
            return command;
        }//from   www  .  j  av a  2 s. c  om
    }
    throw new WebDriverException("cannot find command for " + method + ", " + path);
}

From source file:org.uiautomation.ios.communication.WebDriverLikeCommand.java

License:Apache License

public int getIndex(String variable) {
    String[] pieces = path.split("/");
    for (int i = 0; i < pieces.length; i++) {
        String piece = pieces[i];
        if (piece.startsWith(":") && piece.equals(variable)) {
            return i;
        }/*from   w  w  w  . ja  va2 s .  c  o m*/
    }
    throw new WebDriverException("cannot find the variable " + variable + " in " + path);
}

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

public String getCurrentUrl() {
    long deadline = System.currentTimeMillis() + getTimeout();
    while (System.currentTimeMillis() < deadline) {
        try {/*from   ww w. j a va2  s.co m*/
            return getCurrentUrlOnce();
        } catch (RemoteExceptionException e) {
            if (!e.getMessage().contains("Inspected frame has gone")) {
                throw e;
            }
            log.severe("current url not ready :" + e.getMessage());
        }
    }
    throw new WebDriverException("timeout waiting for the URL to be accessible.");
}

From source file:org.uiautomation.ios.context.BaseWebInspector.java

License:Apache License

private String getCurrentUrlOnce() {

    try {//from ww  w . ja v a2 s  .  c o  m
        RemoteWebElement document = getDocument();
        String f = "(function(arg) { var url=this.URL;return url;})";
        JSONObject cmd = new JSONObject();

        cmd.put("method", "Runtime.callFunctionOn");

        JSONArray args = new JSONArray();

        cmd.put("params", new JSONObject().put("objectId", document.getRemoteObject().getId())
                .put("functionDeclaration", f).put("arguments", args).put("returnByValue", true));

        JSONObject response = sendCommand(cmd);
        return cast(response);
    } catch (JSONException e) {
        throw new WebDriverException(e);
    }

}