List of usage examples for org.openqa.selenium.remote Response getValue
public Object getValue()
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 {/* w ww. j a va 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.mengge.AppiumDriver.java
License:Apache License
/** * @see InteractsWithApps#isAppInstalled(String). *///from ww w. java 2s . co m @Override public boolean isAppInstalled(String bundleId) { Response response = execute(MobileCommand.IS_APP_INSTALLED, ImmutableMap.of("bundleId", bundleId)); return Boolean.parseBoolean(response.getValue().toString()); }
From source file:com.mengge.AppiumDriver.java
License:Apache License
/** * @see DeviceActionShortcuts#getDeviceTime(). *///w w w.ja v a 2 s . c om @Override public String getDeviceTime() { Response response = execute(MobileCommand.GET_DEVICE_TIME); return response.getValue().toString(); }
From source file:com.mengge.AppiumDriver.java
License:Apache License
/** * @see InteractsWithFiles#pullFile(String). *//*from w w w. j a v a 2 s. com*/ @Override public byte[] pullFile(String remotePath) { Response response = execute(MobileCommand.PULL_FILE, ImmutableMap.of("path", remotePath)); String base64String = response.getValue().toString(); return DatatypeConverter.parseBase64Binary(base64String); }
From source file:com.mengge.AppiumDriver.java
License:Apache License
/** * @see InteractsWithFiles#pullFolder(String). *//* w ww . ja v a 2 s . c o m*/ @Override public byte[] pullFolder(String remotePath) { Response response = execute(MobileCommand.PULL_FOLDER, ImmutableMap.of("path", remotePath)); String base64String = response.getValue().toString(); return DatatypeConverter.parseBase64Binary(base64String); }
From source file:com.mengge.AppiumDriver.java
License:Apache License
/** * Get settings stored for this test session It's probably better to use a * convenience function, rather than use this function directly. Try finding * the method for the specific setting you want to read. * * @return JsonObject, a straight-up hash of settings. *///from w ww .j a v a 2 s .c o m public JsonObject getSettings() { Response response = execute(MobileCommand.GET_SETTINGS); JsonParser parser = new JsonParser(); return (JsonObject) parser.parse(response.getValue().toString()); }
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 va 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.AppiumDriver.java
License:Apache License
@Override public ScreenOrientation getOrientation() { Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION); String orientation = response.getValue().toString().toLowerCase(); if (orientation.equals(ScreenOrientation.LANDSCAPE.value())) { return ScreenOrientation.LANDSCAPE; } else if (orientation.equals(ScreenOrientation.PORTRAIT.value())) { return ScreenOrientation.PORTRAIT; } else {/* w w w .j ava2s .c o m*/ throw new WebDriverException("Unexpected orientation returned: " + orientation); } }
From source file:com.mengge.AppiumDriver.java
License:Apache License
/** * @return a map with localized strings defined in the app. * @see HasAppStrings#getAppStringMap(). *//* w ww .ja va 2 s .co m*/ @Override public Map<String, String> getAppStringMap() { Response response = execute(MobileCommand.GET_STRINGS); return (Map<String, String>) response.getValue(); }
From source file:com.mengge.AppiumDriver.java
License:Apache License
/** * @param language strings language code. * @return a map with localized strings defined in the app. * @see HasAppStrings#getAppStringMap(String). *//* w ww . j a v a2s . co m*/ @Override public Map<String, String> getAppStringMap(String language) { Response response = execute(MobileCommand.GET_STRINGS, MobileCommand.prepareArguments("language", language)); return (Map<String, String>) response.getValue(); }