use of org.openqa.selenium.remote.Response in project java-client by appium.
the class AppiumDriver method getOrientation.
@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 {
throw new WebDriverException("Unexpected orientation returned: " + orientation);
}
}
use of org.openqa.selenium.remote.Response in project java-client by appium.
the class AppiumDriver method getContextHandles.
@Override
public Set<String> getContextHandles() {
Response response = execute(DriverCommand.GET_CONTEXT_HANDLES);
Object value = response.getValue();
try {
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);
}
}
use of org.openqa.selenium.remote.Response in project java-client by appium.
the class HasSettings method getSettings.
/**
* 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.
*/
@SuppressWarnings("unchecked")
default Map<String, Object> getSettings() {
Map.Entry<String, Map<String, ?>> keyValuePair = getSettingsCommand();
Response response = execute(keyValuePair.getKey(), keyValuePair.getValue());
return ImmutableMap.<String, Object>builder().putAll(Map.class.cast(response.getValue())).build();
}
use of org.openqa.selenium.remote.Response in project flow by vaadin.
the class ChromeDeviceTest method setConnectionType.
/**
* Change network connection type in the browser.
*
* @param connectionType
* the new connection type
* @throws IOException
*/
protected void setConnectionType(NetworkConnection.ConnectionType connectionType) throws IOException {
RemoteWebDriver driver = (RemoteWebDriver) ((TestBenchDriverProxy) getDriver()).getWrappedDriver();
final Map<String, Integer> parameters = new HashMap<>();
parameters.put("type", connectionType.hashCode());
final Map<String, Object> connectionParams = new HashMap<>();
connectionParams.put("parameters", parameters);
Response response = driver.getCommandExecutor().execute(new Command(driver.getSessionId(), "setNetworkConnection", connectionParams));
if (response.getStatus() != 0) {
throw new RuntimeException("Unable to set connection type");
}
}
use of org.openqa.selenium.remote.Response in project carina by qaprosoft.
the class EventFiringAppiumCommandExecutor method execute.
@Override
public Response execute(Command command) throws WebDriverException {
if (DriverCommand.NEW_SESSION.equals(command.getName())) {
serviceOptional.ifPresent(driverService -> {
try {
driverService.start();
} catch (IOException e) {
throw new WebDriverException(e);
}
});
}
Response response;
try {
for (IDriverCommandListener listener : listeners) {
listener.beforeEvent(command);
}
try {
response = super.execute(command);
} catch (JsonException e) {
// to handle potential grid/hub issue:
// Expected to read a START_MAP but instead have: END. Last 0 characters read
LOGGER.debug("Repeit the command due to the JsonException: " + command.getName(), e);
CommonUtils.pause(0.1);
response = super.execute(command);
}
for (IDriverCommandListener listener : listeners) {
listener.afterEvent(command);
}
} catch (Throwable t) {
Throwable rootCause = Throwables.getRootCause(t);
if (rootCause instanceof ConnectException && rootCause.getMessage().contains("Connection refused")) {
throw serviceOptional.map(service -> {
if (service.isRunning()) {
return new WebDriverException("The session is closed!", rootCause);
}
return new WebDriverException("The appium server has accidentally died!", rootCause);
}).orElseGet((Supplier<WebDriverException>) () -> new WebDriverException(rootCause.getMessage(), rootCause));
}
// throwIfUnchecked(t);
throw new WebDriverException(t);
} finally {
if (DriverCommand.QUIT.equals(command.getName())) {
serviceOptional.ifPresent(DriverService::stop);
}
}
if (DriverCommand.NEW_SESSION.equals(command.getName()) && getCommandCodec() instanceof W3CHttpCommandCodec) {
setCommandCodec(new AppiumW3CHttpCommandCodec());
getAdditionalCommands().forEach(this::defineCommand);
}
return response;
}
Aggregations