List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(Throwable cause)
From source file:com.opera.core.systems.scope.services.ums.Prefs.java
License:Apache License
public void setPrefs(String section, String key, String value) { SetPrefArg.Builder setPrefBuilder = SetPrefArg.newBuilder(); setPrefBuilder.setSection(section);/*from w w w .ja v a 2 s . c o m*/ setPrefBuilder.setKey(key); setPrefBuilder.setValue(value); Response response = executeCommand(PrefsCommand.SET_PREF, setPrefBuilder); if (response == null) { throw new WebDriverException("Internal error while setting a preference"); } }
From source file:com.opera.core.systems.scope.services.ums.UmsServices.java
License:Apache License
private String getVersionForService(List<Service> serviceList, String name) { Service service = findServiceNamed(serviceList, name); if (service == null) throw new WebDriverException("No service named '" + name + "'"); return service.getVersion(); }
From source file:com.opera.core.systems.scope.services.ums.WindowManager.java
License:Apache License
public void openUrl(int windowId, String url) { // Opera Mobile still uses WM 2.0, and so this is a backward compatibility // hack.//w w w. ja v a 2 s . com if (VersionUtil.compare(getVersion(), "2.1") < 0) { services.getExec().action("Go", url); return; } OpenURLArg.Builder openUrlBuilder = OpenURLArg.newBuilder(); openUrlBuilder.setWindowID(windowId); openUrlBuilder.setUrl(url); Response response = executeCommand(WindowManagerCommand.OPEN_URL, openUrlBuilder); if (response == null) { throw new WebDriverException("Internal error while opening " + url); } }
From source file:com.opera.core.systems.scope.services.ums.WindowManager.java
License:Apache License
public void closeWindow(int windowId) { // Opera Mobile still uses WM 2.0. if (VersionUtil.compare(getVersion(), "2.1") < 0) { throw new UnsupportedOperationException( "Window Manager version " + getVersion() + "does not support this method"); }//from ww w.j ava2s . co m CloseWindowArg.Builder closeWindowBuilder = CloseWindowArg.newBuilder(); closeWindowBuilder.setWindowID(windowId); Response response = executeCommand(WindowManagerCommand.CLOSE_WINDOW, closeWindowBuilder); removeWindow(windowId); if (response == null) { throw new WebDriverException("Internal error while closing window"); } }
From source file:com.opera.core.systems.scope.stp.services.ScopeSelftest.java
License:Apache License
public RunStatus runSelftests(Set<String> modules, String groups, String excludes) { checkNotNull(modules, "Modules cannot be empty"); RunTestsArg.Builder argBuilder = RunTestsArg.newBuilder(); if (groups != null) { argBuilder.setTestPattern(groups); }/*from www .j a v a 2 s . c om*/ argBuilder.setModuleList(Joiner.on(',').join(modules)); if (excludes != null) { argBuilder.setExcludePattern(excludes); } Response response = executeMessage(SelftestMessage.RUN_TESTS, argBuilder); SelftestProtos.RunStatus.Builder builder = SelftestProtos.RunStatus.newBuilder(); buildPayload(response, builder); SelftestProtos.RunStatus.RunTestStatus status = builder.build().getStatus(); switch (status) { case RUNNING: return RunStatus.RUNNING; case NOT_AVAILABLE: return RunStatus.NOT_AVAILABLE; default: throw new WebDriverException(String.format("Unknown result: %s", status)); } }
From source file:com.opera.core.systems.scope.stp.StpConnection.java
License:Apache License
/** * Processes an incoming message and passes it to event handler if needed, the following events * are to our interest: Runtime-Started : ecmascript runtime starts in Opera (that we can inject * to) Runtime-Stopped : ecmascript runtime stops (not used, buggy) Message: fired from console * log event Updated-Window: a window is updated OR created (opener-id=0) Active-Window: window * focus changed Window-Closed: self explanatory If message matches none it is added to the * response queue (probably response to command). *///from w ww .jav a 2s.c om public void parseServiceList(String message) { logger.finer("parseServiceList: \"" + message + "\""); int split = message.indexOf(" "); if (split < 0) { connectionHandler.onException(new WebDriverException("Invalid service list received.")); return; } List<String> services = Arrays.asList(message.substring(split + 1).split(",")); connectionHandler.onServiceList(services); logger.fine("Service list ok"); if (!services.contains("stp-1")) { connectionHandler.onException(new WebDriverException("STP/0 is not supported!")); return; } switchToStp1(); }
From source file:com.opera.core.systems.scope.stp.StpConnection.java
License:Apache License
/** * Reads a message from the buffer, and pops the used data out of the buffer. * * @param buffer the buffer containing messages * @return true if we got a message from the buffer */// w w w .j a v a2s . c o m private boolean readMessage(ByteBuffer buffer) { // logger.finest("readMessage: " + bytesRead + " bytes read, remaining=" + // remainingBytes.length + ", state=" + state.toString() + ", recurse=" + // recurse); buffer.position(0); int bytesWeHaveBeenreading = 0; switch (state) { case SERVICELIST: StringBuilder builder = new StringBuilder(); builder.append(buffer.asCharBuffer()); parseServiceList(builder.toString()); buffer.position(0);// reset position! bytesWeHaveBeenreading = buffer.limit(); // bytesWeHaveBeenreading = all // bytes in buffer! break; case HANDSHAKE: if (buffer.limit() >= 6) { byte[] dst = new byte[6]; buffer.position(0);// read from start! buffer.get(dst); buffer.position(0);// reset position! bytesWeHaveBeenreading = 6; // 6 bytes will be removed from buffer String handShake = new String(dst); if (!handShake.equals("STP/1\n")) { close(); connectionHandler .onException(new WebDriverException("Scope Transport Protocol Error : Handshake")); } else { setState(State.EMPTY); connectionHandler.onHandshake(true); } } break; case EMPTY: // read 4 byte header: STP\0 if (buffer.limit() >= 4) { byte[] headerPrefix = new byte[4]; buffer.get(headerPrefix); buffer.position(0); bytesWeHaveBeenreading = 4; ByteString incomingPrefix = ByteString.copyFrom(headerPrefix); if (stpPrefix.equals(incomingPrefix)) { setState(State.STP); /* if(buffer.hasRemaining()){ buffer.compact(); readMessage(buffer, buffer.position(), true); } else { buffer.clear(); } */ } else { close(); connectionHandler .onException(new WebDriverException("Scope Transport Protocol Error : Header")); } } break; case STP: // Try to read size buffer.position(0); if (buffer.limit() <= 0) { logger.finest("STP: Empty buffer"); break; } int messageSize = readRawVarint32(buffer);// read part of buffer bytesWeHaveBeenreading = buffer.position(); buffer.position(0); // If we got size, read more, if not just leave it! if (buffer.limit() >= bytesWeHaveBeenreading + messageSize) { buffer.position(bytesWeHaveBeenreading); // Read type and Payload! int messageType = buffer.get(); bytesWeHaveBeenreading += 1; byte[] payload = new byte[--messageSize]; buffer.get(payload); buffer.position(0); bytesWeHaveBeenreading += messageSize; // 32 bits = 4 bytes :-) setState(State.EMPTY); try { processMessage(messageType, payload); } catch (IOException e) { close(); connectionHandler.onException( new WebDriverException("Error while processing the message: " + e.getMessage())); } } else { // 4 + messageSize because of the int at the beginning logger.finest("tried to read a message, but expected " + (4 + messageSize) + " bytes, and only got " + buffer.limit()); buffer.position(0); bytesWeHaveBeenreading = 0; } break; } // Pop number of read bytes from if (bytesWeHaveBeenreading > 0) { // Pop X bytes, and keep message for the rest int rest = buffer.limit() - bytesWeHaveBeenreading; if (rest <= 0) { buffer.clear(); buffer.limit(0); } else { byte[] temp = new byte[rest]; buffer.position(bytesWeHaveBeenreading); buffer.get(temp, 0, rest); buffer.clear(); buffer.limit(rest); buffer.position(0); buffer.put(temp, 0, rest); buffer.position(0);// set position back to start! } logger.finest("Did read message of " + bytesWeHaveBeenreading + " bytes, new buffer size = " + buffer.limit()); return true; // We did read a message :-) } else { if (buffer.limit() > 0) { logger.finest("did NOT read message from buffer of size = " + buffer.limit()); } else { logger.finest("no messages in empty buffer"); } return false; } }
From source file:com.opera.core.systems.scope.stp.StpConnection.java
License:Apache License
private void processMessage(int stpType, byte[] payload) throws IOException { logger.finest("processMessage: " + stpType); switch (stpType) { //case 1: //command //commands are not supposed to be received //throw new WebDriverException("Received command from host?"); case 2: // response // Log what is being sent. Response response = Response.parseFrom(payload); logger.finest("RECV RESPONSE: " + response.toString()); signalResponse(response.getTag(), response); break;// w w w . j a v a 2 s . c om case 3: // event Event event = Event.parseFrom(payload); logger.finest("RECV EVENT: " + event.toString()); signalEvent(event); break; case 4: // error Error error = Error.parseFrom(payload); logger.finest("RECV ERROR: " + error.toString()); String service = error.getService(); int status = error.getStatus(); // We get exceptions when, in the ecmascript services, we use a runtime // that doesn't exist. We can ignore these exceptions and carry on. if ((service.equals("ecmascript-debugger") && status == Status.INTERNAL_ERROR.getNumber()) || (service.equals("ecmascript") && status == Status.BAD_REQUEST.getNumber())) { signalResponse(error.getTag(), null); } else { logger.log(Level.SEVERE, "Error: {0}", error.toString()); connectionHandler.onException(new WebDriverException("Error on command: " + error.toString())); } break; default: connectionHandler.onException(new WebDriverException("Unhandled STP type: " + stpType)); } }
From source file:com.opera.core.systems.scope.stp.StpConnection.java
License:Apache License
private int readRawVarint32(ByteBuffer bytes) { byte tmp = bytes.get(); if (tmp >= 0) { return tmp; }//from www . ja v a2 s . c o m int result = tmp & 0x7f; if ((tmp = bytes.get()) >= 0) { result |= tmp << 7; } else { result |= (tmp & 0x7f) << 7; if ((tmp = bytes.get()) >= 0) { result |= tmp << 14; } else { result |= (tmp & 0x7f) << 14; if ((tmp = bytes.get()) >= 0) { result |= tmp << 21; } else { result |= (tmp & 0x7f) << 21; result |= (tmp = bytes.get()) << 28; if (tmp < 0) { // Discard upper 32 bits. for (int i = 0; i < 5; i++) { if (bytes.get() >= 0) { return result; } } connectionHandler.onException(new WebDriverException("Error while reading raw int")); } } } } return result; }
From source file:com.opera.core.systems.scope.stp.UmsEventParser.java
License:Apache License
public void handleEvent(Event event) { String service = event.getService(); int eventId = event.getCommandID(); if (service.equals("ecmascript-debugger")) { switch (ESDebuggerCommand.get(eventId)) { case RUNTIME_STARTED: RuntimeInfo.Builder infoBuilder = RuntimeInfo.newBuilder(); buildPayload(event, infoBuilder); eventHandler.onRuntimeStarted(infoBuilder.build()); break; case RUNTIME_STOPPED: RuntimeID.Builder idBuilder = RuntimeID.newBuilder(); buildPayload(event, idBuilder); Integer id = idBuilder.build().getRuntimeID(); eventHandler.onRuntimeStopped(id); break; default:// w ww .j a va2 s .c o m break; } } else if (service.equals("window-manager")) { switch (WindowManagerCommand.get(eventId)) { case WINDOW_ACTIVATED: WindowID.Builder activeWindowIdBuilder = WindowID.newBuilder(); buildPayload(event, activeWindowIdBuilder); Integer activeWindowID = activeWindowIdBuilder.build().getWindowID(); eventHandler.onActiveWindow(activeWindowID); break; case WINDOW_CLOSED: WindowID.Builder closedWindowBuilder = WindowID.newBuilder(); buildPayload(event, closedWindowBuilder); Integer closedWindowID = closedWindowBuilder.build().getWindowID(); eventHandler.onWindowClosed(closedWindowID); break; case WINDOW_UPDATED: WindowInfo.Builder windowInfoBuilder = WindowInfo.newBuilder(); buildPayload(event, windowInfoBuilder); WindowInfo info = windowInfoBuilder.build(); eventHandler.onUpdatedWindow(info); break; case WINDOW_LOADED: WindowID.Builder loadedWindowBuilder = WindowID.newBuilder(); buildPayload(event, loadedWindowBuilder); Integer loadedWindowID = loadedWindowBuilder.build().getWindowID(); eventHandler.onWindowLoaded(loadedWindowID.intValue()); break; default: break; } } else if (service.equals("desktop-window-manager")) { switch (DesktopWindowManagerCommand.get(eventId)) { case WINDOW_SHOWN: DesktopWindowInfo.Builder shownDWBuilder = DesktopWindowInfo.newBuilder(); buildPayload(event, shownDWBuilder); DesktopWindowInfo info_shown = shownDWBuilder.build(); eventHandler.onDesktopWindowShown(info_shown); break; case WINDOW_UPDATED: DesktopWindowInfo.Builder updatedDWBuilder = DesktopWindowInfo.newBuilder(); buildPayload(event, updatedDWBuilder); DesktopWindowInfo info_updated = updatedDWBuilder.build(); eventHandler.onDesktopWindowUpdated(info_updated); break; case WINDOW_ACTIVATED: DesktopWindowInfo.Builder activatedDWBuilder = DesktopWindowInfo.newBuilder(); buildPayload(event, activatedDWBuilder); DesktopWindowInfo info_activated = activatedDWBuilder.build(); eventHandler.onDesktopWindowActivated(info_activated); break; case WINDOW_CLOSED: DesktopWindowInfo.Builder closedDWBuilder = DesktopWindowInfo.newBuilder(); buildPayload(event, closedDWBuilder); DesktopWindowInfo info_closed = closedDWBuilder.build(); eventHandler.onDesktopWindowClosed(info_closed); break; case WINDOW_LOADED: DesktopWindowInfo.Builder loadedDWBuilder = DesktopWindowInfo.newBuilder(); buildPayload(event, loadedDWBuilder); DesktopWindowInfo info_loaded = loadedDWBuilder.build(); eventHandler.onDesktopWindowLoaded(info_loaded); break; case MENU_SHOWN: QuickMenuInfo.Builder shownQMBuilder = QuickMenuInfo.newBuilder(); buildPayload(event, shownQMBuilder); QuickMenuInfo menuInfoShown = shownQMBuilder.build(); eventHandler.onQuickMenuShown(menuInfoShown); break; case MENU_CLOSED: QuickMenuID.Builder closedQMBuilder = QuickMenuID.newBuilder(); buildPayload(event, closedQMBuilder); QuickMenuID menuId = closedQMBuilder.build(); eventHandler.onQuickMenuClosed(menuId); break; case MENU_PRESSED: QuickMenuItemID.Builder pressedQMIBuilder = QuickMenuItemID.newBuilder(); buildPayload(event, pressedQMIBuilder); QuickMenuItemID menuItemID = pressedQMIBuilder.build(); eventHandler.onQuickMenuItemPressed(menuItemID); break; default: break; } } else if (service.equals("console-logger")) { // console logger only sends one message ConsoleMessage.Builder messageBuilder = ConsoleMessage.newBuilder(); buildPayload(event, messageBuilder); eventHandler.onMessage(messageBuilder.build()); } else if (service.equals("ecmascript")) { // we have only one event for this one ReadyStateChange.Builder builder = ReadyStateChange.newBuilder(); buildPayload(event, builder); eventHandler.onReadyStateChange(builder.build()); } else if (service.equals("http-logger") && eventId == 1) { // console logger only sends one message // FIXME make generic Header header; try { header = Header.parseFrom(event.getPayload()); } catch (InvalidProtocolBufferException e) { throw new WebDriverException("Exception while parsing event"); } eventHandler.onRequest(header.getWindowID()); } else if (service.equals("core")) { switch (CoreUtilsCommand.get(eventId)) { case ONACTIVE: // No active event handler... // Opera only becomes active as reaction on other event // sent from operadriver, so we already know. break; case ONIDLE: eventHandler.onOperaIdle(); break; } } else if (service.equals("selftest")) { switch (SelftestCommand.get(eventId)) { case OUTPUT: SelftestOutput.Builder builder = SelftestOutput.newBuilder(); buildPayload(event, builder); eventHandler.onSelftestOutput(builder.build()); break; case FINISHED: eventHandler.onSelftestDone(); break; } } }