public class BrowserSessionFactory extends Object
Maintains a cache of unused and available browser sessions in case the server is reusing sessions. Also manages the creation and finalization of all browser sessions.
Modifier and Type | Class and Description |
---|---|
static class |
BrowserSessionFactory.BrowserSessionInfo
Collection class to hold the objects associated with a browser session.
|
protected class |
BrowserSessionFactory.CleanupTask
TimerTask that looks for unused sessions in the availableSessions collection.
|
Modifier and Type | Field and Description |
---|---|
protected Set<BrowserSessionFactory.BrowserSessionInfo> |
activeSessions |
protected Set<BrowserSessionFactory.BrowserSessionInfo> |
availableSessions |
Modifier | Constructor and Description |
---|---|
|
BrowserSessionFactory(BrowserLauncherFactory blf) |
protected |
BrowserSessionFactory(BrowserLauncherFactory blf,
long cleanupInterval,
long maxIdleSessionTime,
boolean doCleanup)
Constructor for testing purposes.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addToAvailableSessions(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
for testing only
|
protected BrowserSessionFactory.BrowserSessionInfo |
createNewRemoteSession(String browserString,
String startURL,
String extensionJs,
org.openqa.selenium.Capabilities browserConfiguration,
boolean ensureClean,
RemoteControlConfiguration configuration)
Creates and tries to open a new session.
|
protected void |
deregisterExternalSession(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
Removes a previously registered external browser session from the list of active sessions.
|
protected void |
endAllBrowserSessions(RemoteControlConfiguration configuration)
Ends all browser sessions.
|
void |
endBrowserSession(boolean forceClose,
String sessionId,
RemoteControlConfiguration configuration)
Ends a browser session, using SeleniumServer static fields to populate parameters.
|
protected void |
endBrowserSession(boolean forceClose,
String sessionId,
RemoteControlConfiguration configuration,
boolean ensureClean)
Ends a browser session.
|
void |
endBrowserSession(String sessionId,
RemoteControlConfiguration configuration)
Ends a browser session, using SeleniumServer static fields to populate parameters.
|
protected BrowserSessionFactory.BrowserSessionInfo |
getNewBrowserSession(String browserString,
String startURL,
String extensionJs,
org.openqa.selenium.Capabilities browserConfigurations,
boolean useCached,
boolean ensureClean,
RemoteControlConfiguration configuration)
Gets a new browser session
|
BrowserSessionFactory.BrowserSessionInfo |
getNewBrowserSession(String browserString,
String startURL,
String extensionJs,
org.openqa.selenium.Capabilities browserConfigurations,
RemoteControlConfiguration configuration)
Gets a new browser session, using the SeleniumServer static fields to populate parameters.
|
protected FrameGroupCommandQueueSet |
getQueueSet(String sessionId)
Isolated dependency
|
protected BrowserSessionFactory.BrowserSessionInfo |
grabAvailableSession(String browserString,
String baseUrl)
Retrieves an available, unused session from the cache.
|
protected boolean |
hasActiveSession(String sessionId)
for testing only
|
protected boolean |
hasAvailableSession(String sessionId)
for testing only
|
protected BrowserSessionFactory.BrowserSessionInfo |
lookupInfoByBrowserAndUrl(String browserString,
String baseUrl,
Set<BrowserSessionFactory.BrowserSessionInfo> set)
Looks up a session in the named set by browser string and base URL
|
protected BrowserSessionFactory.BrowserSessionInfo |
lookupInfoBySessionId(String sessionId,
Set<BrowserSessionFactory.BrowserSessionInfo> set)
Looks up a session in the named set by session id
|
protected FrameGroupCommandQueueSet |
makeQueueSet(String sessionId,
int port,
RemoteControlConfiguration configuration)
Isolated dependency
|
protected boolean |
registerExternalSession(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
Adds a browser session that was not created by this factory to the set of active sessions.
|
protected void |
removeIdleAvailableSessions() |
protected void |
shutdownBrowserAndClearSessionData(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
Shuts down this browser session's launcher and clears out its session data (if session is not
null).
|
protected final Set<BrowserSessionFactory.BrowserSessionInfo> availableSessions
protected final Set<BrowserSessionFactory.BrowserSessionInfo> activeSessions
public BrowserSessionFactory(BrowserLauncherFactory blf)
protected BrowserSessionFactory(BrowserLauncherFactory blf, long cleanupInterval, long maxIdleSessionTime, boolean doCleanup)
blf
- an injected BrowserLauncherFactory.cleanupInterval
- the time between idle available session cleaning sweeps.maxIdleSessionTime
- the max time in ms for an available session to be idle.doCleanup
- whether or not the idle session cleanup thread should run.public BrowserSessionFactory.BrowserSessionInfo getNewBrowserSession(String browserString, String startURL, String extensionJs, org.openqa.selenium.Capabilities browserConfigurations, RemoteControlConfiguration configuration) throws RemoteCommandException
browserString
- browser name stringstartURL
- starting urlextensionJs
- per-session user extension Javascriptconfiguration
- Remote Control configuration. Cannot be null.browserConfigurations
- capabilities of requested browserRemoteCommandException
- remote command exception if new session failsprotected BrowserSessionFactory.BrowserSessionInfo getNewBrowserSession(String browserString, String startURL, String extensionJs, org.openqa.selenium.Capabilities browserConfigurations, boolean useCached, boolean ensureClean, RemoteControlConfiguration configuration) throws RemoteCommandException
browserString
- browser name stringstartURL
- starting urlextensionJs
- per-session user extension Javascriptconfiguration
- Remote Control configuration. Cannot be null.useCached
- if a cached session should be used if one is availableensureClean
- if a clean session (e.g. no previous cookies) is required.browserConfigurations
- capabilities of requested browserRemoteCommandException
- remote command exception if new session failsprotected void endAllBrowserSessions(RemoteControlConfiguration configuration)
Active and available but inactive sessions are ended.
configuration
- remote control configurationpublic void endBrowserSession(String sessionId, RemoteControlConfiguration configuration)
sessionId
- the id of the session to be endedconfiguration
- Remote Control configuration. Cannot be null.public void endBrowserSession(boolean forceClose, String sessionId, RemoteControlConfiguration configuration)
forceClose
- if the session should not be reusedsessionId
- the id of the session to be endedconfiguration
- Remote Control configuration. Cannot be null.protected void endBrowserSession(boolean forceClose, String sessionId, RemoteControlConfiguration configuration, boolean ensureClean)
forceClose
- if the session should not be reusedsessionId
- the id of the session to be endedconfiguration
- Remote Control configuration. Cannot be null.ensureClean
- if clean sessions (e.g. no leftover cookies) are required.protected void shutdownBrowserAndClearSessionData(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
sessionInfo
- the browser session to end.protected BrowserSessionFactory.BrowserSessionInfo grabAvailableSession(String browserString, String baseUrl)
browserString
- the necessary browser for a suitable sessionbaseUrl
- the necessary baseUrl for a suitable sessionprotected FrameGroupCommandQueueSet makeQueueSet(String sessionId, int port, RemoteControlConfiguration configuration)
sessionId
- session idport
- portconfiguration
- Remote Control Configurationprotected FrameGroupCommandQueueSet getQueueSet(String sessionId)
sessionId
- session idprotected BrowserSessionFactory.BrowserSessionInfo createNewRemoteSession(String browserString, String startURL, String extensionJs, org.openqa.selenium.Capabilities browserConfiguration, boolean ensureClean, RemoteControlConfiguration configuration) throws RemoteCommandException
browserString
- browser name stringstartURL
- starting urlextensionJs
- per-session user extension javascriptconfiguration
- Remote Control configuration. Cannot be null.browserConfiguration
- capabilities of requested browserensureClean
- if a clean session is requiredRemoteCommandException
- if the browser failed to launch and request work in the required
amount of time.protected boolean registerExternalSession(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
Allows for creation of unmanaged sessions (i.e. no FrameGroupCommandQueueSet) for task such as running the HTML tests (see HTMLLauncher.java). All fields other than session are required to be non-null.
sessionInfo
- the session info to register.protected void deregisterExternalSession(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
sessionInfo
- the session to remove.protected BrowserSessionFactory.BrowserSessionInfo lookupInfoBySessionId(String sessionId, Set<BrowserSessionFactory.BrowserSessionInfo> set)
sessionId
- the session id to findset
- the Set to inspectprotected BrowserSessionFactory.BrowserSessionInfo lookupInfoByBrowserAndUrl(String browserString, String baseUrl, Set<BrowserSessionFactory.BrowserSessionInfo> set)
browserString
- the browser string to matchbaseUrl
- the base URL to match.set
- the Set to inspectprotected void removeIdleAvailableSessions()
protected boolean hasActiveSession(String sessionId)
sessionId
- session idprotected boolean hasAvailableSession(String sessionId)
sessionId
- session idprotected void addToAvailableSessions(BrowserSessionFactory.BrowserSessionInfo sessionInfo)
sessionInfo
- browser sesssion infoCopyright © 2015. All rights reserved.