Exemplo n.º 1
0
  /**
   * Parse a Map and reconstruct the {@link SafariOptions}. A temporary directory is created to hold
   * all Safari extension files.
   *
   * @param options A Map derived from the output of {@link #toJson()}.
   * @return A {@link SafariOptions} instance associated with these extensions.
   * @throws IOException If an error occurred while writing the safari extensions to a temporary
   *     directory.
   */
  @SuppressWarnings("unchecked")
  private static SafariOptions fromJsonMap(Map options) throws IOException {
    SafariOptions safariOptions = new SafariOptions();

    Number port = (Number) options.get(Option.PORT);
    if (port != null) {
      safariOptions.setPort(port.intValue());
    }

    Boolean useCleanSession = (Boolean) options.get(Option.CLEAN_SESSION);
    if (useCleanSession != null) {
      safariOptions.setUseCleanSession(useCleanSession);
    }
    return safariOptions;
  }
Exemplo n.º 2
0
 /**
  * Construct a {@link SafariOptions} instance from given capabilites. When the {@link #CAPABILITY}
  * capability is set, all other capabilities will be ignored!
  *
  * @param capabilities Desired capabilities from which the options are derived.
  * @throws WebDriverException If an error occurred during the reconstruction of the options
  */
 public static SafariOptions fromCapabilities(Capabilities capabilities)
     throws WebDriverException {
   Object cap = capabilities.getCapability(SafariOptions.CAPABILITY);
   if (cap instanceof SafariOptions) {
     return (SafariOptions) cap;
   } else if (cap instanceof Map) {
     try {
       return SafariOptions.fromJsonMap((Map) cap);
     } catch (IOException e) {
       throw new WebDriverException(e);
     }
   } else {
     return new SafariOptions();
   }
 }