@Override public Response handle() throws Exception { JSONObject res = generateStatus(); Set<ServerSideSession> sessions = getServer().getSessions(); Response resp = new Response(); resp.setStatus(0); resp.setValue(res); if (sessions.size() == 0) { resp.setSessionId(null); } else if (sessions.size() == 1) { resp.setSessionId(sessions.iterator().next().getSessionId()); } else { throw new WebDriverException("NI multi sessions per server."); } return resp; }
@Override public Response handle() throws Exception { String ref = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(ref); JsonArray array = getRequest().getPayload().getJsonArray("value"); String value = ""; for (JsonValue jsonValue : array) { value += JavaxJson.toJavaObject(jsonValue); } element.setValueAtoms(value); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(new JSONObject()); return res; }
/** * type - {string} The type of operation to set the timeout for. Valid values are: "script" for * script timeouts, "implicit" for modifying the implicit wait timeout and "page load" for setting * a page load timeout. */ @Override public Response handle() throws Exception { JsonObject payload = getRequest().getPayload(); String type = payload.getString("type", ""); final WebDriverLikeCommand command; if ("page load".equals(type)) { command = WebDriverLikeCommand.URL; } else if ("script".equals(type)) { command = WebDriverLikeCommand.EXECUTE_SCRIPT; } else { throw new UnsupportedCommandException("set timeout for " + payload); } long timeout = payload.getJsonNumber("ms").longValue(); getSession().configure(command).set(type, timeout); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(new JSONObject()); return res; }
@Override public Response handle() throws Exception { String name = getRequest().getVariableValue(":command"); WebDriverLikeCommand command = WebDriverLikeCommand.valueOf(name); CommandConfiguration conf = getSession().configure(command); JSONObject res = new JSONObject(); Map<String, Object> m = conf.getAll(); for (String key : m.keySet()) { res.put(key, m.get(key)); } Response resp = new Response(); resp.setSessionId(getSession().getSessionId()); resp.setStatus(0); resp.setValue(res); return resp; }
@Override public Response handle() throws Exception { JSONArray res = new JSONArray(); for (ServerSideSession s : getServer().getSessions()) { JSONObject session = new JSONObject(); session.put("id", s.getSessionId()); session.put("capabilities", new DesiredCapabilities()); res.put(session); } Response resp = new Response(); resp.setSessionId("dummy one"); resp.setStatus(0); resp.setValue(res.toString()); return resp; }
@Override public Response handle() throws Exception { WebDriverLikeCommand command = WebDriverLikeCommand.valueOf(getRequest().getVariableValue(":command")); JSONObject payload = JavaxJson.toOrgJson(getRequest().getPayload()); @SuppressWarnings("unchecked") Iterator<String> iter = payload.keys(); while (iter.hasNext()) { String key = iter.next(); Object value = payload.opt(key); getSession().configure(command).set(key, value); } Response resp = new Response(); resp.setSessionId(getSession().getSessionId()); resp.setStatus(0); resp.setValue(new JSONObject()); return resp; }
@Nonnull private Object send(@Nonnull String cmd, @Nonnull Map<String, Object> params) throws IOException { Map<String, Object> exe = ImmutableMap.of("cmd", cmd, "params", params); Command xc = new Command(m_wd.getSessionId(), "sendCommandWithResult", exe); Response response = m_wd.getCommandExecutor().execute(xc); Object value = response.getValue(); if(response.getStatus() == null || response.getStatus().intValue() != 0) { //System.out.println("resp: " + response); throw new MyChromeDriverException("Command '" + cmd + "' failed: " + value); } if(null == value) throw new MyChromeDriverException("Null response value to command '" + cmd + "'"); //System.out.println("resp: " + value); return value; }
@Override public Response handle() throws Exception { Response response = new Response(); response.setStatus(ErrorCodes.SUCCESS); response.setState(ErrorCodes.SUCCESS_STRING); BuildInfo buildInfo = new BuildInfo(); JsonObject info = new JsonObject(); JsonObject build = new JsonObject(); build.addProperty("version", buildInfo.getReleaseLabel()); build.addProperty("revision", buildInfo.getBuildRevision()); build.addProperty("time", buildInfo.getBuildTime()); info.add("build", build); JsonObject os = new JsonObject(); os.addProperty("name", System.getProperty("os.name")); os.addProperty("arch", System.getProperty("os.arch")); os.addProperty("version", System.getProperty("os.version")); info.add("os", os); JsonObject java = new JsonObject(); java.addProperty("version", System.getProperty("java.version")); info.add("java", java); response.setValue(info); return response; }
@Override public Response handle() throws Exception { // Handle the case where the client does not send any desired capabilities. sessionId = allSessions.newSession(desiredCapabilities != null ? desiredCapabilities : new DesiredCapabilities()); Map<String, Object> capabilities = Maps.newHashMap(allSessions.get(sessionId).getCapabilities().asMap()); // Only servers implementing the server-side webdriver-backed selenium need // to return this particular value capabilities.put("webdriver.remote.sessionid", sessionId.toString()); if (desiredCapabilities != null) { LoggingManager.perSessionLogHandler().configureLogging( (LoggingPreferences)desiredCapabilities.getCapability(CapabilityType.LOGGING_PREFS)); } LoggingManager.perSessionLogHandler().attachToCurrentThread(sessionId); Response response = new Response(); response.setSessionId(sessionId.toString()); response.setValue(capabilities); return response; }
@Override public Response execute(Command command) throws IOException { Response response; if (DriverCommand.QUIT.equals(command.getName())) { response = grid.execute(command); } else { response = node.execute(command); } return response; }
@Override public Response handle() throws Exception { String ref = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(ref); String text = element.getText(); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(text); return res; }
@Override public Response handle() throws Exception { String url = getRequest().getPayload().getString("url"); getWebDriver().get(url); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(new JSONObject()); return res; }
final Response createResponse(Object value) { Response r = new Response(); r.setSessionId(getSession().getSessionId()); r.setStatus(0); r.setValue(value); return r; }
@Override public Response handle() throws Exception { String url = getWebDriver().getCurrentUrl(); List<Cookie> cookies = getWebDriver().getCookies(); for (Cookie c : cookies) { getWebDriver().deleteCookie(c.getName(), url); } Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(new JSONObject()); return res; }
@Override public Response handle() throws Exception { String ref = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(ref); element.clear(); Response resp = new Response(); resp.setSessionId(getSession().getSessionId()); resp.setStatus(0); resp.setValue(new JSONObject()); return resp; }
@Override public Response handle() throws Exception { String attributeName = getRequest().getVariableValue(":name"); String ref = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(ref); Object value = element.getAttribute(attributeName); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(value); return res; }
@Override public Response handle() throws Exception { String ref = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(ref); Dimension size = element.getSize(); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(size); return res; }
@Override public Response handle() throws Exception { String ref = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(ref); boolean isSelected = element.isSelected(); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(isSelected); return res; }
@Override public Response handle() throws Exception { String value = getWebDriver().getCurrentPageId().asString(); Response resp = new Response(); resp.setSessionId(getSession().getSessionId()); resp.setStatus(0); resp.setValue(value); return resp; }
@Override public Response handle() throws Exception { String ref = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(ref); element.submit(); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(new JSONObject()); return res; }
@Override public Response handle() throws Exception { getWebDriver().getContext().newContext(); getWebDriver().refresh(); // needed to add this waitForLoadEvent() as waitForPageToLoad() is empty currently getWebDriver().getContext().waitForLoadEvent(); getWebDriver().waitForPageToLoad(); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(new JSONObject()); return res; }
@Override public Response handle() throws Exception { waitForPageToLoad(); String title = getWebDriver().getTitle(); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(title); return res; }
@Override public Response handle() throws Exception { String url = getWebDriver().getCurrentUrl(); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(url); return res; }
@Override public Response handle() throws Exception { String reference = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(reference); element.click(); Response resp = new Response(); resp.setSessionId(getSession().getSessionId()); resp.setStatus(0); resp.setValue(new JSONObject()); return resp; }
@Override public Response handle() throws Exception { waitForPageToLoad(); int implicitWait = getConf("implicit_wait", 0); long deadline = System.currentTimeMillis() + implicitWait; RemoteWebElement rwe = null; do { try { rwe = findElement(); break; } catch (NoSuchElementException e) { // Ignore and try again. } } while (System.currentTimeMillis() < deadline); if (rwe == null) { throw new NoSuchElementException( "No element found for " + getRequest().getPayload() + " after waiting for " + implicitWait + " ms."); } else { JSONObject res = new JSONObject(); res.put("ELEMENT", rwe.getReference()); Response resp = new Response(); resp.setSessionId(getSession().getSessionId()); resp.setStatus(0); resp.setValue(res); return resp; } }
@Override public Response handle() throws Exception { timeout = getRequest().getPayload().getInt("ms"); for (WebDriverLikeCommand command : impacted) { getSession().configure(command).set("script", timeout); } Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(new JSONObject()); return res; }
@Override public Response handle() throws Exception { getWebDriver().back(); getWebDriver().getContext().newContext(); getWebDriver().waitForPageToLoad(); Response resp = new Response(); resp.setSessionId(getSession().getSessionId()); resp.setStatus(0); resp.setValue(new JSONObject()); return resp; }
@Override public Response handle() throws Exception { JsonValue p = getRequest().getPayload().get("id"); if (JsonValue.NULL.equals(p)) { getWebDriver().getContext().setCurrentFrame(null, null, null); } else { RemoteWebElement iframe; switch (p.getValueType()) { case NUMBER: iframe = getIframe(((JsonNumber) p).intValue()); break; case OBJECT: String id = ((JsonObject) p).getString("ELEMENT"); iframe = getWebDriver().createElement(id); break; case STRING: iframe = getIframe(((JsonString) p).getString()); break; default: throw new UnsupportedCommandException("cannot select frame by " + p.getClass()); } RemoteWebElement document = iframe.getContentDocument(); RemoteWebElement window = iframe.getContentWindow(); getWebDriver().getContext().setCurrentFrame(iframe, document, window); } Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(new JSONObject()); return res; }
@Override public Response handle() throws Exception { int id = Integer.parseInt(getRequest().getVariableValue(":reference")); int other = Integer.parseInt(getRequest().getVariableValue(":other")); boolean equal = equal(id, other); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(equal); return res; }
@Override public Response handle() throws Exception { waitForPageToLoad(); int implicitWait = getConf("implicit_wait", 0); long deadline = System.currentTimeMillis() + implicitWait; List<RemoteWebElement> elements = null; do { try { elements = findElements(); if (elements.size() != 0) { break; } } catch (NoSuchElementException e) { // Ignore and try again. } } while (System.currentTimeMillis() < deadline); List<com.google.gson.JsonObject> list = new ArrayList<>(); for (RemoteWebElement el : elements) { com.google.gson.JsonObject jsonObject = new com.google.gson.JsonObject(); jsonObject.addProperty("ELEMENT", el.getReference()); list.add(jsonObject); } Response resp = new Response(); resp.setSessionId(getSession().getSessionId()); resp.setStatus(0); resp.setValue(list); return resp; }
@Override public Response handle() throws Exception { String ref = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(ref); String value = element.getTagName(); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(value); return res; }
@Override public Response handle() throws Exception { String ref = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(ref); boolean isEnabled = element.isEnabled(); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(isEnabled); return res; }
@Override public Response handle() throws Exception { timeout = getRequest().getPayload().getInt("ms"); for (WebDriverLikeCommand command : impacted) { getSession().configure(command).set("implicit_wait", timeout); } Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(new JSONObject()); return res; }
@Override public Response handle() throws Exception { String name = getRequest().getVariableValue(":name"); String url = getWebDriver().getCurrentUrl(); getWebDriver().deleteCookie(name, url); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(new JSONObject()); return res; }
@Override public Response handle() throws Exception { String reference = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(reference); boolean isDisplayed = element.isDisplayed(); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(isDisplayed); return res; }
@Override public Response handle() throws Exception { Set<String> handles = new HashSet<>(); for (PageId pageId : getWebDriver().listPages()) { handles.add(pageId.asString()); } Response resp = new Response(); resp.setSessionId(getSession().getSessionId()); resp.setStatus(0); resp.setValue(handles); return resp; }
@Override public Response handle() throws Exception { Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(getWebDriver().getSize()); return res; }
@Override public Response handle() throws Exception { String propertyName = getRequest().getVariableValue(":name"); String ref = getRequest().getVariableValue(":reference"); RemoteWebElement element = getWebDriver().createElement(ref); Object value = element.getCssValue(propertyName); Response res = new Response(); res.setSessionId(getSession().getSessionId()); res.setStatus(0); res.setValue(value); return res; }
@Override public Response handle() throws Exception { // We don't have any way currently of dealing with alert dialogs with pure JS, so we respond to // every alert command with the "no alert present" error code. Response response = new Response(); response.setSessionId(getSession().getSessionId()); response.setStatus(ErrorCodes.NO_ALERT_PRESENT); response.setValue(new ErrorCodes().toState(ErrorCodes.NO_ALERT_PRESENT)); return response; }
@Override public Response handle() throws Exception { ServerSideSession session = null; try { JsonObject capsJson = getRequest().getPayload().getJsonObject("desiredCapabilities"); session = safeStart(new DesiredCapabilities(JavaxJson.toJavaMap(capsJson))); if (session == null) { throw new SessionNotCreatedException("Failed to start session."); } Response r = new Response(); r.setSessionId(session.getSessionId()); r.setValue(session.getWebDriver().capabilities()); r.setStatus(0); return r; } catch (Exception e) { logger.atSevere().withCause(e).log(); if (session != null) { session.stop(); } if (e instanceof WebDriverException) { throw e; } else { throw new SessionNotCreatedException(e.getMessage(), e); } } }