Package org.kquiet.browser
Class AbstractActionComposer
- All Implemented Interfaces:
Runnable
,CompletionStage<Void>
,Future<Void>
,ActionComposer
,DynamicActionSequence
,Prioritized
- Direct Known Subclasses:
BasicActionComposer
public abstract class AbstractActionComposer
extends CompletableFuture<Void>
implements ActionComposer
AbstractActionComposer
implements most methods of ActionComposer
to lay ground
works for possible subclasses. AbstractActionComposer
itself is a subclass of CompletableFuture
, so any subclass of AbstractActionComposer
should complete itself
explictly in Runnable.run()
.- Author:
- Kimberly
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Stack<DynamicActionSequence>
The execution context stack of thisAbstractActionComposer
, theDynamicActionSequence
must be pushed into this stack before any action in it gets executed to reflect execution context.protected final Stopwatch
The stop watch used to measure run cost of thisAbstractActionComposer
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSet the function to be executed after any managed action is performed.Set the function to be executed when any managed action is performed.addToHead
(Composable action) Add action to the head of the action sequence.addToHeadByContext
(Composable action) Add action to the head of the action sequence of execution context.addToPosition
(Composable action, int position) Add action to the specified position of the action sequence.addToPositionByContext
(Composable action, int position) Add action to specified position of the action sequence of execution context.addToTail
(Composable action) Add action to the tail of the action sequence.addToTailByContext
(Composable action) Add action to the tail of the action sequence of execution context.callBrowser
(Runnable runnable) protected Function<ActionComposer,
Consumer<Composable>> Get the function to be executed after any managed action is performed.protected Function<ActionComposer,
Consumer<Composable>> Get the function to be executed when any managed action is performed.protected ActionRunner
Get associatedActionRunner
.protected List<Composable>
Get all actions in the action sequence.Get total execution time of thisAbstractActionComposer
.protected Consumer<ActionComposer>
Get the function to be executed when finished.Get the error list from executed actions.protected Consumer<ActionComposer>
Get the function executed when failed.Get the window identity of focus window.getName()
Get the name of thisActionComposer
.int
Get priority.getRegisteredWindow
(String registerName) Get registered window by given name.Get all registered windows.Get the window identity of root window.protected Consumer<ActionComposer>
Get the function executed when finished without fail.getVariable
(String variableName) Get the value of specified variable.org.openqa.selenium.WebDriver
GetWebDriver
from associatedActionRunner
.onDone
(Consumer<ActionComposer> onDoneFunc) Set the function to be executed when thisActionComposer
is done.onFail
(Consumer<ActionComposer> onFailFunc) Set the function to be executed when thisActionComposer
is marked as failed.onSuccess
(Consumer<ActionComposer> onSuccessFunc) Set the function to be executed when thisActionComposer
is finished without being marked as failed.void
perform
(Composable action) Perform action.boolean
registerWindow
(String name, String windowIdentity) Register a window to keep window identity.setActionRunner
(ActionRunner actionRunner) Set associatedActionRunner
.setFocusWindow
(String windowIdentity) Set the specified window as the focus window.Set the name of thisActionComposer
.setPriority
(int priority) Set the priority of thisAbstractActionComposer
.setVariable
(String variableName, Object value) Set variable value.boolean
Switch browser's focus window to thisActionComposer
's focus window.void
switchToInnerFrame
(List<org.openqa.selenium.By> frameBySequence) Switch to send future commands to a frame.boolean
Switch the focus of future commands to either the first frame on the page, or the main document when a page contains iframes.boolean
switchToWindow
(String windowIdentity) Switch browser's focus window to specified window.Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, cancel, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.kquiet.browser.ActionComposer
getFailPage, getFailUrl, isDone, isFail, isSuccessfulDone, keepFailInfo, skipped, skipToFail, skipToSuccess
Methods inherited from interface org.kquiet.browser.DynamicActionSequence
add
-
Field Details
-
executionContextStack
The execution context stack of thisAbstractActionComposer
, theDynamicActionSequence
must be pushed into this stack before any action in it gets executed to reflect execution context. -
totalCostWatch
The stop watch used to measure run cost of thisAbstractActionComposer
.
-
-
Constructor Details
-
AbstractActionComposer
public AbstractActionComposer()Create anAbstractActionComposer
.
-
-
Method Details
-
setActionRunner
Description copied from interface:ActionComposer
Set associatedActionRunner
.- Specified by:
setActionRunner
in interfaceActionComposer
- Parameters:
actionRunner
- action runner to set- Returns:
- self reference
-
getActionRunner
Get associatedActionRunner
.- Returns:
ActionRunner
-
getRootWindow
Description copied from interface:ActionComposer
Get the window identity of root window.- Specified by:
getRootWindow
in interfaceActionComposer
- Returns:
- window identity represented by
String
-
registerWindow
Description copied from interface:ActionComposer
Register a window to keep window identity.- Specified by:
registerWindow
in interfaceActionComposer
- Parameters:
name
- register namewindowIdentity
- 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
Description copied from interface:ActionComposer
Get registered window by given name.- Specified by:
getRegisteredWindow
in interfaceActionComposer
- Parameters:
registerName
- register name of window- Returns:
- window identity
-
getRegisteredWindows
Description copied from interface:ActionComposer
Get all registered windows.- Specified by:
getRegisteredWindows
in interfaceActionComposer
- Returns:
- all registered windows represented by
Map
(register name paire with window identity)
-
getVariable
Description copied from interface:ActionComposer
Get the value of specified variable.- Specified by:
getVariable
in interfaceActionComposer
- Parameters:
variableName
- variable name- Returns:
- variable value
-
setVariable
Description copied from interface:ActionComposer
Set variable value.- Specified by:
setVariable
in interfaceActionComposer
- Parameters:
variableName
- variable namevalue
- variable value- Returns:
- self reference
-
callBrowser
Description copied from interface:ActionComposer
- Specified by:
callBrowser
in interfaceActionComposer
- Parameters:
runnable
- the object whose run method will be invoked- Returns:
- a
CompletableFuture
representing pending completion of givenRunnable
-
perform
Description copied from interface:ActionComposer
Perform action. AnyComposable
should be performed by this method.- Specified by:
perform
in interfaceActionComposer
- Parameters:
action
- action to perform
-
switchToFocusWindow
public boolean switchToFocusWindow()Description copied from interface:ActionComposer
Switch browser's focus window to thisActionComposer
's focus window.- Specified by:
switchToFocusWindow
in interfaceActionComposer
- Returns:
true
if switch success;false
otherwise
-
switchToWindow
Description copied from interface:ActionComposer
Switch browser's focus window to specified window.- Specified by:
switchToWindow
in interfaceActionComposer
- Parameters:
windowIdentity
- the window identity to switch to- Returns:
true
if switch success;false
otherwise
-
switchToInnerFrame
Description copied from interface:ActionComposer
Switch to send future commands to a frame.- Specified by:
switchToInnerFrame
in interfaceActionComposer
- Parameters:
frameBySequence
- the sequence of the frame locating mechanism
-
switchToTop
public boolean switchToTop()Description copied from interface:ActionComposer
Switch the focus of future commands to either the first frame on the page, or the main document when a page contains iframes.- Specified by:
switchToTop
in interfaceActionComposer
- Returns:
true
if switch success;false
otherwise
-
onFail
Description copied from interface:ActionComposer
Set the function to be executed when thisActionComposer
is marked as failed.- Specified by:
onFail
in interfaceActionComposer
- Parameters:
onFailFunc
- the function to be executed- Returns:
- self reference
-
getFailFunction
Get the function executed when failed.- Returns:
- the function consuming
ActionComposer
-
onSuccess
Description copied from interface:ActionComposer
Set the function to be executed when thisActionComposer
is finished without being marked as failed.- Specified by:
onSuccess
in interfaceActionComposer
- Parameters:
onSuccessFunc
- the function to be executed- Returns:
- self reference
-
getSuccessFunction
Get the function executed when finished without fail.- Returns:
- the function consuming
ActionComposer
-
onDone
Description copied from interface:ActionComposer
Set the function to be executed when thisActionComposer
is done. This function is executed after fail function and success function.- Specified by:
onDone
in interfaceActionComposer
- Parameters:
onDoneFunc
- the function to be executed- Returns:
- self reference
-
getActionPerformedFunction
Get the function to be executed after any managed action is performed.- Returns:
- the function consuming
ActionComposer
-
actionPerformed
Description copied from interface:ActionComposer
Set the function to be executed after any managed action is performed.- Specified by:
actionPerformed
in interfaceActionComposer
- Parameters:
func
- the function to be executed- Returns:
- self reference
-
getActionPerformingFunction
Get the function to be executed when any managed action is performed.- Returns:
- the function consuming
ActionComposer
-
actionPerforming
Description copied from interface:ActionComposer
Set the function to be executed when any managed action is performed.- Specified by:
actionPerforming
in interfaceActionComposer
- Parameters:
func
- the function to be executed- Returns:
- self reference
-
getDoneFunction
Get the function to be executed when finished.- Returns:
- the function consuming
ActionComposer
-
getName
Description copied from interface:ActionComposer
Get the name of thisActionComposer
.- Specified by:
getName
in interfaceActionComposer
- Returns:
- name represented by
String
-
setName
Description copied from interface:ActionComposer
Set the name of thisActionComposer
.- Specified by:
setName
in interfaceActionComposer
- Parameters:
name
- name- Returns:
- self reference
-
getPriority
public int getPriority()Description copied from interface:Prioritized
Get priority. Smaller value means higher priority.- Specified by:
getPriority
in interfacePrioritized
- Returns:
- priority
-
setPriority
Set the priority of thisAbstractActionComposer
.- Parameters:
priority
- priority- Returns:
- self reference
-
getCostTime
Get total execution time of thisAbstractActionComposer
.- Returns:
- the total execution time represented by
Duration
-
getWebDriver
public org.openqa.selenium.WebDriver getWebDriver()Description copied from interface:ActionComposer
GetWebDriver
from associatedActionRunner
. Use this with caution because the associatedActionRunner
use the sameWebDriver
when executing browser actions, howeverWebDriver
is not thread-safe.A safer way to use this is to encapsulate the process in a
Runnable
, or use built-incustom action
, and then execute it throughActionRunner.executeAction(java.lang.Runnable, int)
.- Specified by:
getWebDriver
in interfaceActionComposer
- Returns:
- the
WebDriver
of associatedActionRunner
.
-
getFocusWindow
Description copied from interface:ActionComposer
Get the window identity of focus window.- Specified by:
getFocusWindow
in interfaceActionComposer
- Returns:
- window identity represented by
String
-
setFocusWindow
Description copied from interface:ActionComposer
Set the specified window as the focus window.- Specified by:
setFocusWindow
in interfaceActionComposer
- Parameters:
windowIdentity
- the window identity to set as the focus window- Returns:
- self reference
-
addToHead
Description copied from interface:DynamicActionSequence
Add action to the head of the action sequence.- Specified by:
addToHead
in interfaceDynamicActionSequence
- Parameters:
action
- action to add- Returns:
- self reference
-
addToTail
Description copied from interface:DynamicActionSequence
Add action to the tail of the action sequence.- Specified by:
addToTail
in interfaceDynamicActionSequence
- Parameters:
action
- action to add- Returns:
- self reference
-
addToPosition
Description copied from interface:DynamicActionSequence
Add action to the specified position of the action sequence.- Specified by:
addToPosition
in interfaceDynamicActionSequence
- Parameters:
action
- action to addposition
- the position(zero-based) to add given action- Returns:
- self reference
-
addToHeadByContext
Description copied from interface:ActionComposer
Add action to the head of the action sequence of execution context.- Specified by:
addToHeadByContext
in interfaceActionComposer
- Parameters:
action
- action to add- Returns:
- execution context of actions
-
addToTailByContext
Description copied from interface:ActionComposer
Add action to the tail of the action sequence of execution context.- Specified by:
addToTailByContext
in interfaceActionComposer
- Parameters:
action
- action to add- Returns:
- execution context of actions
-
addToPositionByContext
Description copied from interface:ActionComposer
Add action to specified position of the action sequence of execution context.- Specified by:
addToPositionByContext
in interfaceActionComposer
- Parameters:
action
- action to addposition
- the position(zero-based) to add given action- Returns:
- execution context of actions
-
getAllActionInSequence
Get all actions in the action sequence.- Returns:
- list of actions
-
getErrors
Get the error list from executed actions.- Specified by:
getErrors
in interfaceActionComposer
- Returns:
- a list of
Exception
-