org.openqa.selenium.safari
Class SafariOptions

java.lang.Object
  extended by org.openqa.selenium.safari.SafariOptions

public class SafariOptions
extends Object

Class to manage options specific to SafariDriver.

Example usage:


 SafariOptions options = new SafariOptions()
 // Add an extra extension
 options.addExtensions(new File("/path/to/extension.safariextz"));

 // For use with SafariDriver:
 SafariDriver driver = new SafariDriver(options);

 // For use with RemoteWebDriver:
 DesiredCapabilities capabilities = DesiredCapabilities.safari();
 capabilities.setCapability(SafariOptions.CAPABILITY, options);
 RemoteWebDriver driver = new RemoteWebDriver(
     new URL("http://localhost:4444/wd/hub"), capabilities);
 


Field Summary
static String CAPABILITY
          Key used to store SafariOptions in a DesiredCapabilities object.
 
Constructor Summary
SafariOptions()
           
 
Method Summary
 void addExtensions(File... paths)
           
 void addExtensions(List<File> paths)
          Adds a new Safari extension to install on browser startup.
 boolean equals(Object other)
           
static SafariOptions fromCapabilities(org.openqa.selenium.Capabilities capabilities)
          Construct a SafariOptions instance from given capabilites.
 File getDataDir()
           
 List<File> getExtensions()
           
 int getPort()
           
 boolean getSkipExtensionInstallation()
           
 boolean getUseCleanSession()
           
 boolean getUseCustomDriverExtension()
           
 int hashCode()
           
 void setDataDir(File dataDir)
          Specifies the location of Safari installation's data directory.
 void setDriverExtension(File driverExtension)
          Override the SafariDriver Safari extension.
 void setPort(int port)
          Set the port the SafariDriverServer should be started on.
 void setSkipExtensionInstallation(boolean skipExtensionInstallation)
          Whether to skip extension installation.
 void setUseCleanSession(boolean useCleanSession)
          Instruct the SafariDriver to delete all existing session data when starting a new session.
 org.json.JSONObject toJson()
          Converts this instance to its JSON representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAPABILITY

public static final String CAPABILITY
Key used to store SafariOptions in a DesiredCapabilities object.

See Also:
Constant Field Values
Constructor Detail

SafariOptions

public SafariOptions()
Method Detail

fromCapabilities

public static SafariOptions fromCapabilities(org.openqa.selenium.Capabilities capabilities)
                                      throws org.openqa.selenium.WebDriverException
Construct a SafariOptions instance from given capabilites. When the CAPABILITY capability is set, all other capabilities will be ignored!

Parameters:
capabilities - Desired capabilities from which the options are derived.
Throws:
org.openqa.selenium.WebDriverException - If an error occurred during the reconstruction of the options

addExtensions

public void addExtensions(File... paths)
Parameters:
paths - Paths to the extensions to install.
See Also:
addExtensions(java.util.List)

addExtensions

public void addExtensions(List<File> paths)
Adds a new Safari extension to install on browser startup. Each path should specify a signed Safari extension (safariextz file). Use setDriverExtension(File) if you want to install a custom Safari Driver extension.

Parameters:
paths - Paths to the extensions to install.

setDataDir

public void setDataDir(File dataDir)
Specifies the location of Safari installation's data directory. The default location is:

Parameters:
dataDir - A File object pointing to the Safari installation's data directory. If null, the default installation location for the current platform will be used.

setDriverExtension

public void setDriverExtension(File driverExtension)
Override the SafariDriver Safari extension. By default, the Safari driver extension bundled in the .jar file will be installed. Use this method to install a different SafariDriver Safari extension.

Parameters:
driverExtension - A .safariextz file which is compatible with the SafariDriver. If null, the default driver extension is used.

setPort

public void setPort(int port)
Set the port the SafariDriverServer should be started on. Defaults to 0, in which case the server selects a free port.

Parameters:
port - The port the SafariDriverServer should be started on, or 0 if the server should select a free port.

setSkipExtensionInstallation

public void setSkipExtensionInstallation(boolean skipExtensionInstallation)
Whether to skip extension installation. This preference takes precedence over the options set by addExtensions(java.util.List) and setDriverExtension(File).

Parameters:
skipExtensionInstallation - If true, the installation of extensions is skipped.

setUseCleanSession

public void setUseCleanSession(boolean useCleanSession)
Instruct the SafariDriver to delete all existing session data when starting a new session. This includes browser history, cache, cookies, HTML5 local storage, and HTML5 databases.

Warning: Since Safari uses a single profile for the current user, enabling this capability will permanently erase any existing session data.

Parameters:
useCleanSession - If true, the SafariDriver will erase all existing session data.

getDataDir

public File getDataDir()
Returns:
The location of the data dir where the extensions ought to be installed.
See Also:
setDataDir(File)

getExtensions

public List<File> getExtensions()
Returns:
List of all added extensions. If a custom SafariDriver extension was set (using setDriverExtension(File)), then it will be the first element of this list.
See Also:
addExtensions(java.util.List)

getPort

public int getPort()
Returns:
The port the SafariDriverServer should be started on. If 0, the server should select a free port.
See Also:
setPort(int)

getSkipExtensionInstallation

public boolean getSkipExtensionInstallation()
Returns:
Whether installation of the Safari extensions (including the driver) should be skipped.
See Also:
setSkipExtensionInstallation(boolean)

getUseCustomDriverExtension

public boolean getUseCustomDriverExtension()
Returns:
Whether the SafariDriver Safari extension within the jar file should be installed.
See Also:
setDriverExtension(File), setSkipExtensionInstallation(boolean)

getUseCleanSession

public boolean getUseCleanSession()
Returns:
Whether the SafariDriver should erase all session data before launching Safari.
See Also:
setUseCleanSession(boolean)

toJson

public org.json.JSONObject toJson()
                           throws IOException,
                                  org.json.JSONException
Converts this instance to its JSON representation.

Returns:
The JSON representation of the options.
Throws:
IOException - If an error occurred while reading the Safari extension files.
org.json.JSONException

equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2013. All rights reserved.