public void quit() { extension.quit(); }
protected String sendMessage(Class<? extends RuntimeException> throwOnFailure, Command command) { Response response = extension.sendMessageAndWaitForResponse(throwOnFailure, command); context = response.getContext(); response.ifNecessaryThrow(throwOnFailure); return response.getResponseText(); }
public Object executeScript(String script, Object... args) { // Escape the quote marks script = script.replaceAll("\"", "\\\""); Object[] convertedArgs = convertToJsObjects(args); Command command = new Command(context, null, "executeScript", script, convertedArgs); Response response = extension.sendMessageAndWaitForResponse(WebDriverException.class, command); context = response.getContext(); response.ifNecessaryThrow(WebDriverException.class); if ("NULL".equals(response.getExtraResult("resultType"))) return null; String resultType = (String) response.getExtraResult("resultType"); if ("ELEMENT".equals(resultType)) return new FirefoxWebElement(this, response.getResponseText()); Object result = response.getExtraResult("response"); if (result instanceof Integer) return new Long(response.getResponseText()); return result; }
@Deprecated protected void connectAndKill(int port) { try { ExtensionConnection connection = new RunningInstanceConnection("localhost", port, 5000); connection.quit(); } catch (ConnectException e) { // This is fine. It just means that Firefox isn't running with the webdriver extension installed already } catch (NotConnectedException e) { // This is fine. It just means that Firefox isn't running with the webdriver extension installed already } catch (IOException e) { throw new WebDriverException(e); } }
private void repeatedlyConnectUntilFirefoxAppearsStable(int port) { ExtensionConnection connection; // maximum wait time is a minute long maxWaitTime = System.currentTimeMillis() + binary.getTimeout(); do { try { connection = new RunningInstanceConnection("localhost", port, 1000); Thread.sleep(2000); connection.quit(); return; } catch (ConnectException e) { // Fine. Nothing listening. Perhaps in a restart? } catch (IOException e) { // Expected. It'll do that } catch (InterruptedException e) { throw new WebDriverException(e); } } while (System.currentTimeMillis() < maxWaitTime); } }