List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(Throwable cause)
From source file:org.uiautomation.ios.mobileSafari.remoteWebkitProtocol.SimulatorSession.java
License:Apache License
private void waitForSimToRegister() { try {//from w w w. j a v a2 s . c om simLock.lock(); if (device != null) { return; } simRegistered.await(5, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new WebDriverException("InterruptedException while waiting for the simulator to respond."); } finally { simLock.unlock(); } }
From source file:org.uiautomation.ios.mobileSafari.remoteWebkitProtocol.SimulatorSession.java
License:Apache License
private void waitForSimToSendApps() { try {/*from ww w . j av a2s.co m*/ simLock.lock(); if (applications != null) { return; } simSentApps.await(5, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new WebDriverException("InterruptedException while waiting for the simulator to send its apps."); } finally { simLock.unlock(); } }
From source file:org.uiautomation.ios.mobileSafari.remoteWebkitProtocol.SimulatorSession.java
License:Apache License
public BaseWebInspector connect(WebkitPage webkitPage, ServerSideSession session) { for (WebkitPage page : getPages()) { if (page.equals(webkitPage)) { WebInspector inspector = new WebInspector(null, webkitPage.getPageId(), simulatorProtocol, bundleId, connectionKey, session); // TODO move to webinspector simulatorProtocol.sendSetConnectionKey(connectionKey); simulatorProtocol.sendConnectToApplication(connectionKey, bundleId); simulatorProtocol.sendSenderKey(connectionKey, bundleId, inspector.getSenderKey(), "" + page.getPageId()); inspector.sendCommand(Page.enablePageEvent()); boolean ok = created.add(inspector); if (ok) { simulatorProtocol.addListener(inspector); }/*from w w w. j a va 2 s. com*/ return inspector; } } throw new WebDriverException("Cannot connect to page " + webkitPage + ".Cannot find it."); }
From source file:org.uiautomation.ios.mobileSafari.SimulatorProtocolImpl.java
License:Apache License
public void init() { try {//from w w w. j av a 2 s . c om if (socket != null && (socket.isConnected() || !socket.isClosed())) { socket.close(); } socket = new Socket(LOCALHOST_IPV6, port); } catch (IOException e) { throw new WebDriverException(e); } //sendCommand(PlistManager.SET_CONNECTION_KEY); //sendCommand(PlistManager.CONNECT_TO_APP); //sendCommand(PlistManager.SET_SENDER_KEY); }
From source file:org.uiautomation.ios.mobileSafari.SimulatorProtocolImpl.java
License:Apache License
/** * sends the json formated command./*from w w w . j av a 2s . c om*/ * * @param command . For command format, read https://www.webkit.org/blog/?p=1875&preview=true. */ public synchronized JSONObject sendCommand(JSONObject command, String connectionIdentifier, String bundleId, String senderKey, String pageId) { try { commandId++; command.put("id", commandId); long start = System.currentTimeMillis(); String xml = plist.JSONCommand(command); // perf("got xml \t" + (System.currentTimeMillis() - start) + "ms."); Map<String, String> var = ImmutableMap.of("$WIRConnectionIdentifierKey", connectionIdentifier, "$bundleId", bundleId, "$WIRSenderKey", senderKey, "$WIRPageIdentifierKey", pageId); for (String key : var.keySet()) { xml = xml.replace(key, var.get(key)); } //System.out.println("sending "+xml); byte[] bytes = plist.plistXmlToBinary(xml); // perf("prepared request \t" + (System.currentTimeMillis() - start) + // "ms."); sendBinaryMessage(bytes); // perf("sent request \t\t" + (System.currentTimeMillis() - start) + "ms."); JSONObject response = handler.getResponse(command.getInt("id")); // perf("got response\t\t" + (System.currentTimeMillis() - start) + "ms."); JSONObject error = response.optJSONObject("error"); if (error != null) { throw new RemoteExceptionException(error, command); } else if (response.optBoolean("wasThrown", false)) { throw new WebDriverException("remote JS exception " + response.toString(2)); } else { log.fine(System.currentTimeMillis() + "\t\t" + (System.currentTimeMillis() - start) + "ms\t" + command.getString("method") + " " + command); JSONObject res = response.getJSONObject("result"); if (res == null) { System.err.println("GOT a null result from " + response.toString(2)); } return res; } } catch (JSONException e) { throw new WebDriverException(e); } }
From source file:org.uiautomation.ios.mobileSafari.SimulatorProtocolImpl.java
License:Apache License
/** * sends the message to the AUT.//from w w w . j av a2 s . com */ private void sendBinaryMessage(byte[] bytes) { try { OutputStream os = socket.getOutputStream(); os.write((byte) ((bytes.length >> 24) & 0xFF)); os.write((byte) ((bytes.length >> 16) & 0xFF)); os.write((byte) ((bytes.length >> 8) & 0xFF)); os.write((byte) (bytes.length & 0xFF)); os.write(bytes); } catch (IOException e) { throw new WebDriverException(e); } }
From source file:org.uiautomation.ios.mobileSafari.WebInspector.java
License:Apache License
public Object executeScript(String script, JSONArray args) throws Exception { RemoteWebElement document = getDocument(); RemoteWebElement window = session.getContext().getDOMContext().getWindow(); JSONObject cmd = new JSONObject(); JSONArray arguments = new JSONArray(); int nbParam = args.length(); for (int i = 0; i < nbParam; i++) { Object arg = args.get(i); if (arg instanceof JSONObject) { JSONObject jsonArg = (JSONObject) arg; if (jsonArg.optInt("ELEMENT") > 0) { RemoteWebElement rwep = new RemoteWebElement(new NodeId(jsonArg.optInt("ELEMENT")), session); arguments.put(new JSONObject().put("objectId", rwep.getRemoteObject().getId())); }/*from w w w .j ava 2 s . c om*/ } else if (arg instanceof JSONArray) { JSONArray jsonArr = (JSONArray) arg; // maybe by executing some JS returning the array, and using that result // as a param ? throw new WebDriverException("no support argument = array."); } else { arguments.put(new JSONObject().put("value", arg)); } } if (!session.getContext().getDOMContext().isOnMainFrame()) { arguments.put(new JSONObject().put("objectId", document.getRemoteObject().getId())); arguments.put(new JSONObject().put("objectId", window.getRemoteObject().getId())); script = script.replace(" document", " arguments[" + nbParam + "]"); script = script.replace(" window", " arguments[" + (nbParam + 1) + "]"); } cmd.put("method", "Runtime.callFunctionOn"); cmd.put("params", new JSONObject().put("objectId", document.getRemoteObject().getId()) .put("functionDeclaration", "(function() { " + script + "})").put("arguments", arguments) .put("returnByValue", false)); JSONObject response = protocol.sendCommand(cmd); checkForJSErrors(response); Object o = cast(response); return o; }
From source file:org.uiautomation.ios.mobileSafari.WebInspector.java
License:Apache License
private void checkForJSErrors(JSONObject response) throws Exception { // {"result":{"description":"TypeError: 'undefined' is not an object (evaluating 'arguments[0][0].tagName')","objectId":"{\"injectedScriptId\":2,\"id\":7}","className":"Error","type":"object"},"wasThrown":true} if (response.optBoolean("wasThrown")) { JSONObject details = response.getJSONObject("result"); String desc = details.optString("description"); throw new WebDriverException("JS error :" + desc); }/* w w w. j a va 2s . c o m*/ }
From source file:org.uiautomation.ios.server.application.APPIOSApplication.java
License:Apache License
/** * @param pathToApp/*from w ww . j a v a 2s .co m*/ * @throws WebDriverException */ public APPIOSApplication(String pathToApp) { this.app = new File(pathToApp); if (!app.exists()) { throw new WebDriverException(pathToApp + "isn't an IOS app."); } loadAllContent(); try { metadata = getFullPlist(); } catch (Exception e) { throw new WebDriverException("cannot load the metadata from the Info.plist file for " + pathToApp); } }
From source file:org.uiautomation.ios.server.application.APPIOSApplication.java
License:Apache License
public AppleLanguage getLanguage(String languageCode) { if (getSupportedLanguages().isEmpty()) { return AppleLanguage.emptyLocale(languageCode); }// www . j ava 2s. com if (languageCode == null) { // default to english if none specified languageCode = "en"; } for (AppleLanguage loc : getSupportedLanguages()) { if (languageCode.equals(loc.getIsoCode())) { return loc; } } throw new WebDriverException("Cannot find AppleLocale for " + languageCode); }