use of io.appium.java_client.remote.AppiumW3CHttpCommandCodec 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