List of usage examples for org.openqa.selenium WebDriverException WebDriverException
public WebDriverException(String message, Throwable cause)
From source file:com.google.android.testing.nativedriver.server.RootSearchScope.java
License:Apache License
protected View[] getTopLevelViewsAndroid17() { try {/* w w w. ja v a 2s.c o m*/ Class<?> wmgClass = Class.forName("android.view.WindowManagerGlobal"); Object wmg = wmgClass.getDeclaredMethod("getInstance").invoke(null); Field views = wmgClass.getDeclaredField("mViews"); views.setAccessible(true); synchronized (wmg) { return ((View[]) views.get(wmg)).clone(); } } catch (ClassNotFoundException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (NoSuchMethodException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (NoSuchFieldException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (IllegalArgumentException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (InvocationTargetException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (SecurityException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (IllegalAccessException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } }
From source file:com.google.android.testing.nativedriver.server.RootSearchScope.java
License:Apache License
protected View[] getTopLevelViews() { try {// www. j ava 2s .co m return getTopLevelViewsAndroid17(); } catch (Exception e) { Log.i("appdriver getTopLevelViews()", "Failed using android-17 method, falling back to original: " + e.toString()); } try { Class<?> wmClass = getWindowManagerImplClass(); Object wm = wmClass.getDeclaredMethod("getDefault").invoke(null); Field views = wmClass.getDeclaredField("mViews"); views.setAccessible(true); synchronized (wm) { return ((View[]) views.get(wm)).clone(); } } catch (ClassNotFoundException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (NoSuchMethodException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (NoSuchFieldException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (IllegalArgumentException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (InvocationTargetException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (SecurityException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } catch (IllegalAccessException exception) { throw new WebDriverException(REFLECTION_ERROR_MESSAGE, exception); } }
From source file:com.hotwire.selenium.desktop.row.FieldWrapper.java
License:Open Source License
private <T> T createWrapper(final ClassLoader loader, final ElementLocator locator, final Class<T> clazz) { final WebElement proxy = proxyForLocator(loader, locator); try {//from w w w .j a va 2 s . co m return clazz.getConstructor(WebElement.class).newInstance(proxy); } catch (Exception e) { throw new WebDriverException("Can't wrap WebElement by " + clazz, e); } }
From source file:com.jobaline.uiautomation.framework.selenium.phantomJsThreeHourTimeoutFix.HttpCommandExecutor.java
License:Apache License
private Response createResponse(HttpResponse httpResponse, HttpContext context, EntityWithEncoding entityWithEncoding) throws IOException { final Response response; Header header = httpResponse.getFirstHeader("Content-Type"); if (header != null && header.getValue().startsWith("application/json")) { String responseAsText = entityWithEncoding.getContentString(); try {/*from www . j a v a 2 s . com*/ response = new JsonToBeanConverter().convert(Response.class, responseAsText); } catch (ClassCastException e) { if (responseAsText != null && "".equals(responseAsText)) { // The remote server has died, but has already set some headers. // Normally this occurs when the final window of the firefox driver // is closed on OS X. Return null, as the return value _should_ be // being ignored. This is not an elegant solution. return null; } throw new WebDriverException("Cannot convert text to response: " + responseAsText, e); } } else { response = new Response(); if (header != null && header.getValue().startsWith("image/png")) { response.setValue(entityWithEncoding.getContent()); } else if (entityWithEncoding.hasEntityContent()) { response.setValue(entityWithEncoding.getContentString()); } HttpHost finalHost = (HttpHost) context.getAttribute(HTTP_TARGET_HOST); String uri = finalHost.toURI(); String sessionId = HttpSessionId.getSessionId(uri); if (sessionId != null) { response.setSessionId(sessionId); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (!(statusCode > 199 && statusCode < 300)) { // 4xx represents an unknown command or a bad request. if (statusCode > 399 && statusCode < 500) { response.setStatus(ErrorCodes.UNKNOWN_COMMAND); } else if (statusCode > 499 && statusCode < 600) { // 5xx represents an internal server error. The response status should already be set, but // if not, set it to a general error code. if (response.getStatus() == ErrorCodes.SUCCESS) { response.setStatus(ErrorCodes.UNHANDLED_ERROR); } } else { response.setStatus(ErrorCodes.UNHANDLED_ERROR); } } if (response.getValue() instanceof String) { // We normalise to \n because Java will translate this to \r\n // if this is suitable on our platform, and if we have \r\n, java will // turn this into \r\r\n, which would be Bad! response.setValue(((String) response.getValue()).replace("\r\n", "\n")); } } response.setState(errorCodes.toState(response.getStatus())); return response; }
From source file:com.machinepublishers.jbrowserdriver.Util.java
License:Apache License
static void handleException(Throwable throwable) { if (throwable != null) { String message = throwable.getMessage(); if ((throwable instanceof UncheckedExecutionException || throwable instanceof RemoteException) && throwable.getCause() != null) { throwable = throwable.getCause(); message = throwable.getMessage(); }/* ww w . ja v a 2s . c o m*/ if (throwable instanceof WebDriverException && throwable instanceof RuntimeException) { //Wrap the exception to ensure complete/helpful stack trace info and also preserve the original subtype try { throwable = throwable.getClass().getConstructor(String.class, Throwable.class) .newInstance(message, throwable); } catch (Throwable t) { try { throwable = throwable.getClass().getConstructor(Throwable.class).newInstance(throwable); } catch (Throwable t2) { } } throw (RuntimeException) throwable; } throw new WebDriverException(message, throwable); } }
From source file:com.mengge.AppiumDriver.java
License:Apache License
@Override public Set<String> getContextHandles() { Response response = execute(DriverCommand.GET_CONTEXT_HANDLES); Object value = response.getValue(); try {/*from ww w . j a v a 2 s.c o m*/ List<String> returnedValues = (List<String>) value; return new LinkedHashSet<>(returnedValues); } catch (ClassCastException ex) { throw new WebDriverException("Returned value cannot be converted to List<String>: " + value, ex); } }
From source file:com.mengge.remote.AppiumCommandExecutor.java
License:Apache License
@Override public Response execute(Command command) throws IOException, WebDriverException { if (DriverCommand.NEW_SESSION.equals(command.getName()) && service != null) { service.start();/*from ww w . jav a 2 s.c o m*/ } try { return super.execute(command); } catch (Throwable t) { Throwable rootCause = Throwables.getRootCause(t); if (rootCause instanceof ConnectException && rootCause.getMessage().contains("Connection refused") && service != null) { if (service.isRunning()) { throw new WebDriverException("The session is closed!", t); } if (!service.isRunning()) { throw new WebDriverException("The appium server has accidentally died!", t); } } Throwables.propagateIfPossible(t); throw new WebDriverException(t); } finally { if (DriverCommand.QUIT.equals(command.getName()) && service != null) { service.stop(); } } }
From source file:io.appium.java_client.AppiumDriver.java
License:Apache License
@Override public Set<String> getContextHandles() { Response response = execute(DriverCommand.GET_CONTEXT_HANDLES); Object value = response.getValue(); try {/*from w w w. j a v a 2 s. c o m*/ List<String> returnedValues = (List<String>) value; return new LinkedHashSet<String>(returnedValues); } catch (ClassCastException ex) { throw new WebDriverException("Returned value cannot be converted to List<String>: " + value, ex); } }
From source file:io.appium.java_client.remote.AppiumCommandExecutor.java
License:Apache License
@Override public Response execute(Command command) throws IOException, WebDriverException { if (DriverCommand.NEW_SESSION.equals(command.getName()) && service != null) { service.start();/* w w w.ja v a 2 s. co m*/ } try { return super.execute(command); } catch (Throwable t) { Throwable rootCause = Throwables.getRootCause(t); if (rootCause instanceof ConnectException && rootCause.getMessage().contains("Connection refused") && service != null) { if (service.isRunning()) throw new WebDriverException("The session is closed!", t); if (!service.isRunning()) throw new WebDriverException("The appium server has accidentally died!", t); } Throwables.propagateIfPossible(t); throw new WebDriverException(t); } finally { if (DriverCommand.QUIT.equals(command.getName()) && service != null) { service.stop(); } } }
From source file:io.selendroid.client.SelendroidDriver.java
License:Apache License
@Override public Set<String> getContextHandles() { Response response = execute(org.openqa.selenium.remote.DriverCommand.GET_CONTEXT_HANDLES); Object value = response.getValue(); try {//from ww w . j av a2 s .c o m List<String> returnedValues = (List<String>) value; return new LinkedHashSet<String>(returnedValues); } catch (ClassCastException ex) { throw new WebDriverException("Returned value cannot be converted to List<String>: " + value, ex); } }