use of org.openqa.selenium.remote.Response in project java-client by appium.
the class HasSessionDetails method getSessionDetails.
/**
* The current session details.
*
* @return a map with values that hold session details.
*/
@SuppressWarnings("unchecked")
default Map<String, Object> getSessionDetails() {
Response response = execute(GET_SESSION);
Map<String, Object> resultMap = Map.class.cast(response.getValue());
// results of further operations should be simply interpreted by users
return ImmutableMap.<String, Object>builder().putAll(resultMap.entrySet().stream().filter(entry -> {
String key = entry.getKey();
Object value = entry.getValue();
return !isBlank(key) && value != null && !isBlank(String.valueOf(value));
}).collect(toMap(Map.Entry::getKey, Map.Entry::getValue))).build();
}
use of org.openqa.selenium.remote.Response in project java-client by appium.
the class InteractsWithFiles method pullFile.
/**
* Pull a file from the simulator/device.
*
* @param remotePath On Android and iOS, this is either the path to the file
* (relative to the root of the app's file system). On iOS only,
* if path starts with /AppName.app, which will be replaced with
* the application's .app directory
* @return A byte array of Base64 encoded data.
*/
default byte[] pullFile(String remotePath) {
Response response = execute(PULL_FILE, ImmutableMap.of("path", remotePath));
String base64String = response.getValue().toString();
return DatatypeConverter.parseBase64Binary(base64String);
}
use of org.openqa.selenium.remote.Response in project java-client by appium.
the class InteractsWithFiles method pullFolder.
/**
* Pull a folder from the simulator/device. Does not work on iOS Real
* Devices, but works on simulators
*
* @param remotePath On Android and iOS, this is either the path to the file
* (relative to the root of the app's file system). On iOS only,
* if path starts with /AppName.app, which will be replaced with
* the application's .app directory
* @return A byte array of Base64 encoded data, representing a ZIP ARCHIVE
* of the contents of the requested folder.
*/
default byte[] pullFolder(String remotePath) {
Response response = execute(PULL_FOLDER, ImmutableMap.of("path", remotePath));
String base64String = response.getValue().toString();
return DatatypeConverter.parseBase64Binary(base64String);
}
use of org.openqa.selenium.remote.Response in project java-client by appium.
the class AndroidTest method setUp.
@Before
public void setUp() {
startsActivity = new StartsActivity() {
@Override
public Response execute(String driverCommand, Map<String, ?> parameters) {
return driver.execute(driverCommand, parameters);
}
@Override
public Response execute(String driverCommand) {
return driver.execute(driverCommand);
}
};
Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
startsActivity.startActivity(activity);
}
use of org.openqa.selenium.remote.Response in project java-client by appium.
the class AppiumCommandExecutor 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.getMessage(), e);
}
});
}
Response response;
try {
response = super.execute(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