Class HtmlUnitDriverOptions
- java.lang.Object
-
- org.openqa.selenium.MutableCapabilities
-
- org.openqa.selenium.remote.AbstractDriverOptions<HtmlUnitDriverOptions>
-
- org.openqa.selenium.htmlunit.options.HtmlUnitDriverOptions
-
- All Implemented Interfaces:
Serializable,org.openqa.selenium.Capabilities
public class HtmlUnitDriverOptions extends org.openqa.selenium.remote.AbstractDriverOptions<HtmlUnitDriverOptions>
Class to manage options specific toHtmlUnitDriver.Example usage:
HtmlUnitDriverOptions options = new HtmlUnitDriverOptions() .setWebClientVersion(BrowserVersion.FIREFOX_ESR) .setJavaScriptEnabled(true); // For use with HtmlUnitDriver: HtmlUnitDriver driver = new HtmlUnitDriver(options); // For use with RemoteWebDriver: RemoteWebDriver driver = new RemoteWebDriver( new URL("http://localhost:4444/"), new HtmlUnitDriverOptions());Getting/setting HtmlUnitDriver options:
In addition to methods for reading and writing specific HtmlUnitDriver options, you can use the standard
MutableCapabilitiesAPI:Capabilities.is(String)getCapability(String)setCapability(String, Object)
Example usage:
HtmlUnitDriverOptions options = new HtmlUnitDriverOptions(); boolean popupBlockerEnabled = options.is(HtmlUnitOption.optPopupBlockerEnabled); // NOTE: See "Getting individual browser version traits" below String browserLanguage = (String) options.getCapability(BrowserVersionTrait.optBrowserLanguage); options.setCapability(HtmlUnitOption.optGeolocationEnabled, true);Getting individual browser version traits:
HtmlUnitDriverOption contains a
The individual traits of the BrowserVersion object can be read directly as well via the standardBrowserVersionwhich can be read and written directly:CapabilitiesAPI. For example:
NOTE: Although HtmlUnitDriverOptions objects are mutable (their properties can be altered), the individual traits of theHtmlUnitDriverOptions options = new HtmlUnitDriverOptions(BrowserVersion.EDGE); // System time zone accessed via BrowserVersion API TimeZone viaBrowserVersion = options.getWebClientVersion.getSystemTimezone(); // System time zone accessed via standard Capabilities API TimeZone viaCapabilityName = (TimeZone) options.getCapability(BrowserVersionTrait.optSystemTimezone);BrowserVersionobject within these objects cannot be altered:HtmlUnitDriverOptions options = new HtmlUnitDriverOptions(BrowserVersion.CHROME); options.setCapability(BrowserVersionTrait.optUserAgent, "HtmlUnitDriver emulating Google Chrome"); // => UnsupporterOperationException: Individual browser version traits are immutable; 'optUserAgent' cannot be set- Since:
- HtmlUnitDriver v4.22.0
- Author:
- Scott Babcock, Ronald Brill
- See Also:
HtmlUnitOption,BrowserVersionTrait, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringBROWSER_VERSIONKey used to store the browser version in aCapabilitiesobject.static StringHTMLUNIT_OPTIONSKey used to store a set of HtmlUnitDriverOptions in aCapabilitiesobject.
-
Constructor Summary
Constructors Constructor Description HtmlUnitDriverOptions()Default constructor.HtmlUnitDriverOptions(Map<String,Object> optionsMap)Constructs HtmlUnitDriverOptions from a map of options.HtmlUnitDriverOptions(BrowserVersion version)Constructs HtmlUnitDriverOptions with a specificBrowserVersion.HtmlUnitDriverOptions(BrowserVersion version, boolean enableJavascript)Constructs HtmlUnitDriverOptions with a specificBrowserVersionand JavaScript support enabled/disabled.HtmlUnitDriverOptions(org.openqa.selenium.Capabilities source)Constructs HtmlUnitDriverOptions from an existingCapabilitiesobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyOptions(WebClientOptions target)Apply values from this HtmlUnitDriver options object to the specifies target.StringgetBrowserVersion()ObjectgetCapability(String capabilityName)protected ObjectgetExtraCapability(String capabilityName)protected Set<String>getExtraCapabilityNames()BrowserVersiongetWebClientVersion()Returns the configuredBrowserVersionused by the underlying WebClient.HtmlUnitDriverOptionsimportOptions(WebClientOptions source)Import values from the specified source into this HtmlUnitDriver options object.booleanisDownloadImages()Returns whether images are downloaded automatically.booleanisJavaScriptEnabled()Returns whether JavaScript execution is enabled.HtmlUnitDriverOptionssetBrowserVersion(String browserVersion)voidsetCapability(String capabilityName, Object value)HtmlUnitDriverOptionssetDownloadImages(boolean downloadImages)Enables or disables automatic image downloading.HtmlUnitDriverOptionssetJavaScriptEnabled(boolean enableJavascript)Enables or disables JavaScript execution.HtmlUnitDriverOptionssetSSLClientCertificateKeyStore(InputStream keyStoreInputStream, String keyStorePassword, String keyStoreType)Sets the SSL client certificate key store from anInputStream.HtmlUnitDriverOptionssetSSLClientCertificateKeyStore(URL keyStoreUrl, String keyStorePassword, String keyStoreType)Sets the SSL client certificate key store using a URL.HtmlUnitDriverOptionssetSSLClientCertificateKeyStore(KeyStore keyStore, char[] keyStorePassword)Sets the SSL client certificate key store from an existingKeyStore.HtmlUnitDriverOptionssetSSLTrustStore(URL sslTrustStoreUrl, String sslTrustStorePassword, String sslTrustStoreType)Sets the SSL trust store using a URL.HtmlUnitDriverOptionssetWebClientVersion(BrowserVersion webClientVersion)Sets theBrowserVersionused by the underlying WebClient.-
Methods inherited from class org.openqa.selenium.remote.AbstractDriverOptions
asMap, getCapabilityNames, setAcceptInsecureCerts, setEnableDownloads, setImplicitWaitTimeout, setPageLoadStrategy, setPageLoadTimeout, setPlatformName, setProxy, setScriptTimeout, setStrictFileInteractability, setUnhandledPromptBehaviour
-
Methods inherited from class org.openqa.selenium.MutableCapabilities
equals, hashCode, merge, setCapability, setCapability, setCapability, toJson, toString
-
-
-
-
Field Detail
-
HTMLUNIT_OPTIONS
public static final String HTMLUNIT_OPTIONS
Key used to store a set of HtmlUnitDriverOptions in aCapabilitiesobject.- See Also:
- Constant Field Values
-
BROWSER_VERSION
public static final String BROWSER_VERSION
Key used to store the browser version in aCapabilitiesobject.This key includes the "garg:" vendor prefix so that the Grid Distributor will ignore it. Using the standard "browserVersion" key instead results in slot match failures, because the distributor requires the version specified in the requested capabilities to match the version specified by the slot stereotype.
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HtmlUnitDriverOptions
public HtmlUnitDriverOptions()
Default constructor.Initializes HtmlUnitDriverOptions with default capabilities:
- Browser name set to "htmlunit"
- Home page set to "about:blank"
- Exceptions on failing status codes disabled
- Print content on failing status code disabled
- Use insecure SSL enabled
-
HtmlUnitDriverOptions
public HtmlUnitDriverOptions(BrowserVersion version)
Constructs HtmlUnitDriverOptions with a specificBrowserVersion.- Parameters:
version- the browser version to use
-
HtmlUnitDriverOptions
public HtmlUnitDriverOptions(BrowserVersion version, boolean enableJavascript)
Constructs HtmlUnitDriverOptions with a specificBrowserVersionand JavaScript support enabled/disabled.- Parameters:
version- the browser version to useenableJavascript- true to enable JavaScript support, false to disable
-
HtmlUnitDriverOptions
public HtmlUnitDriverOptions(org.openqa.selenium.Capabilities source)
Constructs HtmlUnitDriverOptions from an existingCapabilitiesobject.Transfers mapped capabilities and legacy HtmlUnit options. If the source is another HtmlUnitDriverOptions instance, copies the
WebClientOptionsandBrowserVersionfrom it.- Parameters:
source- source capabilities to copy
-
-
Method Detail
-
setBrowserVersion
public HtmlUnitDriverOptions setBrowserVersion(String browserVersion)
- Overrides:
setBrowserVersionin classorg.openqa.selenium.remote.AbstractDriverOptions<HtmlUnitDriverOptions>
-
getBrowserVersion
public String getBrowserVersion()
-
getCapability
public Object getCapability(String capabilityName)
- Specified by:
getCapabilityin interfaceorg.openqa.selenium.Capabilities- Overrides:
getCapabilityin classorg.openqa.selenium.remote.AbstractDriverOptions<HtmlUnitDriverOptions>
-
setCapability
public void setCapability(String capabilityName, Object value)
- Overrides:
setCapabilityin classorg.openqa.selenium.MutableCapabilities
-
getExtraCapabilityNames
protected Set<String> getExtraCapabilityNames()
- Specified by:
getExtraCapabilityNamesin classorg.openqa.selenium.remote.AbstractDriverOptions<HtmlUnitDriverOptions>
-
getExtraCapability
protected Object getExtraCapability(String capabilityName)
- Specified by:
getExtraCapabilityin classorg.openqa.selenium.remote.AbstractDriverOptions<HtmlUnitDriverOptions>
-
importOptions
public HtmlUnitDriverOptions importOptions(WebClientOptions source)
Import values from the specified source into this HtmlUnitDriver options object.- Parameters:
source- sourceWebClientOptionsobject- Returns:
- this
HtmlUnitDriverOptionsobject
-
applyOptions
public void applyOptions(WebClientOptions target)
Apply values from this HtmlUnitDriver options object to the specifies target.- Parameters:
target- targetWebClientOptionsobject
-
isJavaScriptEnabled
public boolean isJavaScriptEnabled()
Returns whether JavaScript execution is enabled.- Returns:
trueif JavaScript is enabled;falseotherwise
-
setJavaScriptEnabled
public HtmlUnitDriverOptions setJavaScriptEnabled(boolean enableJavascript)
Enables or disables JavaScript execution.- Parameters:
enableJavascript-trueto enable JavaScript;falseto disable it- Returns:
- this options instance
-
isDownloadImages
public boolean isDownloadImages()
Returns whether images are downloaded automatically.- Returns:
trueif image downloading is enabled;falseotherwise
-
setDownloadImages
public HtmlUnitDriverOptions setDownloadImages(boolean downloadImages)
Enables or disables automatic image downloading.- Parameters:
downloadImages-trueto download images;falseotherwise- Returns:
- this options instance
-
getWebClientVersion
public BrowserVersion getWebClientVersion()
Returns the configuredBrowserVersionused by the underlying WebClient.- Returns:
- the current web client browser version
-
setWebClientVersion
public HtmlUnitDriverOptions setWebClientVersion(BrowserVersion webClientVersion)
Sets theBrowserVersionused by the underlying WebClient.- Parameters:
webClientVersion- the browser version to use- Returns:
- this options instance
- Throws:
NullPointerException- ifwebClientVersionisnull
-
setSSLClientCertificateKeyStore
public HtmlUnitDriverOptions setSSLClientCertificateKeyStore(KeyStore keyStore, char[] keyStorePassword)
Sets the SSL client certificate key store from an existingKeyStore.- Parameters:
keyStore- the key store containing the client certificatekeyStorePassword- the password for the key store- Returns:
- this options instance
-
setSSLClientCertificateKeyStore
public HtmlUnitDriverOptions setSSLClientCertificateKeyStore(URL keyStoreUrl, String keyStorePassword, String keyStoreType)
Sets the SSL client certificate key store using a URL.- Parameters:
keyStoreUrl- the URL to the key storekeyStorePassword- the key store passwordkeyStoreType- the key store type (e.g.,"PKCS12")- Returns:
- this options instance
- Throws:
NullPointerException- ifkeyStoreUrlisnull
-
setSSLClientCertificateKeyStore
public HtmlUnitDriverOptions setSSLClientCertificateKeyStore(InputStream keyStoreInputStream, String keyStorePassword, String keyStoreType)
Sets the SSL client certificate key store from anInputStream.- Parameters:
keyStoreInputStream- the input stream providing the key storekeyStorePassword- the key store passwordkeyStoreType- the key store type (e.g.,"PKCS12")- Returns:
- this options instance
-
setSSLTrustStore
public HtmlUnitDriverOptions setSSLTrustStore(URL sslTrustStoreUrl, String sslTrustStorePassword, String sslTrustStoreType)
Sets the SSL trust store using a URL.- Parameters:
sslTrustStoreUrl- the URL to the trust storesslTrustStorePassword- the trust store passwordsslTrustStoreType- the trust store type (e.g.,"JKS")- Returns:
- this options instance
- Throws:
NullPointerException- ifsslTrustStoreUrlisnull
-
-