Interface ActionComposer

All Superinterfaces:
DynamicActionSequence, Prioritized, Runnable
All Known Implementing Classes:
AbstractActionComposer, BasicActionComposer

public interface ActionComposer extends Runnable, Prioritized, DynamicActionSequence
ActionComposer is responsible to maintain a sequence of actions, arrange them to be executed and track their execution result. If any executed action fails, ActionComposer should mark itself failed as well.

ActionComposer also works as a context across actions. It provides some methods to keep information of windows and variables for these actions to use.

Author:
Kimberly
  • Method Details

    • getName

      String getName()
      Get the name of this ActionComposer.
      Returns:
      name represented by String
    • setName

      ActionComposer setName(String name)
      Set the name of this ActionComposer.
      Parameters:
      name - name
      Returns:
      self reference
    • setActionRunner

      ActionComposer setActionRunner(ActionRunner actionRunner)
      Set associated ActionRunner.
      Parameters:
      actionRunner - action runner to set
      Returns:
      self reference
    • registerWindow

      boolean registerWindow(String name, String windowIdentity)
      Register a window to keep window identity.
      Parameters:
      name - register name
      windowIdentity - window identity
      Returns:
      true if register name is not null and window identity are not empty and the register name isn't registered; false otherwise
    • getRegisteredWindow

      String getRegisteredWindow(String registerName)
      Get registered window by given name.
      Parameters:
      registerName - register name of window
      Returns:
      window identity
    • getRegisteredWindows

      Map<String,String> getRegisteredWindows()
      Get all registered windows.
      Returns:
      all registered windows represented by Map (register name paire with window identity)
    • getVariable

      Object getVariable(String variableName)
      Get the value of specified variable.
      Parameters:
      variableName - variable name
      Returns:
      variable value
    • setVariable

      ActionComposer setVariable(String variableName, Object value)
      Set variable value.
      Parameters:
      variableName - variable name
      value - variable value
      Returns:
      self reference
    • callBrowser

      CompletableFuture<Void> callBrowser(Runnable runnable)
      Delegate the execution of Runnable to associated ActionRunner with this ActionComposer's priority.
      Parameters:
      runnable - the object whose run method will be invoked
      Returns:
      a CompletableFuture representing pending completion of given Runnable
    • perform

      void perform(Composable action)
      Perform action. Any Composable should be performed by this method.
      Parameters:
      action - action to perform
    • getRootWindow

      String getRootWindow()
      Get the window identity of root window.
      Returns:
      window identity represented by String
    • switchToFocusWindow

      boolean switchToFocusWindow()
      Switch browser's focus window to this ActionComposer's focus window.
      Returns:
      true if switch success; false otherwise
    • getFocusWindow

      String getFocusWindow()
      Get the window identity of focus window.
      Returns:
      window identity represented by String
    • setFocusWindow

      ActionComposer setFocusWindow(String windowIdentity)
      Set the specified window as the focus window.
      Parameters:
      windowIdentity - the window identity to set as the focus window
      Returns:
      self reference
    • switchToWindow

      boolean switchToWindow(String windowIdentity)
      Switch browser's focus window to specified window.
      Parameters:
      windowIdentity - the window identity to switch to
      Returns:
      true if switch success; false otherwise
    • switchToInnerFrame

      void switchToInnerFrame(List<org.openqa.selenium.By> frameBySequence)
      Switch to send future commands to a frame.
      Parameters:
      frameBySequence - the sequence of the frame locating mechanism
    • switchToTop

      boolean switchToTop()
      Switch the focus of future commands to either the first frame on the page, or the main document when a page contains iframes.
      Returns:
      true if switch success; false otherwise
    • isFail

      boolean isFail()
      Check if this ActionComposer has been marked as failed.
      Returns:
      true if this ActionComposer has been marked as failed; false otherwise
    • isSuccessfulDone

      boolean isSuccessfulDone()
      Check if this ActionComposer is done without being marked as failed.
      Returns:
      true if this ActionComposer is done without being marked as failed; false otherwise
    • isDone

      boolean isDone()
      Check if this ActionComposer is done.
      Returns:
      true if this ActionComposer is done; false otherwise
    • skipToFail

      void skipToFail()
      Skip the execution of remaining actions and mark this ActionComposer as failed.
    • skipToSuccess

      void skipToSuccess()
      Skip the execution of remaining actions.
    • skipped

      boolean skipped()
      Check if skipToFail() or skipToSuccess() of this ActionComposer has been invoked.
      Returns:
      true if any of both methods has been invoked; otherwise false
    • getErrors

      List<Exception> getErrors()
      Get the error list from executed actions.
      Returns:
      the error list represented as a list of Exception
    • getFailUrl

      String getFailUrl()
      Get the url of the last page when this ActionComposer is marked as failed and the flag to keep fail information is enabled.
      Returns:
      the url represented by String
    • getFailPage

      String getFailPage()
      Get the content of the last page when this ActionComposer is marked as failed and the flag to keep fail information is enabled.
      Returns:
      the content represented by String
    • keepFailInfo

      ActionComposer keepFailInfo(boolean flag)
      Enable/Disable the function of keeping fail information when this ActionComposer is marked as failed. The function of keeping fail information takes about one second to complete, however this may seem wasteful in many applications, hence this method can be used to determine keep or not.
      Parameters:
      flag - true to enable; false to disable
      Returns:
      self reference
    • onFail

      ActionComposer onFail(Consumer<ActionComposer> onFailFunc)
      Set the function to be executed when this ActionComposer is marked as failed.
      Parameters:
      onFailFunc - the function to be executed
      Returns:
      self reference
    • onSuccess

      ActionComposer onSuccess(Consumer<ActionComposer> onSuccessFunc)
      Set the function to be executed when this ActionComposer is finished without being marked as failed.
      Parameters:
      onSuccessFunc - the function to be executed
      Returns:
      self reference
    • onDone

      ActionComposer onDone(Consumer<ActionComposer> onDoneFunc)
      Set the function to be executed when this ActionComposer is done. This function is executed after fail function and success function.
      Parameters:
      onDoneFunc - the function to be executed
      Returns:
      self reference
    • actionPerformed

      Set the function to be executed after any managed action is performed.
      Parameters:
      func - the function to be executed
      Returns:
      self reference
    • actionPerforming

      Set the function to be executed when any managed action is performed.
      Parameters:
      func - the function to be executed
      Returns:
      self reference
    • getWebDriver

      org.openqa.selenium.WebDriver getWebDriver()
      Get WebDriver from associated ActionRunner. Use this with caution because the associated ActionRunner use the same WebDriver when executing browser actions, however WebDriver is not thread-safe.

      A safer way to use this is to encapsulate the process in a Runnable, or use built-in custom action, and then execute it through ActionRunner.executeAction(java.lang.Runnable, int).

      Returns:
      the WebDriver of associated ActionRunner.
    • addToHeadByContext

      DynamicActionSequence addToHeadByContext(Composable action)
      Add action to the head of the action sequence of execution context.
      Parameters:
      action - action to add
      Returns:
      execution context of actions
    • addToTailByContext

      DynamicActionSequence addToTailByContext(Composable action)
      Add action to the tail of the action sequence of execution context.
      Parameters:
      action - action to add
      Returns:
      execution context of actions
    • addToPositionByContext

      DynamicActionSequence addToPositionByContext(Composable action, int position)
      Add action to specified position of the action sequence of execution context.
      Parameters:
      action - action to add
      position - the position(zero-based) to add given action
      Returns:
      execution context of actions