Package org.kquiet.browser
Interface ActionComposer
- All Superinterfaces:
DynamicActionSequence,Prioritized,Runnable
- All Known Implementing Classes:
AbstractActionComposer,BasicActionComposer
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 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.addToHeadByContext(Composable action) Add action to the head of the action sequence of execution context.addToPositionByContext(Composable action, int position) Add action to specified position of the action sequence of execution context.addToTailByContext(Composable action) Add action to the tail of the action sequence of execution context.callBrowser(Runnable runnable) Get the error list from executed actions.Get the content of the last page when thisActionComposeris marked as failed andthe flag to keep fail informationis enabled.Get the url of the last page when thisActionComposeris marked as failed andthe flag to keep fail informationis enabled.Get the window identity of focus window.getName()Get the name of thisActionComposer.getRegisteredWindow(String registerName) Get registered window by given name.Get all registered windows.Get the window identity of root window.getVariable(String variableName) Get the value of specified variable.org.openqa.selenium.WebDriverGetWebDriverfrom associatedActionRunner.booleanisDone()Check if thisActionComposeris done.booleanisFail()Check if thisActionComposerhas been marked as failed.booleanCheck if thisActionComposeris done without being marked as failed.keepFailInfo(boolean flag) Enable/Disable the function of keeping fail information when thisActionComposeris marked as failed.onDone(Consumer<ActionComposer> onDoneFunc) Set the function to be executed when thisActionComposeris done.onFail(Consumer<ActionComposer> onFailFunc) Set the function to be executed when thisActionComposeris marked as failed.onSuccess(Consumer<ActionComposer> onSuccessFunc) Set the function to be executed when thisActionComposeris finished without being marked as failed.voidperform(Composable action) Perform action.booleanregisterWindow(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.setVariable(String variableName, Object value) Set variable value.booleanskipped()voidSkip the execution of remaining actions and mark thisActionComposeras failed.voidSkip the execution of remaining actions.booleanSwitch browser's focus window to thisActionComposer's focus window.voidswitchToInnerFrame(List<org.openqa.selenium.By> frameBySequence) Switch to send future commands to a frame.booleanSwitch the focus of future commands to either the first frame on the page, or the main document when a page contains iframes.booleanswitchToWindow(String windowIdentity) Switch browser's focus window to specified window.Methods inherited from interface org.kquiet.browser.DynamicActionSequence
add, addToHead, addToPosition, addToTailMethods inherited from interface org.kquiet.concurrent.Prioritized
getPriority
-
Method Details
-
getName
String getName()Get the name of thisActionComposer.- Returns:
- name represented by
String
-
setName
Set the name of thisActionComposer.- Parameters:
name- name- Returns:
- self reference
-
setActionRunner
Set associatedActionRunner.- Parameters:
actionRunner- action runner to set- Returns:
- self reference
-
registerWindow
Register a window to keep window identity.- Parameters:
name- register namewindowIdentity- window identity- Returns:
trueif register name is not null and window identity are not empty and the register name isn't registered;falseotherwise
-
getRegisteredWindow
Get registered window by given name.- Parameters:
registerName- register name of window- Returns:
- window identity
-
getRegisteredWindows
Get all registered windows.- Returns:
- all registered windows represented by
Map(register name paire with window identity)
-
getVariable
Get the value of specified variable.- Parameters:
variableName- variable name- Returns:
- variable value
-
setVariable
Set variable value.- Parameters:
variableName- variable namevalue- variable value- Returns:
- self reference
-
callBrowser
- Parameters:
runnable- the object whose run method will be invoked- Returns:
- a
CompletableFuturerepresenting pending completion of givenRunnable
-
perform
Perform action. AnyComposableshould 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 thisActionComposer's focus window.- Returns:
trueif switch success;falseotherwise
-
getFocusWindow
String getFocusWindow()Get the window identity of focus window.- Returns:
- window identity represented by
String
-
setFocusWindow
Set the specified window as the focus window.- Parameters:
windowIdentity- the window identity to set as the focus window- Returns:
- self reference
-
switchToWindow
Switch browser's focus window to specified window.- Parameters:
windowIdentity- the window identity to switch to- Returns:
trueif switch success;falseotherwise
-
switchToInnerFrame
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:
trueif switch success;falseotherwise
-
isFail
boolean isFail()Check if thisActionComposerhas been marked as failed.- Returns:
trueif thisActionComposerhas been marked as failed;falseotherwise
-
isSuccessfulDone
boolean isSuccessfulDone()Check if thisActionComposeris done without being marked as failed.- Returns:
trueif thisActionComposeris done without being marked as failed;falseotherwise
-
isDone
boolean isDone()Check if thisActionComposeris done.- Returns:
trueif thisActionComposeris done;falseotherwise
-
skipToFail
void skipToFail()Skip the execution of remaining actions and mark thisActionComposeras failed. -
skipToSuccess
void skipToSuccess()Skip the execution of remaining actions. -
skipped
boolean skipped()- Returns:
trueif any of both methods has been invoked; otherwisefalse
-
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 thisActionComposeris marked as failed andthe flag to keep fail informationis enabled.- Returns:
- the url represented by
String
-
getFailPage
String getFailPage()Get the content of the last page when thisActionComposeris marked as failed andthe flag to keep fail informationis enabled.- Returns:
- the content represented by
String
-
keepFailInfo
Enable/Disable the function of keeping fail information when thisActionComposeris 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-trueto enable;falseto disable- Returns:
- self reference
-
onFail
Set the function to be executed when thisActionComposeris marked as failed.- Parameters:
onFailFunc- the function to be executed- Returns:
- self reference
-
onSuccess
Set the function to be executed when thisActionComposeris finished without being marked as failed.- Parameters:
onSuccessFunc- the function to be executed- Returns:
- self reference
-
onDone
Set the function to be executed when thisActionComposeris 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()GetWebDriverfrom associatedActionRunner. Use this with caution because the associatedActionRunneruse the sameWebDriverwhen executing browser actions, howeverWebDriveris 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).- Returns:
- the
WebDriverof associatedActionRunner.
-
addToHeadByContext
Add action to the head of the action sequence of execution context.- Parameters:
action- action to add- Returns:
- execution context of actions
-
addToTailByContext
Add action to the tail of the action sequence of execution context.- Parameters:
action- action to add- Returns:
- execution context of actions
-
addToPositionByContext
Add action to specified position of the action sequence of execution context.- Parameters:
action- action to addposition- the position(zero-based) to add given action- Returns:
- execution context of actions
-