Class MultiPhaseAction

java.lang.Object
org.kquiet.browser.action.MultiPhaseAction
All Implemented Interfaces:
Composable, MultiPhased
Direct Known Subclasses:
Click, Custom, Extract, JustWait, MouseOver, ReplyAlert, ScrollToView, Select, SendKey, SinglePhaseAction, Upload, WaitUntil

public abstract class MultiPhaseAction extends Object implements Composable, MultiPhased
MultiPhaseAction models a browser action with multiple phases which is executed through ActionComposer or ActionRunner. It will be executed for multiple times and works just like a loop. noNextPhase() needs to be invoked to signal that there is no more phase to execute.

Why multi-phase is required is because WebDriver is not thread-safe. Therefore, ActionRunner uses a single thread to control the concurrency between different brwoser actions, and the browser thread shouldn't be occupied for a long time by any single browser action.

Author:
Kimberly
  • Constructor Details

    • MultiPhaseAction

      public MultiPhaseAction()
  • Method Details

    • noNextPhase

      public void noNextPhase()
      Description copied from interface: MultiPhased
      Signals that no more phases to execute.
      Specified by:
      noNextPhase in interface MultiPhased
    • hasNextPhase

      public boolean hasNextPhase()
      Description copied from interface: MultiPhased
      Check if has next phase to execute.
      Specified by:
      hasNextPhase in interface MultiPhased
      Returns:
      true if has next phase to execute; false otherwise
    • perform

      public void perform()
      Description copied from interface: Composable
      Perform action.
      Specified by:
      perform in interface Composable
    • performMultiPhase

      protected abstract void performMultiPhase()
      Perform multiple-phased browser action. noNextPhase() needs to be invoked to signal that there is no more phase to execute.
    • isDone

      public boolean isDone()
      When the state of action is one of the following, then it's called done.
      Specified by:
      isDone in interface Composable
      Returns:
      true if the action is done; false otherwise
    • isFail

      public boolean isFail()
      When the action is marked as failed(ActionState.COMPLETE_WITH_ERROR), then it's called fail.
      Specified by:
      isFail in interface Composable
      Returns:
      true if the action is failed; false otherwise
    • getErrors

      public List<Exception> getErrors()
      Description copied from interface: Composable
      Get the errors occurred during execution.
      Specified by:
      getErrors in interface Composable
      Returns:
      the errors as a list of Exception
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getCostTime

      public Duration getCostTime()
      Get the total cost time of execution.
      Returns:
      the total cost time represented by Duration
    • getComposer

      public ActionComposer getComposer()
      Description copied from interface: Composable
      Get containing composer.
      Specified by:
      getComposer in interface Composable
      Returns:
      containing composer
    • setComposer

      public MultiPhaseAction setComposer(ActionComposer containingComposer)
      Description copied from interface: Composable
      Set containing composer.
      Specified by:
      setComposer in interface Composable
      Parameters:
      containingComposer - the containing composer to set
      Returns:
      invoking Composable
    • getActionState

      public ActionState getActionState()
      Get the state of this MultiPhaseAction.
      Returns:
      state represented by ActionState
    • setActionState

      protected void setActionState(ActionState actionState)
      Set the state of this MultiPhaseAction.
      Parameters:
      actionState - the action state to set
    • switchToTopForFirefox

      protected void switchToTopForFirefox()
      Switch to top for firefox. Firefox doesn't switch focus to top after switching to a window, so this method is required for firefox.