Search in sources :

Example 6 with Response

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();
}
Also used : Response(org.openqa.selenium.remote.Response) Response(org.openqa.selenium.remote.Response) GET_SESSION(io.appium.java_client.MobileCommand.GET_SESSION) Collectors.toMap(java.util.stream.Collectors.toMap) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ImmutableMap(com.google.common.collect.ImmutableMap) Optional.ofNullable(java.util.Optional.ofNullable) Map(java.util.Map) Nullable(javax.annotation.Nullable) Collectors.toMap(java.util.stream.Collectors.toMap) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 7 with Response

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);
}
Also used : Response(org.openqa.selenium.remote.Response)

Example 8 with Response

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);
}
Also used : Response(org.openqa.selenium.remote.Response)

Example 9 with Response

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);
}
Also used : Response(org.openqa.selenium.remote.Response) Activity(io.appium.java_client.android.Activity) StartsActivity(io.appium.java_client.android.StartsActivity) StartsActivity(io.appium.java_client.android.StartsActivity) Before(org.junit.Before)

Example 10 with Response

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;
}
Also used : Response(org.openqa.selenium.remote.Response) W3CHttpCommandCodec(org.openqa.selenium.remote.http.W3CHttpCommandCodec) Supplier(com.google.common.base.Supplier) IOException(java.io.IOException) WebDriverException(org.openqa.selenium.WebDriverException) ConnectException(java.net.ConnectException) DriverService(org.openqa.selenium.remote.service.DriverService)

Aggregations

Response (org.openqa.selenium.remote.Response)11 WebDriverException (org.openqa.selenium.WebDriverException)5 Supplier (com.google.common.base.Supplier)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2 Map (java.util.Map)2 W3CHttpCommandCodec (org.openqa.selenium.remote.http.W3CHttpCommandCodec)2 DriverService (org.openqa.selenium.remote.service.DriverService)2 GET_SESSION (io.appium.java_client.MobileCommand.GET_SESSION)1 Activity (io.appium.java_client.android.Activity)1 StartsActivity (io.appium.java_client.android.StartsActivity)1 AppiumW3CHttpCommandCodec (io.appium.java_client.remote.AppiumW3CHttpCommandCodec)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Nullable (javax.annotation.Nullable)1 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)1