Package jp.vmi.selenium.selenese
Class Runner
- java.lang.Object
-
- jp.vmi.selenium.selenese.Runner
-
- All Implemented Interfaces:
HtmlResultHolder,JUnitResultHolder,Context,HighlightHandler,ScreenshotHandler,SubCommandMapProvider,org.openqa.selenium.WrapsDriver
public class Runner extends Object implements Context, ScreenshotHandler, HighlightHandler, JUnitResultHolder, HtmlResultHolder
Provide Java API to run Selenese script.
-
-
Constructor Summary
Constructors Constructor Description Runner()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Resultexecute(Selenese selenese)Execute test-suite / test-case.voidfinish()Finish test.StringgetBrowserName()Get browser name.CollectionMapgetCollectionMap()Get collection map.CommandFactorygetCommandFactory()Get CommandFactory instance.CommandListIteratorgetCommandListIterator()Get current CommandListIterator.CookieFiltergetCookieFilter()Get cookie filter.StringgetCurrentBaseURL()Get current base URL.TestCasegetCurrentTestCase()Get current test-case.WebDriverElementFindergetElementFinder()Get elemnt finder.EvalgetEval()Get evaluater.protected FilegetFilenameForScreenshotAll(String prefix, int index)Get filename for screenshot all.protected FilegetFilenameForScreenshotOnFail(String prefix, int index)Get filename for screenshot on fail.<T extends FlowControlState>
TgetFlowControlState(ICommand command)Get flow control state.HtmlResultgetHtmlResult()Get HTML result instance.longgetInitialSpeed()Get initial speed at starting test-suite.StringgetInitialWindowHandle()Get initial window handle.JSLibrarygetJSLibrary()Get JavaScript library handler.JUnitResultgetJUnitResult()Get JUnit result instance.PageInformationgetLatestPageInformation()Get latest page information.EnumSet<LogFilter>getLogFilter()Get list of disabled page information.intgetMaxRetries()Get maximum number of retries allowed for a given test.ModifierKeyStategetModifierKeyState()Get modifier key state.AlertActionListenergetNextNativeAlertActionListener()Get next native alert action.StringgetOverridingBaseURL()Get base URL for overriding test-case base URL.PrintStreamgetPrintStream()Get PrintStream for logging.intgetRetries()Get number of actually used retries.RollupRulesgetRollupRules()Get rollup rules.longgetSpeed()Get speed for setSpeed command.SubCommandMapgetSubCommandMap()Get SubCommandMap instance.protected org.openqa.selenium.TakesScreenshotgetTakesScreenshot()Get TakesScreenshot instance.TestCaseMapgetTestCaseMap()Get test-case map.intgetTimeout()Get timeout for waiting.VarsMapgetVarsMap()Get variables map.org.openqa.selenium.WebDrivergetWrappedDriver()booleanhasReachedMaxRetries()True if number of actually used retries has reached maximum number of retries.voidhighlight(Locator ploc, HighlightStyle highlightStyle)Highlight and backup specified locator.voidincrementRetries()Increment number of actually used retries.booleanisHighlight()Get locator highlighting.booleanisIgnoredScreenshotCommand()Get ignore screenshot command flag.booleanisInteractive()Get interactive.booleanisTrue(String expr)Get boolean value of expr.booleanisW3cAction()Is Action command W3C compatible?protected FilenormalizeScreenshotFilename(String filename)Normalize filename for screenshot.voidpopCommandListIterator()Pop CommandListIterator.voidprepareWebDriver()Prepare WebDriver.voidpushCommandListIterator(CommandListIterator commandListIterator)Push CommandListIterator.voidresetRetries()Reset number of actually used retries.voidresetSpeed()Reset speed as initial speed.voidresetState()Reset internal state.Resultrun(String... filenames)Run Selenese script files.Resultrun(String filename, InputStream is)Run Selenese script from input stream.voidsetCommandLineArgs(String[] args)Set command line arguments.voidsetCookieFilter(CookieFilter cookieFilter)Set cookie filter.voidsetCurrentTestCase(TestCase currentTestCase)Set current test-case.voidsetDriver(org.openqa.selenium.WebDriver driver)Set WebDriver.<T extends FlowControlState>
voidsetFlowControlState(ICommand command, T state)Set flow control state.voidsetHighlight(boolean isHighlight)Set locator highlighting.voidsetHtmlResultDir(String dir)Initialize HTMLResult.voidsetIgnoredScreenshotCommand(boolean isIgnoredScreenshotCommand)Set ignore screenshot command flag.voidsetInitialSpeed(long initialSpeed)Set initial speed at starting test-suite.voidsetInteractive(boolean isInteractive)Set interactive.voidsetJSLibrary(JSLibrary jsLibrary)Set JavaScript library handler.voidsetJUnitResultDir(String dir)Initialize JUnitResult.voidsetLatestPageInformation(PageInformation pageInformation)Set latest page information.voidsetMaxRetries(int maxRetries)Set the maximum number of retries allowed for a given test.voidsetOverridingBaseURL(String overridingBaseURL)Set URL for overriding test-case base URL.voidsetPrintStream(PrintStream ps)Set PrintStream for logging.voidsetScreenshotAllDir(String screenshotAllDir)Set directory for storing screenshots at all commands.voidsetScreenshotDir(String screenshotDir)Set directory for storing screenshots.voidsetScreenshotOnFailDir(String screenshotOnFailDir)Set directory for storing screenshot on fail.voidsetScreenshotScrollTimeout(int timeout)Set screenshot scroll timeout.voidsetSpeed(long speed)Set speed for setSpeed command.voidsetTestCaseMap(TestCaseMap testCaseMap)Set test-case map.voidsetTimeout(int timeout)Set timeout for waiting.voidsetVarsMap(VarsMap varsMap)Set variables map used for this session.voidsetW3cAction(Boolean isW3cAction)Set W3C action compatibility.voidsetWebDriverPreparator(WebDriverPreparator preparator)Set WebDriverPreparator.StringtakeEntirePageScreenshot(String filename)Take entire page screenshot to filename.protected StringtakeScreenshot(File file, boolean entirePage)Take screenshot.StringtakeScreenshot(String filename)Take screenshot to filename.StringtakeScreenshotAll(String prefix, int index)Take screenshot at all commands if --screenshot-all option specified.StringtakeScreenshotOnFail(String prefix, int index)Take screenshot on fail commands if --screenshot-on-fail option specified.voidunhighlight()Unhighlight backed up styles.voidwaitSpeed()Wait according to speed setting.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jp.vmi.selenium.selenese.Context
executeAsyncScript, executeScript, findElement, findElements, isBrowser
-
-
-
-
Method Detail
-
setCommandLineArgs
public void setCommandLineArgs(String[] args)
Set command line arguments.- Parameters:
args- command line arguments.
-
getCurrentTestCase
public TestCase getCurrentTestCase()
Description copied from interface:ContextGet current test-case.- Specified by:
getCurrentTestCasein interfaceContext- Returns:
- current test-case.
-
setCurrentTestCase
public void setCurrentTestCase(TestCase currentTestCase)
Description copied from interface:ContextSet current test-case.- Specified by:
setCurrentTestCasein interfaceContext- Parameters:
currentTestCase- current test-case.
-
setPrintStream
public void setPrintStream(PrintStream ps)
Set PrintStream for logging.- Parameters:
ps- PrintStream for logging.
-
getPrintStream
public PrintStream getPrintStream()
Description copied from interface:ContextGet PrintStream for logging.- Specified by:
getPrintStreamin interfaceContext- Returns:
- PrintStram object.
-
getTakesScreenshot
protected org.openqa.selenium.TakesScreenshot getTakesScreenshot()
Get TakesScreenshot instance.- Returns:
- TakesScreenshot instance.
-
takeScreenshot
protected String takeScreenshot(File file, boolean entirePage) throws UnsupportedOperationException, org.openqa.selenium.WebDriverException
Take screenshot.- Parameters:
file- file instance.entirePage- true if take screenshot of entire page.- Returns:
- path of screenshot or null.
- Throws:
UnsupportedOperationException- throw this exception ifgetTakesScreenshot()returns null.org.openqa.selenium.WebDriverException- throw this exception if it fails to get the screenshot.
-
normalizeScreenshotFilename
protected File normalizeScreenshotFilename(String filename)
Normalize filename for screenshot.- Parameters:
filename- filename for screenshot.- Returns:
- normalized file instance.
-
getFilenameForScreenshotAll
protected File getFilenameForScreenshotAll(String prefix, int index)
Get filename for screenshot all.- Parameters:
prefix- filename prefix.index- filename index.- Returns:
- File instance for screenshot all.
-
getFilenameForScreenshotOnFail
protected File getFilenameForScreenshotOnFail(String prefix, int index)
Get filename for screenshot on fail.- Parameters:
prefix- filename prefix.index- filename index.- Returns:
- File instance for screenshot on fail.
-
takeEntirePageScreenshot
public String takeEntirePageScreenshot(String filename) throws org.openqa.selenium.WebDriverException, UnsupportedOperationException
Description copied from interface:ScreenshotHandlerTake entire page screenshot to filename. (override directory if --screenshot-dir option specified)- Specified by:
takeEntirePageScreenshotin interfaceScreenshotHandler- Parameters:
filename- filename.- Returns:
- screenshot image path.
- Throws:
UnsupportedOperationException- WebDriver does not supoort capturing screenshot.org.openqa.selenium.WebDriverException
-
takeScreenshot
public String takeScreenshot(String filename) throws org.openqa.selenium.WebDriverException, UnsupportedOperationException
Description copied from interface:ScreenshotHandlerTake screenshot to filename. (override directory if --screenshot-dir option specified)- Specified by:
takeScreenshotin interfaceScreenshotHandler- Parameters:
filename- filename.- Returns:
- screenshot image path.
- Throws:
UnsupportedOperationException- WebDriver does not supoort capturing screenshot.org.openqa.selenium.WebDriverException
-
takeScreenshotAll
public String takeScreenshotAll(String prefix, int index)
Description copied from interface:ScreenshotHandlerTake screenshot at all commands if --screenshot-all option specified.- Specified by:
takeScreenshotAllin interfaceScreenshotHandler- Parameters:
prefix- prefix name.index- command index.- Returns:
- screenshot image path.
-
takeScreenshotOnFail
public String takeScreenshotOnFail(String prefix, int index)
Description copied from interface:ScreenshotHandlerTake screenshot on fail commands if --screenshot-on-fail option specified.- Specified by:
takeScreenshotOnFailin interfaceScreenshotHandler- Parameters:
prefix- prefix name.index- command index.- Returns:
- screenshot image path.
-
getWrappedDriver
public org.openqa.selenium.WebDriver getWrappedDriver()
- Specified by:
getWrappedDriverin interfaceorg.openqa.selenium.WrapsDriver
-
getInitialWindowHandle
public String getInitialWindowHandle()
Description copied from interface:ContextGet initial window handle.- Specified by:
getInitialWindowHandlein interfaceContext- Returns:
- window handle.
-
setDriver
public void setDriver(org.openqa.selenium.WebDriver driver)
Set WebDriver.- Parameters:
driver- WebDriver.
-
prepareWebDriver
public void prepareWebDriver()
Description copied from interface:ContextPrepare WebDriver.- Specified by:
prepareWebDriverin interfaceContext
-
setWebDriverPreparator
public void setWebDriverPreparator(WebDriverPreparator preparator)
Set WebDriverPreparator.- Parameters:
preparator- WebDriverPreparator.
-
getBrowserName
public String getBrowserName()
Description copied from interface:ContextGet browser name.- Specified by:
getBrowserNamein interfaceContext- Returns:
- browser name.
-
setScreenshotDir
public void setScreenshotDir(String screenshotDir) throws IllegalArgumentException
Set directory for storing screenshots.- Parameters:
screenshotDir- directory.- Throws:
IllegalArgumentException- throws if screenshotDir is not directory.
-
setScreenshotAllDir
public void setScreenshotAllDir(String screenshotAllDir) throws IllegalArgumentException
Set directory for storing screenshots at all commands.- Parameters:
screenshotAllDir- directory.- Throws:
IllegalArgumentException- throws if screenshotAllDir is not directory.
-
setScreenshotOnFailDir
public void setScreenshotOnFailDir(String screenshotOnFailDir)
Set directory for storing screenshot on fail.- Parameters:
screenshotOnFailDir- directory.
-
getCurrentBaseURL
public String getCurrentBaseURL()
Description copied from interface:ContextGet current base URL.- Specified by:
getCurrentBaseURLin interfaceContext- Returns:
- base URL.
-
setOverridingBaseURL
public void setOverridingBaseURL(String overridingBaseURL)
Set URL for overriding test-case base URL.- Parameters:
overridingBaseURL- base URL.
-
getOverridingBaseURL
public String getOverridingBaseURL()
Description copied from interface:ContextGet base URL for overriding test-case base URL.- Specified by:
getOverridingBaseURLin interfaceContext- Returns:
- base URL.
-
setIgnoredScreenshotCommand
public void setIgnoredScreenshotCommand(boolean isIgnoredScreenshotCommand)
Set ignore screenshot command flag.- Parameters:
isIgnoredScreenshotCommand- set true if you want to ignore "captureEntirePageScreenshot"
-
isIgnoredScreenshotCommand
public boolean isIgnoredScreenshotCommand()
Description copied from interface:ScreenshotHandlerGet ignore screenshot command flag.- Specified by:
isIgnoredScreenshotCommandin interfaceScreenshotHandler- Returns:
- flag to ignore "captureEntirePageScreenshot"
-
isHighlight
public boolean isHighlight()
Description copied from interface:HighlightHandlerGet locator highlighting.- Specified by:
isHighlightin interfaceHighlightHandler- Returns:
- true if use locator highlighting.
-
setHighlight
public void setHighlight(boolean isHighlight)
Set locator highlighting.- Parameters:
isHighlight- true if use locator highlighting.
-
isInteractive
public boolean isInteractive()
Description copied from interface:ContextGet interactive.- Specified by:
isInteractivein interfaceContext- Returns:
- interactive.
-
isW3cAction
public boolean isW3cAction()
Description copied from interface:ContextIs Action command W3C compatible?- Specified by:
isW3cActionin interfaceContext- Returns:
- true if Action command is W3C compatible.
-
setW3cAction
public void setW3cAction(Boolean isW3cAction)
Set W3C action compatibility.- Parameters:
isW3cAction- true if Action command is W3C compatible.
-
setScreenshotScrollTimeout
public void setScreenshotScrollTimeout(int timeout)
Set screenshot scroll timeout.- Parameters:
timeout- timeout (ms)
-
getNextNativeAlertActionListener
public AlertActionListener getNextNativeAlertActionListener()
Description copied from interface:ContextGet next native alert action.- Specified by:
getNextNativeAlertActionListenerin interfaceContext- Returns:
- next native alert state
-
setInteractive
public void setInteractive(boolean isInteractive)
Set interactive.- Parameters:
isInteractive- true if Runner executes test step-by-step upon user key stroke.
-
getTimeout
public int getTimeout()
Description copied from interface:ContextGet timeout for waiting. (ms)- Specified by:
getTimeoutin interfaceContext- Returns:
- timeout for waiting.
-
setTimeout
public void setTimeout(int timeout)
Description copied from interface:ContextSet timeout for waiting. (ms)- Specified by:
setTimeoutin interfaceContext- Parameters:
timeout- for waiting.
-
resetRetries
public void resetRetries()
Description copied from interface:ContextReset number of actually used retries.- Specified by:
resetRetriesin interfaceContext
-
incrementRetries
public void incrementRetries()
Description copied from interface:ContextIncrement number of actually used retries.- Specified by:
incrementRetriesin interfaceContext
-
hasReachedMaxRetries
public boolean hasReachedMaxRetries()
Description copied from interface:ContextTrue if number of actually used retries has reached maximum number of retries.- Specified by:
hasReachedMaxRetriesin interfaceContext- Returns:
- true if retries has reached max retries.
-
getRetries
public int getRetries()
Description copied from interface:ContextGet number of actually used retries.- Specified by:
getRetriesin interfaceContext- Returns:
- number of actually used retries.
-
getMaxRetries
public int getMaxRetries()
Description copied from interface:ContextGet maximum number of retries allowed for a given test.- Specified by:
getMaxRetriesin interfaceContext- Returns:
- the maximum number of retries allowed for a given test.
-
setMaxRetries
public void setMaxRetries(int maxRetries)
Description copied from interface:ContextSet the maximum number of retries allowed for a given test.- Specified by:
setMaxRetriesin interfaceContext- Parameters:
maxRetries- the maximum number of retries allowed for a given test.
-
getInitialSpeed
public long getInitialSpeed()
Get initial speed at starting test-suite. (ms)- Returns:
- initial speed.
-
setInitialSpeed
public void setInitialSpeed(long initialSpeed)
Set initial speed at starting test-suite. (ms)- Parameters:
initialSpeed- initial speed.
-
resetSpeed
public void resetSpeed()
Description copied from interface:ContextReset speed as initial speed.- Specified by:
resetSpeedin interfaceContext
-
getSpeed
public long getSpeed()
Description copied from interface:ContextGet speed for setSpeed command.
-
setSpeed
public void setSpeed(long speed)
Description copied from interface:ContextSet speed for setSpeed command.
-
waitSpeed
public void waitSpeed()
Description copied from interface:ContextWait according to speed setting.
-
getSubCommandMap
public SubCommandMap getSubCommandMap()
Description copied from interface:SubCommandMapProviderGet SubCommandMap instance.- Specified by:
getSubCommandMapin interfaceSubCommandMapProvider- Returns:
- SubCommandMap instance.
-
getCommandFactory
public CommandFactory getCommandFactory()
Description copied from interface:ContextGet CommandFactory instance.- Specified by:
getCommandFactoryin interfaceContext- Returns:
- CommandFactory instance.
-
getCommandListIterator
public CommandListIterator getCommandListIterator()
Description copied from interface:ContextGet current CommandListIterator.- Specified by:
getCommandListIteratorin interfaceContext- Returns:
- current CommanListIterator.
-
pushCommandListIterator
public void pushCommandListIterator(CommandListIterator commandListIterator)
Description copied from interface:ContextPush CommandListIterator.- Specified by:
pushCommandListIteratorin interfaceContext- Parameters:
commandListIterator- CommanListIterator.
-
popCommandListIterator
public void popCommandListIterator()
Description copied from interface:ContextPop CommandListIterator.- Specified by:
popCommandListIteratorin interfaceContext
-
getVarsMap
public VarsMap getVarsMap()
Description copied from interface:ContextGet variables map.- Specified by:
getVarsMapin interfaceContext- Returns:
- VarsMap.
-
setVarsMap
public void setVarsMap(VarsMap varsMap)
Set variables map used for this session.- Parameters:
varsMap- the evaluated variables (state) for the current context.
-
getTestCaseMap
public TestCaseMap getTestCaseMap()
Description copied from interface:ContextGet test-case map.- Specified by:
getTestCaseMapin interfaceContext- Returns:
- test-case map.
-
setTestCaseMap
public void setTestCaseMap(TestCaseMap testCaseMap)
Description copied from interface:ContextSet test-case map.- Specified by:
setTestCaseMapin interfaceContext- Parameters:
testCaseMap- test-case map.
-
getFlowControlState
public <T extends FlowControlState> T getFlowControlState(ICommand command)
Description copied from interface:ContextGet flow control state.- Specified by:
getFlowControlStatein interfaceContext- Type Parameters:
T- the class implements FlowControlState.- Parameters:
command- flow control command.- Returns:
- flow control state.
-
setFlowControlState
public <T extends FlowControlState> void setFlowControlState(ICommand command, T state)
Description copied from interface:ContextSet flow control state.- Specified by:
setFlowControlStatein interfaceContext- Type Parameters:
T- the class implements FlowControlState.- Parameters:
command- flow control command.state- flow control state.
-
getCollectionMap
public CollectionMap getCollectionMap()
Description copied from interface:ContextGet collection map.- Specified by:
getCollectionMapin interfaceContext- Returns:
- CollectionMap.
-
getRollupRules
public RollupRules getRollupRules()
Description copied from interface:ContextGet rollup rules.- Specified by:
getRollupRulesin interfaceContext- Returns:
- RollupRules object.
-
getElementFinder
public WebDriverElementFinder getElementFinder()
Description copied from interface:ContextGet elemnt finder.- Specified by:
getElementFinderin interfaceContext- Returns:
- element finder.
-
getLatestPageInformation
public PageInformation getLatestPageInformation()
Description copied from interface:ContextGet latest page information.- Specified by:
getLatestPageInformationin interfaceContext- Returns:
- page information.
-
setLatestPageInformation
public void setLatestPageInformation(PageInformation pageInformation)
Description copied from interface:ContextSet latest page information.- Specified by:
setLatestPageInformationin interfaceContext- Parameters:
pageInformation- page information.
-
getLogFilter
public EnumSet<LogFilter> getLogFilter()
Description copied from interface:ContextGet list of disabled page information.- Specified by:
getLogFilterin interfaceContext- Returns:
- list of disabled page information.
-
getCookieFilter
public CookieFilter getCookieFilter()
Description copied from interface:ContextGet cookie filter.- Specified by:
getCookieFilterin interfaceContext- Returns:
- cookie filter.
-
setCookieFilter
public void setCookieFilter(CookieFilter cookieFilter)
Description copied from interface:ContextSet cookie filter.- Specified by:
setCookieFilterin interfaceContext- Parameters:
cookieFilter- cookie filter.
-
getJSLibrary
public JSLibrary getJSLibrary()
Description copied from interface:ContextGet JavaScript library handler.- Specified by:
getJSLibraryin interfaceContext- Returns:
- JavaScript library handler.
-
setJSLibrary
public void setJSLibrary(JSLibrary jsLibrary)
Description copied from interface:ContextSet JavaScript library handler.- Specified by:
setJSLibraryin interfaceContext- Parameters:
jsLibrary- JavaScript library handler.
-
getModifierKeyState
public ModifierKeyState getModifierKeyState()
Description copied from interface:ContextGet modifier key state.- Specified by:
getModifierKeyStatein interfaceContext- Returns:
- modifier key state.
-
resetState
public void resetState()
Description copied from interface:ContextReset internal state.- Specified by:
resetStatein interfaceContext
-
execute
public Result execute(Selenese selenese)
Execute test-suite / test-case.- Parameters:
selenese- test-suite or test-case.- Returns:
- result.
-
isTrue
public boolean isTrue(String expr)
Description copied from interface:ContextGet boolean value of expr.
-
run
public Result run(String... filenames)
Run Selenese script files.- Parameters:
filenames- Selenese script filenames.- Returns:
- result.
-
run
public Result run(String filename, InputStream is)
Run Selenese script from input stream.- Parameters:
filename- selenese script file. (not open. used for label or generating output filename)is- input stream of script file. (test-case or test-suite)- Returns:
- result.
-
setJUnitResultDir
public void setJUnitResultDir(String dir)
Initialize JUnitResult.- Parameters:
dir- JUnit result directory.
-
getJUnitResult
public JUnitResult getJUnitResult()
Description copied from interface:JUnitResultHolderGet JUnit result instance.- Specified by:
getJUnitResultin interfaceJUnitResultHolder- Returns:
- JUnit result instance.
-
setHtmlResultDir
public void setHtmlResultDir(String dir)
Initialize HTMLResult.- Parameters:
dir- HTML result directory.
-
getHtmlResult
public HtmlResult getHtmlResult()
Description copied from interface:HtmlResultHolderGet HTML result instance.- Specified by:
getHtmlResultin interfaceHtmlResultHolder- Returns:
- HTML result instance.
-
finish
public void finish()
Finish test. generate index.html for HTML result.
-
highlight
public void highlight(Locator ploc, HighlightStyle highlightStyle)
Description copied from interface:HighlightHandlerHighlight and backup specified locator.- Specified by:
highlightin interfaceHighlightHandler- Parameters:
ploc- parsed locator.highlightStyle- highlight style.
-
unhighlight
public void unhighlight()
Description copied from interface:HighlightHandlerUnhighlight backed up styles.- Specified by:
unhighlightin interfaceHighlightHandler
-
-