public class RemoteDriver
extends org.openqa.selenium.remote.RemoteWebDriver
implements org.openqa.selenium.TakesScreenshot
RemoteDriver.SessionInfo
.Modifier and Type | Class and Description |
---|---|
static class |
RemoteDriver.SessionInfo
This class contains information for reconnecting a session.
The session info string contains some fields separated by SPLITTER The current format of the session info string is as below: |
org.openqa.selenium.remote.RemoteWebDriver.RemoteTargetLocator, org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriverOptions, org.openqa.selenium.remote.RemoteWebDriver.When
org.openqa.selenium.WebDriver.ImeHandler, org.openqa.selenium.WebDriver.Navigation, org.openqa.selenium.WebDriver.Options, org.openqa.selenium.WebDriver.TargetLocator, org.openqa.selenium.WebDriver.Timeouts, org.openqa.selenium.WebDriver.Window
Modifier and Type | Field and Description |
---|---|
protected org.openqa.selenium.Capabilities |
capabilities
In superclass RemoteWebDriver, there is a private field named 'capabilities', which is set in the method
RemoteWebDriver.startSession(Capabilities, Capabilities) ; But this RemoteWebDriver.startSession(Capabilities, Capabilities) has been
overridden in this class. |
static java.lang.String |
CAPABILITY_ID
"ID"
|
static java.lang.String |
CAPABILITY_RECONNECT
"RECONNECT"
|
static java.lang.String |
CAPABILITY_REMOTESERVER
"REMOTESERVER"
|
protected static java.lang.String |
CLASSNAME_JSONHTTP_COMMANDCODEC
"org.openqa.selenium.remote.http.JsonHttpCommandCodec"
|
protected static java.lang.String |
CLASSNAME_JSONHTTP_RESPONSECODEC
"org.openqa.selenium.remote.http.JsonHttpResponseCodec"
|
protected static java.lang.String |
CLASSNAME_W3CHTTP_COMMANDCODEC
"org.openqa.selenium.remote.http.W3CHttpCommandCodec"
|
protected static java.lang.String |
CLASSNAME_W3CHTTP_RESPONSECODEC
"org.openqa.selenium.remote.http.W3CHttpResponseCodec"
|
static java.io.File |
debugLogFile
The debug log file containing debug message when calling main() to start "selenium server".
|
static java.lang.String |
debugLogFileName |
static java.lang.String |
DEFAULT_CONNECTION_TEST_COMMAND
"getAlertText" defines the default selenium-driver-command
used to test the connection between WebDriver and BrowserDriver.
|
protected static java.util.Map<java.lang.String,org.openqa.selenium.remote.CommandExecutor> |
executorMap
Started from Selenium 3.X: A Map to store CommandExecutor, the key is sessionID.
|
protected static java.lang.String |
FIELDNAME_COMMANDCODEC
"commandCodec"
|
protected static java.lang.String |
FIELDNAME_RESPONSECODEC
"responseCodec"
|
protected boolean |
isGrid
if this is a grid-hub server
|
static java.lang.String |
JAVA_TMPDIR
"java.io.tmpdir"
|
static java.lang.String |
LAST_SESSION_KEY
"LASTSESSION"
|
static java.lang.String |
PARAM_PROJECT
"-project"
|
java.lang.String |
remote_hostname
parsed hostname of the remote selenium server (standalone or grid-hub)
might be needed for additional Selenium RMI Server communication.
|
int |
remote_port
parsed port number of the remote selenium server (standalone or grid-hub)
might be needed for get grid-node information.
|
java.net.URL |
remote_URL
The URL provided at construction time.
|
java.lang.String |
rmi_hostname
hostname of the remote grid-node.
|
int |
rmi_registry_port |
SeleniumAgent |
rmiAgent
A SeleniumRMIAgent, if enabled, to communicate with a remote SAFS Selenium RMI Server.
This may be null if we could not initialize an agent or find a server. This may also be non-null, but not connected to an RMI server if the server is not running. |
static java.lang.String |
SESSION_FILE
"selenium.session.tmp"
|
Constructor and Description |
---|
RemoteDriver(org.openqa.selenium.remote.DesiredCapabilities capabilities)
Not used by SAFS Selenium.
|
RemoteDriver(org.openqa.selenium.remote.HttpCommandExecutor command,
org.openqa.selenium.remote.DesiredCapabilities capabilities) |
RemoteDriver(java.net.URL selenium_server_url,
org.openqa.selenium.remote.DesiredCapabilities capabilities)
Connect to a remote selenium standalone server.
We will also parse the URL to attempt to connect to a SAFS Selenium RMI Server on RMI-SERVER-HOST. The RMI-SERVER-HOST can be: 1. |
Modifier and Type | Method and Description |
---|---|
static void |
deleteSessionFile() |
static void |
deleteSessionIdFromFile(java.lang.String Id)
Delete the session from the RemoteDriver file with the given Id.
|
protected org.openqa.selenium.remote.Response |
execute(java.lang.String driverCommand,
java.util.Map<java.lang.String,?> parameters) |
java.lang.Object |
executeScript(java.lang.String script,
java.lang.Object... args) |
java.lang.String |
getBrowserName() |
java.lang.String |
getBrowserVersion() |
org.openqa.selenium.Capabilities |
getCapabilities() |
java.lang.String |
getDriverVersion() |
long |
getExecutionTime(java.lang.String command,
int timeoutWaitForComponent) |
protected static org.openqa.selenium.remote.CommandExecutor |
getExecutor(java.lang.String sessionid) |
java.lang.String |
getPlatform() |
<X> X |
getScreenshotAs(org.openqa.selenium.OutputType<X> target) |
static java.io.File |
getSessionFile() |
static java.util.List<RemoteDriver.SessionInfo> |
getSessionsFromFile()
Returns a List of SessionInfo objects.
|
boolean |
hasQuit() |
protected void |
init(java.net.URL seleniumServerURL,
org.openqa.selenium.Capabilities myCapabilities)
This method will initialize some local fields:
remote_URL
newSession
capabilities
remote_hostname
rmi_hostname
This method will also store session-information into a session fileand restore session-information from a session file. |
static RemoteDriver |
instance(java.net.URL selenium_server_url,
org.openqa.selenium.remote.DesiredCapabilities capabilities)
Connect to a remote selenium standalone server.
We will also parse the URL to attempt to connect to a SAFS Selenium RMI Server on RMI-SERVER-HOST. The RMI-SERVER-HOST can be: 1. |
boolean |
isConnectionFine(java.lang.String command,
long maxDuration,
int timeoutWaitForComponent)
Test if the connection between WebDriver and the browser-driver is good enough to satisfy user's need.
|
boolean |
isLocalServer() |
boolean |
isNewSession() |
static void |
main(java.lang.String[] args)
This main method will start a Selenium Server (standalone, hub, or node).
|
protected void |
parseSeleniumServerURL(java.net.URL url)
Extract the needed remote_hostname and remote_port from the selenium server URL.
|
void |
quit() |
protected static org.openqa.selenium.remote.CommandExecutor |
removeExecutor(java.lang.String sessionid) |
static RemoteDriver.SessionInfo |
retrieveSessionInfoFromFile(java.lang.String Id)
Retrieve the remote server's session information for the session with the given id.
|
static RemoteDriver.SessionInfo |
retriveLastSessionInfoFromFile()
Retrieve SessionInfo representing the "current" or "last" session
|
static java.lang.String |
retriveSessionIdFromFile(java.lang.String Id)
Retrieve the remote server's session string for the session with the given id.
|
static void |
setLastSessionId(java.lang.String Id) |
protected void |
startRMIAgent(java.lang.String rmihost,
int rmiRegistryPort)
try to start a SAFS Selenium RMI Agent if our "selenium server" is NOT on localhost or it is a "grid hub server".
|
void |
startSession(org.openqa.selenium.Capabilities desiredCapabilities)
Called internally by OpenQA RemoteWebDriver during Constructor initialization.
NOTE: Do NOT set any local fields in this method, they will be RESET. |
protected static void |
storeExecutor(java.lang.String sessionid,
org.openqa.selenium.remote.CommandExecutor executor) |
protected void |
storeSession(java.lang.String sessionid,
org.openqa.selenium.Capabilities desiredCapabilities) |
protected void |
storeSessionIdToFile(java.lang.String serverHostname,
java.lang.String Id,
java.lang.String browserName,
java.lang.String sessionid,
org.openqa.selenium.Capabilities desiredCapabilities) |
close, execute, executeAsyncScript, findElement, findElement, findElementByClassName, findElementByCssSelector, findElementById, findElementByLinkText, findElementByName, findElementByPartialLinkText, findElementByTagName, findElementByXPath, findElements, findElements, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByLinkText, findElementsByName, findElementsByPartialLinkText, findElementsByTagName, findElementsByXPath, get, getCommandExecutor, getCurrentUrl, getElementConverter, getErrorHandler, getExecuteMethod, getFileDetector, getKeyboard, getMouse, getPageSource, getSessionId, getTitle, getW3CStandardComplianceLevel, getWindowHandle, getWindowHandles, log, manage, navigate, setCommandExecutor, setElementConverter, setErrorHandler, setFileDetector, setFoundBy, setLogLevel, setSessionId, startClient, startSession, stopClient, switchTo, toString
public java.net.URL remote_URL
public java.lang.String remote_hostname
public int remote_port
public java.lang.String rmi_hostname
public int rmi_registry_port
public SeleniumAgent rmiAgent
public static final java.lang.String LAST_SESSION_KEY
public static final java.lang.String JAVA_TMPDIR
public static final java.lang.String SESSION_FILE
public static final java.lang.String CAPABILITY_ID
public static final java.lang.String CAPABILITY_RECONNECT
public static final java.lang.String CAPABILITY_REMOTESERVER
protected boolean isGrid
protected org.openqa.selenium.Capabilities capabilities
RemoteWebDriver.startSession(Capabilities, Capabilities)
; But this RemoteWebDriver.startSession(Capabilities, Capabilities)
has been
overridden in this class. If we reconnect a session, we will not call the super.startSession() and the private field
'capabilities' will not be set.#init(Capabilities)
and it can be got by the overridden method getCapabilities()
.getCapabilities()
,
#init(Capabilities)
,
RemoteDriver(DesiredCapabilities)
,
RemoteDriver(URL, DesiredCapabilities)
protected static java.util.Map<java.lang.String,org.openqa.selenium.remote.CommandExecutor> executorMap
protected static final java.lang.String CLASSNAME_JSONHTTP_COMMANDCODEC
protected static final java.lang.String CLASSNAME_JSONHTTP_RESPONSECODEC
protected static final java.lang.String CLASSNAME_W3CHTTP_COMMANDCODEC
protected static final java.lang.String CLASSNAME_W3CHTTP_RESPONSECODEC
protected static final java.lang.String FIELDNAME_COMMANDCODEC
protected static final java.lang.String FIELDNAME_RESPONSECODEC
public static final java.lang.String DEFAULT_CONNECTION_TEST_COMMAND
public static final java.lang.String debugLogFileName
public static final java.io.File debugLogFile
public static final java.lang.String PARAM_PROJECT
public RemoteDriver(org.openqa.selenium.remote.DesiredCapabilities capabilities)
capabilities
- RemoteDriver(URL, DesiredCapabilities)
public RemoteDriver(java.net.URL selenium_server_url, org.openqa.selenium.remote.DesiredCapabilities capabilities)
selenium_server_url
- -- URL of the remote Selenium Server.
capabilities
- -- to enable the possibility of SAFS Selenium RMI Server/Agent communication
you must set a "capability" of REMOTESERVER to be the hostname of the remote selenium server.
Ex: capabilities.setCapability(RemoteDriver.CAPABILITY_REMOTESERVER, hostname);
This is done automatically within the SAFS Selenium code where needed. Only advanced users doing
custom initialization and instantiation need set this capability.
NOTE: Please call instance(URL, DesiredCapabilities)
instead. This constructor will be non-visible.
RemoteDriver(org.openqa.selenium.remote.HttpCommandExecutor command, org.openqa.selenium.remote.DesiredCapabilities capabilities)
command
- HttpCommandExecutor, the CommandExecutor used to create WebDrivercapabilities
- DesiredCapabilities, the capabilities used to create WebDriverinstance(URL, DesiredCapabilities)
public static RemoteDriver instance(java.net.URL selenium_server_url, org.openqa.selenium.remote.DesiredCapabilities capabilities)
selenium_server_url
- -- URL of the remote Selenium Server.
capabilities
- DesiredCapabilities, the capabilities used to create WebDriver.Ex: capabilities.setCapability(RemoteDriver.CAPABILITY_REMOTESERVER, hostname);
This is done automatically within the SAFS Selenium code where needed. Only advanced users doing
custom initialization and instantiation need set this capability.
To enable the possibility of control the network-conditions for chrome browser
you must set a "capability" of Constants.BrowserConstants.KEY_SET_NETWORK_CONDITIONS
to a initial network-conditions (it can be an empty string).
Ex: capabilities.setCapability(ChromeHttpCommandExecutor.SET_NETWORK_CONDITIONS, ""); Ex: capabilities.setCapability(ChromeHttpCommandExecutor.SET_NETWORK_CONDITIONS, "{"offline":false, "latency":5, "download_throughput":5000 , "upload_throughput":5000}");
public org.openqa.selenium.Capabilities getCapabilities()
getCapabilities
in interface org.openqa.selenium.HasCapabilities
getCapabilities
in class org.openqa.selenium.remote.RemoteWebDriver
protected void init(java.net.URL seleniumServerURL, org.openqa.selenium.Capabilities myCapabilities)
We will also parse the URL to attempt to connect to a SAFS Selenium RMI Server on RMI-SERVER-HOST.
The RMI-SERVER-HOST can be:
1. The same host as this Selenium Server (Standalone).
2. The node host assigned by this Selenium Server (grid-hub).
We will also try to execute special command 'setNetworkConditions' related to the chrome browser.
seleniumServerURL
- URL, the URL representing the selenium server, such as new URL("http://localhost:4444/wd/hub")myCapabilities
- Capabilities to setRemoteDriver(DesiredCapabilities)
,
RemoteDriver(URL, DesiredCapabilities)
,
instance(URL, DesiredCapabilities)
public java.lang.String getBrowserName()
public java.lang.String getBrowserVersion()
public java.lang.String getPlatform()
public java.lang.String getDriverVersion()
protected void startRMIAgent(java.lang.String rmihost, int rmiRegistryPort)
rmihost
- String, the host name of the RMI serverrmiRegistryPort
- int, the port number of the registry for looking up the RMI server, default is 1099public boolean isLocalServer()
protected void parseSeleniumServerURL(java.net.URL url)
URL
- - URL of the Selenium Server used.public void quit()
quit
in interface org.openqa.selenium.WebDriver
quit
in class org.openqa.selenium.remote.RemoteWebDriver
public boolean hasQuit()
protected static org.openqa.selenium.remote.CommandExecutor removeExecutor(java.lang.String sessionid)
protected static void storeExecutor(java.lang.String sessionid, org.openqa.selenium.remote.CommandExecutor executor)
protected static org.openqa.selenium.remote.CommandExecutor getExecutor(java.lang.String sessionid)
public void startSession(org.openqa.selenium.Capabilities desiredCapabilities)
#init(Capabilities)
. startSession
in class org.openqa.selenium.remote.RemoteWebDriver
public boolean isConnectionFine(java.lang.String command, long maxDuration, int timeoutWaitForComponent) throws SeleniumPlusException
command
- String, the selenium driver command to use to test execution timemaxDuration
- long, the maximum execution duration that user can accepttimeoutWaitForComponent
- int, the original timeout to wait for a GUI componentSeleniumPlusException
- if the parameter command is null or emptypublic long getExecutionTime(java.lang.String command, int timeoutWaitForComponent) throws SeleniumPlusException
command
- String, the selenium driver command to use to test execution timetimeoutWaitForComponent
- int, the original timeout to wait for a GUI componentSeleniumPlusException
- if the parameter command is null or emptyprotected org.openqa.selenium.remote.Response execute(java.lang.String driverCommand, java.util.Map<java.lang.String,?> parameters)
execute
in class org.openqa.selenium.remote.RemoteWebDriver
public boolean isNewSession()
public static java.io.File getSessionFile()
protected void storeSessionIdToFile(java.lang.String serverHostname, java.lang.String Id, java.lang.String browserName, java.lang.String sessionid, org.openqa.selenium.Capabilities desiredCapabilities) throws java.lang.Exception
java.lang.Exception
protected void storeSession(java.lang.String sessionid, org.openqa.selenium.Capabilities desiredCapabilities) throws java.lang.Exception
java.lang.Exception
public static void deleteSessionIdFromFile(java.lang.String Id) throws java.lang.Exception
Id
- java.lang.Exception
- if there is a problem reading or deleting the session info.public static RemoteDriver.SessionInfo retrieveSessionInfoFromFile(java.lang.String Id) throws java.lang.Exception
Id
- java.lang.Exception
public static java.lang.String retriveSessionIdFromFile(java.lang.String Id) throws java.lang.Exception
Id
- java.lang.Exception
public static void setLastSessionId(java.lang.String Id) throws java.lang.Exception
java.lang.Exception
public static RemoteDriver.SessionInfo retriveLastSessionInfoFromFile() throws java.lang.Exception
java.lang.Exception
public static java.util.List<RemoteDriver.SessionInfo> getSessionsFromFile() throws java.lang.Exception
java.lang.Exception
- if the sessions are not retrievable (do not exist).public static void deleteSessionFile()
public <X> X getScreenshotAs(org.openqa.selenium.OutputType<X> target) throws org.openqa.selenium.WebDriverException
getScreenshotAs
in interface org.openqa.selenium.TakesScreenshot
getScreenshotAs
in class org.openqa.selenium.remote.RemoteWebDriver
org.openqa.selenium.WebDriverException
public java.lang.Object executeScript(java.lang.String script, java.lang.Object... args)
executeScript
in interface org.openqa.selenium.JavascriptExecutor
executeScript
in class org.openqa.selenium.remote.RemoteWebDriver
public static void main(java.lang.String[] args)
args
- String[], it accepts following arguments:DriverConstant.SeleniumConfigConstant.DEFAULT_TIMEOUT
) in seconds before the hub automatically releases a node that hasn't received any requests for more than the specified number of seconds. Ex: "-timeout=120",
"-browserTimeout=N", optional, The timeout (default is DriverConstant.SeleniumConfigConstant.DEFAULT_BROWSER_TIMEOUT
) in seconds a node is willing to hang inside the browser. Ex: "-browserTimeout=120"
DriverConstant.SeleniumConfigConstant.PROPERTY_SELENIUMSERVER_JVM_OPTIONS
DriverConstant.SeleniumConfigConstant.PROPERTY_SELENIUMSERVER_JVM_Xms
DriverConstant.SeleniumConfigConstant.PROPERTY_SELENIUMSERVER_JVM_Xmx
DriverConstant.PROPERTY_SAFS_PROJECT_ROOT
Copyright © SAS Institute. All Rights Reserved.