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 thisActionComposer
is marked as failed andthe flag to keep fail information
is enabled.Get the url of the last page when thisActionComposer
is marked as failed andthe flag to keep fail information
is 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.WebDriver
GetWebDriver
from associatedActionRunner
.boolean
isDone()
Check if thisActionComposer
is done.boolean
isFail()
Check if thisActionComposer
has been marked as failed.boolean
Check if thisActionComposer
is done without being marked as failed.keepFailInfo
(boolean flag) Enable/Disable the function of keeping fail information when thisActionComposer
is marked as failed.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
.setVariable
(String variableName, Object value) Set variable value.boolean
skipped()
void
Skip the execution of remaining actions and mark thisActionComposer
as failed.void
Skip the execution of remaining actions.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 interface org.kquiet.browser.DynamicActionSequence
add, addToHead, addToPosition, addToTail
Methods 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:
true
if register name is not null and window identity are not empty and the register name isn't registered;false
otherwise
-
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
CompletableFuture
representing pending completion of givenRunnable
-
perform
Perform action. AnyComposable
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 thisActionComposer
'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
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:
true
if switch success;false
otherwise
-
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:
true
if switch success;false
otherwise
-
isFail
boolean isFail()Check if thisActionComposer
has been marked as failed.- Returns:
true
if thisActionComposer
has been marked as failed;false
otherwise
-
isSuccessfulDone
boolean isSuccessfulDone()Check if thisActionComposer
is done without being marked as failed.- Returns:
true
if thisActionComposer
is done without being marked as failed;false
otherwise
-
isDone
boolean isDone()Check if thisActionComposer
is done.- Returns:
true
if thisActionComposer
is done;false
otherwise
-
skipToFail
void skipToFail()Skip the execution of remaining actions and mark thisActionComposer
as failed. -
skipToSuccess
void skipToSuccess()Skip the execution of remaining actions. -
skipped
boolean skipped()- Returns:
true
if 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 thisActionComposer
is marked as failed andthe flag to keep fail information
is enabled.- Returns:
- the url represented by
String
-
getFailPage
String getFailPage()Get the content of the last page when thisActionComposer
is marked as failed andthe flag to keep fail information
is enabled.- Returns:
- the content represented by
String
-
keepFailInfo
Enable/Disable the function of keeping fail information when thisActionComposer
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
Set the function to be executed when thisActionComposer
is marked as failed.- Parameters:
onFailFunc
- the function to be executed- Returns:
- self reference
-
onSuccess
Set the function to be executed when thisActionComposer
is finished without being marked as failed.- Parameters:
onSuccessFunc
- the function to be executed- Returns:
- self reference
-
onDone
Set the function to be executed when thisActionComposer
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()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)
.- Returns:
- the
WebDriver
of 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
-