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 Details

    • Runner

      public Runner()
      Constructor.
  • Method Details

    • setCommandLineArgs

      public void setCommandLineArgs​(String[] args)
      Set command line arguments.
      Parameters:
      args - command line arguments.
    • getCurrentTestCase

      public TestCase getCurrentTestCase()
      Description copied from interface: Context
      Get current test-case.
      Specified by:
      getCurrentTestCase in interface Context
      Returns:
      current test-case.
    • setCurrentTestCase

      public void setCurrentTestCase​(TestCase currentTestCase)
      Description copied from interface: Context
      Set current test-case.
      Specified by:
      setCurrentTestCase in interface Context
      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: Context
      Get PrintStream for logging.
      Specified by:
      getPrintStream in interface Context
      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 if getTakesScreenshot() 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: ScreenshotHandler
      Take entire page screenshot to filename. (override directory if --screenshot-dir option specified)
      Specified by:
      takeEntirePageScreenshot in interface ScreenshotHandler
      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: ScreenshotHandler
      Take screenshot to filename. (override directory if --screenshot-dir option specified)
      Specified by:
      takeScreenshot in interface ScreenshotHandler
      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: ScreenshotHandler
      Take screenshot at all commands if --screenshot-all option specified.
      Specified by:
      takeScreenshotAll in interface ScreenshotHandler
      Parameters:
      prefix - prefix name.
      index - command index.
      Returns:
      screenshot image path.
    • takeScreenshotOnFail

      public String takeScreenshotOnFail​(String prefix, int index)
      Description copied from interface: ScreenshotHandler
      Take screenshot on fail commands if --screenshot-on-fail option specified.
      Specified by:
      takeScreenshotOnFail in interface ScreenshotHandler
      Parameters:
      prefix - prefix name.
      index - command index.
      Returns:
      screenshot image path.
    • getWrappedDriver

      public org.openqa.selenium.WebDriver getWrappedDriver()
      Specified by:
      getWrappedDriver in interface org.openqa.selenium.WrapsDriver
    • getInitialWindowHandle

      public String getInitialWindowHandle()
      Description copied from interface: Context
      Get initial window handle.
      Specified by:
      getInitialWindowHandle in interface Context
      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: Context
      Prepare WebDriver.
      Specified by:
      prepareWebDriver in interface Context
    • setWebDriverPreparator

      public void setWebDriverPreparator​(WebDriverPreparator preparator)
      Set WebDriverPreparator.
      Parameters:
      preparator - WebDriverPreparator.
    • getBrowserName

      public String getBrowserName()
      Description copied from interface: Context
      Get browser name.
      Specified by:
      getBrowserName in interface Context
      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: Context
      Get current base URL.
      Specified by:
      getCurrentBaseURL in interface Context
      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: Context
      Get base URL for overriding test-case base URL.
      Specified by:
      getOverridingBaseURL in interface Context
      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: ScreenshotHandler
      Get ignore screenshot command flag.
      Specified by:
      isIgnoredScreenshotCommand in interface ScreenshotHandler
      Returns:
      flag to ignore "captureEntirePageScreenshot"
    • isHighlight

      public boolean isHighlight()
      Description copied from interface: HighlightHandler
      Get locator highlighting.
      Specified by:
      isHighlight in interface HighlightHandler
      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: Context
      Get interactive.
      Specified by:
      isInteractive in interface Context
      Returns:
      interactive.
    • isW3cAction

      public boolean isW3cAction()
      Description copied from interface: Context
      Is Action command W3C compatible?
      Specified by:
      isW3cAction in interface Context
      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: Context
      Get next native alert action.
      Specified by:
      getNextNativeAlertActionListener in interface Context
      Returns:
      next native alert state
    • setInteractive

      @Deprecated 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: Context
      Get timeout for waiting. (ms)
      Specified by:
      getTimeout in interface Context
      Returns:
      timeout for waiting.
    • setTimeout

      public void setTimeout​(int timeout)
      Description copied from interface: Context
      Set timeout for waiting. (ms)
      Specified by:
      setTimeout in interface Context
      Parameters:
      timeout - for waiting.
    • resetRetries

      public void resetRetries()
      Description copied from interface: Context
      Reset number of actually used retries.
      Specified by:
      resetRetries in interface Context
    • incrementRetries

      public void incrementRetries()
      Description copied from interface: Context
      Increment number of actually used retries.
      Specified by:
      incrementRetries in interface Context
    • hasReachedMaxRetries

      public boolean hasReachedMaxRetries()
      Description copied from interface: Context
      True if number of actually used retries has reached maximum number of retries.
      Specified by:
      hasReachedMaxRetries in interface Context
      Returns:
      true if retries has reached max retries.
    • getRetries

      public int getRetries()
      Description copied from interface: Context
      Get number of actually used retries.
      Specified by:
      getRetries in interface Context
      Returns:
      number of actually used retries.
    • getMaxRetries

      public int getMaxRetries()
      Description copied from interface: Context
      Get maximum number of retries allowed for a given test.
      Specified by:
      getMaxRetries in interface Context
      Returns:
      the maximum number of retries allowed for a given test.
    • setMaxRetries

      public void setMaxRetries​(int maxRetries)
      Description copied from interface: Context
      Set the maximum number of retries allowed for a given test.
      Specified by:
      setMaxRetries in interface Context
      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: Context
      Reset speed as initial speed.
      Specified by:
      resetSpeed in interface Context
    • getSpeed

      public long getSpeed()
      Description copied from interface: Context
      Get speed for setSpeed command.
      Specified by:
      getSpeed in interface Context
      Returns:
      speed.
    • setSpeed

      public void setSpeed​(long speed)
      Description copied from interface: Context
      Set speed for setSpeed command.
      Specified by:
      setSpeed in interface Context
      Parameters:
      speed - speed.
    • waitSpeed

      public void waitSpeed()
      Description copied from interface: Context
      Wait according to speed setting.
      Specified by:
      waitSpeed in interface Context
    • getSubCommandMap

      public SubCommandMap getSubCommandMap()
      Description copied from interface: SubCommandMapProvider
      Get SubCommandMap instance.
      Specified by:
      getSubCommandMap in interface SubCommandMapProvider
      Returns:
      SubCommandMap instance.
    • getCommandFactory

      public CommandFactory getCommandFactory()
      Description copied from interface: Context
      Get CommandFactory instance.
      Specified by:
      getCommandFactory in interface Context
      Returns:
      CommandFactory instance.
    • getCommandListIterator

      public CommandListIterator getCommandListIterator()
      Description copied from interface: Context
      Get current CommandListIterator.
      Specified by:
      getCommandListIterator in interface Context
      Returns:
      current CommanListIterator.
    • pushCommandListIterator

      public void pushCommandListIterator​(CommandListIterator commandListIterator)
      Description copied from interface: Context
      Push CommandListIterator.
      Specified by:
      pushCommandListIterator in interface Context
      Parameters:
      commandListIterator - CommanListIterator.
    • popCommandListIterator

      public void popCommandListIterator()
      Description copied from interface: Context
      Pop CommandListIterator.
      Specified by:
      popCommandListIterator in interface Context
    • getVarsMap

      public VarsMap getVarsMap()
      Description copied from interface: Context
      Get variables map.
      Specified by:
      getVarsMap in interface Context
      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: Context
      Get test-case map.
      Specified by:
      getTestCaseMap in interface Context
      Returns:
      test-case map.
    • setTestCaseMap

      public void setTestCaseMap​(TestCaseMap testCaseMap)
      Description copied from interface: Context
      Set test-case map.
      Specified by:
      setTestCaseMap in interface Context
      Parameters:
      testCaseMap - test-case map.
    • getFlowControlState

      public <T extends FlowControlState> T getFlowControlState​(ICommand command)
      Description copied from interface: Context
      Get flow control state.
      Specified by:
      getFlowControlState in interface Context
      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: Context
      Set flow control state.
      Specified by:
      setFlowControlState in interface Context
      Type Parameters:
      T - the class implements FlowControlState.
      Parameters:
      command - flow control command.
      state - flow control state.
    • getCollectionMap

      public CollectionMap getCollectionMap()
      Description copied from interface: Context
      Get collection map.
      Specified by:
      getCollectionMap in interface Context
      Returns:
      CollectionMap.
    • getRollupRules

      public RollupRules getRollupRules()
      Description copied from interface: Context
      Get rollup rules.
      Specified by:
      getRollupRules in interface Context
      Returns:
      RollupRules object.
    • getEval

      public Eval getEval()
      Description copied from interface: Context
      Get evaluater.
      Specified by:
      getEval in interface Context
      Returns:
      eval object.
    • getElementFinder

      public WebDriverElementFinder getElementFinder()
      Description copied from interface: Context
      Get elemnt finder.
      Specified by:
      getElementFinder in interface Context
      Returns:
      element finder.
    • getLatestPageInformation

      public PageInformation getLatestPageInformation()
      Description copied from interface: Context
      Get latest page information.
      Specified by:
      getLatestPageInformation in interface Context
      Returns:
      page information.
    • setLatestPageInformation

      public void setLatestPageInformation​(PageInformation pageInformation)
      Description copied from interface: Context
      Set latest page information.
      Specified by:
      setLatestPageInformation in interface Context
      Parameters:
      pageInformation - page information.
    • getLogFilter

      public EnumSet<LogFilter> getLogFilter()
      Description copied from interface: Context
      Get list of disabled page information.
      Specified by:
      getLogFilter in interface Context
      Returns:
      list of disabled page information.
    • getCookieFilter

      public CookieFilter getCookieFilter()
      Description copied from interface: Context
      Get cookie filter.
      Specified by:
      getCookieFilter in interface Context
      Returns:
      cookie filter.
    • setCookieFilter

      public void setCookieFilter​(CookieFilter cookieFilter)
      Description copied from interface: Context
      Set cookie filter.
      Specified by:
      setCookieFilter in interface Context
      Parameters:
      cookieFilter - cookie filter.
    • getJSLibrary

      public JSLibrary getJSLibrary()
      Description copied from interface: Context
      Get JavaScript library handler.
      Specified by:
      getJSLibrary in interface Context
      Returns:
      JavaScript library handler.
    • setJSLibrary

      public void setJSLibrary​(JSLibrary jsLibrary)
      Description copied from interface: Context
      Set JavaScript library handler.
      Specified by:
      setJSLibrary in interface Context
      Parameters:
      jsLibrary - JavaScript library handler.
    • getModifierKeyState

      public ModifierKeyState getModifierKeyState()
      Description copied from interface: Context
      Get modifier key state.
      Specified by:
      getModifierKeyState in interface Context
      Returns:
      modifier key state.
    • resetState

      public void resetState()
      Description copied from interface: Context
      Reset internal state.
      Specified by:
      resetState in interface Context
    • 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: Context
      Get boolean value of expr.
      Specified by:
      isTrue in interface Context
      Parameters:
      expr - expression.
      Returns:
      cast from result of expr to Javascript Boolean.
    • 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: JUnitResultHolder
      Get JUnit result instance.
      Specified by:
      getJUnitResult in interface JUnitResultHolder
      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: HtmlResultHolder
      Get HTML result instance.
      Specified by:
      getHtmlResult in interface HtmlResultHolder
      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: HighlightHandler
      Highlight and backup specified locator.
      Specified by:
      highlight in interface HighlightHandler
      Parameters:
      ploc - parsed locator.
      highlightStyle - highlight style.
    • unhighlight

      public void unhighlight()
      Description copied from interface: HighlightHandler
      Unhighlight backed up styles.
      Specified by:
      unhighlight in interface HighlightHandler
    • setupMaxTimeTimer

      public void setupMaxTimeTimer​(long maxTime)
      Description copied from interface: Context
      Setup MaxTimeActiveTimer.
      Specified by:
      setupMaxTimeTimer in interface Context
      Parameters:
      maxTime - the maxTime in milliseconds.
    • isReplaceAlertMethod

      public boolean isReplaceAlertMethod()
      Description copied from interface: Context
      Return whether to replace alert methods.
      Specified by:
      isReplaceAlertMethod in interface Context
      Returns:
      true to replace alert method, false otherwise.
    • setReplaceAlertMethod

      public void setReplaceAlertMethod​(boolean replaceAlertMethod)
      Set whether to repalce alert methods.
      Parameters:
      replaceAlertMethod - replace alert methods or not.
    • getInteractiveModeHandler

      public InteractiveModeHandler getInteractiveModeHandler()
      Description copied from interface: Context
      Get interactive mode handler.
      Specified by:
      getInteractiveModeHandler in interface Context
      Returns:
      interactive mode handler.
    • setInteractiveMode

      public void setInteractiveMode​(InteractiveModeHandler interactiveModeHandler)
      Set interactive mode handler.
      Parameters:
      interactiveModeHandler - interactive mode handler.