Class SeleniumVirtualUser
- java.lang.Object
-
- com.facilita.fc.runtime.VirtualUser
-
- com.facilita.fc.selenium.SeleniumVirtualUser
-
- All Implemented Interfaces:
com.facilita.fc.runtime.Commands,DataDictionary,com.facilita.fc.runtime.IMonitoredVU,SeleniumVirtualUserInterface,java.lang.Runnable
public class SeleniumVirtualUser extends VirtualUser implements SeleniumVirtualUserInterface
A Selenium Virtual User.Each Selenium Virtual User provides access to a single
WebDriverinstance. TheWebDriverinstance could drive a real browser (e.g. Firefox, Internet Explorer, Chrome), or the headless HtmlUnit browser.The user can set the type of
WebDriverby callinginitialiseWebDriver(WebDriverType)
-
-
Constructor Summary
Constructors Constructor Description SeleniumVirtualUser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JavascriptExecutorgetJavascriptExecutor()Get aJavascriptExecutorfor thisSeleniumVirtualUserWebDrivergetUnderlyingWebDriver()Get the underlyingWebDriverinstance for thisSeleniumVirtualUser.WebDrivergetWebDriver()Get theWebDriverinstance for thisSeleniumVirtualUser.voidinitialiseChromeDriver(java.lang.String pathToChromeDriver)Create a newChromeDriverinstance for thisSeleniumVirtualUser.voidinitialiseFirefoxDriver()Create a newFirefoxDriverinstance for thisSeleniumVirtualUser.voidinitialiseHtmlUnitDriver()Create a newHtmlUnitDriverinstance for thisSeleniumVirtualUser.voidinitialiseHtmlUnitDriver(com.gargoylesoftware.htmlunit.BrowserVersion browserVersion)Create a newHtmlUnitDriverinstance for thisSeleniumVirtualUser, impersonating theBrowserVersionspecified.voidinitialiseInternetExplorerDriver(java.lang.String pathToIEDriverServer)Create a newInternetExplorerDriverinstance for thisSeleniumVirtualUser.voidinitialisePhantomJSDriver(java.lang.String pathToPhantomJSExe)Create a newPhantomJSDriverinstance for thisSeleniumVirtualUser.voidinitialiseWebDriver(WebDriverType driverType)Create a newWebDriverinstance for thisSeleniumVirtualUser.voidinitialiseWebDriver(WebDriver driver)Create a newWebDriverinstance for thisSeleniumVirtualUser.protected voidpost()This method is called after all scripts have finished executing.voidpre()This method is called before any scripts are executed.-
Methods inherited from class com.facilita.fc.runtime.VirtualUser
add, atEndOfIteration, atStartOfIteration, attachLogMessageSender, clearProgressPoint, createBackgroundScript, createMonitorSnapshot, endRequest, endRequest, endRequest, endTiming, endTiming, endTiming, endTransaction, endTransaction, endTransaction, endTransaction, error, error, error, error, error, executeCommand, executeCommand, exitVU, exitVU, exitVU, fail, failAction, failTiming, failTiming, failTransaction, failTransaction, failTransaction, finalSequence, finishIterating, finishIteratingRequested, flushEventLog, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, formatDateTime, get, get, getBackgroundScriptIDs, getBackgroundScriptStatus, getBoolean, getBoolean, getContextState, getCurrentIteration, getCurrentScript, getCurrentTimeInXml, getCurrentTransaction, getDataDictionary, getDataDictionary, getDataPath, getDataTable, getDouble, getDouble, getElapsedTime, getFilesDataPath, getFloat, getFloat, getGroupSize, getGroupSize, getGroupSizes, getIndex, getIndexForEngineGroup, getInitialDelay, getInjectorFamilyName, getInjectorName, getInt, getInt, getInteger, getInteger, getIteration, getIterationDelay, getIterationForTime, getJmeterTestPlanName, getLastError, getLastTransaction, getList, getList, getLong, getLong, getMap, getMaxFailures, getMillisecondsSinceEpoch, getMillisecondsSinceEpoch, getName, getNumberOfErrors, getNumberOfFailures, getNumberOfIterations, getNumberOfWarmupIterations, getNumberOfWarnings, getPauseFactor, getProgressPoint, getRunPath, getSandboxPath, getSecondsSinceEpoch, getSecondsSinceEpoch, getService, getServices, getStartTime, getStartTimeSeconds, getString, getString, getTimingElapsedTime, getTimingElapsedTime, getTransactionData, getTransactionElapsedTime, getTransactionElapsedTime, getTransactionElapsedTime, getTransactionLoggingOn, getUniqueID, getUniqueID, getVUName, hasKey, isDebugMode, isFinalScript, isFirstScript, isInitialScript, isIteratedScript, isLastIteration, isPacing, isReadOnly, keys, lastIterationDelay, logCurrentDataValues, nextIteration, nextScript, nextSequence, nowSeconds, onDataDictionaryChanged, onEndTiming, onEndTransaction, onError, onException, onExitVU, onRaiseAlert, onResumeTransaction, onSetProgressPoint, onStartFinalSection, onStartInitialSection, onStartTiming, onStartTransaction, onSuspendTransaction, onWarn, onWriteMessage, openEventLog, pause, pause, pause, pause, raiseAlert, recordMetric, recordMetric, recordMetrics, recordMetrics, recordTransaction, recordTransaction, recordTransaction, recordTransaction, recordTransaction, recordTransaction, requestToStopBackgroundScript, resumeBackgroundScript, resumeTransaction, resumeTransaction, resumeTransaction, run, runAsBackgroundThread, selectRandomEntryFromList, set, setBoolean, setDebugMode, setDouble, setFloat, setInt, setInteger, setList, setLong, setName, setNumberOfWarmupIterations, setPauseFactor, setProgressPoint, setProgressPoint, setProgressPoint, setProgressPoint, setString, setSynchronizationPoint, setTransactionLoggingOn, setup, startBackgroundScript, startCustomVUWatcher, startRequest, startRequest, startTiming, startTransaction, startTransaction, startTransaction, stopBackgroundScriptImmediately, stopCustomVUWatcher, suspendBackgroundScript, suspendTransaction, suspendTransaction, suspendTransaction, timeToPause, toString, unsetSynchronizationPoint, verify, verifyEQ, verifyEQ, verifyEQ, verifyEQ, verifyLE, verifyLE, verifyLE, verifyLE, verifyLT, verifyLT, verifyLT, verifyLT, waitFor, waitForBackgroundScriptToFinish, waitForBoolean, waitForDouble, waitForFloat, waitForInt, waitForList, waitForLong, waitForString, waitForSynchronizationPoint, warn, warn, warn, warn, writeMessage, writeMessage, writeMessage, writeMessage, writeSystemLog, writeSystemLog
-
-
-
-
Method Detail
-
pre
public void pre() throws java.lang.ExceptionDescription copied from class:VirtualUserThis method is called before any scripts are executed.Override this method in your custom Virtual User if you have code which should be run only once, before any scripts are executed.
This method initialises logging systems. If you override this method in a custom Virtual User, then a call to
super.pre()must be made and must occur before any code that may cause an exception or write to a log.- Overrides:
prein classVirtualUser- Throws:
java.lang.Exception- An error occurred
-
post
protected void post() throws java.lang.ExceptionDescription copied from class:VirtualUserThis method is called after all scripts have finished executing.Override this method in your custom Virtual User if you have code which should be run only once, after all scripts have finished executing.
This method shuts down logging systems. If you override this method in a custom Virtual User, then a call to
super.post()must be made at the end of the method. All exceptions thrown during the execution of this method must be caught and handled.- Overrides:
postin classVirtualUser- Throws:
java.lang.Exception- An error occurred
-
initialiseHtmlUnitDriver
public void initialiseHtmlUnitDriver() throws java.lang.ExceptionDescription copied from interface:SeleniumVirtualUserInterfaceCreate a newHtmlUnitDriverinstance for thisSeleniumVirtualUser.The
HtmlUnitDriverwill be set to use the defaultBrowserVersion. If you need to impersonate a differentBrowserVersionthen you can callSeleniumVirtualUserInterface.initialiseHtmlUnitDriver(BrowserVersion)instead.Typically, this method is called from the
VirtualUser.pre()method.- Specified by:
initialiseHtmlUnitDriverin interfaceSeleniumVirtualUserInterface- Throws:
java.lang.Exception- An error occurred
-
initialiseHtmlUnitDriver
public void initialiseHtmlUnitDriver(com.gargoylesoftware.htmlunit.BrowserVersion browserVersion) throws java.lang.ExceptionDescription copied from interface:SeleniumVirtualUserInterfaceCreate a newHtmlUnitDriverinstance for thisSeleniumVirtualUser, impersonating theBrowserVersionspecified.Typically, this method is called from the
VirtualUser.pre()method.- Specified by:
initialiseHtmlUnitDriverin interfaceSeleniumVirtualUserInterface- Parameters:
browserVersion- TheBrowserVersionto impersonate.- Throws:
java.lang.Exception- An error occurred
-
initialiseFirefoxDriver
public void initialiseFirefoxDriver() throws java.lang.ExceptionDescription copied from interface:SeleniumVirtualUserInterfaceCreate a newFirefoxDriverinstance for thisSeleniumVirtualUser.Typically, this method is called from the
VirtualUser.pre()method.- Specified by:
initialiseFirefoxDriverin interfaceSeleniumVirtualUserInterface- Throws:
java.lang.Exception- An error occurred
-
initialiseInternetExplorerDriver
public void initialiseInternetExplorerDriver(java.lang.String pathToIEDriverServer) throws java.lang.ExceptionDescription copied from interface:SeleniumVirtualUserInterfaceCreate a newInternetExplorerDriverinstance for thisSeleniumVirtualUser.In order to use the
InternetExplorerDriver, you need to install the IE driver server (IEDriverServer.exe) on each injector in your test. You must then pass the full path of the driver server to this method, e.g:
For more information on setting up the IE driver server, please refer to the documentation on the selenium website.initialiseInternetExplorerDriver("C:/tools/SeleniumDrivers/IEDriverServer.exe");Typically, this method is called from the
VirtualUser.pre()method.- Specified by:
initialiseInternetExplorerDriverin interfaceSeleniumVirtualUserInterface- Parameters:
pathToIEDriverServer- The full path to the IE driver server on the injector.- Throws:
java.lang.Exception- An error occurred
-
initialiseChromeDriver
public void initialiseChromeDriver(java.lang.String pathToChromeDriver) throws java.lang.ExceptionDescription copied from interface:SeleniumVirtualUserInterfaceCreate a newChromeDriverinstance for thisSeleniumVirtualUser.In order to use the
ChromeDriver, you need to install the chrome driver server (chromedriver.exe) on each injector in your test. You must then pass the full path of the driver server to this method, e.g:
For more information on setting up the chrome driver server, please refer to the documentation on the selenium website.initialiseChromeDriver("C:/tools/SeleniumDrivers/chromedriver.exe");Typically, this method is called from the
VirtualUser.pre()method.- Specified by:
initialiseChromeDriverin interfaceSeleniumVirtualUserInterface- Parameters:
pathToChromeDriver- The full path to the chrome driver server on the injector.- Throws:
java.lang.Exception- An error occurred
-
initialisePhantomJSDriver
public void initialisePhantomJSDriver(java.lang.String pathToPhantomJSExe) throws java.lang.ExceptionDescription copied from interface:SeleniumVirtualUserInterfaceCreate a newPhantomJSDriverinstance for thisSeleniumVirtualUser.In order to use the
PhantomJSDriver, you need to install the PhantomJS on each injector in your test. You must then pass the full path ofphantomjs.exeto this method, e.g:
For more information on PhantomJS, please refer to the PhantomJS website.initialisePhantomJSDriver("C:/tools/phantomjs-1.9.7-windows/phantomjs.exe");Typically, this method is called from the
VirtualUser.pre()method.- Specified by:
initialisePhantomJSDriverin interfaceSeleniumVirtualUserInterface- Parameters:
pathToPhantomJSExe- The full path ofphantomjs.exe- Throws:
java.lang.Exception- An error occurred
-
initialiseWebDriver
public void initialiseWebDriver(WebDriver driver) throws java.lang.Exception
Description copied from interface:SeleniumVirtualUserInterfaceCreate a newWebDriverinstance for thisSeleniumVirtualUser.This method provides a way to alter the type of
WebDriverfor this Virtual User.- Specified by:
initialiseWebDriverin interfaceSeleniumVirtualUserInterface- Parameters:
driver- The type ofWebDriverto be used by this Virtual User- Throws:
java.lang.Exception- An error occurred
-
initialiseWebDriver
public void initialiseWebDriver(WebDriverType driverType) throws java.lang.Exception
Description copied from interface:SeleniumVirtualUserInterfaceCreate a newWebDriverinstance for thisSeleniumVirtualUser.This method provides a way to alter the type of
WebDriverfor this Virtual User. Valid driver types are as follows:- HtmlUnit
- FireFox
- Chrome
- InternetExplorer
- PhantomJS
e.g.
// Create a new FirefoxDriver for this Virtual User initialiseWebDriver(WebDriverType.FireFox);- Specified by:
initialiseWebDriverin interfaceSeleniumVirtualUserInterface- Parameters:
driverType- The web driver type to create- Throws:
java.lang.Exception- An error occurred
-
getWebDriver
public WebDriver getWebDriver()
Description copied from interface:SeleniumVirtualUserInterfaceGet theWebDriverinstance for thisSeleniumVirtualUser.- Specified by:
getWebDriverin interfaceSeleniumVirtualUserInterface- Returns:
- The
WebDriverinstance for thisSeleniumVirtualUser.
-
getJavascriptExecutor
public JavascriptExecutor getJavascriptExecutor()
Description copied from interface:SeleniumVirtualUserInterfaceGet aJavascriptExecutorfor thisSeleniumVirtualUser- Specified by:
getJavascriptExecutorin interfaceSeleniumVirtualUserInterface- Returns:
- A
JavascriptExecutorfor thisSeleniumVirtualUser
-
getUnderlyingWebDriver
public WebDriver getUnderlyingWebDriver()
Description copied from interface:SeleniumVirtualUserInterfaceGet the underlyingWebDriverinstance for thisSeleniumVirtualUser.This is useful if you need to call a method that is specific to the
WebDrivertype that you are using. For example, if you are using theHtmlUnitDriver, you could use this method to call thesetJavascriptEnabledmethod:HtmlUnitDriver htmlUnitDriver = (HtmlUnitDriver)getUnderlyingWebDriver(); htmlUnitDriver.setJavascriptEnabled(false);- Specified by:
getUnderlyingWebDriverin interfaceSeleniumVirtualUserInterface- Returns:
- The underlying
WebDriverinstance for thisSeleniumVirtualUser.
-
-